/
githubmirror
/
PowerShell
Обзор
Документация
Войти
/
githubmirror
/
PowerShell
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/Microsoft.PowerShell.ConsoleHost/WindowsTaskbarJumpList/PropVariant.cs
65 строк
2 KB
xtqqczze
Remove unnecessary `CS0618` suppressions from Variant APIs (#26006)
07 сен 2025, 17:44
Не верифицирован
07 сен 2025, 17:44
43c2d98
Код
Авторство
О чём код?
// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. using System; using System.Runtime.InteropServices; namespace Microsoft.PowerShell { /// <summary> /// Represents the OLE struct PROPVARIANT. /// This class is intended for internal use only. /// </summary> /// <remarks> /// Originally sourced from https://blogs.msdn.com/adamroot/pages/interop-with-propvariants-in-net.aspx /// and modified to add ability to set values /// </remarks> [StructLayout(LayoutKind.Explicit)] internal sealed class PropVariant : IDisposable { // This is actually a VarEnum value, but the VarEnum type requires 4 bytes instead of the expected 2. [FieldOffset(0)] private readonly ushort _valueType; [FieldOffset(8)] private readonly IntPtr _ptr; /// <summary> /// Set a string value. /// </summary> internal PropVariant(string value) { if (value == null) { throw new ArgumentException("PropVariantNullString", nameof(value)); } _valueType = (ushort)VarEnum.VT_LPWSTR; _ptr = Marshal.StringToCoTaskMemUni(value); } /// <summary> /// Disposes the object, calls the clear function. /// </summary> public void Dispose() { PropVariantNativeMethods.PropVariantClear(this); GC.SuppressFinalize(this); } /// <summary> /// Finalizes an instance of the <see cref="PropVariant"/> class. /// </summary> ~PropVariant() { Dispose(); } private static class PropVariantNativeMethods { [DllImport("Ole32.dll", PreserveSig = false)] internal static extern void PropVariantClear([In, Out] PropVariant pvar); } } }