using System; using System.Collections; using System.Collections.Concurrent; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Collections.Specialized; using System.ComponentModel; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Dynamic; using System.Globalization; using System.IO; using System.Linq; using System.Linq.Expressions; using System.Numerics; using System.Reflection; using System.Resources; using System.Runtime.CompilerServices; using System.Runtime.ExceptionServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Security; using System.Security.Cryptography; using System.Security.Permissions; using System.Text; using System.Threading; using System.Windows.Input; using ABI.Microsoft.UI.Xaml.Data; using ABI.Microsoft.UI.Xaml.Interop; using ABI.System; using ABI.System.Collections; using ABI.System.Collections.Generic; using ABI.System.Collections.Specialized; using ABI.System.ComponentModel; using ABI.System.Numerics; using ABI.System.Windows.Input; using ABI.WinRT; using ABI.WinRT.Interop; using ABI.Windows.Foundation; using ABI.Windows.Foundation.Collections; using Microsoft.CodeAnalysis; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Automation; using Microsoft.UI.Xaml.Data; using Microsoft.UI.Xaml.Interop; using Microsoft.UI.Xaml.Markup; using WinRT; using WinRT.Interop; using Windows.Foundation; using Windows.Foundation.Collections; using Windows.UI.Xaml; using Windows.UI.Xaml.Automation; using Windows.UI.Xaml.Markup; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: SupportedOSPlatform("Windows")] [assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")] [assembly: AssemblyMetadata("IsTrimmable", "True")] [assembly: AssemblyCompany("Microsoft Corporation")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyCopyright("Copyright (c) Microsoft Corporation. All rights reserved.")] [assembly: AssemblyDescription("C#/WinRT Runtime v2.2.0.241111.1")] [assembly: AssemblyFileVersion("2.2.0.48161")] [assembly: AssemblyInformationalVersion("2.2.0.48161+8649ee3eeb2445ca2a36d80d878ef60b96a6c65d")] [assembly: AssemblyProduct("C#/WinRT")] [assembly: AssemblyTitle("C#/WinRT Runtime v2.2.0.241111.1")] [assembly: NeutralResourcesLanguage("en")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("2.1.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] internal class { static () { ProjectionInitializer.InitalizeProjection(); } } namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] internal sealed class IsUnmanagedAttribute : Attribute { } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace Windows.Foundation { internal static class GSR { public static string ArgumentOutOfRange_NeedNonNegNum = "Non-negative number required."; } [WindowsRuntimeType("Windows.Foundation.FoundationContract")] [WindowsRuntimeHelperType(typeof(ABI.Windows.Foundation.Point))] [WinRTExposedType(typeof(StructTypeDetails))] public struct Point : IFormattable { public float _x; public float _y; public double X { get { return _x; } set { _x = (float)value; } } public double Y { get { return _y; } set { _y = (float)value; } } public Point(float x, float y) { _x = x; _y = y; } public Point(double x, double y) : this((float)x, (float)y) { } public override string ToString() { return ConvertToString(null, null); } public string ToString(IFormatProvider provider) { return ConvertToString(null, provider); } string IFormattable.ToString(string format, IFormatProvider provider) { return ConvertToString(format, provider); } private string ConvertToString(string format, IFormatProvider provider) { char numericListSeparator = GetNumericListSeparator(provider); return string.Format(provider, "{1:" + format + "}{0}{2:" + format + "}", numericListSeparator, _x, _y); } private static char GetNumericListSeparator(IFormatProvider provider) { char c = ','; NumberFormatInfo instance = NumberFormatInfo.GetInstance(provider); if (instance.NumberDecimalSeparator.Length > 0 && instance.NumberDecimalSeparator[0] == c) { c = ';'; } return c; } public static bool operator ==(Point point1, Point point2) { if (point1._x == point2._x) { return point1._y == point2._y; } return false; } public static bool operator !=(Point point1, Point point2) { return !(point1 == point2); } public override bool Equals(object o) { if (o is Point) { return this == (Point)o; } return false; } public bool Equals(Point value) { return this == value; } public override int GetHashCode() { return X.GetHashCode() ^ Y.GetHashCode(); } } [WindowsRuntimeType("Windows.Foundation.FoundationContract")] [WindowsRuntimeHelperType(typeof(ABI.Windows.Foundation.Rect))] [WinRTExposedType(typeof(StructTypeDetails))] public struct Rect : IFormattable { public float _x; public float _y; public float _width; public float _height; private const double EmptyX = double.PositiveInfinity; private const double EmptyY = double.PositiveInfinity; private const double EmptyWidth = double.NegativeInfinity; private const double EmptyHeight = double.NegativeInfinity; private static readonly Rect s_empty = CreateEmptyRect(); public double X { get { return _x; } set { _x = (float)value; } } public double Y { get { return _y; } set { _y = (float)value; } } public double Width { get { return _width; } set { if (value < 0.0) { throw new ArgumentOutOfRangeException("Width", GSR.ArgumentOutOfRange_NeedNonNegNum); } _width = (float)value; } } public double Height { get { return _height; } set { if (value < 0.0) { throw new ArgumentOutOfRangeException("Height", GSR.ArgumentOutOfRange_NeedNonNegNum); } _height = (float)value; } } public double Left => _x; public double Top => _y; public double Right { get { if (IsEmpty) { return double.NegativeInfinity; } return _x + _width; } } public double Bottom { get { if (IsEmpty) { return double.NegativeInfinity; } return _y + _height; } } public static Rect Empty => s_empty; public bool IsEmpty => _width < 0f; public Rect(float x, float y, float width, float height) { if (width < 0f) { throw new ArgumentOutOfRangeException("width", GSR.ArgumentOutOfRange_NeedNonNegNum); } if (height < 0f) { throw new ArgumentOutOfRangeException("height", GSR.ArgumentOutOfRange_NeedNonNegNum); } _x = x; _y = y; _width = width; _height = height; } public Rect(double x, double y, double width, double height) : this((float)x, (float)y, (float)width, (float)height) { } public Rect(Point point1, Point point2) { _x = Math.Min(point1._x, point2._x); _y = Math.Min(point1._y, point2._y); _width = Math.Max(Math.Max(point1._x, point2._x) - _x, 0f); _height = Math.Max(Math.Max(point1._y, point2._y) - _y, 0f); } public Rect(Point location, Size size) { if (size.IsEmpty) { this = s_empty; return; } _x = location._x; _y = location._y; _width = size._width; _height = size._height; } public bool Contains(Point point) { return ContainsInternal(point._x, point._y); } public void Intersect(Rect rect) { if (!IntersectsWith(rect)) { this = s_empty; return; } double num = Math.Max(X, rect.X); double num2 = Math.Max(Y, rect.Y); Width = Math.Max(Math.Min(X + Width, rect.X + rect.Width) - num, 0.0); Height = Math.Max(Math.Min(Y + Height, rect.Y + rect.Height) - num2, 0.0); X = num; Y = num2; } public void Union(Rect rect) { if (IsEmpty) { this = rect; } else if (!rect.IsEmpty) { double num = Math.Min(Left, rect.Left); double num2 = Math.Min(Top, rect.Top); if (rect.Width == double.PositiveInfinity || Width == double.PositiveInfinity) { Width = double.PositiveInfinity; } else { double num3 = Math.Max(Right, rect.Right); Width = Math.Max(num3 - num, 0.0); } if (rect.Height == double.PositiveInfinity || Height == double.PositiveInfinity) { Height = double.PositiveInfinity; } else { double num4 = Math.Max(Bottom, rect.Bottom); Height = Math.Max(num4 - num2, 0.0); } X = num; Y = num2; } } public void Union(Point point) { Union(new Rect(point, point)); } private bool ContainsInternal(float x, float y) { if (x >= _x && x - _width <= _x && y >= _y) { return y - _height <= _y; } return false; } internal bool IntersectsWith(Rect rect) { if (_width < 0f || rect._width < 0f) { return false; } if (rect._x <= _x + _width && rect._x + rect._width >= _x && rect._y <= _y + _height) { return rect._y + rect._height >= _y; } return false; } private static Rect CreateEmptyRect() { return new Rect { _x = float.PositiveInfinity, _y = float.PositiveInfinity, _width = float.NegativeInfinity, _height = float.NegativeInfinity }; } public override string ToString() { return ConvertToString(null, null); } public string ToString(IFormatProvider provider) { return ConvertToString(null, provider); } string IFormattable.ToString(string format, IFormatProvider provider) { return ConvertToString(format, provider); } internal string ConvertToString(string format, IFormatProvider provider) { if (IsEmpty) { return "Empty."; } char numericListSeparator = TokenizerHelper.GetNumericListSeparator(provider); return string.Format(provider, "{1:" + format + "}{0}{2:" + format + "}{0}{3:" + format + "}{0}{4:" + format + "}", numericListSeparator, _x, _y, _width, _height); } public bool Equals(Rect value) { return this == value; } public static bool operator ==(Rect rect1, Rect rect2) { if (rect1._x == rect2._x && rect1._y == rect2._y && rect1._width == rect2._width) { return rect1._height == rect2._height; } return false; } public static bool operator !=(Rect rect1, Rect rect2) { return !(rect1 == rect2); } public override bool Equals(object o) { if (o is Rect) { return this == (Rect)o; } return false; } public override int GetHashCode() { return X.GetHashCode() ^ Y.GetHashCode() ^ Width.GetHashCode() ^ Height.GetHashCode(); } } [WindowsRuntimeType("Windows.Foundation.FoundationContract")] [WindowsRuntimeHelperType(typeof(ABI.Windows.Foundation.Size))] [WinRTExposedType(typeof(StructTypeDetails))] public struct Size { public float _width; public float _height; private static readonly Size s_empty = CreateEmptySize(); public double Width { get { return _width; } set { if (value < 0.0) { throw new ArgumentOutOfRangeException("Width", GSR.ArgumentOutOfRange_NeedNonNegNum); } _width = (float)value; } } public double Height { get { return _height; } set { if (value < 0.0) { throw new ArgumentOutOfRangeException("Height", GSR.ArgumentOutOfRange_NeedNonNegNum); } _height = (float)value; } } public static Size Empty => s_empty; public bool IsEmpty => Width < 0.0; public Size(float width, float height) { if (width < 0f) { throw new ArgumentOutOfRangeException("width", GSR.ArgumentOutOfRange_NeedNonNegNum); } if (height < 0f) { throw new ArgumentOutOfRangeException("height", GSR.ArgumentOutOfRange_NeedNonNegNum); } _width = width; _height = height; } public Size(double width, double height) : this((float)width, (float)height) { } private static Size CreateEmptySize() { return new Size { _width = float.NegativeInfinity, _height = float.NegativeInfinity }; } public static bool operator ==(Size size1, Size size2) { if (size1._width == size2._width) { return size1._height == size2._height; } return false; } public static bool operator !=(Size size1, Size size2) { return !(size1 == size2); } public override bool Equals(object o) { if (o is Size) { return Equals(this, (Size)o); } return false; } public bool Equals(Size value) { return Equals(this, value); } public override int GetHashCode() { if (IsEmpty) { return 0; } return Width.GetHashCode() ^ Height.GetHashCode(); } private static bool Equals(Size size1, Size size2) { if (size1.IsEmpty) { return size2.IsEmpty; } if (size1._width.Equals(size2._width)) { return size1._height.Equals(size2._height); } return false; } public override string ToString() { if (IsEmpty) { return "Empty"; } return $"{_width},{_height}"; } } public static class TokenizerHelper { public static char GetNumericListSeparator(IFormatProvider provider) { char c = ','; NumberFormatInfo instance = NumberFormatInfo.GetInstance(provider); if (instance.NumberDecimalSeparator.Length > 0 && c == instance.NumberDecimalSeparator[0]) { c = ';'; } return c; } } internal enum PropertyType : uint { Empty = 0u, UInt8 = 1u, Int16 = 2u, UInt16 = 3u, Int32 = 4u, UInt32 = 5u, Int64 = 6u, UInt64 = 7u, Single = 8u, Double = 9u, Char16 = 10u, Boolean = 11u, String = 12u, Inspectable = 13u, DateTime = 14u, TimeSpan = 15u, Guid = 16u, Point = 17u, Size = 18u, Rect = 19u, OtherType = 20u, UInt8Array = 1025u, Int16Array = 1026u, UInt16Array = 1027u, Int32Array = 1028u, UInt32Array = 1029u, Int64Array = 1030u, UInt64Array = 1031u, SingleArray = 1032u, DoubleArray = 1033u, Char16Array = 1034u, BooleanArray = 1035u, StringArray = 1036u, InspectableArray = 1037u, DateTimeArray = 1038u, TimeSpanArray = 1039u, GuidArray = 1040u, PointArray = 1041u, SizeArray = 1042u, RectArray = 1043u, OtherTypeArray = 1044u } [Guid("4BD682DD-7554-40E9-9A9B-82654EDE7E62")] internal interface IPropertyValue { bool IsNumericScalar { get; } PropertyType Type { get; } byte GetUInt8(); short GetInt16(); ushort GetUInt16(); int GetInt32(); uint GetUInt32(); long GetInt64(); ulong GetUInt64(); float GetSingle(); double GetDouble(); char GetChar16(); bool GetBoolean(); string GetString(); Guid GetGuid(); System.DateTimeOffset GetDateTime(); System.TimeSpan GetTimeSpan(); Point GetPoint(); Size GetSize(); Rect GetRect(); void GetUInt8Array(out byte[] value); void GetInt16Array(out short[] value); void GetUInt16Array(out ushort[] value); void GetInt32Array(out int[] value); void GetUInt32Array(out uint[] value); void GetInt64Array(out long[] value); void GetUInt64Array(out ulong[] value); void GetSingleArray(out float[] value); void GetDoubleArray(out double[] value); void GetChar16Array(out char[] value); void GetBooleanArray(out bool[] value); void GetStringArray(out string[] value); void GetInspectableArray(out object[] value); void GetGuidArray(out Guid[] value); void GetDateTimeArray(out System.DateTimeOffset[] value); void GetTimeSpanArray(out System.TimeSpan[] value); void GetPointArray(out Point[] value); void GetSizeArray(out Size[] value); void GetRectArray(out Rect[] value); } [Guid("61C17707-2D65-11E0-9AE8-D48564015472")] [WindowsRuntimeHelperType(typeof(ABI.Windows.Foundation.IReferenceArray<>))] internal interface IReferenceArray { T[] Value { get; } } } namespace Windows.Foundation.Collections { [Guid("3C2925FE-8519-45C1-AA79-197B6718C1C1")] internal interface IMap : IIterable> { uint Size { get; } V Lookup(K key); bool HasKey(K key); System.Collections.Generic.IReadOnlyDictionary GetView(); bool Insert(K key, V value); void _Remove(K key); void Clear(); } [Guid("FAA585EA-6214-4217-AFDA-7F46DE5869B3")] internal interface IIterable { System.Collections.Generic.IEnumerator First(); } [Guid("6A79E863-4300-459A-9966-CBB660963EE1")] internal interface IIterator { T _Current { get; } bool HasCurrent { get; } bool _MoveNext(); uint GetMany(ref T[] items); } [Guid("913337E9-11A1-4345-A3A2-4E7F956E222D")] internal interface IVector : IIterable { uint Size { get; } T GetAt(uint index); System.Collections.Generic.IReadOnlyList GetView(); bool IndexOf(T value, out uint index); void SetAt(uint index, T value); void InsertAt(uint index, T value); void RemoveAt(uint index); void Append(T value); void RemoveAtEnd(); void _Clear(); uint GetMany(uint startIndex, ref T[] items); void ReplaceAll(T[] items); } [Guid("E480CE40-A338-4ADA-ADCF-272272E48CB9")] internal interface IMapView : IIterable> { uint Size { get; } V Lookup(K key); bool HasKey(K key); void Split(out IMapView first, out IMapView second); } [Guid("BBE1FA4C-B0E3-4583-BAEF-1F1B2E483E56")] internal interface IVectorView : IIterable { uint Size { get; } T GetAt(uint index); bool IndexOf(T value, out uint index); uint GetMany(uint startIndex, ref T[] items); } [Guid("02B51929-C1C4-4A7E-8940-0312B5C18500")] internal interface IKeyValuePair { K Key { get; } V Value { get; } } } namespace Windows.UI.Xaml { public class LayoutCycleException : System.Exception { public LayoutCycleException() : base("A cycle occurred while laying out the GUI.") { base.HResult = -2144665580; } public LayoutCycleException(string message) : base(message) { base.HResult = -2144665580; } public LayoutCycleException(string message, System.Exception innerException) : base(message, innerException) { base.HResult = -2144665580; } } } namespace Windows.UI.Xaml.Markup { public class XamlParseException : System.Exception { public XamlParseException() : base("XAML parsing failed.") { base.HResult = -2144665590; } public XamlParseException(string message) : base(message) { base.HResult = -2144665590; } public XamlParseException(string message, System.Exception innerException) : base(message, innerException) { base.HResult = -2144665590; } } } namespace Windows.UI.Xaml.Automation { public class ElementNotAvailableException : System.Exception { public ElementNotAvailableException() : base("The element is not available.") { base.HResult = -2144665569; } public ElementNotAvailableException(string message) : base(message) { base.HResult = -2144665569; } public ElementNotAvailableException(string message, System.Exception innerException) : base(message, innerException) { base.HResult = -2144665569; } } public class ElementNotEnabledException : System.Exception { public ElementNotEnabledException() : base("The element is not enabled.") { base.HResult = -2144665570; } public ElementNotEnabledException(string message) : base(message) { base.HResult = -2144665570; } public ElementNotEnabledException(string message, System.Exception innerException) : base(message, innerException) { base.HResult = -2144665570; } } } namespace Microsoft.UI.Xaml { public class LayoutCycleException : System.Exception { public LayoutCycleException() : base("A cycle occurred while laying out the GUI.") { base.HResult = -2144665580; } public LayoutCycleException(string message) : base(message) { base.HResult = -2144665580; } public LayoutCycleException(string message, System.Exception innerException) : base(message, innerException) { base.HResult = -2144665580; } } } namespace Microsoft.UI.Xaml.Data { [WindowsRuntimeType(null)] [WindowsRuntimeHelperType(typeof(ABI.Microsoft.UI.Xaml.Data.ICustomProperty))] [Guid("30DA92C0-23E8-42A0-AE7C-734A0E5D2782")] internal interface ICustomProperty { bool CanRead { get; } bool CanWrite { get; } string Name { get; } System.Type Type { get; } object GetValue(object target); void SetValue(object target, object value); object GetIndexedValue(object target, object index); void SetIndexedValue(object target, object value, object index); } public interface IBindableCustomPropertyImplementation { BindableCustomProperty GetProperty(string name); BindableCustomProperty GetProperty(System.Type indexParameterType); } [WinRTExposedType(typeof(ManagedCustomPropertyWinRTTypeDetails))] public sealed class BindableCustomProperty : ICustomProperty { private readonly bool _canRead; private readonly bool _canWrite; private readonly string _name; private readonly System.Type _type; private readonly Func _getValue; private readonly Action _setValue; private readonly Func _getIndexedValue; private readonly Action _setIndexedValue; bool ICustomProperty.CanRead => _canRead; bool ICustomProperty.CanWrite => _canWrite; string ICustomProperty.Name => _name; System.Type ICustomProperty.Type => _type; public BindableCustomProperty(bool canRead, bool canWrite, string name, System.Type type, Func getValue, Action setValue, Func getIndexedValue, Action setIndexedValue) { _canRead = canRead; _canWrite = canWrite; _name = name; _type = type; _getValue = getValue; _setValue = setValue; _getIndexedValue = getIndexedValue; _setIndexedValue = setIndexedValue; } object ICustomProperty.GetIndexedValue(object target, object index) { if (_getIndexedValue == null) { throw new NotImplementedException(); } return _getIndexedValue(target, index); } object ICustomProperty.GetValue(object target) { if (_getValue == null) { throw new NotImplementedException(); } return _getValue(target); } void ICustomProperty.SetIndexedValue(object target, object value, object index) { if (_setIndexedValue == null) { throw new NotImplementedException(); } _setIndexedValue(target, value, index); } void ICustomProperty.SetValue(object target, object value) { if (_setValue == null) { throw new NotImplementedException(); } _setValue(target, value); } } } namespace Microsoft.UI.Xaml.Interop { [WindowsRuntimeType(null)] [Guid("036D2C08-DF29-41AF-8AA2-D774BE62BA6F")] [WindowsRuntimeHelperType(typeof(ABI.Microsoft.UI.Xaml.Interop.IBindableIterable))] internal interface IBindableIterable { IBindableIterator First(); } [WindowsRuntimeType(null)] [Guid("6A1D6C07-076D-49F2-8314-F52C9C9A8331")] [WindowsRuntimeHelperType(typeof(ABI.Microsoft.UI.Xaml.Interop.IBindableIterator))] internal interface IBindableIterator { object Current { get; } bool HasCurrent { get; } bool MoveNext(); uint GetMany(ref object[] items); } [WindowsRuntimeType(null)] [Guid("393DE7DE-6FD0-4C0D-BB71-47244A113E93")] internal interface IBindableVector : System.Collections.IEnumerable { uint Size { get; } object GetAt(uint index); IBindableVectorView GetView(); bool IndexOf(object value, out uint index); void SetAt(uint index, object value); void InsertAt(uint index, object value); void RemoveAt(uint index); void Append(object value); void RemoveAtEnd(); void Clear(); } [WindowsRuntimeType(null)] [Guid("346DD6E7-976E-4BC3-815D-ECE243BC0F33")] [WindowsRuntimeHelperType(typeof(ABI.Microsoft.UI.Xaml.Interop.IBindableVectorView))] internal interface IBindableVectorView : System.Collections.IEnumerable { uint Size { get; } object GetAt(uint index); bool IndexOf(object value, out uint index); } } namespace Microsoft.UI.Xaml.Markup { public class XamlParseException : System.Exception { public XamlParseException() : base("XAML parsing failed.") { base.HResult = -2144665590; } public XamlParseException(string message) : base(message) { base.HResult = -2144665590; } public XamlParseException(string message, System.Exception innerException) : base(message, innerException) { base.HResult = -2144665590; } } } namespace Microsoft.UI.Xaml.Automation { public class ElementNotAvailableException : System.Exception { public ElementNotAvailableException() : base("The element is not available.") { base.HResult = -2144665569; } public ElementNotAvailableException(string message) : base(message) { base.HResult = -2144665569; } public ElementNotAvailableException(string message, System.Exception innerException) : base(message, innerException) { base.HResult = -2144665569; } } public class ElementNotEnabledException : System.Exception { public ElementNotEnabledException() : base("The element is not enabled.") { base.HResult = -2144665570; } public ElementNotEnabledException(string message) : base(message) { base.HResult = -2144665570; } public ElementNotEnabledException(string message, System.Exception innerException) : base(message, innerException) { base.HResult = -2144665570; } } } namespace ABI.Windows.Foundation { public static class Point { public static string GetGuidSignature() { return "struct(Windows.Foundation.Point;f4;f4)"; } } public static class Rect { public static string GetGuidSignature() { return "struct(Windows.Foundation.Rect;f4;f4;f4;f4)"; } } public static class Size { public static string GetGuidSignature() { return "struct(Windows.Foundation.Size;f4;f4)"; } } internal static class ManagedIPropertyValueImpl { private const int TYPE_E_TYPEMISMATCH = -2147316576; private const int DISP_E_OVERFLOW = -2147352566; private static IPropertyValue.Vftbl AbiToProjectionVftable; public static IntPtr AbiToProjectionVftablePtr; private static volatile Dictionary s_numericScalarTypes; private static Dictionary NumericScalarTypes { get { if (s_numericScalarTypes == null) { Dictionary dictionary = new Dictionary(); dictionary.Add(typeof(byte), PropertyType.UInt8); dictionary.Add(typeof(short), PropertyType.Int16); dictionary.Add(typeof(ushort), PropertyType.UInt16); dictionary.Add(typeof(int), PropertyType.Int32); dictionary.Add(typeof(uint), PropertyType.UInt32); dictionary.Add(typeof(long), PropertyType.Int64); dictionary.Add(typeof(ulong), PropertyType.UInt64); dictionary.Add(typeof(float), PropertyType.Single); dictionary.Add(typeof(double), PropertyType.Double); Dictionary dictionary2 = dictionary; s_numericScalarTypes = dictionary2; } return s_numericScalarTypes; } } unsafe static ManagedIPropertyValueImpl() { AbiToProjectionVftable = new IPropertyValue.Vftbl { IInspectableVftbl = IInspectable.Vftbl.AbiToProjectionVftable, _get_Type_0 = (delegate*)(&Do_Abi_get_Type_0), _get_IsNumericScalar_1 = (delegate*)(&Do_Abi_get_IsNumericScalar_1), _GetUInt8_2 = (delegate*)(&Do_Abi_GetUInt8_2), _GetInt16_3 = (delegate*)(&Do_Abi_GetInt16_3), _GetUInt16_4 = (delegate*)(&Do_Abi_GetUInt16_4), _GetInt32_5 = (delegate*)(&Do_Abi_GetInt32_5), _GetUInt32_6 = (delegate*)(&Do_Abi_GetUInt32_6), _GetInt64_7 = (delegate*)(&Do_Abi_GetInt64_7), _GetUInt64_8 = (delegate*)(&Do_Abi_GetUInt64_8), _GetSingle_9 = (delegate*)(&Do_Abi_GetSingle_9), _GetDouble_10 = (delegate*)(&Do_Abi_GetDouble_10), _GetChar16_11 = (delegate*)(&Do_Abi_GetChar16_11), _GetBoolean_12 = (delegate*)(&Do_Abi_GetBoolean_12), _GetString_13 = (delegate*)(&Do_Abi_GetString_13), _GetGuid_14 = (delegate*)(&Do_Abi_GetGuid_14), _GetDateTime_15 = (delegate*)(&Do_Abi_GetDateTime_15), _GetTimeSpan_16 = (delegate*)(&Do_Abi_GetTimeSpan_16), _GetPoint_17 = (delegate*)(&Do_Abi_GetPoint_17), _GetSize_18 = (delegate*)(&Do_Abi_GetSize_18), _GetRect_19 = (delegate*)(&Do_Abi_GetRect_19), _GetUInt8Array_20 = (delegate*)(&Do_Abi_GetUInt8Array_20), _GetInt16Array_21 = (delegate*)(&Do_Abi_GetInt16Array_21), _GetUInt16Array_22 = (delegate*)(&Do_Abi_GetUInt16Array_22), _GetInt32Array_23 = (delegate*)(&Do_Abi_GetInt32Array_23), _GetUInt32Array_24 = (delegate*)(&Do_Abi_GetUInt32Array_24), _GetInt64Array_25 = (delegate*)(&Do_Abi_GetInt64Array_25), _GetUInt64Array_26 = (delegate*)(&Do_Abi_GetUInt64Array_26), _GetSingleArray_27 = (delegate*)(&Do_Abi_GetSingleArray_27), _GetDoubleArray_28 = (delegate*)(&Do_Abi_GetDoubleArray_28), _GetChar16Array_29 = (delegate*)(&Do_Abi_GetChar16Array_29), _GetBooleanArray_30 = (delegate*)(&Do_Abi_GetBooleanArray_30), _GetStringArray_31 = (delegate*)(&Do_Abi_GetStringArray_31), _GetInspectableArray_32 = (delegate*)(&Do_Abi_GetInspectableArray_32), _GetGuidArray_33 = (delegate*)(&Do_Abi_GetGuidArray_33), _GetDateTimeArray_34 = (delegate*)(&Do_Abi_GetDateTimeArray_34), _GetTimeSpanArray_35 = (delegate*)(&Do_Abi_GetTimeSpanArray_35), _GetPointArray_36 = (delegate*)(&Do_Abi_GetPointArray_36), _GetSizeArray_37 = (delegate*)(&Do_Abi_GetSizeArray_37), _GetRectArray_38 = (delegate*)(&Do_Abi_GetRectArray_38) }; IntPtr* ptr = (IntPtr*)(void*)ComWrappersSupport.AllocateVtableMemory(typeof(ManagedIPropertyValueImpl), sizeof(IInspectable.Vftbl) + sizeof(IntPtr) * 39); *(IPropertyValue.Vftbl*)ptr = AbiToProjectionVftable; AbiToProjectionVftablePtr = (IntPtr)ptr; } private static T UnboxValue(object value) where T : struct { if (value.GetType() == typeof(T)) { return (T)value; } throw new InvalidCastException("", -2147316576); } private static T[] UnboxArray(object value) where T : struct { if (!(value is Array array)) { throw new InvalidCastException(); } T[] array2 = new T[array.Length]; for (int i = 0; i < array.Length; i++) { try { array2[i] = UnboxValue(array.GetValue(i)); } catch (InvalidCastException ex) { global::System.Exception ex2 = new InvalidCastException("", ex.HResult); throw ex2; } } return array2; } private static bool IsCoercable(object value) { if (value.GetType() == typeof(string) || value.GetType() == typeof(Guid) || value.GetType() != typeof(object)) { return true; } PropertyType value2; return NumericScalarTypes.TryGetValue(value.GetType(), out value2); } private static T CoerceValue(object value) { if (value is T) { return (T)value; } if (value is global::Windows.Foundation.IPropertyValue propertyValue) { if (typeof(T) == typeof(byte)) { return (T)(object)propertyValue.GetUInt8(); } if (typeof(T) == typeof(short)) { return (T)(object)propertyValue.GetInt16(); } if (typeof(T) == typeof(ushort)) { return (T)(object)propertyValue.GetUInt16(); } if (typeof(T) == typeof(int)) { return (T)(object)propertyValue.GetInt32(); } if (typeof(T) == typeof(uint)) { return (T)(object)propertyValue.GetUInt32(); } if (typeof(T) == typeof(long)) { return (T)(object)propertyValue.GetInt64(); } if (typeof(T) == typeof(ulong)) { return (T)(object)propertyValue.GetUInt64(); } if (typeof(T) == typeof(float)) { return (T)(object)propertyValue.GetSingle(); } if (typeof(T) == typeof(double)) { return (T)(object)propertyValue.GetDouble(); } } if (!IsCoercable(value)) { throw new InvalidCastException(); } try { if (value is string input && typeof(T) == typeof(Guid)) { return (T)(object)Guid.Parse(input); } if (value is Guid guid && typeof(T) == typeof(string)) { return (T)(object)guid.ToString("D", CultureInfo.InvariantCulture); } if (typeof(T) == typeof(byte)) { return (T)(object)Convert.ToByte(value, CultureInfo.InvariantCulture); } if (typeof(T) == typeof(short)) { return (T)(object)Convert.ToInt16(value, CultureInfo.InvariantCulture); } if (typeof(T) == typeof(ushort)) { return (T)(object)Convert.ToUInt16(value, CultureInfo.InvariantCulture); } if (typeof(T) == typeof(int)) { return (T)(object)Convert.ToInt32(value, CultureInfo.InvariantCulture); } if (typeof(T) == typeof(uint)) { return (T)(object)Convert.ToUInt32(value, CultureInfo.InvariantCulture); } if (typeof(T) == typeof(long)) { return (T)(object)Convert.ToInt64(value, CultureInfo.InvariantCulture); } if (typeof(T) == typeof(ulong)) { return (T)(object)Convert.ToUInt64(value, CultureInfo.InvariantCulture); } if (typeof(T) == typeof(float)) { return (T)(object)Convert.ToSingle(value, CultureInfo.InvariantCulture); } if (typeof(T) == typeof(double)) { return (T)(object)Convert.ToDouble(value, CultureInfo.InvariantCulture); } throw new InvalidCastException("", -2147316576); } catch (FormatException) { throw new InvalidCastException("", -2147316576); } catch (InvalidCastException) { throw new InvalidCastException("", -2147316576); } catch (OverflowException) { throw new InvalidCastException("", -2147352566); } } private static T[] CoerceArray(object value) { if (value is T[] result) { return result; } if (!(value is Array array)) { throw new InvalidCastException(); } T[] array2 = new T[array.Length]; for (int i = 0; i < array.Length; i++) { try { array2[i] = CoerceValue(array.GetValue(i)); } catch (InvalidCastException ex) { global::System.Exception ex2 = new InvalidCastException("", ex.HResult); throw ex2; } } return array2; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_GetUInt8_2(IntPtr thisPtr, byte* value) { try { *value = CoerceValue(ComWrappersSupport.FindObject(thisPtr)); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_GetInt16_3(IntPtr thisPtr, short* value) { try { *value = CoerceValue(ComWrappersSupport.FindObject(thisPtr)); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_GetUInt16_4(IntPtr thisPtr, ushort* value) { try { *value = CoerceValue(ComWrappersSupport.FindObject(thisPtr)); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_GetInt32_5(IntPtr thisPtr, int* value) { try { *value = CoerceValue(ComWrappersSupport.FindObject(thisPtr)); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_GetUInt32_6(IntPtr thisPtr, uint* value) { try { *value = CoerceValue(ComWrappersSupport.FindObject(thisPtr)); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_GetInt64_7(IntPtr thisPtr, long* value) { try { *value = CoerceValue(ComWrappersSupport.FindObject(thisPtr)); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_GetUInt64_8(IntPtr thisPtr, ulong* value) { try { *value = CoerceValue(ComWrappersSupport.FindObject(thisPtr)); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_GetSingle_9(IntPtr thisPtr, float* value) { try { *value = CoerceValue(ComWrappersSupport.FindObject(thisPtr)); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_GetDouble_10(IntPtr thisPtr, double* value) { try { *value = CoerceValue(ComWrappersSupport.FindObject(thisPtr)); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_GetChar16_11(IntPtr thisPtr, ushort* value) { try { *value = CoerceValue(ComWrappersSupport.FindObject(thisPtr)); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_GetBoolean_12(IntPtr thisPtr, byte* value) { try { *value = (CoerceValue(ComWrappersSupport.FindObject(thisPtr)) ? ((byte)1) : ((byte)0)); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_GetString_13(IntPtr thisPtr, IntPtr* value) { try { *value = MarshalString.FromManaged(CoerceValue(ComWrappersSupport.FindObject(thisPtr))); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_GetGuid_14(IntPtr thisPtr, Guid* value) { try { *value = CoerceValue(ComWrappersSupport.FindObject(thisPtr)); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_GetDateTime_15(IntPtr thisPtr, ABI.System.DateTimeOffset* value) { try { *value = ABI.System.DateTimeOffset.FromManaged(CoerceValue(ComWrappersSupport.FindObject(thisPtr))); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_GetTimeSpan_16(IntPtr thisPtr, ABI.System.TimeSpan* value) { try { *value = ABI.System.TimeSpan.FromManaged(CoerceValue(ComWrappersSupport.FindObject(thisPtr))); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_GetPoint_17(IntPtr thisPtr, global::Windows.Foundation.Point* value) { try { *value = UnboxValue(ComWrappersSupport.FindObject(thisPtr)); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_GetSize_18(IntPtr thisPtr, global::Windows.Foundation.Size* value) { try { *value = UnboxValue(ComWrappersSupport.FindObject(thisPtr)); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_GetRect_19(IntPtr thisPtr, global::Windows.Foundation.Rect* value) { try { *value = UnboxValue(ComWrappersSupport.FindObject(thisPtr)); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_GetUInt8Array_20(IntPtr thisPtr, int* __valueSize, IntPtr* value) { byte[] array = null; try { array = CoerceArray(ComWrappersSupport.FindObject(thisPtr)); ref IntPtr reference = ref *value; (int, IntPtr) tuple = MarshalBlittable.FromManagedArray(array); *__valueSize = tuple.Item1; reference = tuple.Item2; } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_GetInt16Array_21(IntPtr thisPtr, int* __valueSize, IntPtr* value) { short[] array = null; try { array = CoerceArray(ComWrappersSupport.FindObject(thisPtr)); ref IntPtr reference = ref *value; (int, IntPtr) tuple = MarshalBlittable.FromManagedArray(array); *__valueSize = tuple.Item1; reference = tuple.Item2; } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_GetUInt16Array_22(IntPtr thisPtr, int* __valueSize, IntPtr* value) { ushort[] array = null; try { array = CoerceArray(ComWrappersSupport.FindObject(thisPtr)); ref IntPtr reference = ref *value; (int, IntPtr) tuple = MarshalBlittable.FromManagedArray(array); *__valueSize = tuple.Item1; reference = tuple.Item2; } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_GetInt32Array_23(IntPtr thisPtr, int* __valueSize, IntPtr* value) { int[] array = null; try { array = CoerceArray(ComWrappersSupport.FindObject(thisPtr)); ref IntPtr reference = ref *value; (int, IntPtr) tuple = MarshalBlittable.FromManagedArray(array); *__valueSize = tuple.Item1; reference = tuple.Item2; } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_GetUInt32Array_24(IntPtr thisPtr, int* __valueSize, IntPtr* value) { uint[] array = null; try { array = CoerceArray(ComWrappersSupport.FindObject(thisPtr)); ref IntPtr reference = ref *value; (int, IntPtr) tuple = MarshalBlittable.FromManagedArray(array); *__valueSize = tuple.Item1; reference = tuple.Item2; } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_GetInt64Array_25(IntPtr thisPtr, int* __valueSize, IntPtr* value) { long[] array = null; try { array = CoerceArray(ComWrappersSupport.FindObject(thisPtr)); ref IntPtr reference = ref *value; (int, IntPtr) tuple = MarshalBlittable.FromManagedArray(array); *__valueSize = tuple.Item1; reference = tuple.Item2; } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_GetUInt64Array_26(IntPtr thisPtr, int* __valueSize, IntPtr* value) { ulong[] array = null; try { array = CoerceArray(ComWrappersSupport.FindObject(thisPtr)); ref IntPtr reference = ref *value; (int, IntPtr) tuple = MarshalBlittable.FromManagedArray(array); *__valueSize = tuple.Item1; reference = tuple.Item2; } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_GetSingleArray_27(IntPtr thisPtr, int* __valueSize, IntPtr* value) { float[] array = null; try { array = CoerceArray(ComWrappersSupport.FindObject(thisPtr)); ref IntPtr reference = ref *value; (int, IntPtr) tuple = MarshalBlittable.FromManagedArray(array); *__valueSize = tuple.Item1; reference = tuple.Item2; } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_GetDoubleArray_28(IntPtr thisPtr, int* __valueSize, IntPtr* value) { double[] array = null; try { array = CoerceArray(ComWrappersSupport.FindObject(thisPtr)); ref IntPtr reference = ref *value; (int, IntPtr) tuple = MarshalBlittable.FromManagedArray(array); *__valueSize = tuple.Item1; reference = tuple.Item2; } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_GetChar16Array_29(IntPtr thisPtr, int* __valueSize, IntPtr* value) { char[] array = null; try { array = CoerceArray(ComWrappersSupport.FindObject(thisPtr)); ref IntPtr reference = ref *value; (int, IntPtr) tuple = MarshalNonBlittable.FromManagedArray(array); *__valueSize = tuple.Item1; reference = tuple.Item2; } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_GetBooleanArray_30(IntPtr thisPtr, int* __valueSize, IntPtr* value) { bool[] array = null; try { array = CoerceArray(ComWrappersSupport.FindObject(thisPtr)); ref IntPtr reference = ref *value; (int, IntPtr) tuple = MarshalNonBlittable.FromManagedArray(array); *__valueSize = tuple.Item1; reference = tuple.Item2; } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_GetStringArray_31(IntPtr thisPtr, int* __valueSize, IntPtr* value) { string[] array = null; try { array = CoerceArray(ComWrappersSupport.FindObject(thisPtr)); ref IntPtr reference = ref *value; (int, IntPtr) tuple = MarshalString.FromManagedArray(array); *__valueSize = tuple.Item1; reference = tuple.Item2; } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_GetInspectableArray_32(IntPtr thisPtr, int* __valueSize, IntPtr* value) { object[] array = null; try { array = CoerceArray(ComWrappersSupport.FindObject(thisPtr)); ref IntPtr reference = ref *value; (int, IntPtr) tuple = MarshalInspectable.FromManagedArray(array); *__valueSize = tuple.Item1; reference = tuple.Item2; } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_GetGuidArray_33(IntPtr thisPtr, int* __valueSize, IntPtr* value) { Guid[] array = null; try { array = CoerceArray(ComWrappersSupport.FindObject(thisPtr)); ref IntPtr reference = ref *value; (int, IntPtr) tuple = MarshalBlittable.FromManagedArray(array); *__valueSize = tuple.Item1; reference = tuple.Item2; } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_GetDateTimeArray_34(IntPtr thisPtr, int* __valueSize, IntPtr* value) { global::System.DateTimeOffset[] array = null; try { array = CoerceArray(ComWrappersSupport.FindObject(thisPtr)); ref IntPtr reference = ref *value; (int, IntPtr) tuple = MarshalNonBlittable.FromManagedArray(array); *__valueSize = tuple.Item1; reference = tuple.Item2; } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_GetTimeSpanArray_35(IntPtr thisPtr, int* __valueSize, IntPtr* value) { global::System.TimeSpan[] array = null; try { array = CoerceArray(ComWrappersSupport.FindObject(thisPtr)); ref IntPtr reference = ref *value; (int, IntPtr) tuple = MarshalNonBlittable.FromManagedArray(array); *__valueSize = tuple.Item1; reference = tuple.Item2; } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_GetPointArray_36(IntPtr thisPtr, int* __valueSize, IntPtr* value) { global::Windows.Foundation.Point[] array = null; try { array = UnboxArray(ComWrappersSupport.FindObject(thisPtr)); ref IntPtr reference = ref *value; (int, IntPtr) tuple = MarshalBlittable.FromManagedArray(array); *__valueSize = tuple.Item1; reference = tuple.Item2; } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_GetSizeArray_37(IntPtr thisPtr, int* __valueSize, IntPtr* value) { global::Windows.Foundation.Size[] array = null; try { array = UnboxArray(ComWrappersSupport.FindObject(thisPtr)); ref IntPtr reference = ref *value; (int, IntPtr) tuple = MarshalBlittable.FromManagedArray(array); *__valueSize = tuple.Item1; reference = tuple.Item2; } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_GetRectArray_38(IntPtr thisPtr, int* __valueSize, IntPtr* value) { global::Windows.Foundation.Rect[] array = null; try { array = UnboxArray(ComWrappersSupport.FindObject(thisPtr)); ref IntPtr reference = ref *value; (int, IntPtr) tuple = MarshalBlittable.FromManagedArray(array); *__valueSize = tuple.Item1; reference = tuple.Item2; } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_get_IsNumericScalar_1(IntPtr thisPtr, byte* value) { try { *value = (NumericScalarTypes.TryGetValue(ComWrappersSupport.FindObject(thisPtr).GetType(), out var _) ? ((byte)1) : ((byte)0)); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_get_Type_0(IntPtr thisPtr, PropertyType* value) { try { *value = GetPropertyTypeOfObject(ComWrappersSupport.FindObject(thisPtr)); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } private static PropertyType GetPropertyTypeOfObject(object obj) { global::System.Type type = obj.GetType(); bool isArray = type.IsArray; if (isArray) { type = type.GetElementType(); } if (!NumericScalarTypes.TryGetValue(type, out var value)) { value = ((type == typeof(string)) ? PropertyType.String : ((type == typeof(char)) ? PropertyType.Char16 : ((type == typeof(bool)) ? PropertyType.Boolean : ((type == typeof(global::System.DateTimeOffset)) ? PropertyType.DateTime : ((type == typeof(global::System.TimeSpan)) ? PropertyType.TimeSpan : ((type == typeof(Guid)) ? PropertyType.Guid : ((string.CompareOrdinal(type.FullName, "Windows.Foundation.Point") == 0) ? PropertyType.Point : ((string.CompareOrdinal(type.FullName, "Windows.Foundation.Rect") == 0) ? PropertyType.Rect : ((string.CompareOrdinal(type.FullName, "Windows.Foundation.Size") == 0) ? PropertyType.Size : ((type == typeof(object)) ? PropertyType.Inspectable : (typeof(Delegate).IsAssignableFrom(type) ? PropertyType.OtherType : ((!(!type.IsValueType && type != typeof(global::System.Type) && isArray)) ? PropertyType.OtherType : PropertyType.Inspectable)))))))))))); } if (isArray) { value += 1024; } return value; } } [DynamicInterfaceCastableImplementation] [Guid("4BD682DD-7554-40E9-9A9B-82654EDE7E62")] internal interface IPropertyValue : global::Windows.Foundation.IPropertyValue { [Guid("4BD682DD-7554-40E9-9A9B-82654EDE7E62")] public struct Vftbl { internal IInspectable.Vftbl IInspectableVftbl; internal unsafe void* _get_Type_0; public unsafe void* _get_IsNumericScalar_1; internal unsafe void* _GetUInt8_2; internal unsafe void* _GetInt16_3; internal unsafe void* _GetUInt16_4; internal unsafe void* _GetInt32_5; internal unsafe void* _GetUInt32_6; internal unsafe void* _GetInt64_7; internal unsafe void* _GetUInt64_8; internal unsafe void* _GetSingle_9; internal unsafe void* _GetDouble_10; internal unsafe void* _GetChar16_11; internal unsafe void* _GetBoolean_12; internal unsafe void* _GetString_13; internal unsafe void* _GetGuid_14; internal unsafe void* _GetDateTime_15; internal unsafe void* _GetTimeSpan_16; internal unsafe void* _GetPoint_17; internal unsafe void* _GetSize_18; internal unsafe void* _GetRect_19; internal unsafe void* _GetUInt8Array_20; internal unsafe void* _GetInt16Array_21; internal unsafe void* _GetUInt16Array_22; internal unsafe void* _GetInt32Array_23; internal unsafe void* _GetUInt32Array_24; internal unsafe void* _GetInt64Array_25; internal unsafe void* _GetUInt64Array_26; internal unsafe void* _GetSingleArray_27; internal unsafe void* _GetDoubleArray_28; internal unsafe void* _GetChar16Array_29; internal unsafe void* _GetBooleanArray_30; internal unsafe void* _GetStringArray_31; internal unsafe void* _GetInspectableArray_32; internal unsafe void* _GetGuidArray_33; internal unsafe void* _GetDateTimeArray_34; internal unsafe void* _GetTimeSpanArray_35; internal unsafe void* _GetPointArray_36; internal unsafe void* _GetSizeArray_37; internal unsafe void* _GetRectArray_38; public unsafe delegate* unmanaged[Stdcall] get_Type_0 { get { return (delegate* unmanaged[Stdcall])_get_Type_0; } set { _get_Type_0 = value; } } public unsafe delegate* unmanaged[Stdcall] get_IsNumericScalar_1 { get { return (delegate* unmanaged[Stdcall])_get_IsNumericScalar_1; } set { _get_IsNumericScalar_1 = value; } } public unsafe delegate* unmanaged[Stdcall] GetUInt8_2 { get { return (delegate* unmanaged[Stdcall])_GetUInt8_2; } set { _GetUInt8_2 = value; } } public unsafe delegate* unmanaged[Stdcall] GetInt16_3 { get { return (delegate* unmanaged[Stdcall])_GetInt16_3; } set { _GetInt16_3 = value; } } public unsafe delegate* unmanaged[Stdcall] GetUInt16_4 { get { return (delegate* unmanaged[Stdcall])_GetUInt16_4; } set { _GetUInt16_4 = value; } } public unsafe delegate* unmanaged[Stdcall] GetInt32_5 { get { return (delegate* unmanaged[Stdcall])_GetInt32_5; } set { _GetInt32_5 = value; } } public unsafe delegate* unmanaged[Stdcall] GetUInt32_6 { get { return (delegate* unmanaged[Stdcall])_GetUInt32_6; } set { _GetUInt32_6 = value; } } public unsafe delegate* unmanaged[Stdcall] GetInt64_7 { get { return (delegate* unmanaged[Stdcall])_GetInt64_7; } set { _GetInt64_7 = value; } } public unsafe delegate* unmanaged[Stdcall] GetUInt64_8 { get { return (delegate* unmanaged[Stdcall])_GetUInt64_8; } set { _GetUInt64_8 = value; } } public unsafe delegate* unmanaged[Stdcall] GetSingle_9 { get { return (delegate* unmanaged[Stdcall])_GetSingle_9; } set { _GetSingle_9 = value; } } public unsafe delegate* unmanaged[Stdcall] GetDouble_10 { get { return (delegate* unmanaged[Stdcall])_GetDouble_10; } set { _GetDouble_10 = value; } } public unsafe delegate* unmanaged[Stdcall] GetChar16_11 { get { return (delegate* unmanaged[Stdcall])_GetChar16_11; } set { _GetChar16_11 = value; } } public unsafe delegate* unmanaged[Stdcall] GetBoolean_12 { get { return (delegate* unmanaged[Stdcall])_GetBoolean_12; } set { _GetBoolean_12 = value; } } public unsafe delegate* unmanaged[Stdcall] GetString_13 { get { return (delegate* unmanaged[Stdcall])_GetString_13; } set { _GetString_13 = value; } } public unsafe delegate* unmanaged[Stdcall] GetGuid_14 { get { return (delegate* unmanaged[Stdcall])_GetGuid_14; } set { _GetGuid_14 = value; } } public unsafe delegate* unmanaged[Stdcall] GetDateTime_15 { get { return (delegate* unmanaged[Stdcall])_GetDateTime_15; } set { _GetDateTime_15 = value; } } public unsafe delegate* unmanaged[Stdcall] GetTimeSpan_16 { get { return (delegate* unmanaged[Stdcall])_GetTimeSpan_16; } set { _GetTimeSpan_16 = value; } } public unsafe delegate* unmanaged[Stdcall] GetPoint_17 { get { return (delegate* unmanaged[Stdcall])_GetPoint_17; } set { _GetPoint_17 = value; } } public unsafe delegate* unmanaged[Stdcall] GetSize_18 { get { return (delegate* unmanaged[Stdcall])_GetSize_18; } set { _GetSize_18 = value; } } public unsafe delegate* unmanaged[Stdcall] GetRect_19 { get { return (delegate* unmanaged[Stdcall])_GetRect_19; } set { _GetRect_19 = value; } } public unsafe delegate* unmanaged[Stdcall] GetUInt8Array_20 { get { return (delegate* unmanaged[Stdcall])_GetUInt8Array_20; } set { _GetUInt8Array_20 = value; } } public unsafe delegate* unmanaged[Stdcall] GetInt16Array_21 { get { return (delegate* unmanaged[Stdcall])_GetInt16Array_21; } set { _GetInt16Array_21 = value; } } public unsafe delegate* unmanaged[Stdcall] GetUInt16Array_22 { get { return (delegate* unmanaged[Stdcall])_GetUInt16Array_22; } set { _GetUInt16Array_22 = value; } } public unsafe delegate* unmanaged[Stdcall] GetInt32Array_23 { get { return (delegate* unmanaged[Stdcall])_GetInt32Array_23; } set { _GetInt32Array_23 = value; } } public unsafe delegate* unmanaged[Stdcall] GetUInt32Array_24 { get { return (delegate* unmanaged[Stdcall])_GetUInt32Array_24; } set { _GetUInt32Array_24 = value; } } public unsafe delegate* unmanaged[Stdcall] GetInt64Array_25 { get { return (delegate* unmanaged[Stdcall])_GetInt64Array_25; } set { _GetInt64Array_25 = value; } } public unsafe delegate* unmanaged[Stdcall] GetUInt64Array_26 { get { return (delegate* unmanaged[Stdcall])_GetUInt64Array_26; } set { _GetUInt64Array_26 = value; } } public unsafe delegate* unmanaged[Stdcall] GetSingleArray_27 { get { return (delegate* unmanaged[Stdcall])_GetSingleArray_27; } set { _GetSingleArray_27 = value; } } public unsafe delegate* unmanaged[Stdcall] GetDoubleArray_28 { get { return (delegate* unmanaged[Stdcall])_GetDoubleArray_28; } set { _GetDoubleArray_28 = value; } } public unsafe delegate* unmanaged[Stdcall] GetChar16Array_29 { get { return (delegate* unmanaged[Stdcall])_GetChar16Array_29; } set { _GetChar16Array_29 = value; } } public unsafe delegate* unmanaged[Stdcall] GetBooleanArray_30 { get { return (delegate* unmanaged[Stdcall])_GetBooleanArray_30; } set { _GetBooleanArray_30 = value; } } public unsafe delegate* unmanaged[Stdcall] GetStringArray_31 { get { return (delegate* unmanaged[Stdcall])_GetStringArray_31; } set { _GetStringArray_31 = value; } } public unsafe delegate* unmanaged[Stdcall] GetInspectableArray_32 { get { return (delegate* unmanaged[Stdcall])_GetInspectableArray_32; } set { _GetInspectableArray_32 = value; } } public unsafe delegate* unmanaged[Stdcall] GetGuidArray_33 { get { return (delegate* unmanaged[Stdcall])_GetGuidArray_33; } set { _GetGuidArray_33 = value; } } public unsafe delegate* unmanaged[Stdcall] GetDateTimeArray_34 { get { return (delegate* unmanaged[Stdcall])_GetDateTimeArray_34; } set { _GetDateTimeArray_34 = value; } } public unsafe delegate* unmanaged[Stdcall] GetTimeSpanArray_35 { get { return (delegate* unmanaged[Stdcall])_GetTimeSpanArray_35; } set { _GetTimeSpanArray_35 = value; } } public unsafe delegate* unmanaged[Stdcall] GetPointArray_36 { get { return (delegate* unmanaged[Stdcall])_GetPointArray_36; } set { _GetPointArray_36 = value; } } public unsafe delegate* unmanaged[Stdcall] GetSizeArray_37 { get { return (delegate* unmanaged[Stdcall])_GetSizeArray_37; } set { _GetSizeArray_37 = value; } } public unsafe delegate* unmanaged[Stdcall] GetRectArray_38 { get { return (delegate* unmanaged[Stdcall])_GetRectArray_38; } set { _GetRectArray_38 = value; } } } unsafe bool global::Windows.Foundation.IPropertyValue.IsNumericScalar { get { ObjectReference objectReference = (ObjectReference)((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Windows.Foundation.IPropertyValue).TypeHandle); IntPtr thisPtr = objectReference.ThisPtr; byte b = 0; ExceptionHelpers.ThrowExceptionForHR(objectReference.Vftbl.get_IsNumericScalar_1(thisPtr, &b)); GC.KeepAlive(objectReference); return b != 0; } } unsafe PropertyType global::Windows.Foundation.IPropertyValue.Type { get { ObjectReference objectReference = (ObjectReference)((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Windows.Foundation.IPropertyValue).TypeHandle); IntPtr thisPtr = objectReference.ThisPtr; PropertyType result = PropertyType.Empty; ExceptionHelpers.ThrowExceptionForHR(objectReference.Vftbl.get_Type_0(thisPtr, &result)); GC.KeepAlive(objectReference); return result; } } unsafe byte global::Windows.Foundation.IPropertyValue.GetUInt8() { ObjectReference objectReference = (ObjectReference)((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Windows.Foundation.IPropertyValue).TypeHandle); IntPtr thisPtr = objectReference.ThisPtr; byte result = 0; ExceptionHelpers.ThrowExceptionForHR(objectReference.Vftbl.GetUInt8_2(thisPtr, &result)); GC.KeepAlive(objectReference); return result; } unsafe short global::Windows.Foundation.IPropertyValue.GetInt16() { ObjectReference objectReference = (ObjectReference)((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Windows.Foundation.IPropertyValue).TypeHandle); IntPtr thisPtr = objectReference.ThisPtr; short result = 0; ExceptionHelpers.ThrowExceptionForHR(objectReference.Vftbl.GetInt16_3(thisPtr, &result)); GC.KeepAlive(objectReference); return result; } unsafe ushort global::Windows.Foundation.IPropertyValue.GetUInt16() { ObjectReference objectReference = (ObjectReference)((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Windows.Foundation.IPropertyValue).TypeHandle); IntPtr thisPtr = objectReference.ThisPtr; ushort result = 0; ExceptionHelpers.ThrowExceptionForHR(objectReference.Vftbl.GetUInt16_4(thisPtr, &result)); GC.KeepAlive(objectReference); return result; } unsafe int global::Windows.Foundation.IPropertyValue.GetInt32() { ObjectReference objectReference = (ObjectReference)((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Windows.Foundation.IPropertyValue).TypeHandle); IntPtr thisPtr = objectReference.ThisPtr; int result = 0; ExceptionHelpers.ThrowExceptionForHR(objectReference.Vftbl.GetInt32_5(thisPtr, &result)); GC.KeepAlive(objectReference); return result; } unsafe uint global::Windows.Foundation.IPropertyValue.GetUInt32() { ObjectReference objectReference = (ObjectReference)((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Windows.Foundation.IPropertyValue).TypeHandle); IntPtr thisPtr = objectReference.ThisPtr; uint result = 0u; ExceptionHelpers.ThrowExceptionForHR(objectReference.Vftbl.GetUInt32_6(thisPtr, &result)); GC.KeepAlive(objectReference); return result; } unsafe long global::Windows.Foundation.IPropertyValue.GetInt64() { ObjectReference objectReference = (ObjectReference)((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Windows.Foundation.IPropertyValue).TypeHandle); IntPtr thisPtr = objectReference.ThisPtr; long result = 0L; ExceptionHelpers.ThrowExceptionForHR(objectReference.Vftbl.GetInt64_7(thisPtr, &result)); GC.KeepAlive(objectReference); return result; } unsafe ulong global::Windows.Foundation.IPropertyValue.GetUInt64() { ObjectReference objectReference = (ObjectReference)((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Windows.Foundation.IPropertyValue).TypeHandle); IntPtr thisPtr = objectReference.ThisPtr; ulong result = 0uL; ExceptionHelpers.ThrowExceptionForHR(objectReference.Vftbl.GetUInt64_8(thisPtr, &result)); GC.KeepAlive(objectReference); return result; } unsafe float global::Windows.Foundation.IPropertyValue.GetSingle() { ObjectReference objectReference = (ObjectReference)((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Windows.Foundation.IPropertyValue).TypeHandle); IntPtr thisPtr = objectReference.ThisPtr; float result = 0f; ExceptionHelpers.ThrowExceptionForHR(objectReference.Vftbl.GetSingle_9(thisPtr, &result)); GC.KeepAlive(objectReference); return result; } unsafe double global::Windows.Foundation.IPropertyValue.GetDouble() { ObjectReference objectReference = (ObjectReference)((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Windows.Foundation.IPropertyValue).TypeHandle); IntPtr thisPtr = objectReference.ThisPtr; double result = 0.0; ExceptionHelpers.ThrowExceptionForHR(objectReference.Vftbl.GetDouble_10(thisPtr, &result)); GC.KeepAlive(objectReference); return result; } unsafe char global::Windows.Foundation.IPropertyValue.GetChar16() { ObjectReference objectReference = (ObjectReference)((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Windows.Foundation.IPropertyValue).TypeHandle); IntPtr thisPtr = objectReference.ThisPtr; ushort result = 0; ExceptionHelpers.ThrowExceptionForHR(objectReference.Vftbl.GetChar16_11(thisPtr, &result)); GC.KeepAlive(objectReference); return (char)result; } unsafe bool global::Windows.Foundation.IPropertyValue.GetBoolean() { ObjectReference objectReference = (ObjectReference)((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Windows.Foundation.IPropertyValue).TypeHandle); IntPtr thisPtr = objectReference.ThisPtr; byte b = 0; ExceptionHelpers.ThrowExceptionForHR(objectReference.Vftbl.GetBoolean_12(thisPtr, &b)); GC.KeepAlive(objectReference); return b != 0; } unsafe string global::Windows.Foundation.IPropertyValue.GetString() { ObjectReference objectReference = (ObjectReference)((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Windows.Foundation.IPropertyValue).TypeHandle); IntPtr thisPtr = objectReference.ThisPtr; IntPtr intPtr = default(IntPtr); try { ExceptionHelpers.ThrowExceptionForHR(objectReference.Vftbl.GetString_13(thisPtr, &intPtr)); GC.KeepAlive(objectReference); return MarshalString.FromAbi(intPtr); } finally { MarshalString.DisposeAbi(intPtr); } } unsafe Guid global::Windows.Foundation.IPropertyValue.GetGuid() { ObjectReference objectReference = (ObjectReference)((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Windows.Foundation.IPropertyValue).TypeHandle); IntPtr thisPtr = objectReference.ThisPtr; Guid result = default(Guid); ExceptionHelpers.ThrowExceptionForHR(objectReference.Vftbl.GetGuid_14(thisPtr, &result)); GC.KeepAlive(objectReference); return result; } unsafe global::System.DateTimeOffset global::Windows.Foundation.IPropertyValue.GetDateTime() { ObjectReference objectReference = (ObjectReference)((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Windows.Foundation.IPropertyValue).TypeHandle); IntPtr thisPtr = objectReference.ThisPtr; ABI.System.DateTimeOffset dateTimeOffset = default(ABI.System.DateTimeOffset); try { ExceptionHelpers.ThrowExceptionForHR(objectReference.Vftbl.GetDateTime_15(thisPtr, &dateTimeOffset)); GC.KeepAlive(objectReference); return ABI.System.DateTimeOffset.FromAbi(dateTimeOffset); } finally { ABI.System.DateTimeOffset.DisposeAbi(dateTimeOffset); } } unsafe global::System.TimeSpan global::Windows.Foundation.IPropertyValue.GetTimeSpan() { ObjectReference objectReference = (ObjectReference)((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Windows.Foundation.IPropertyValue).TypeHandle); IntPtr thisPtr = objectReference.ThisPtr; ABI.System.TimeSpan timeSpan = default(ABI.System.TimeSpan); try { ExceptionHelpers.ThrowExceptionForHR(objectReference.Vftbl.GetTimeSpan_16(thisPtr, &timeSpan)); GC.KeepAlive(objectReference); return ABI.System.TimeSpan.FromAbi(timeSpan); } finally { ABI.System.TimeSpan.DisposeAbi(timeSpan); } } unsafe global::Windows.Foundation.Point global::Windows.Foundation.IPropertyValue.GetPoint() { ObjectReference objectReference = (ObjectReference)((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Windows.Foundation.IPropertyValue).TypeHandle); IntPtr thisPtr = objectReference.ThisPtr; global::Windows.Foundation.Point result = default(global::Windows.Foundation.Point); ExceptionHelpers.ThrowExceptionForHR(objectReference.Vftbl.GetPoint_17(thisPtr, &result)); GC.KeepAlive(objectReference); return result; } unsafe global::Windows.Foundation.Size global::Windows.Foundation.IPropertyValue.GetSize() { ObjectReference objectReference = (ObjectReference)((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Windows.Foundation.IPropertyValue).TypeHandle); IntPtr thisPtr = objectReference.ThisPtr; global::Windows.Foundation.Size result = default(global::Windows.Foundation.Size); ExceptionHelpers.ThrowExceptionForHR(objectReference.Vftbl.GetSize_18(thisPtr, &result)); GC.KeepAlive(objectReference); return result; } unsafe global::Windows.Foundation.Rect global::Windows.Foundation.IPropertyValue.GetRect() { ObjectReference objectReference = (ObjectReference)((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Windows.Foundation.IPropertyValue).TypeHandle); IntPtr thisPtr = objectReference.ThisPtr; global::Windows.Foundation.Rect result = default(global::Windows.Foundation.Rect); ExceptionHelpers.ThrowExceptionForHR(objectReference.Vftbl.GetRect_19(thisPtr, &result)); GC.KeepAlive(objectReference); return result; } unsafe void global::Windows.Foundation.IPropertyValue.GetUInt8Array(out byte[] value) { ObjectReference objectReference = (ObjectReference)((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Windows.Foundation.IPropertyValue).TypeHandle); IntPtr thisPtr = objectReference.ThisPtr; int item = 0; IntPtr item2 = default(IntPtr); try { ExceptionHelpers.ThrowExceptionForHR(objectReference.Vftbl.GetUInt8Array_20(thisPtr, &item, &item2)); GC.KeepAlive(objectReference); value = MarshalBlittable.FromAbiArray((item, item2)); } finally { MarshalBlittable.DisposeAbiArray((item, item2)); } } unsafe void global::Windows.Foundation.IPropertyValue.GetInt16Array(out short[] value) { ObjectReference objectReference = (ObjectReference)((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Windows.Foundation.IPropertyValue).TypeHandle); IntPtr thisPtr = objectReference.ThisPtr; int item = 0; IntPtr item2 = default(IntPtr); try { ExceptionHelpers.ThrowExceptionForHR(objectReference.Vftbl.GetInt16Array_21(thisPtr, &item, &item2)); GC.KeepAlive(objectReference); value = MarshalBlittable.FromAbiArray((item, item2)); } finally { MarshalBlittable.DisposeAbiArray((item, item2)); } } unsafe void global::Windows.Foundation.IPropertyValue.GetUInt16Array(out ushort[] value) { ObjectReference objectReference = (ObjectReference)((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Windows.Foundation.IPropertyValue).TypeHandle); IntPtr thisPtr = objectReference.ThisPtr; int item = 0; IntPtr item2 = default(IntPtr); try { ExceptionHelpers.ThrowExceptionForHR(objectReference.Vftbl.GetUInt16Array_22(thisPtr, &item, &item2)); GC.KeepAlive(objectReference); value = MarshalBlittable.FromAbiArray((item, item2)); } finally { MarshalBlittable.DisposeAbiArray((item, item2)); } } unsafe void global::Windows.Foundation.IPropertyValue.GetInt32Array(out int[] value) { ObjectReference objectReference = (ObjectReference)((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Windows.Foundation.IPropertyValue).TypeHandle); IntPtr thisPtr = objectReference.ThisPtr; int item = 0; IntPtr item2 = default(IntPtr); try { ExceptionHelpers.ThrowExceptionForHR(objectReference.Vftbl.GetInt32Array_23(thisPtr, &item, &item2)); GC.KeepAlive(objectReference); value = MarshalBlittable.FromAbiArray((item, item2)); } finally { MarshalBlittable.DisposeAbiArray((item, item2)); } } unsafe void global::Windows.Foundation.IPropertyValue.GetUInt32Array(out uint[] value) { ObjectReference objectReference = (ObjectReference)((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Windows.Foundation.IPropertyValue).TypeHandle); IntPtr thisPtr = objectReference.ThisPtr; int item = 0; IntPtr item2 = default(IntPtr); try { ExceptionHelpers.ThrowExceptionForHR(objectReference.Vftbl.GetUInt32Array_24(thisPtr, &item, &item2)); GC.KeepAlive(objectReference); value = MarshalBlittable.FromAbiArray((item, item2)); } finally { MarshalBlittable.DisposeAbiArray((item, item2)); } } unsafe void global::Windows.Foundation.IPropertyValue.GetInt64Array(out long[] value) { ObjectReference objectReference = (ObjectReference)((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Windows.Foundation.IPropertyValue).TypeHandle); IntPtr thisPtr = objectReference.ThisPtr; int item = 0; IntPtr item2 = default(IntPtr); try { ExceptionHelpers.ThrowExceptionForHR(objectReference.Vftbl.GetInt64Array_25(thisPtr, &item, &item2)); GC.KeepAlive(objectReference); value = MarshalBlittable.FromAbiArray((item, item2)); } finally { MarshalBlittable.DisposeAbiArray((item, item2)); } } unsafe void global::Windows.Foundation.IPropertyValue.GetUInt64Array(out ulong[] value) { ObjectReference objectReference = (ObjectReference)((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Windows.Foundation.IPropertyValue).TypeHandle); IntPtr thisPtr = objectReference.ThisPtr; int item = 0; IntPtr item2 = default(IntPtr); try { ExceptionHelpers.ThrowExceptionForHR(objectReference.Vftbl.GetUInt64Array_26(thisPtr, &item, &item2)); GC.KeepAlive(objectReference); value = MarshalBlittable.FromAbiArray((item, item2)); } finally { MarshalBlittable.DisposeAbiArray((item, item2)); } } unsafe void global::Windows.Foundation.IPropertyValue.GetSingleArray(out float[] value) { ObjectReference objectReference = (ObjectReference)((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Windows.Foundation.IPropertyValue).TypeHandle); IntPtr thisPtr = objectReference.ThisPtr; int item = 0; IntPtr item2 = default(IntPtr); try { ExceptionHelpers.ThrowExceptionForHR(objectReference.Vftbl.GetSingleArray_27(thisPtr, &item, &item2)); GC.KeepAlive(objectReference); value = MarshalBlittable.FromAbiArray((item, item2)); } finally { MarshalBlittable.DisposeAbiArray((item, item2)); } } unsafe void global::Windows.Foundation.IPropertyValue.GetDoubleArray(out double[] value) { ObjectReference objectReference = (ObjectReference)((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Windows.Foundation.IPropertyValue).TypeHandle); IntPtr thisPtr = objectReference.ThisPtr; int item = 0; IntPtr item2 = default(IntPtr); try { ExceptionHelpers.ThrowExceptionForHR(objectReference.Vftbl.GetDoubleArray_28(thisPtr, &item, &item2)); GC.KeepAlive(objectReference); value = MarshalBlittable.FromAbiArray((item, item2)); } finally { MarshalBlittable.DisposeAbiArray((item, item2)); } } unsafe void global::Windows.Foundation.IPropertyValue.GetChar16Array(out char[] value) { ObjectReference objectReference = (ObjectReference)((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Windows.Foundation.IPropertyValue).TypeHandle); IntPtr thisPtr = objectReference.ThisPtr; int item = 0; IntPtr item2 = default(IntPtr); try { ExceptionHelpers.ThrowExceptionForHR(objectReference.Vftbl.GetChar16Array_29(thisPtr, &item, &item2)); GC.KeepAlive(objectReference); value = MarshalNonBlittable.FromAbiArray((item, item2)); } finally { MarshalNonBlittable.DisposeAbiArray((item, item2)); } } unsafe void global::Windows.Foundation.IPropertyValue.GetBooleanArray(out bool[] value) { ObjectReference objectReference = (ObjectReference)((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Windows.Foundation.IPropertyValue).TypeHandle); IntPtr thisPtr = objectReference.ThisPtr; int item = 0; IntPtr item2 = default(IntPtr); try { ExceptionHelpers.ThrowExceptionForHR(objectReference.Vftbl.GetBooleanArray_30(thisPtr, &item, &item2)); GC.KeepAlive(objectReference); value = MarshalNonBlittable.FromAbiArray((item, item2)); } finally { MarshalNonBlittable.DisposeAbiArray((item, item2)); } } unsafe void global::Windows.Foundation.IPropertyValue.GetStringArray(out string[] value) { ObjectReference objectReference = (ObjectReference)((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Windows.Foundation.IPropertyValue).TypeHandle); IntPtr thisPtr = objectReference.ThisPtr; int item = 0; IntPtr item2 = default(IntPtr); try { ExceptionHelpers.ThrowExceptionForHR(objectReference.Vftbl.GetStringArray_31(thisPtr, &item, &item2)); GC.KeepAlive(objectReference); value = MarshalString.FromAbiArray((item, item2)); } finally { MarshalString.DisposeAbiArray((item, item2)); } } unsafe void global::Windows.Foundation.IPropertyValue.GetInspectableArray(out object[] value) { ObjectReference objectReference = (ObjectReference)((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Windows.Foundation.IPropertyValue).TypeHandle); IntPtr thisPtr = objectReference.ThisPtr; int item = 0; IntPtr item2 = default(IntPtr); try { ExceptionHelpers.ThrowExceptionForHR(objectReference.Vftbl.GetInspectableArray_32(thisPtr, &item, &item2)); GC.KeepAlive(objectReference); value = MarshalInspectable.FromAbiArray((item, item2)); } finally { MarshalInspectable.DisposeAbiArray((item, item2)); } } unsafe void global::Windows.Foundation.IPropertyValue.GetGuidArray(out Guid[] value) { ObjectReference objectReference = (ObjectReference)((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Windows.Foundation.IPropertyValue).TypeHandle); IntPtr thisPtr = objectReference.ThisPtr; int item = 0; IntPtr item2 = default(IntPtr); try { ExceptionHelpers.ThrowExceptionForHR(objectReference.Vftbl.GetGuidArray_33(thisPtr, &item, &item2)); GC.KeepAlive(objectReference); value = MarshalBlittable.FromAbiArray((item, item2)); } finally { MarshalBlittable.DisposeAbiArray((item, item2)); } } unsafe void global::Windows.Foundation.IPropertyValue.GetDateTimeArray(out global::System.DateTimeOffset[] value) { ObjectReference objectReference = (ObjectReference)((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Windows.Foundation.IPropertyValue).TypeHandle); IntPtr thisPtr = objectReference.ThisPtr; int item = 0; IntPtr item2 = default(IntPtr); try { ExceptionHelpers.ThrowExceptionForHR(objectReference.Vftbl.GetDateTimeArray_34(thisPtr, &item, &item2)); GC.KeepAlive(objectReference); value = MarshalNonBlittable.FromAbiArray((item, item2)); } finally { MarshalNonBlittable.DisposeAbiArray((item, item2)); } } unsafe void global::Windows.Foundation.IPropertyValue.GetTimeSpanArray(out global::System.TimeSpan[] value) { ObjectReference objectReference = (ObjectReference)((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Windows.Foundation.IPropertyValue).TypeHandle); IntPtr thisPtr = objectReference.ThisPtr; int item = 0; IntPtr item2 = default(IntPtr); try { ExceptionHelpers.ThrowExceptionForHR(objectReference.Vftbl.GetTimeSpanArray_35(thisPtr, &item, &item2)); GC.KeepAlive(objectReference); value = MarshalNonBlittable.FromAbiArray((item, item2)); } finally { MarshalNonBlittable.DisposeAbiArray((item, item2)); } } unsafe void global::Windows.Foundation.IPropertyValue.GetPointArray(out global::Windows.Foundation.Point[] value) { ObjectReference objectReference = (ObjectReference)((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Windows.Foundation.IPropertyValue).TypeHandle); IntPtr thisPtr = objectReference.ThisPtr; int item = 0; IntPtr item2 = default(IntPtr); try { ExceptionHelpers.ThrowExceptionForHR(objectReference.Vftbl.GetPointArray_36(thisPtr, &item, &item2)); GC.KeepAlive(objectReference); value = MarshalBlittable.FromAbiArray((item, item2)); } finally { MarshalBlittable.DisposeAbiArray((item, item2)); } } unsafe void global::Windows.Foundation.IPropertyValue.GetSizeArray(out global::Windows.Foundation.Size[] value) { ObjectReference objectReference = (ObjectReference)((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Windows.Foundation.IPropertyValue).TypeHandle); IntPtr thisPtr = objectReference.ThisPtr; int item = 0; IntPtr item2 = default(IntPtr); try { ExceptionHelpers.ThrowExceptionForHR(objectReference.Vftbl.GetSizeArray_37(thisPtr, &item, &item2)); GC.KeepAlive(objectReference); value = MarshalBlittable.FromAbiArray((item, item2)); } finally { MarshalBlittable.DisposeAbiArray((item, item2)); } } unsafe void global::Windows.Foundation.IPropertyValue.GetRectArray(out global::Windows.Foundation.Rect[] value) { ObjectReference objectReference = (ObjectReference)((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Windows.Foundation.IPropertyValue).TypeHandle); IntPtr thisPtr = objectReference.ThisPtr; int item = 0; IntPtr item2 = default(IntPtr); try { ExceptionHelpers.ThrowExceptionForHR(objectReference.Vftbl.GetRectArray_38(thisPtr, &item, &item2)); GC.KeepAlive(objectReference); value = MarshalBlittable.FromAbiArray((item, item2)); } finally { MarshalBlittable.DisposeAbiArray((item, item2)); } } } internal static class IPropertyValue_Delegates { public unsafe delegate int get_Type_0(IntPtr thisPtr, PropertyType* value); public unsafe delegate int get_IsNumericScalar_1(IntPtr thisPtr, byte* value); public unsafe delegate int GetUInt8_2(IntPtr thisPtr, byte* value); public unsafe delegate int GetInt16_3(IntPtr thisPtr, short* value); public unsafe delegate int GetUInt16_4(IntPtr thisPtr, ushort* value); public unsafe delegate int GetInt32_5(IntPtr thisPtr, int* value); public unsafe delegate int GetUInt32_6(IntPtr thisPtr, uint* value); public unsafe delegate int GetInt64_7(IntPtr thisPtr, long* value); public unsafe delegate int GetUInt64_8(IntPtr thisPtr, ulong* value); public unsafe delegate int GetSingle_9(IntPtr thisPtr, float* value); public unsafe delegate int GetDouble_10(IntPtr thisPtr, double* value); public unsafe delegate int GetChar16_11(IntPtr thisPtr, ushort* value); public unsafe delegate int GetBoolean_12(IntPtr thisPtr, byte* value); public unsafe delegate int GetString_13(IntPtr thisPtr, IntPtr* value); public unsafe delegate int GetGuid_14(IntPtr thisPtr, Guid* value); public unsafe delegate int GetDateTime_15(IntPtr thisPtr, ABI.System.DateTimeOffset* value); public unsafe delegate int GetTimeSpan_16(IntPtr thisPtr, ABI.System.TimeSpan* value); public unsafe delegate int GetPoint_17(IntPtr thisPtr, global::Windows.Foundation.Point* value); public unsafe delegate int GetSize_18(IntPtr thisPtr, global::Windows.Foundation.Size* value); public unsafe delegate int GetRect_19(IntPtr thisPtr, global::Windows.Foundation.Rect* value); public unsafe delegate int GetUInt8Array_20(IntPtr thisPtr, int* __valueSize, IntPtr* value); public unsafe delegate int GetInt16Array_21(IntPtr thisPtr, int* __valueSize, IntPtr* value); public unsafe delegate int GetUInt16Array_22(IntPtr thisPtr, int* __valueSize, IntPtr* value); public unsafe delegate int GetInt32Array_23(IntPtr thisPtr, int* __valueSize, IntPtr* value); public unsafe delegate int GetUInt32Array_24(IntPtr thisPtr, int* __valueSize, IntPtr* value); public unsafe delegate int GetInt64Array_25(IntPtr thisPtr, int* __valueSize, IntPtr* value); public unsafe delegate int GetUInt64Array_26(IntPtr thisPtr, int* __valueSize, IntPtr* value); public unsafe delegate int GetSingleArray_27(IntPtr thisPtr, int* __valueSize, IntPtr* value); public unsafe delegate int GetDoubleArray_28(IntPtr thisPtr, int* __valueSize, IntPtr* value); public unsafe delegate int GetChar16Array_29(IntPtr thisPtr, int* __valueSize, IntPtr* value); public unsafe delegate int GetBooleanArray_30(IntPtr thisPtr, int* __valueSize, IntPtr* value); public unsafe delegate int GetStringArray_31(IntPtr thisPtr, int* __valueSize, IntPtr* value); public unsafe delegate int GetInspectableArray_32(IntPtr thisPtr, int* __valueSize, IntPtr* value); public unsafe delegate int GetGuidArray_33(IntPtr thisPtr, int* __valueSize, IntPtr* value); public unsafe delegate int GetDateTimeArray_34(IntPtr thisPtr, int* __valueSize, IntPtr* value); public unsafe delegate int GetTimeSpanArray_35(IntPtr thisPtr, int* __valueSize, IntPtr* value); public unsafe delegate int GetPointArray_36(IntPtr thisPtr, int* __valueSize, IntPtr* value); public unsafe delegate int GetSizeArray_37(IntPtr thisPtr, int* __valueSize, IntPtr* value); public unsafe delegate int GetRectArray_38(IntPtr thisPtr, int* __valueSize, IntPtr* value); } internal static class BoxedArrayIReferenceArrayImpl { public static readonly IntPtr AbiToProjectionVftablePtr; private static readonly IReferenceArray_Delegates.get_Value_0 DelegateCache; unsafe static BoxedArrayIReferenceArrayImpl() { DelegateCache = Do_Abi_get_Value_0; AbiToProjectionVftablePtr = ComWrappersSupport.AllocateVtableMemory(typeof(BoxedArrayIReferenceArrayImpl), sizeof(IInspectable.Vftbl) + sizeof(IntPtr)); *(IInspectable.Vftbl*)(void*)AbiToProjectionVftablePtr = IInspectable.Vftbl.AbiToProjectionVftable; ((IntPtr*)(void*)AbiToProjectionVftablePtr)[6] = Marshal.GetFunctionPointerForDelegate(DelegateCache); } private unsafe static int Do_Abi_get_Value_0(IntPtr thisPtr, int* ____return_value__Size, IntPtr* __return_value__) { T[] array = null; *__return_value__ = default(IntPtr); *____return_value__Size = 0; try { array = (T[])ComWrappersSupport.FindObject(thisPtr); ref IntPtr reference = ref *__return_value__; (int, IntPtr) tuple = Marshaler.FromManagedArray(array); *____return_value__Size = tuple.Item1; reference = tuple.Item2; } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } } [Guid("61C17707-2D65-11E0-9AE8-D48564015472")] internal sealed class IReferenceArray : global::Windows.Foundation.IReferenceArray { public static readonly Guid PIID = GuidGenerator.CreateIIDUnsafe(typeof(IReferenceArray)); private readonly ObjectReference _obj; public IntPtr ThisPtr => _obj.ThisPtr; public unsafe T[] Value { get { int item = 0; IntPtr item2 = default(IntPtr); try { ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)ThisPtr) + (nint)6 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(ThisPtr, &item, &item2)); GC.KeepAlive(_obj); return Marshaler.FromAbiArray((item, item2)); } finally { Marshaler.DisposeAbiArray((item, item2)); } } } public static IObjectReference CreateMarshaler(object value) { if (value != null) { return ComWrappersSupport.CreateCCWForObject(value, PIID); } return null; } public static ObjectReferenceValue CreateMarshaler2(object value) { return ComWrappersSupport.CreateCCWForObjectForMarshaling(value, PIID); } public static IntPtr GetAbi(IObjectReference m) { return m?.ThisPtr ?? IntPtr.Zero; } public static object FromAbi(IntPtr ptr) { if (ptr == IntPtr.Zero) { return null; } IReferenceArray referenceArray = new IReferenceArray(ObjectReference.FromAbi(ptr, PIID)); return referenceArray.Value; } public unsafe static object GetValue(IInspectable inspectable) { IntPtr ppv = IntPtr.Zero; int item = 0; IntPtr item2 = default(IntPtr); try { ExceptionHelpers.ThrowExceptionForHR(Marshal.QueryInterface(inspectable.ThisPtr, in Unsafe.AsRef(in PIID), out ppv)); GC.KeepAlive(inspectable); ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)ppv) + (nint)6 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(ppv, &item, &item2)); return Marshaler.FromAbiArray((item, item2)); } finally { Marshaler.DisposeAbiArray((item, item2)); MarshalExtensions.ReleaseIfNotNull(ppv); } } public unsafe static void CopyManaged(object o, IntPtr dest) { *(IntPtr*)dest.ToPointer() = CreateMarshaler2(o).Detach(); } public static IntPtr FromManaged(object value) { if (value == null) { return IntPtr.Zero; } return CreateMarshaler2(value).Detach(); } public static void DisposeMarshaler(IObjectReference m) { m?.Dispose(); } public static void DisposeAbi(IntPtr abi) { MarshalInspectable.DisposeAbi(abi); } public static string GetGuidSignature() { return GuidGenerator.GetSignature(typeof(IReferenceArray)); } public IReferenceArray(ObjectReference obj) { _obj = obj; } } internal static class IReferenceArray_Delegates { public unsafe delegate int get_Value_0(IntPtr thisPtr, int* ____return_value__Size, IntPtr* __return_value__); } [Guid("96369F54-8EB6-48F0-ABCE-C1B211E627C3")] internal struct ManagedIStringableVftbl { internal IInspectable.Vftbl IInspectableVftbl; private unsafe void* _ToString_0; private static readonly ManagedIStringableVftbl AbiToProjectionVftable; public static readonly IntPtr AbiToProjectionVftablePtr; private unsafe delegate* unmanaged[Stdcall] ToString_0 { get { return (delegate* unmanaged[Stdcall])_ToString_0; } set { _ToString_0 = value; } } unsafe static ManagedIStringableVftbl() { AbiToProjectionVftable = new ManagedIStringableVftbl { IInspectableVftbl = IInspectable.Vftbl.AbiToProjectionVftable, _ToString_0 = (delegate*)(&Do_Abi_ToString_0) }; IntPtr* ptr = (IntPtr*)(void*)ComWrappersSupport.AllocateVtableMemory(typeof(ManagedIStringableVftbl), sizeof(IInspectable.Vftbl) + sizeof(IntPtr)); *(ManagedIStringableVftbl*)ptr = AbiToProjectionVftable; AbiToProjectionVftablePtr = (IntPtr)ptr; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_ToString_0(IntPtr thisPtr, IntPtr* value) { try { string value2 = ComWrappersSupport.FindObject(thisPtr).ToString(); *value = MarshalString.FromManaged(value2); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } } internal static class BoxedValueIReferenceImpl { private static ABI.System.Nullable.Vftbl AbiToProjectionVftable; public static IntPtr AbiToProjectionVftablePtr; [UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", Justification = "ABI types used with MakeGenericType are not reflected on.")] static unsafe BoxedValueIReferenceImpl() { AbiToProjectionVftable = new ABI.System.Nullable.Vftbl { IInspectableVftbl = IInspectable.Vftbl.AbiToProjectionVftable, get_Value_0 = GetValueDelegateForAbi(out var nativePtr) }; IntPtr* ptr = (IntPtr*)(void*)ComWrappersSupport.AllocateVtableMemory(typeof(BoxedValueIReferenceImpl), sizeof(IInspectable.Vftbl) + sizeof(IntPtr)); *(IInspectable.Vftbl*)ptr = AbiToProjectionVftable.IInspectableVftbl; ptr[6] = nativePtr; AbiToProjectionVftablePtr = (IntPtr)ptr; } private unsafe static int Do_Abi_get_Value_0_Blittable(void* thisPtr, void* result) { if (result == null) { return -2147467261; } try { T value = (T)ComWrappersSupport.FindObject(new IntPtr(thisPtr)); Unsafe.WriteUnaligned(result, value); return 0; } catch (global::System.Exception ex) { Unsafe.WriteUnaligned(result, default(T)); ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } } private unsafe static int Do_Abi_get_Value_0_DateTimeOffset(void* thisPtr, ABI.System.DateTimeOffset* result) { if (result == null) { return -2147467261; } try { T source = (T)ComWrappersSupport.FindObject(new IntPtr(thisPtr)); Unsafe.WriteUnaligned(result, ABI.System.DateTimeOffset.FromManaged(Unsafe.As(ref source))); return 0; } catch (global::System.Exception ex) { Unsafe.WriteUnaligned(result, default(T)); ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } } private unsafe static int Do_Abi_get_Value_0(void* thisPtr, out TAbi __return_value__) { T val = default(T); __return_value__ = default(TAbi); try { val = (T)ComWrappersSupport.FindObject(new IntPtr(thisPtr)); __return_value__ = (TAbi)Marshaler.FromManaged(val); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } internal unsafe static Delegate GetValueDelegateForAbi(out IntPtr nativePtr) { if (typeof(T) == typeof(int) || typeof(T) == typeof(byte) || typeof(T) == typeof(bool) || typeof(T) == typeof(sbyte) || typeof(T) == typeof(short) || typeof(T) == typeof(ushort) || typeof(T) == typeof(char) || typeof(T) == typeof(uint) || typeof(T) == typeof(long) || typeof(T) == typeof(ulong) || typeof(T) == typeof(float) || typeof(T) == typeof(double) || typeof(T) == typeof(Guid) || typeof(T) == typeof(global::System.TimeSpan) || typeof(T) == typeof(global::Windows.Foundation.Point) || typeof(T) == typeof(global::Windows.Foundation.Rect) || typeof(T) == typeof(global::Windows.Foundation.Size) || typeof(T) == typeof(global::System.Numerics.Matrix3x2) || typeof(T) == typeof(global::System.Numerics.Matrix4x4) || typeof(T) == typeof(global::System.Numerics.Plane) || typeof(T) == typeof(global::System.Numerics.Quaternion) || typeof(T) == typeof(global::System.Numerics.Vector2) || typeof(T) == typeof(global::System.Numerics.Vector3) || typeof(T) == typeof(global::System.Numerics.Vector4) || (typeof(T).IsEnum && Enum.GetUnderlyingType(typeof(T)) == typeof(int)) || (typeof(T).IsEnum && Enum.GetUnderlyingType(typeof(T)) == typeof(uint))) { Nullable_Delegates.GetValueDelegateAbi getValueDelegateAbi = Do_Abi_get_Value_0_Blittable; nativePtr = Marshal.GetFunctionPointerForDelegate(getValueDelegateAbi); return getValueDelegateAbi; } if (typeof(T) == typeof(global::System.DateTimeOffset)) { Nullable_Delegates.GetValueDelegateAbiDateTimeOffset getValueDelegateAbiDateTimeOffset = Do_Abi_get_Value_0_DateTimeOffset; nativePtr = Marshal.GetFunctionPointerForDelegate(getValueDelegateAbiDateTimeOffset); return getValueDelegateAbiDateTimeOffset; } if (RuntimeFeature.IsDynamicCodeCompiled) { if ((object)ABI.System.Nullable.Vftbl.get_Value_0_Type == null) { ABI.System.Nullable.Vftbl.get_Value_0_Type = Projections.GetAbiDelegateType(typeof(void*), Marshaler.AbiType.MakeByRefType(), typeof(int)); } Delegate obj = Delegate.CreateDelegate(ABI.System.Nullable.Vftbl.get_Value_0_Type, typeof(BoxedValueIReferenceImpl).GetMethod("Do_Abi_get_Value_0", BindingFlags.Static | BindingFlags.NonPublic).MakeGenericMethod(Marshaler.AbiType)); nativePtr = Marshal.GetFunctionPointerForDelegate(obj); return obj; } throw new NotSupportedException($"Failed to get the marshalling delegate for BoxedValueIReferenceImpl`1 with type '{typeof(T)}'."); } } internal static class BoxedValueIReferenceImpl where TAbi : unmanaged { public static IntPtr AbiToProjectionVftablePtr; private static readonly Nullable_Delegates.GetValueDelegateAbi GetValue; unsafe static BoxedValueIReferenceImpl() { if (typeof(T) == typeof(TAbi)) { GetValue = Do_Abi_get_Value_0_Blittable; } else { GetValue = Do_Abi_get_Value_0; } AbiToProjectionVftablePtr = ComWrappersSupport.AllocateVtableMemory(typeof(BoxedValueIReferenceImpl), sizeof(IInspectable.Vftbl) + sizeof(IntPtr)); *(IInspectable.Vftbl*)(void*)AbiToProjectionVftablePtr = IInspectable.Vftbl.AbiToProjectionVftable; ((IntPtr*)(void*)AbiToProjectionVftablePtr)[6] = Marshal.GetFunctionPointerForDelegate(GetValue); } private unsafe static int Do_Abi_get_Value_0(void* thisPtr, void* __return_value__) { *(TAbi*)__return_value__ = default(TAbi); try { T arg = (T)ComWrappersSupport.FindObject(new IntPtr(thisPtr)); *(TAbi*)__return_value__ = (TAbi)Marshaler.FromManaged(arg); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } private unsafe static int Do_Abi_get_Value_0_Blittable(void* thisPtr, void* __return_value__) { *(TAbi*)__return_value__ = default(TAbi); try { *(TAbi*)__return_value__ = (TAbi)ComWrappersSupport.FindObject(new IntPtr(thisPtr)); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } } [Guid("9E365E57-48B2-4160-956F-C7385120BBFC")] internal struct IUriRuntimeClassVftbl { internal IInspectable.Vftbl IInspectableVftbl; public IntPtr get_AbsoluteUri_0; public IntPtr get_DisplayUri_1; public IntPtr get_Domain_2; public IntPtr get_Extension_3; public IntPtr get_Fragment_4; public IntPtr get_Host_5; public IntPtr get_Password_6; public IntPtr get_Path_7; public IntPtr get_Query_8; public IntPtr get_QueryParsed_9; public unsafe void* _get_RawUri_10; public IntPtr get_SchemeName_11; public IntPtr get_UserName_12; public IntPtr get_Port_13; public IntPtr get_Suspicious_14; public IntPtr Equals_15; public IntPtr CombineUri_16; public unsafe delegate* unmanaged[Stdcall] get_RawUri_10 => (delegate* unmanaged[Stdcall])_get_RawUri_10; } } namespace ABI.Windows.Foundation.Collections { internal static class IMapMethods { internal unsafe static volatile delegate* _Lookup; internal unsafe static volatile delegate* _HasKey; internal unsafe static volatile delegate*> _GetView; internal unsafe static volatile delegate* _Insert; internal unsafe static volatile delegate* _Remove; internal static volatile bool _RcwHelperInitialized; [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static void EnsureInitialized() { if (!RuntimeFeature.IsDynamicCodeCompiled && !_RcwHelperInitialized) { ThrowNotInitialized(); } [DoesNotReturn] static void ThrowNotInitialized() { throw new NotImplementedException($"Type '{typeof(global::System.Collections.Generic.IDictionary)}' was called without initializing the RCW methods using 'IDictionaryMethods.InitRcwHelper'. If using 'IDynamicInterfaceCastable' support to do a dynamic cast to this interface, ensure the 'InitRcwHelper' method is called."); } } public unsafe static V Lookup(IObjectReference obj, K key) { EnsureInitialized(); return _Lookup(obj, key); } public unsafe static bool HasKey(IObjectReference obj, K key) { EnsureInitialized(); return _HasKey(obj, key); } public unsafe static global::System.Collections.Generic.IReadOnlyDictionary GetView(IObjectReference obj) { if (!RuntimeFeature.IsDynamicCodeCompiled) { EnsureInitialized(); return _GetView(obj); } if (_GetView != (delegate*>)null) { return _GetView(obj); } IntPtr thisPtr = obj.ThisPtr; IntPtr intPtr = default(IntPtr); try { ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)9 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(thisPtr, &intPtr)); GC.KeepAlive(obj); return MarshalInterface>.FromAbi(intPtr); } finally { MarshalInterface>.DisposeAbi(intPtr); } } public unsafe static bool Insert(IObjectReference obj, K key, V value) { EnsureInitialized(); return _Insert(obj, key, value); } public unsafe static void Remove(IObjectReference obj, K key) { EnsureInitialized(); _Remove(obj, key); } public static void Clear(IObjectReference obj) { _ClearHelper(obj); } private unsafe static void _ClearHelper(IObjectReference obj) { IntPtr thisPtr = obj.ThisPtr; ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)12 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(thisPtr)); GC.KeepAlive(obj); } public unsafe static uint get_Size(IObjectReference obj) { IntPtr thisPtr = obj.ThisPtr; uint result = 0u; ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)7 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(thisPtr, &result)); GC.KeepAlive(obj); return result; } } internal static class IIterableMethods { internal unsafe static volatile delegate*> _First; internal static volatile bool _RcwHelperInitialized; [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static void EnsureInitialized() { if (!RuntimeFeature.IsDynamicCodeCompiled && !_RcwHelperInitialized) { ThrowNotInitialized(); } [DoesNotReturn] static void ThrowNotInitialized() { throw new NotImplementedException($"Type '{typeof(global::System.Collections.Generic.IEnumerable)}' was called without initializing the RCW methods using 'IEnumerableMethods.InitRcwHelper'. If using 'IDynamicInterfaceCastable' support to do a dynamic cast to this interface, ensure the 'InitRcwHelper' method is called."); } } public unsafe static global::System.Collections.Generic.IEnumerator First(IObjectReference obj) { if (!RuntimeFeature.IsDynamicCodeCompiled) { EnsureInitialized(); return _First(obj); } if (_First != (delegate*>)null) { return _First(obj); } IntPtr abi = default(IntPtr); try { IntPtr thisPtr = obj.ThisPtr; ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)6 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(thisPtr, &abi)); GC.KeepAlive(obj); return FromAbiEnumerator.FromAbi(abi); } finally { FromAbiEnumerator.DisposeAbi(abi); } } } [DynamicInterfaceCastableImplementation] [Guid("FAA585EA-6214-4217-AFDA-7F46DE5869B3")] internal interface IIterable : ABI.System.Collections.Generic.IEnumerable, global::System.Collections.Generic.IEnumerable, global::System.Collections.IEnumerable, global::Windows.Foundation.Collections.IIterable { new static Guid PIID = IEnumerableMethods.PIID; } internal static class IMapViewMethods { internal unsafe static volatile delegate* _Lookup; internal unsafe static volatile delegate* _HasKey; internal unsafe static volatile delegate*, out IMapView, void> _Split; internal static volatile bool _RcwHelperInitialized; [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static void EnsureInitialized() { if (!RuntimeFeature.IsDynamicCodeCompiled && !_RcwHelperInitialized) { ThrowNotInitialized(); } [DoesNotReturn] static void ThrowNotInitialized() { throw new NotImplementedException($"Type '{typeof(global::System.Collections.Generic.IReadOnlyDictionary)}' was called without initializing the RCW methods using 'IReadOnlyDictionaryMethods.InitRcwHelper'. If using 'IDynamicInterfaceCastable' support to do a dynamic cast to this interface, ensure the 'InitRcwHelper' method is called."); } } public unsafe static V Lookup(IObjectReference obj, K key) { EnsureInitialized(); return _Lookup(obj, key); } public unsafe static bool HasKey(IObjectReference obj, K key) { EnsureInitialized(); return _HasKey(obj, key); } public unsafe static void Split(IObjectReference obj, out IMapView first, out IMapView second) { if (!RuntimeFeature.IsDynamicCodeCompiled) { EnsureInitialized(); _Split(obj, out first, out second); return; } if (_Split != (delegate*, out IMapView, void>)null) { _Split(obj, out first, out second); return; } IntPtr thisPtr = obj.ThisPtr; IntPtr intPtr = default(IntPtr); IntPtr intPtr2 = default(IntPtr); try { ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)9 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(thisPtr, &intPtr, &intPtr2)); GC.KeepAlive(obj); first = MarshalInterface>.FromAbi(intPtr); second = MarshalInterface>.FromAbi(intPtr2); } finally { MarshalInterface>.DisposeAbi(intPtr); MarshalInterface>.DisposeAbi(intPtr2); } } public unsafe static uint get_Size(IObjectReference obj) { IntPtr thisPtr = obj.ThisPtr; uint result = 0u; ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)7 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(thisPtr, &result)); GC.KeepAlive(obj); return result; } } internal static class IVectorViewMethods { internal unsafe static volatile delegate* _GetAt; internal unsafe static volatile delegate* _IndexOf; internal unsafe static volatile delegate* _GetMany; internal static volatile bool _RcwHelperInitialized; internal static void EnsureInitialized() { if (RuntimeFeature.IsDynamicCodeCompiled) { InitRcwHelperFallbackIfNeeded(); } else if (!_RcwHelperInitialized) { ThrowNotInitialized(); } [MethodImpl(MethodImplOptions.NoInlining)] [UnconditionalSuppressMessage("Trimming", "IL2080", Justification = "All ABI types never have a constructor that would need to be accessed via reflection.")] static void InitRcwHelperFallbackIfNeeded() { if (!_RcwHelperInitialized) { Func func = (Func)typeof(IReadOnlyListMethods<, >).MakeGenericType(typeof(T), Marshaler.AbiType).GetMethod("InitRcwHelperFallback", BindingFlags.Static | BindingFlags.NonPublic).CreateDelegate(typeof(Func)); func(); } } [DoesNotReturn] static void ThrowNotInitialized() { throw new NotImplementedException($"Type '{typeof(global::System.Collections.Generic.IReadOnlyList)}' was called without initializing the RCW methods using 'IReadOnlyListMethods.InitRcwHelper'. If using 'IDynamicInterfaceCastable' support to do a dynamic cast to this interface, ensure the 'InitRcwHelper' method is called."); } } public unsafe static T GetAt(IObjectReference obj, uint index) { EnsureInitialized(); return _GetAt(obj, index); } public unsafe static uint get_Size(IObjectReference obj) { IntPtr thisPtr = obj.ThisPtr; uint result = 0u; ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)7 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(thisPtr, &result)); GC.KeepAlive(obj); return result; } public unsafe static bool IndexOf(IObjectReference obj, T value, out uint index) { EnsureInitialized(); return _IndexOf(obj, value, out index); } public unsafe static uint GetMany(IObjectReference obj, uint startIndex, ref T[] items) { if (!RuntimeFeature.IsDynamicCodeCompiled) { EnsureInitialized(); return _GetMany(obj, startIndex, items); } if (_GetMany != (delegate*)null) { return _GetMany(obj, startIndex, items); } IntPtr thisPtr = obj.ThisPtr; object obj2 = null; int num = 0; IntPtr intPtr = default(IntPtr); uint result = 0u; try { obj2 = Marshaler.CreateMarshalerArray(items); (num, intPtr) = Marshaler.GetAbiArray(obj2); ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)9 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(thisPtr, startIndex, num, intPtr, &result)); GC.KeepAlive(obj); items = Marshaler.FromAbiArray((num, intPtr)); return result; } finally { Marshaler.DisposeMarshalerArray(obj2); } } } } namespace ABI.Microsoft.UI.Xaml.Data { [Guid("D026DD64-5F26-5F15-A86A-0DEC8A431796")] internal struct IDataErrorsChangedEventArgsVftbl { internal IInspectable.Vftbl IInspectableVftbl; private unsafe void* _get_PropertyName_0; private unsafe void* _put_PropertyName_1; public unsafe delegate* unmanaged[Stdcall] get_PropertyName_0 => (delegate* unmanaged[Stdcall])_get_PropertyName_0; public unsafe delegate* unmanaged[Stdcall] put_PropertyName_1 => (delegate* unmanaged[Stdcall])_put_PropertyName_1; } [Guid("62D0BD1E-B85F-5FCC-842A-7CB0DDA37FE5")] internal sealed class WinRTDataErrorsChangedEventArgsRuntimeClassFactory { [Guid("62D0BD1E-B85F-5FCC-842A-7CB0DDA37FE5")] public struct Vftbl { internal IInspectable.Vftbl IInspectableVftbl; private unsafe void* _CreateInstance_0; public unsafe delegate* unmanaged[Stdcall] CreateInstance_0 => (delegate* unmanaged[Stdcall])_CreateInstance_0; } private readonly ObjectReference _obj; public IntPtr ThisPtr => _obj.ThisPtr; public static ObjectReference FromAbi(IntPtr thisPtr) { return ObjectReference.FromAbi(thisPtr, IID.IID_DataErrorsChangedEventArgsRuntimeClassFactory); } public WinRTDataErrorsChangedEventArgsRuntimeClassFactory(IObjectReference obj) : this(obj.As(IID.IID_DataErrorsChangedEventArgsRuntimeClassFactory)) { } public WinRTDataErrorsChangedEventArgsRuntimeClassFactory(ObjectReference obj) { _obj = obj; } public unsafe IObjectReference CreateInstance(string name) { IntPtr thisPtr = default(IntPtr); try { MarshalString.Pinnable p = new MarshalString.Pinnable(name); fixed (char* ptr = p) { void* ptr2 = ptr; ExceptionHelpers.ThrowExceptionForHR(_obj.Vftbl.CreateInstance_0(ThisPtr, MarshalString.GetAbi(ref p), &thisPtr)); GC.KeepAlive(_obj); return ObjectReference.Attach(ref thisPtr, IID.IID_IUnknown); } } finally { MarshalInspectable.DisposeAbi(thisPtr); } } public unsafe ObjectReferenceValue CreateInstanceForMarshaling(string name) { IntPtr ptr = default(IntPtr); MarshalString.Pinnable p = new MarshalString.Pinnable(name); fixed (char* ptr2 = p) { void* ptr3 = ptr2; ExceptionHelpers.ThrowExceptionForHR(_obj.Vftbl.CreateInstance_0(ThisPtr, MarshalString.GetAbi(ref p), &ptr)); GC.KeepAlive(_obj); return new ObjectReferenceValue(ptr); } } } [Guid("30DA92C0-23E8-42A0-AE7C-734A0E5D2782")] internal interface ICustomProperty { static readonly IntPtr AbiToProjectionVftablePtr; static Guid IID => global::WinRT.Interop.IID.IID_ICustomProperty; unsafe static ICustomProperty() { AbiToProjectionVftablePtr = ComWrappersSupport.AllocateVtableMemory(typeof(ICustomProperty), sizeof(IInspectable.Vftbl) + sizeof(IntPtr) * 8); *(IInspectable.Vftbl*)(void*)AbiToProjectionVftablePtr = IInspectable.Vftbl.AbiToProjectionVftable; *(IntPtr*)((byte*)(void*)AbiToProjectionVftablePtr + (nint)6 * (nint)sizeof(delegate* unmanaged)) = (nint)(delegate*)(&Do_Abi_get_Type_0); *(IntPtr*)((byte*)(void*)AbiToProjectionVftablePtr + (nint)7 * (nint)sizeof(delegate* unmanaged)) = (nint)(delegate*)(&Do_Abi_get_Name_1); *(IntPtr*)((byte*)(void*)AbiToProjectionVftablePtr + (nint)8 * (nint)sizeof(delegate* unmanaged)) = (nint)(delegate*)(&Do_Abi_GetValue_2); *(IntPtr*)((byte*)(void*)AbiToProjectionVftablePtr + (nint)9 * (nint)sizeof(delegate* unmanaged)) = (nint)(delegate*)(&Do_Abi_SetValue_3); *(IntPtr*)((byte*)(void*)AbiToProjectionVftablePtr + (nint)10 * (nint)sizeof(delegate* unmanaged)) = (nint)(delegate*)(&Do_Abi_GetIndexedValue_4); *(IntPtr*)((byte*)(void*)AbiToProjectionVftablePtr + (nint)11 * (nint)sizeof(delegate* unmanaged)) = (nint)(delegate*)(&Do_Abi_SetIndexedValue_5); *(IntPtr*)((byte*)(void*)AbiToProjectionVftablePtr + (nint)12 * (nint)sizeof(delegate* unmanaged)) = (nint)(delegate*)(&Do_Abi_get_CanWrite_6); *(IntPtr*)((byte*)(void*)AbiToProjectionVftablePtr + (nint)13 * (nint)sizeof(delegate* unmanaged)) = (nint)(delegate*)(&Do_Abi_get_CanRead_7); } [UnmanagedCallersOnly] private unsafe static int Do_Abi_GetValue_2(IntPtr thisPtr, IntPtr target, IntPtr* result) { object obj = null; *result = default(IntPtr); try { obj = ComWrappersSupport.FindObject(thisPtr).GetValue(MarshalInspectable.FromAbi(target)); *result = MarshalInspectable.FromManaged(obj); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly] private static int Do_Abi_SetValue_3(IntPtr thisPtr, IntPtr target, IntPtr value) { try { ComWrappersSupport.FindObject(thisPtr).SetValue(MarshalInspectable.FromAbi(target), MarshalInspectable.FromAbi(value)); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_GetIndexedValue_4(IntPtr thisPtr, IntPtr target, IntPtr index, IntPtr* result) { object obj = null; try { obj = ComWrappersSupport.FindObject(thisPtr).GetIndexedValue(MarshalInspectable.FromAbi(target), MarshalInspectable.FromAbi(index)); *result = MarshalInspectable.FromManaged(obj); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly] private static int Do_Abi_SetIndexedValue_5(IntPtr thisPtr, IntPtr target, IntPtr value, IntPtr index) { try { ComWrappersSupport.FindObject(thisPtr).SetIndexedValue(MarshalInspectable.FromAbi(target), MarshalInspectable.FromAbi(value), MarshalInspectable.FromAbi(index)); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_get_CanRead_7(IntPtr thisPtr, byte* value) { bool flag = false; try { flag = ComWrappersSupport.FindObject(thisPtr).CanRead; *value = (flag ? ((byte)1) : ((byte)0)); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_get_CanWrite_6(IntPtr thisPtr, byte* value) { bool flag = false; try { flag = ComWrappersSupport.FindObject(thisPtr).CanWrite; *value = (flag ? ((byte)1) : ((byte)0)); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_get_Name_1(IntPtr thisPtr, IntPtr* value) { string text = null; try { text = ComWrappersSupport.FindObject(thisPtr).Name; *value = MarshalString.FromManaged(text); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_get_Type_0(IntPtr thisPtr, ABI.System.Type* value) { global::System.Type type = null; try { type = ComWrappersSupport.FindObject(thisPtr).Type; *value = ABI.System.Type.FromManaged(type); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } } internal static class ICustomProperty_Delegates { public unsafe delegate int get_Type_0(IntPtr thisPtr, ABI.System.Type* value); public unsafe delegate int get_Name_1(IntPtr thisPtr, IntPtr* value); public unsafe delegate int GetValue_2(IntPtr thisPtr, IntPtr target, IntPtr* result); public delegate int SetValue_3(IntPtr thisPtr, IntPtr target, IntPtr value); public unsafe delegate int GetIndexedValue_4(IntPtr thisPtr, IntPtr target, IntPtr index, IntPtr* result); public delegate int SetIndexedValue_5(IntPtr thisPtr, IntPtr target, IntPtr value, IntPtr index); public unsafe delegate int get_CanWrite_6(IntPtr thisPtr, byte* value); public unsafe delegate int get_CanRead_7(IntPtr thisPtr, byte* value); } internal sealed class ManagedCustomPropertyWinRTTypeDetails : IWinRTExposedTypeDetails { public ComWrappers.ComInterfaceEntry[] GetExposedInterfaces() { return new ComWrappers.ComInterfaceEntry[1] { new ComWrappers.ComInterfaceEntry { IID = ICustomProperty.IID, Vtable = ICustomProperty.AbiToProjectionVftablePtr } }; } } [WinRTExposedType(typeof(ManagedCustomPropertyWinRTTypeDetails))] internal sealed class ManagedCustomProperty : global::Microsoft.UI.Xaml.Data.ICustomProperty { private readonly PropertyInfo _property; public bool CanRead => _property.CanRead; public bool CanWrite => _property.CanWrite; public string Name => _property.Name; public global::System.Type Type => _property.PropertyType; public ManagedCustomProperty(PropertyInfo property) { _property = property; } public object GetIndexedValue(object target, object index) { return _property.GetValue(target, new object[1] { index }); } public object GetValue(object target) { return _property.GetValue(target); } public void SetIndexedValue(object target, object value, object index) { _property.SetValue(target, value, new object[1] { index }); } public void SetValue(object target, object value) { _property.SetValue(target, value); } } [Guid("7C925755-3E48-42B4-8677-76372267033F")] internal struct ManagedCustomPropertyProviderVftbl { internal IInspectable.Vftbl IInspectableVftbl; private unsafe void* GetCustomProperty_0; private unsafe void* GetIndexedProperty_1; private unsafe void* GetStringRepresentation_2; private unsafe void* get_Type_3; private static readonly ManagedCustomPropertyProviderVftbl AbiToProjectionVftable; public static readonly IntPtr AbiToProjectionVftablePtr; unsafe static ManagedCustomPropertyProviderVftbl() { AbiToProjectionVftable = new ManagedCustomPropertyProviderVftbl { IInspectableVftbl = IInspectable.Vftbl.AbiToProjectionVftable, GetCustomProperty_0 = (delegate*)(&Do_Abi_GetCustomProperty_0), GetIndexedProperty_1 = (delegate*)(&Do_Abi_GetIndexedProperty_1), GetStringRepresentation_2 = (delegate*)(&Do_Abi_GetStringRepresentation_2), get_Type_3 = (delegate*)(&Do_Abi_get_Type_3) }; IntPtr* ptr = (IntPtr*)(void*)ComWrappersSupport.AllocateVtableMemory(typeof(ManagedCustomPropertyProviderVftbl), sizeof(IInspectable.Vftbl) + sizeof(IntPtr) * 4); *(ManagedCustomPropertyProviderVftbl*)ptr = AbiToProjectionVftable; AbiToProjectionVftablePtr = (IntPtr)ptr; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_GetCustomProperty_0(IntPtr thisPtr, IntPtr name, IntPtr* result) { global::Microsoft.UI.Xaml.Data.ICustomProperty customProperty = null; try { string text = MarshalString.FromAbi(name); object obj = ComWrappersSupport.FindObject(thisPtr); if (obj is IBindableCustomPropertyImplementation bindableCustomPropertyImplementation) { customProperty = bindableCustomPropertyImplementation.GetProperty(text); *result = MarshalInterface.FromManaged(customProperty); return 0; } if (!RuntimeFeature.IsDynamicCodeCompiled) { throw new NotSupportedException($"ICustomProperty support used by XAML binding for type '{obj.GetType()}' (property '{text}') requires the type to marked with 'WinRT.GeneratedBindableCustomPropertyAttribute'. If this is a built-in type or a type that can't be marked, a wrapper type should be used around it that is marked to enable this support."); } GetCustomPropertyForJit(obj, text, result); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; [MethodImpl(MethodImplOptions.NoInlining)] [UnconditionalSuppressMessage("Trimming", "IL2075", Justification = "Fallback method for JIT environments that is not trim-safe by design.")] static unsafe void GetCustomPropertyForJit(object target, string name2, IntPtr* ptr) { global::Microsoft.UI.Xaml.Data.ICustomProperty value = null; PropertyInfo property = target.GetType().GetProperty(name2, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public); if ((object)property != null) { value = new ManagedCustomProperty(property); } *ptr = MarshalInterface.FromManaged(value); } } [UnmanagedCallersOnly] private unsafe static int Do_Abi_GetIndexedProperty_1(IntPtr thisPtr, IntPtr name, ABI.System.Type type, IntPtr* result) { global::Microsoft.UI.Xaml.Data.ICustomProperty customProperty = null; try { global::System.Type type2 = ABI.System.Type.FromAbi(type); object obj = ComWrappersSupport.FindObject(thisPtr); if (obj is IBindableCustomPropertyImplementation bindableCustomPropertyImplementation) { customProperty = bindableCustomPropertyImplementation.GetProperty(type2); *result = MarshalInterface.FromManaged(customProperty); return 0; } if (!RuntimeFeature.IsDynamicCodeCompiled) { throw new NotSupportedException($"ICustomProperty support used by XAML binding for type '{obj.GetType()}' (indexer with parameter of type '{type2}') requires the type to marked with 'WinRT.GeneratedBindableCustomPropertyAttribute'. If this is a built-in type or a type that can't be marked, a wrapper type should be used around it that is marked to enable this support."); } string name2 = MarshalString.FromAbi(name); GetCustomPropertyForJit(obj, name2, type2, result); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; [MethodImpl(MethodImplOptions.NoInlining)] [UnconditionalSuppressMessage("Trimming", "IL2075", Justification = "Fallback method for JIT environments that is not trim-safe by design.")] static unsafe void GetCustomPropertyForJit(object target, string name3, global::System.Type type3, IntPtr* ptr) { global::Microsoft.UI.Xaml.Data.ICustomProperty value = null; PropertyInfo property = target.GetType().GetProperty(name3, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public, null, null, new global::System.Type[1] { type3 }, null); if ((object)property != null) { value = new ManagedCustomProperty(property); } *ptr = MarshalInterface.FromManaged(value); } } [UnmanagedCallersOnly] private unsafe static int Do_Abi_GetStringRepresentation_2(IntPtr thisPtr, IntPtr* result) { string text = null; try { text = ComWrappersSupport.FindObject(thisPtr).ToString(); *result = MarshalString.FromManaged(text); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_get_Type_3(IntPtr thisPtr, ABI.System.Type* value) { global::System.Type type = null; try { type = ComWrappersSupport.FindObject(thisPtr).GetType(); *value = ABI.System.Type.FromManaged(type); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } } internal sealed class PropertyChangedEventArgsRuntimeClassFactory { private readonly IObjectReference _obj; public PropertyChangedEventArgsRuntimeClassFactory() { _obj = (FeatureSwitches.UseWindowsUIXamlProjections ? ActivationFactory.Get("Windows.UI.Xaml.Data.PropertyChangedEventArgs", IID.IID_WUX_PropertyChangedEventArgsRuntimeClassFactory) : ActivationFactory.Get("Microsoft.UI.Xaml.Data.PropertyChangedEventArgs", IID.IID_MUX_PropertyChangedEventArgsRuntimeClassFactory)); } public unsafe IObjectReference CreateInstance(string name, object baseInterface, out IObjectReference innerInterface) { IObjectReference objRef = null; IntPtr intPtr = default(IntPtr); IntPtr thisPtr = default(IntPtr); try { MarshalString.Pinnable p = new MarshalString.Pinnable(name); fixed (char* ptr = p) { void* ptr2 = ptr; objRef = MarshalInspectable.CreateMarshaler(baseInterface); IntPtr thisPtr2 = _obj.ThisPtr; ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr2) + (nint)6 * (nint)sizeof(void*))))(thisPtr2, MarshalString.GetAbi(ref p), MarshalInspectable.GetAbi(objRef), &intPtr, &thisPtr)); GC.KeepAlive(_obj); innerInterface = ObjectReference.FromAbi(intPtr, IID.IID_IUnknown); return ObjectReference.Attach(ref thisPtr, IID.IID_IUnknown); } } finally { MarshalInspectable.DisposeMarshaler(objRef); MarshalInspectable.DisposeAbi(intPtr); MarshalInspectable.DisposeAbi(thisPtr); } } public unsafe ObjectReferenceValue CreateInstance(string name) { IntPtr ptr = default(IntPtr); IntPtr ptr2 = default(IntPtr); try { MarshalString.Pinnable p = new MarshalString.Pinnable(name); fixed (char* ptr3 = p) { void* ptr4 = ptr3; IntPtr thisPtr = _obj.ThisPtr; ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)6 * (nint)sizeof(void*))))(thisPtr, MarshalString.GetAbi(ref p), IntPtr.Zero, &ptr, &ptr2)); GC.KeepAlive(_obj); return new ObjectReferenceValue(ptr2); } } finally { MarshalInspectable.DisposeAbi(ptr); } } } } namespace ABI.Microsoft.UI.Xaml.Interop { [DynamicInterfaceCastableImplementation] [Guid("036D2C08-DF29-41AF-8AA2-D774BE62BA6F")] internal interface IBindableIterable : global::Microsoft.UI.Xaml.Interop.IBindableIterable, ABI.System.Collections.IEnumerable, global::System.Collections.IEnumerable { } [DynamicInterfaceCastableImplementation] [Guid("6A1D6C07-076D-49F2-8314-F52C9C9A8331")] internal interface IBindableIterator : global::Microsoft.UI.Xaml.Interop.IBindableIterator { static readonly IntPtr AbiToProjectionVftablePtr; unsafe object global::Microsoft.UI.Xaml.Interop.IBindableIterator.Current { get { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Microsoft.UI.Xaml.Interop.IBindableIterator).TypeHandle); IntPtr thisPtr = objectReferenceForType.ThisPtr; IntPtr ptr = default(IntPtr); try { ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)6 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(thisPtr, &ptr)); GC.KeepAlive(objectReferenceForType); return MarshalInspectable.FromAbi(ptr); } finally { MarshalInspectable.DisposeAbi(ptr); } } } unsafe bool global::Microsoft.UI.Xaml.Interop.IBindableIterator.HasCurrent { get { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Microsoft.UI.Xaml.Interop.IBindableIterator).TypeHandle); IntPtr thisPtr = objectReferenceForType.ThisPtr; byte b = 0; ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)7 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(thisPtr, &b)); GC.KeepAlive(objectReferenceForType); return b != 0; } } unsafe static IBindableIterator() { AbiToProjectionVftablePtr = ComWrappersSupport.AllocateVtableMemory(typeof(IBindableIterator), sizeof(IInspectable.Vftbl) + sizeof(IntPtr) * 4); *(IInspectable.Vftbl*)(void*)AbiToProjectionVftablePtr = IInspectable.Vftbl.AbiToProjectionVftable; *(IntPtr*)((byte*)(void*)AbiToProjectionVftablePtr + (nint)6 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)(delegate*)(&Do_Abi_get_Current_0); *(IntPtr*)((byte*)(void*)AbiToProjectionVftablePtr + (nint)7 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)(delegate*)(&Do_Abi_get_HasCurrent_1); *(IntPtr*)((byte*)(void*)AbiToProjectionVftablePtr + (nint)8 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)(delegate*)(&Do_Abi_MoveNext_2); *(IntPtr*)((byte*)(void*)AbiToProjectionVftablePtr + (nint)9 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)(delegate*)(&Do_Abi_GetMany_3); } [UnmanagedCallersOnly(CallConvs = new global::System.Type[] { typeof(CallConvStdcall) })] private unsafe static int Do_Abi_MoveNext_2(IntPtr thisPtr, byte* result) { bool flag = false; *result = 0; try { flag = ComWrappersSupport.FindObject(thisPtr).MoveNext(); *result = (flag ? ((byte)1) : ((byte)0)); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly(CallConvs = new global::System.Type[] { typeof(CallConvStdcall) })] private unsafe static int Do_Abi_GetMany_3(IntPtr thisPtr, int __itemsSize, IntPtr items, uint* result) { *result = 0u; try { throw new NotImplementedException(); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } } [UnmanagedCallersOnly(CallConvs = new global::System.Type[] { typeof(CallConvStdcall) })] private unsafe static int Do_Abi_get_Current_0(IntPtr thisPtr, IntPtr* value) { object obj = null; *value = default(IntPtr); try { obj = ComWrappersSupport.FindObject(thisPtr).Current; *value = MarshalInspectable.FromManaged(obj); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly(CallConvs = new global::System.Type[] { typeof(CallConvStdcall) })] private unsafe static int Do_Abi_get_HasCurrent_1(IntPtr thisPtr, byte* value) { bool flag = false; *value = 0; try { flag = ComWrappersSupport.FindObject(thisPtr).HasCurrent; *value = (flag ? ((byte)1) : ((byte)0)); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } internal static ObjectReference FromAbi(IntPtr thisPtr) { return ObjectReference.FromAbi(thisPtr, IID.IID_IUnknown); } unsafe bool global::Microsoft.UI.Xaml.Interop.IBindableIterator.MoveNext() { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Microsoft.UI.Xaml.Interop.IBindableIterator).TypeHandle); IntPtr thisPtr = objectReferenceForType.ThisPtr; byte b = 0; ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)8 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(thisPtr, &b)); GC.KeepAlive(objectReferenceForType); return b != 0; } uint global::Microsoft.UI.Xaml.Interop.IBindableIterator.GetMany(ref object[] items) { throw new NotImplementedException(); } } [EditorBrowsable(EditorBrowsableState.Never)] internal static class IBindableIterator_Delegates { public unsafe delegate int get_Current_0(IntPtr thisPtr, IntPtr* result); public unsafe delegate int get_HasCurrent_1(IntPtr thisPtr, byte* result); public unsafe delegate int MoveNext_2(IntPtr thisPtr, byte* result); public unsafe delegate int GetMany_3(IntPtr thisPtr, int itemSize, IntPtr items, uint* result); } [DynamicInterfaceCastableImplementation] [Guid("346DD6E7-976E-4BC3-815D-ECE243BC0F33")] internal interface IBindableVectorView : global::Microsoft.UI.Xaml.Interop.IBindableVectorView, global::System.Collections.IEnumerable { static readonly IntPtr AbiToProjectionVftablePtr; private static readonly ConditionalWeakTable _helperTable; unsafe uint global::Microsoft.UI.Xaml.Interop.IBindableVectorView.Size { get { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Microsoft.UI.Xaml.Interop.IBindableIterator).TypeHandle); IntPtr thisPtr = objectReferenceForType.ThisPtr; uint result = 0u; ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)7 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(thisPtr, &result)); GC.KeepAlive(objectReferenceForType); return result; } } unsafe static IBindableVectorView() { _helperTable = new ConditionalWeakTable(); AbiToProjectionVftablePtr = ComWrappersSupport.AllocateVtableMemory(typeof(IBindableVectorView), sizeof(IInspectable.Vftbl) + sizeof(IntPtr) * 3); *(IInspectable.Vftbl*)(void*)AbiToProjectionVftablePtr = IInspectable.Vftbl.AbiToProjectionVftable; *(IntPtr*)((byte*)(void*)AbiToProjectionVftablePtr + (nint)6 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)(delegate*)(&Do_Abi_GetAt_0); *(IntPtr*)((byte*)(void*)AbiToProjectionVftablePtr + (nint)7 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)(delegate*)(&Do_Abi_get_Size_1); *(IntPtr*)((byte*)(void*)AbiToProjectionVftablePtr + (nint)8 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)(delegate*)(&Do_Abi_IndexOf_2); } [UnmanagedCallersOnly(CallConvs = new global::System.Type[] { typeof(CallConvStdcall) })] private unsafe static int Do_Abi_GetAt_0(IntPtr thisPtr, uint index, IntPtr* result) { object obj = null; try { obj = ComWrappersSupport.FindObject(thisPtr).GetAt(index); *result = MarshalInspectable.FromManaged(obj); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly(CallConvs = new global::System.Type[] { typeof(CallConvStdcall) })] private unsafe static int Do_Abi_IndexOf_2(IntPtr thisPtr, IntPtr value, uint* index, byte* returnValue) { bool flag = false; *index = 0u; *returnValue = 0; uint index2 = 0u; try { flag = ComWrappersSupport.FindObject(thisPtr).IndexOf(MarshalInspectable.FromAbi(value), out index2); *index = index2; *returnValue = (flag ? ((byte)1) : ((byte)0)); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly(CallConvs = new global::System.Type[] { typeof(CallConvStdcall) })] private unsafe static int Do_Abi_get_Size_1(IntPtr thisPtr, uint* value) { uint num = 0u; *value = 0u; try { num = ComWrappersSupport.FindObject(thisPtr).Size; *value = num; } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } internal static ObjectReference FromAbi(IntPtr thisPtr) { return ObjectReference.FromAbi(thisPtr, IID.IID_IBindableVectorView); } unsafe object global::Microsoft.UI.Xaml.Interop.IBindableVectorView.GetAt(uint index) { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Microsoft.UI.Xaml.Interop.IBindableIterator).TypeHandle); IntPtr thisPtr = objectReferenceForType.ThisPtr; IntPtr ptr = default(IntPtr); try { ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)6 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(thisPtr, index, &ptr)); GC.KeepAlive(objectReferenceForType); return MarshalInspectable.FromAbi(ptr); } finally { MarshalInspectable.DisposeAbi(ptr); } } unsafe bool global::Microsoft.UI.Xaml.Interop.IBindableVectorView.IndexOf(object value, out uint index) { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Microsoft.UI.Xaml.Interop.IBindableIterator).TypeHandle); IntPtr thisPtr = objectReferenceForType.ThisPtr; ObjectReferenceValue value2 = default(ObjectReferenceValue); uint num = 0u; byte b = 0; try { value2 = MarshalInspectable.CreateMarshaler2(value); ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)8 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(thisPtr, MarshalInspectable.GetAbi(value2), &num, &b)); GC.KeepAlive(objectReferenceForType); index = num; return b != 0; } finally { MarshalInspectable.DisposeMarshaler(value2); } } IEnumerator global::System.Collections.IEnumerable.GetEnumerator() { return _helperTable.GetValue((IWinRTObject)this, (IWinRTObject enumerable) => new ABI.System.Collections.IEnumerable.FromAbiHelper((global::System.Collections.IEnumerable)enumerable)).GetEnumerator(); } } [EditorBrowsable(EditorBrowsableState.Never)] internal static class IBindableVectorView_Delegates { public unsafe delegate int GetAt_0(IntPtr thisPtr, uint index, IntPtr* result); public unsafe delegate int get_Size_1(IntPtr thisPtr, uint* result); public unsafe delegate int IndexOf_2(IntPtr thisPtr, IntPtr value, uint* index, byte* returnValue); } [Guid("5108EBA4-4892-5A20-8374-A96815E0FD27")] internal sealed class WinRTNotifyCollectionChangedEventArgsRuntimeClassFactory { private readonly IObjectReference _obj; public static readonly WinRTNotifyCollectionChangedEventArgsRuntimeClassFactory Instance = new WinRTNotifyCollectionChangedEventArgsRuntimeClassFactory(); public IntPtr ThisPtr => _obj.ThisPtr; private WinRTNotifyCollectionChangedEventArgsRuntimeClassFactory() { _obj = (FeatureSwitches.UseWindowsUIXamlProjections ? ActivationFactory.Get("Windows.UI.Xaml.Interop.NotifyCollectionChangedEventArgs", IID.IID_WUX_INotifyCollectionChangedEventArgsFactory) : ActivationFactory.Get("Microsoft.UI.Xaml.Interop.NotifyCollectionChangedEventArgs", IID.IID_MUX_INotifyCollectionChangedEventArgsFactory)); } public unsafe ObjectReferenceValue CreateInstanceWithAllParameters(global::System.Collections.Specialized.NotifyCollectionChangedAction action, global::System.Collections.IList newItems, global::System.Collections.IList oldItems, int newIndex, int oldIndex) { ObjectReferenceValue value = default(ObjectReferenceValue); ObjectReferenceValue value2 = default(ObjectReferenceValue); IntPtr ptr = default(IntPtr); IntPtr ptr2 = default(IntPtr); try { value = MarshalInterface.CreateMarshaler2(newItems, IListMethods.IID); value2 = MarshalInterface.CreateMarshaler2(oldItems, IListMethods.IID); ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)ThisPtr) + (nint)6 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(ThisPtr, action, MarshalInterface.GetAbi(value), MarshalInterface.GetAbi(value2), newIndex, oldIndex, IntPtr.Zero, &ptr, &ptr2)); GC.KeepAlive(_obj); return new ObjectReferenceValue(ptr2); } finally { value.Dispose(); value2.Dispose(); MarshalInspectable.DisposeAbi(ptr); } } } } namespace ABI.System { internal static class NonBlittableMarshallingStubs { public static readonly Action NoOpFunc = NoOp; public static object Boolean_CreateMarshaler(bool value) { return Boolean.CreateMarshaler(value); } public static object Boolean_GetAbi(object value) { return Boolean.GetAbi((bool)value); } public static bool Boolean_FromAbi(object abi) { return Boolean.FromAbi((byte)abi); } public static void Boolean_CopyAbi(object value, IntPtr dest) { Boolean.CopyAbi((bool)value, dest); } public static object Boolean_FromManaged(bool value) { return Boolean.FromManaged(value); } public static object Char_CreateMarshaler(char value) { return Char.CreateMarshaler(value); } public static object Char_GetAbi(object value) { return Char.GetAbi((char)value); } public static char Char_FromAbi(object abi) { return Char.FromAbi((ushort)abi); } public static void Char_CopyAbi(object value, IntPtr dest) { Char.CopyAbi((char)value, dest); } public static object Char_FromManaged(char value) { return Char.FromManaged(value); } public static object TimeSpan_CreateMarshaler(global::System.TimeSpan value) { return TimeSpan.CreateMarshaler(value); } public static object TimeSpan_GetAbi(object value) { return TimeSpan.GetAbi((TimeSpan.Marshaler)value); } public static global::System.TimeSpan TimeSpan_FromAbi(object abi) { return TimeSpan.FromAbi((TimeSpan)abi); } public static void TimeSpan_CopyAbi(object value, IntPtr dest) { TimeSpan.CopyAbi((TimeSpan.Marshaler)value, dest); } public static object TimeSpan_FromManaged(global::System.TimeSpan value) { return TimeSpan.FromManaged(value); } public static object DateTimeOffset_CreateMarshaler(global::System.DateTimeOffset value) { return DateTimeOffset.CreateMarshaler(value); } public static object DateTimeOffset_GetAbi(object value) { return DateTimeOffset.GetAbi((DateTimeOffset.Marshaler)value); } public static global::System.DateTimeOffset DateTimeOffset_FromAbi(object abi) { return DateTimeOffset.FromAbi((DateTimeOffset)abi); } public static void DateTimeOffset_CopyAbi(object value, IntPtr dest) { DateTimeOffset.CopyAbi((DateTimeOffset.Marshaler)value, dest); } public static object DateTimeOffset_FromManaged(global::System.DateTimeOffset value) { return DateTimeOffset.FromManaged(value); } public static object Type_CreateMarshalerArray(global::System.Type[] value) { return Type.CreateMarshalerArray(value); } public static object Exception_CreateMarshalerArray(global::System.Exception[] value) { return MarshalNonBlittable.CreateMarshalerArray(value); } private static void NoOp(object obj) { } } [StructLayout(LayoutKind.Sequential, Size = 1)] internal struct Boolean { public static bool CreateMarshaler(bool value) { return value; } public static byte GetAbi(bool value) { return value ? ((byte)1) : ((byte)0); } public static bool FromAbi(byte abi) { return abi != 0; } public unsafe static void CopyAbi(bool value, IntPtr dest) { *(byte*)dest.ToPointer() = GetAbi(value); } public static byte FromManaged(bool value) { return GetAbi(value); } public unsafe static void CopyManaged(bool arg, IntPtr dest) { *(byte*)dest.ToPointer() = FromManaged(arg); } public static void DisposeMarshaler(bool m) { } public static void DisposeAbi(byte abi) { } } [StructLayout(LayoutKind.Sequential, Size = 1)] internal struct Char { public static char CreateMarshaler(char value) { return value; } public static ushort GetAbi(char value) { return value; } public static char FromAbi(ushort abi) { return (char)abi; } public unsafe static void CopyAbi(char value, IntPtr dest) { *(ushort*)dest.ToPointer() = GetAbi(value); } public static ushort FromManaged(char value) { return GetAbi(value); } public unsafe static void CopyManaged(char arg, IntPtr dest) { *(ushort*)dest.ToPointer() = FromManaged(arg); } public static void DisposeMarshaler(char m) { } public static void DisposeAbi(ushort abi) { } } internal static class EventHandlerMethods { internal unsafe static volatile delegate* _Invoke; private static IntPtr abiToProjectionVftablePtr; internal static IntPtr AbiToProjectionVftablePtr => abiToProjectionVftablePtr; internal static bool TryInitCCWVtable(IntPtr ptr) { bool flag = Interlocked.CompareExchange(ref abiToProjectionVftablePtr, ptr, IntPtr.Zero) == IntPtr.Zero; if (flag) { EventHandler.AbiToProjectionVftablePtr = abiToProjectionVftablePtr; ComWrappersSupport.RegisterComInterfaceEntries(typeof(global::System.EventHandler), DelegateTypeDetails>.GetExposedInterfaces(new ComWrappers.ComInterfaceEntry { IID = EventHandler.PIID, Vtable = abiToProjectionVftablePtr })); } return flag; } } public static class EventHandlerMethods where TAbi : unmanaged { public unsafe static bool InitRcwHelper(delegate* invoke) { if (EventHandlerMethods._Invoke == (delegate*)null) { EventHandlerMethods._Invoke = invoke; } return true; } public unsafe static bool InitCcw(delegate* unmanaged[Stdcall] invoke) { if (EventHandlerMethods.AbiToProjectionVftablePtr != (IntPtr)0) { return false; } IntPtr intPtr = (IntPtr)NativeMemory.AllocZeroed((nuint)(sizeof(IUnknownVftbl) + sizeof(IntPtr))); *(IUnknownVftbl*)(void*)intPtr = IUnknownVftbl.AbiToProjectionVftbl; *(IntPtr*)((byte*)(void*)intPtr + (nint)3 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)invoke; if (!EventHandlerMethods.TryInitCCWVtable(intPtr)) { NativeMemory.Free((void*)intPtr); return false; } return true; } public static void Abi_Invoke(IntPtr thisPtr, object sender, T args) { global::System.EventHandler eventHandler = ComWrappersSupport.FindObject>(thisPtr); eventHandler(sender, args); } } [Guid("9DE1C535-6AE1-11E0-84E1-18A905BCC53F")] [EditorBrowsable(EditorBrowsableState.Never)] public static class EventHandler { private sealed class NativeDelegateWrapper : IWinRTObject, IDynamicInterfaceCastable { private readonly ObjectReference _nativeDelegate; private volatile ConcurrentDictionary _queryInterfaceCache; private volatile ConcurrentDictionary _additionalTypeData; IObjectReference IWinRTObject.NativeObject => _nativeDelegate; bool IWinRTObject.HasUnwrappableNativeObject => true; ConcurrentDictionary IWinRTObject.QueryInterfaceCache => _queryInterfaceCache ?? MakeQueryInterfaceCache(); ConcurrentDictionary IWinRTObject.AdditionalTypeData => _additionalTypeData ?? MakeAdditionalTypeData(); public NativeDelegateWrapper(ObjectReference nativeDelegate) { _nativeDelegate = nativeDelegate; } private ConcurrentDictionary MakeQueryInterfaceCache() { Interlocked.CompareExchange(ref _queryInterfaceCache, new ConcurrentDictionary(), null); return _queryInterfaceCache; } private ConcurrentDictionary MakeAdditionalTypeData() { Interlocked.CompareExchange(ref _additionalTypeData, new ConcurrentDictionary(), null); return _additionalTypeData; } public unsafe void Invoke(object sender, T args) { if (!RuntimeFeature.IsDynamicCodeCompiled) { EventHandlerMethods._Invoke(_nativeDelegate, sender, args); return; } if (EventHandlerMethods._Invoke != (delegate*)null) { EventHandlerMethods._Invoke(_nativeDelegate, sender, args); return; } if ((object)Volatile.Read(in EventHandler._abi_invoke_type) == null) { Interlocked.CompareExchange(ref EventHandler._abi_invoke_type, Projections.GetAbiDelegateType(typeof(void*), typeof(IntPtr), Marshaler.AbiType, typeof(int)), null); } IntPtr thisPtr = _nativeDelegate.ThisPtr; Delegate delegateForFunctionPointer = Marshal.GetDelegateForFunctionPointer(_nativeDelegate.Vftbl.Invoke, EventHandler._abi_invoke_type); ObjectReferenceValue value = default(ObjectReferenceValue); object obj = null; object[] array = new object[3] { thisPtr, null, null }; try { value = MarshalInspectable.CreateMarshaler2(sender); array[1] = MarshalInspectable.GetAbi(value); obj = Marshaler.CreateMarshaler2(args); array[2] = Marshaler.GetAbi(obj); delegateForFunctionPointer.DynamicInvokeAbi(array); GC.KeepAlive(_nativeDelegate); GC.KeepAlive(array); } finally { MarshalInspectable.DisposeMarshaler(value); Marshaler.DisposeMarshaler(obj); } } } public static readonly Guid PIID; private static global::System.Type _abi_invoke_type; public static IntPtr AbiToProjectionVftablePtr; public static Guid IID => PIID; public static Delegate AbiInvokeDelegate { get; } unsafe static EventHandler() { PIID = GuidGenerator.CreateIIDUnsafe(typeof(global::System.EventHandler)); ComWrappersSupport.RegisterHelperType(typeof(global::System.EventHandler), typeof(EventHandler)); ComWrappersSupport.RegisterDelegateFactory(typeof(global::System.EventHandler), CreateRcw); if (!RuntimeFeature.IsDynamicCodeCompiled) { AbiToProjectionVftablePtr = EventHandlerMethods.AbiToProjectionVftablePtr; return; } if (EventHandlerMethods.AbiToProjectionVftablePtr != (IntPtr)0) { AbiToProjectionVftablePtr = EventHandlerMethods.AbiToProjectionVftablePtr; return; } _abi_invoke_type = Projections.GetAbiDelegateType(typeof(void*), typeof(IntPtr), Marshaler.AbiType, typeof(int)); AbiInvokeDelegate = Delegate.CreateDelegate(_abi_invoke_type, typeof(EventHandler).GetMethod("Do_Abi_Invoke", BindingFlags.Static | BindingFlags.NonPublic).MakeGenericMethod(Marshaler.AbiType)); AbiToProjectionVftablePtr = ComWrappersSupport.AllocateVtableMemory(typeof(EventHandler), sizeof(IDelegateVftbl)); *(IUnknownVftbl*)(void*)AbiToProjectionVftablePtr = IUnknownVftbl.AbiToProjectionVftbl; ((IntPtr*)(void*)AbiToProjectionVftablePtr)[3] = Marshal.GetFunctionPointerForDelegate(AbiInvokeDelegate); } public static IObjectReference CreateMarshaler(global::System.EventHandler managedDelegate) { if (managedDelegate != null) { return MarshalDelegate.CreateMarshaler(managedDelegate, PIID); } return null; } public static ObjectReferenceValue CreateMarshaler2(global::System.EventHandler managedDelegate) { return MarshalDelegate.CreateMarshaler2(managedDelegate, PIID); } public static IntPtr GetAbi(IObjectReference value) { if (value != null) { return MarshalInterfaceHelper>.GetAbi(value); } return IntPtr.Zero; } public static global::System.EventHandler FromAbi(IntPtr nativeDelegate) { return MarshalDelegate.FromAbi>(nativeDelegate); } public static global::System.EventHandler CreateRcw(IntPtr ptr) { return new NativeDelegateWrapper(ComWrappersSupport.GetObjectReferenceForInterface(ptr, PIID)).Invoke; } public static IntPtr FromManaged(global::System.EventHandler managedDelegate) { return CreateMarshaler2(managedDelegate).Detach(); } public static void DisposeMarshaler(IObjectReference value) { MarshalInterfaceHelper>.DisposeMarshaler(value); } public static void DisposeAbi(IntPtr abi) { MarshalInterfaceHelper>.DisposeAbi(abi); } public static MarshalInterfaceHelper>.MarshalerArray CreateMarshalerArray(global::System.EventHandler[] array) { return MarshalInterfaceHelper>.CreateMarshalerArray2(array, CreateMarshaler2); } public static (int length, IntPtr data) GetAbiArray(object box) { return MarshalInterfaceHelper>.GetAbiArray(box); } public static global::System.EventHandler[] FromAbiArray(object box) { return MarshalInterfaceHelper>.FromAbiArray(box, FromAbi); } public static void CopyAbiArray(global::System.EventHandler[] array, object box) { MarshalInterfaceHelper>.CopyAbiArray(array, box, FromAbi); } public static (int length, IntPtr data) FromManagedArray(global::System.EventHandler[] array) { return MarshalInterfaceHelper>.FromManagedArray(array, FromManaged); } public static void DisposeMarshalerArray(MarshalInterfaceHelper>.MarshalerArray array) { MarshalInterfaceHelper>.DisposeMarshalerArray(array); } public static void DisposeAbiArray(object box) { MarshalInspectable.DisposeAbiArray(box); } private unsafe static int Do_Abi_Invoke(void* thisPtr, IntPtr sender, TAbi args) { try { global::System.EventHandler eventHandler = ComWrappersSupport.FindObject>(new IntPtr(thisPtr)); eventHandler(MarshalInspectable.FromAbi(sender), Marshaler.FromAbi(args)); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } } [Guid("c50898f6-c536-5f47-8583-8b2c2438a13b")] internal static class EventHandler { private sealed class NativeDelegateWrapper : IWinRTObject, IDynamicInterfaceCastable { private readonly ObjectReference _nativeDelegate; private volatile ConcurrentDictionary _queryInterfaceCache; private volatile ConcurrentDictionary _additionalTypeData; IObjectReference IWinRTObject.NativeObject => _nativeDelegate; bool IWinRTObject.HasUnwrappableNativeObject => true; ConcurrentDictionary IWinRTObject.QueryInterfaceCache => _queryInterfaceCache ?? MakeQueryInterfaceCache(); ConcurrentDictionary IWinRTObject.AdditionalTypeData => _additionalTypeData ?? MakeAdditionalTypeData(); public NativeDelegateWrapper(ObjectReference nativeDelegate) { _nativeDelegate = nativeDelegate; } private ConcurrentDictionary MakeQueryInterfaceCache() { Interlocked.CompareExchange(ref _queryInterfaceCache, new ConcurrentDictionary(), null); return _queryInterfaceCache; } private ConcurrentDictionary MakeAdditionalTypeData() { Interlocked.CompareExchange(ref _additionalTypeData, new ConcurrentDictionary(), null); return _additionalTypeData; } public unsafe void Invoke(object sender, EventArgs args) { IntPtr thisPtr = _nativeDelegate.ThisPtr; delegate* unmanaged[Stdcall] delegate* = (delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)3 * (nint)sizeof(void*))); ObjectReferenceValue value = default(ObjectReferenceValue); ObjectReferenceValue value2 = default(ObjectReferenceValue); try { value = MarshalInspectable.CreateMarshaler2(sender); value2 = MarshalInspectable.CreateMarshaler2(args); ExceptionHelpers.ThrowExceptionForHR(delegate*(thisPtr, MarshalInspectable.GetAbi(value), MarshalInspectable.GetAbi(value2))); GC.KeepAlive(_nativeDelegate); } finally { MarshalInspectable.DisposeMarshaler(value); MarshalInspectable.DisposeMarshaler(value2); } } } private static readonly IDelegateVftbl AbiToProjectionVftable; public static readonly IntPtr AbiToProjectionVftablePtr; public static Guid IID => global::WinRT.Interop.IID.IID_EventHandler; unsafe static EventHandler() { AbiToProjectionVftable = new IDelegateVftbl { IUnknownVftbl = IUnknownVftbl.AbiToProjectionVftbl, Invoke = (IntPtr)(delegate*)(&Do_Abi_Invoke) }; IntPtr intPtr = ComWrappersSupport.AllocateVtableMemory(typeof(EventHandler), sizeof(IDelegateVftbl)); *(IDelegateVftbl*)(void*)intPtr = AbiToProjectionVftable; AbiToProjectionVftablePtr = intPtr; ComWrappersSupport.RegisterDelegateFactory(typeof(global::System.EventHandler), CreateRcw); } public static IObjectReference CreateMarshaler(global::System.EventHandler managedDelegate) { if (managedDelegate != null) { return MarshalDelegate.CreateMarshaler(managedDelegate, IID); } return null; } public static ObjectReferenceValue CreateMarshaler2(global::System.EventHandler managedDelegate) { return MarshalDelegate.CreateMarshaler2(managedDelegate, IID); } public static IntPtr GetAbi(IObjectReference value) { if (value != null) { return MarshalInterfaceHelper>.GetAbi(value); } return IntPtr.Zero; } public static global::System.EventHandler FromAbi(IntPtr nativeDelegate) { return MarshalDelegate.FromAbi(nativeDelegate); } public static global::System.EventHandler CreateRcw(IntPtr ptr) { return new NativeDelegateWrapper(ComWrappersSupport.GetObjectReferenceForInterface(ptr, IID)).Invoke; } public static IntPtr FromManaged(global::System.EventHandler managedDelegate) { return CreateMarshaler2(managedDelegate).Detach(); } public static void DisposeMarshaler(IObjectReference value) { MarshalInterfaceHelper>.DisposeMarshaler(value); } public static void DisposeAbi(IntPtr abi) { MarshalInterfaceHelper>.DisposeAbi(abi); } public static MarshalInterfaceHelper.MarshalerArray CreateMarshalerArray(global::System.EventHandler[] array) { return MarshalInterfaceHelper.CreateMarshalerArray2(array, CreateMarshaler2); } public static (int length, IntPtr data) GetAbiArray(object box) { return MarshalInterfaceHelper.GetAbiArray(box); } public static global::System.EventHandler[] FromAbiArray(object box) { return MarshalInterfaceHelper.FromAbiArray(box, FromAbi); } public static void CopyAbiArray(global::System.EventHandler[] array, object box) { MarshalInterfaceHelper.CopyAbiArray(array, box, FromAbi); } public static (int length, IntPtr data) FromManagedArray(global::System.EventHandler[] array) { return MarshalInterfaceHelper.FromManagedArray(array, FromManaged); } public static void DisposeMarshalerArray(MarshalInterfaceHelper.MarshalerArray array) { MarshalInterfaceHelper.DisposeMarshalerArray(array); } public static void DisposeAbiArray(object box) { MarshalInspectable.DisposeAbiArray(box); } [UnmanagedCallersOnly(CallConvs = new global::System.Type[] { typeof(CallConvStdcall) })] private static int Do_Abi_Invoke(IntPtr thisPtr, IntPtr sender, IntPtr args) { try { global::System.EventHandler eventHandler = ComWrappersSupport.FindObject(thisPtr); eventHandler(MarshalInspectable.FromAbi(sender), (MarshalInspectable.FromAbi(args) as EventArgs) ?? EventArgs.Empty); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [SkipLocalsInit] internal static ComWrappers.ComInterfaceEntry[] GetExposedInterfaces() { Span span = stackalloc ComWrappers.ComInterfaceEntry[3]; int length = 0; span[length++] = new ComWrappers.ComInterfaceEntry { IID = IID, Vtable = AbiToProjectionVftablePtr }; if (FeatureSwitches.EnableIReferenceSupport) { span[length++] = new ComWrappers.ComInterfaceEntry { IID = global::WinRT.Interop.IID.IID_IPropertyValue, Vtable = ManagedIPropertyValueImpl.AbiToProjectionVftablePtr }; span[length++] = new ComWrappers.ComInterfaceEntry { IID = global::WinRT.Interop.IID.IID_NullableEventHandler, Vtable = Nullable_EventHandler.AbiToProjectionVftablePtr }; } return span.Slice(0, length).ToArray(); } } public static class IDisposableMethods { public static Guid IID => global::WinRT.Interop.IID.IID_IDisposable; public static IntPtr AbiToProjectionVftablePtr => IDisposable.AbiToProjectionVftablePtr; public unsafe static void Dispose(IObjectReference obj) { IntPtr thisPtr = obj.ThisPtr; ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)6 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(thisPtr)); GC.KeepAlive(obj); } } [DynamicInterfaceCastableImplementation] [EditorBrowsable(EditorBrowsableState.Never)] [Guid("30D5A829-7FA4-4026-83BB-D75BAE4EA99E")] internal interface IDisposable : global::System.IDisposable { static readonly IntPtr AbiToProjectionVftablePtr; unsafe static IDisposable() { AbiToProjectionVftablePtr = ComWrappersSupport.AllocateVtableMemory(typeof(IDisposable), sizeof(IInspectable.Vftbl) + sizeof(IntPtr)); *(IInspectable.Vftbl*)(void*)AbiToProjectionVftablePtr = IInspectable.Vftbl.AbiToProjectionVftable; *(IntPtr*)((byte*)(void*)AbiToProjectionVftablePtr + (nint)6 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)(delegate*)(&Do_Abi_Close_0); } [UnmanagedCallersOnly(CallConvs = new global::System.Type[] { typeof(CallConvStdcall) })] private static int Do_Abi_Close_0(IntPtr thisPtr) { try { ComWrappersSupport.FindObject(thisPtr).Dispose(); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } void global::System.IDisposable.Dispose() { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.IDisposable).TypeHandle); IDisposableMethods.Dispose(objectReferenceForType); } } public static class IServiceProviderMethods { public static Guid IID => global::WinRT.Interop.IID.IID_IServiceProvider; public static IntPtr AbiToProjectionVftablePtr => IServiceProvider.AbiToProjectionVftablePtr; public unsafe static object GetService(IObjectReference obj, global::System.Type type) { Type.Marshaler m = default(Type.Marshaler); IntPtr ptr = default(IntPtr); try { IntPtr thisPtr = obj.ThisPtr; m = Type.CreateMarshaler(type); ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)6 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(thisPtr, Type.GetAbi(m), &ptr)); GC.KeepAlive(obj); return MarshalInspectable.FromAbi(ptr); } finally { Type.DisposeMarshaler(m); MarshalInspectable.DisposeAbi(ptr); } } } [EditorBrowsable(EditorBrowsableState.Never)] [Guid("68B3A2DF-8173-539F-B524-C8A2348F5AFB")] [DynamicInterfaceCastableImplementation] internal interface IServiceProvider : global::System.IServiceProvider { static readonly IntPtr AbiToProjectionVftablePtr; unsafe static IServiceProvider() { AbiToProjectionVftablePtr = ComWrappersSupport.AllocateVtableMemory(typeof(IServiceProvider), sizeof(IInspectable.Vftbl) + sizeof(IntPtr)); *(IInspectable.Vftbl*)(void*)AbiToProjectionVftablePtr = IInspectable.Vftbl.AbiToProjectionVftable; *(IntPtr*)((byte*)(void*)AbiToProjectionVftablePtr + (nint)6 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)(delegate*)(&Do_Abi_GetService_0); } [UnmanagedCallersOnly(CallConvs = new global::System.Type[] { typeof(CallConvStdcall) })] private unsafe static int Do_Abi_GetService_0(IntPtr thisPtr, Type type, IntPtr* result) { object obj = null; *result = default(IntPtr); try { obj = ComWrappersSupport.FindObject(thisPtr).GetService(Type.FromAbi(type)); *result = MarshalInspectable.FromManaged(obj); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } object global::System.IServiceProvider.GetService(global::System.Type type) { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.IServiceProvider).TypeHandle); return IServiceProviderMethods.GetService(objectReferenceForType, type); } } internal static class IXamlServiceProvider_Delegates { public unsafe delegate int GetService_0(IntPtr thisPtr, Type type, IntPtr* result); } [Guid("61C17706-2D65-11E0-9AE8-D48564015472")] public class Nullable { [Guid("61C17706-2D65-11E0-9AE8-D48564015472")] public struct Vftbl { internal IInspectable.Vftbl IInspectableVftbl; public Delegate get_Value_0; public static readonly Guid PIID = Nullable.PIID; public static global::System.Type get_Value_0_Type; internal unsafe Vftbl(IntPtr thisPtr) { void** ptr = *(void***)(void*)thisPtr; IntPtr* ptr2 = (IntPtr*)ptr; IInspectableVftbl = *(IInspectable.Vftbl*)ptr; get_Value_0 = GetValueDelegateForFunctionPointer(ptr2[6]); } internal unsafe static Delegate GetValueDelegateForFunctionPointer(IntPtr ptr) { if (typeof(T) == typeof(int) || typeof(T) == typeof(byte) || typeof(T) == typeof(bool) || typeof(T) == typeof(sbyte) || typeof(T) == typeof(short) || typeof(T) == typeof(ushort) || typeof(T) == typeof(char) || typeof(T) == typeof(uint) || typeof(T) == typeof(long) || typeof(T) == typeof(ulong) || typeof(T) == typeof(float) || typeof(T) == typeof(double) || typeof(T) == typeof(Guid) || typeof(T) == typeof(global::System.TimeSpan) || typeof(T) == typeof(global::Windows.Foundation.Point) || typeof(T) == typeof(global::Windows.Foundation.Rect) || typeof(T) == typeof(global::Windows.Foundation.Size) || typeof(T) == typeof(global::System.Numerics.Matrix3x2) || typeof(T) == typeof(global::System.Numerics.Matrix4x4) || typeof(T) == typeof(global::System.Numerics.Plane) || typeof(T) == typeof(global::System.Numerics.Quaternion) || typeof(T) == typeof(global::System.Numerics.Vector2) || typeof(T) == typeof(global::System.Numerics.Vector3) || typeof(T) == typeof(global::System.Numerics.Vector4) || (typeof(T).IsEnum && Enum.GetUnderlyingType(typeof(T)) == typeof(int)) || (typeof(T).IsEnum && Enum.GetUnderlyingType(typeof(T)) == typeof(uint))) { return Marshal.GetDelegateForFunctionPointer(ptr); } if (typeof(T) == typeof(DateTimeOffset)) { return Marshal.GetDelegateForFunctionPointer(ptr); } if (RuntimeFeature.IsDynamicCodeCompiled) { if ((object)get_Value_0_Type == null) { get_Value_0_Type = Projections.GetAbiDelegateType(typeof(void*), Marshaler.AbiType.MakeByRefType(), typeof(int)); } return Marshal.GetDelegateForFunctionPointer(ptr, get_Value_0_Type); } throw new NotSupportedException($"Failed to get the marshalling delegate for Nullable`1 with type '{typeof(T)}'."); } } public static readonly Guid PIID = NullableType.GetIID(); protected readonly ObjectReference _obj; public IntPtr ThisPtr => _obj.ThisPtr; public T Value { get { T valueFromAbi = GetValueFromAbi(ThisPtr, _obj.Vftbl.get_Value_0); GC.KeepAlive(this); return valueFromAbi; } } public static IObjectReference CreateMarshaler(object value) { if (value != null) { return ComWrappersSupport.CreateCCWForObject(value, PIID); } return null; } public static ObjectReferenceValue CreateMarshaler2(object value) { return ComWrappersSupport.CreateCCWForObjectForMarshaling(value, PIID); } public static IntPtr GetAbi(IObjectReference m) { return m?.ThisPtr ?? IntPtr.Zero; } public static object FromAbi(IntPtr ptr) { if (ptr == IntPtr.Zero) { return null; } Vftbl vftblT = new Vftbl(ptr); Nullable nullable = new Nullable(ObjectReference.FromAbi(ptr, vftblT, PIID)); return nullable.Value; } public unsafe static void CopyManaged(object o, IntPtr dest) { *(IntPtr*)dest.ToPointer() = CreateMarshaler2(o).Detach(); } public static IntPtr FromManaged(object value) { if (value == null) { return IntPtr.Zero; } return CreateMarshaler2(value).Detach(); } public static void DisposeMarshaler(IObjectReference m) { m?.Dispose(); } public static void DisposeAbi(IntPtr abi) { MarshalInspectable.DisposeAbi(abi); } public static string GetGuidSignature() { return CreateGuidSignature(); } private static string CreateGuidSignature() { if (typeof(T) == typeof(int)) { return Nullable_int.GetGuidSignature(); } if (typeof(T) == typeof(byte)) { return Nullable_byte.GetGuidSignature(); } if (typeof(T) == typeof(bool)) { return Nullable_bool.GetGuidSignature(); } if (typeof(T) == typeof(sbyte)) { return Nullable_sbyte.GetGuidSignature(); } if (typeof(T) == typeof(short)) { return Nullable_short.GetGuidSignature(); } if (typeof(T) == typeof(ushort)) { return Nullable_ushort.GetGuidSignature(); } if (typeof(T) == typeof(char)) { return Nullable_char.GetGuidSignature(); } if (typeof(T) == typeof(uint)) { return Nullable_uint.GetGuidSignature(); } if (typeof(T) == typeof(long)) { return Nullable_long.GetGuidSignature(); } if (typeof(T) == typeof(ulong)) { return Nullable_ulong.GetGuidSignature(); } if (typeof(T) == typeof(float)) { return Nullable_float.GetGuidSignature(); } if (typeof(T) == typeof(double)) { return Nullable_double.GetGuidSignature(); } if (typeof(T) == typeof(Guid)) { return Nullable_guid.GetGuidSignature(); } if (typeof(T) == typeof(global::System.Type)) { return Nullable_Type.GetGuidSignature(); } if (typeof(T) == typeof(global::System.TimeSpan)) { return Nullable_TimeSpan.GetGuidSignature(); } if (typeof(T) == typeof(global::System.DateTimeOffset)) { return Nullable_DateTimeOffset.GetGuidSignature(); } if (typeof(T) == typeof(global::Windows.Foundation.Point)) { return "pinterface({61c17706-2d65-11e0-9ae8-d48564015472};struct(Windows.Foundation.Point;f4;f4))"; } if (typeof(T) == typeof(global::Windows.Foundation.Size)) { return "pinterface({61c17706-2d65-11e0-9ae8-d48564015472};struct(Windows.Foundation.Size;f4;f4))"; } if (typeof(T) == typeof(global::Windows.Foundation.Rect)) { return "pinterface({61c17706-2d65-11e0-9ae8-d48564015472};struct(Windows.Foundation.Rect;f4;f4;f4;f4))"; } if (typeof(T) == typeof(global::System.Numerics.Matrix3x2)) { return "pinterface({61c17706-2d65-11e0-9ae8-d48564015472};struct(Windows.Foundation.Numerics.Matrix3x2;f4;f4;f4;f4;f4;f4))"; } if (typeof(T) == typeof(global::System.Numerics.Matrix4x4)) { return "pinterface({61c17706-2d65-11e0-9ae8-d48564015472};struct(Windows.Foundation.Numerics.Matrix4x4;f4;f4;f4;f4;f4;f4;f4;f4;f4;f4;f4;f4;f4;f4;f4;f4))"; } if (typeof(T) == typeof(global::System.Numerics.Plane)) { return "pinterface({61c17706-2d65-11e0-9ae8-d48564015472};struct(Windows.Foundation.Numerics.Plane;struct(Windows.Foundation.Numerics.Vector3;f4;f4;f4);f4))"; } if (typeof(T) == typeof(global::System.Numerics.Quaternion)) { return "pinterface({61c17706-2d65-11e0-9ae8-d48564015472};struct(Windows.Foundation.Numerics.Quaternion;f4;f4;f4;f4))"; } if (typeof(T) == typeof(global::System.Numerics.Vector2)) { return "pinterface({61c17706-2d65-11e0-9ae8-d48564015472};struct(Windows.Foundation.Numerics.Vector2;f4;f4))"; } if (typeof(T) == typeof(global::System.Numerics.Vector3)) { return "pinterface({61c17706-2d65-11e0-9ae8-d48564015472};struct(Windows.Foundation.Numerics.Vector3;f4;f4;f4))"; } if (typeof(T) == typeof(global::System.Numerics.Vector4)) { return "pinterface({61c17706-2d65-11e0-9ae8-d48564015472};struct(Windows.Foundation.Numerics.Vector4;f4;f4;f4;f4))"; } return GuidGenerator.GetSignature(typeof(Nullable)); } public Nullable(IObjectReference obj) : this(obj.As(Vftbl.PIID)) { } public Nullable(ObjectReference obj) { _obj = obj; } public unsafe static T GetValue(IInspectable inspectable) { IntPtr ppv = IntPtr.Zero; try { ExceptionHelpers.ThrowExceptionForHR(Marshal.QueryInterface(inspectable.ThisPtr, in Unsafe.AsRef(in PIID), out ppv)); Delegate valueDelegateForFunctionPointer = Vftbl.GetValueDelegateForFunctionPointer(*(IntPtr*)((nint)(*(IntPtr*)(void*)ppv) + (nint)6 * (nint)sizeof(IntPtr))); return GetValueFromAbi(ppv, valueDelegateForFunctionPointer); } finally { MarshalExtensions.ReleaseIfNotNull(ppv); } } private unsafe static T GetValueFromAbi(IntPtr thisPtr, Delegate marshallingDelegate) { if (marshallingDelegate.GetType() == typeof(Nullable_Delegates.GetValueDelegateAbi)) { T result = default(T); Marshal.ThrowExceptionForHR(((Nullable_Delegates.GetValueDelegateAbi)marshallingDelegate)((void*)thisPtr, &result)); return result; } if (marshallingDelegate.GetType() == typeof(Nullable_Delegates.GetValueDelegateAbiDateTimeOffset)) { DateTimeOffset value = default(DateTimeOffset); Marshal.ThrowExceptionForHR(((Nullable_Delegates.GetValueDelegateAbiDateTimeOffset)marshallingDelegate)((void*)thisPtr, &value)); global::System.DateTimeOffset source = DateTimeOffset.FromAbi(value); return Unsafe.As(ref source); } if (RuntimeFeature.IsDynamicCodeCompiled) { object[] array = new object[2] { thisPtr, null }; try { marshallingDelegate.DynamicInvokeAbi(array); return Marshaler.FromAbi(array[1]); } finally { Marshaler.DisposeAbi(array[1]); } } throw new NotSupportedException($"Cannot retrieve the value for the current Nullable`1 instance with type '{typeof(T)}'."); } } internal sealed class Nullable { public object Value { get; } public Nullable(object boxedObject) { Value = boxedObject; } } [Guid("548cefbd-bc8a-5fa0-8df2-957440fc8bf4")] internal static class Nullable_int { [Guid("548cefbd-bc8a-5fa0-8df2-957440fc8bf4")] public struct Vftbl { internal IInspectable.Vftbl IInspectableVftbl; private unsafe void* _Get_Value_0; private static readonly Vftbl AbiToProjectionVftable; public static readonly IntPtr AbiToProjectionVftablePtr; public unsafe delegate* unmanaged[Stdcall] Get_Value_0 { get { return (delegate* unmanaged[Stdcall])_Get_Value_0; } set { _Get_Value_0 = value; } } unsafe static Vftbl() { AbiToProjectionVftable = new Vftbl { IInspectableVftbl = IInspectable.Vftbl.AbiToProjectionVftable, _Get_Value_0 = (delegate*)(&Do_Abi_get_Value_0) }; IntPtr* ptr = (IntPtr*)(void*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), sizeof(IInspectable.Vftbl) + sizeof(IntPtr)); *(Vftbl*)ptr = AbiToProjectionVftable; AbiToProjectionVftablePtr = (IntPtr)ptr; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_get_Value_0(IntPtr thisPtr, int* __return_value__) { int num = 0; *__return_value__ = 0; try { num = (int)ComWrappersSupport.FindObject(thisPtr); *__return_value__ = num; } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } } public static string GetGuidSignature() { return "pinterface({61c17706-2d65-11e0-9ae8-d48564015472};i4)"; } } [Guid("fd416dfb-2a07-52eb-aae3-dfce14116c05")] internal static class Nullable_string { [Guid("fd416dfb-2a07-52eb-aae3-dfce14116c05")] public struct Vftbl { internal IInspectable.Vftbl IInspectableVftbl; private unsafe void* _Get_Value_0; private static readonly Vftbl AbiToProjectionVftable; public static readonly IntPtr AbiToProjectionVftablePtr; public unsafe delegate* unmanaged[Stdcall] Get_Value_0 { get { return (delegate* unmanaged[Stdcall])_Get_Value_0; } set { _Get_Value_0 = value; } } unsafe static Vftbl() { AbiToProjectionVftable = new Vftbl { IInspectableVftbl = IInspectable.Vftbl.AbiToProjectionVftable, _Get_Value_0 = (delegate*)(&Do_Abi_get_Value_0) }; IntPtr* ptr = (IntPtr*)(void*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), sizeof(IInspectable.Vftbl) + sizeof(IntPtr)); *(Vftbl*)ptr = AbiToProjectionVftable; AbiToProjectionVftablePtr = (IntPtr)ptr; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_get_Value_0(IntPtr thisPtr, IntPtr* __return_value__) { string text = null; *__return_value__ = default(IntPtr); try { text = (string)ComWrappersSupport.FindObject(thisPtr); *__return_value__ = MarshalString.FromManaged(text); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } } public static string GetGuidSignature() { return "pinterface({61c17706-2d65-11e0-9ae8-d48564015472};string)"; } public unsafe static Nullable GetValue(IInspectable inspectable) { IntPtr ppv = IntPtr.Zero; IntPtr intPtr = default(IntPtr); try { ExceptionHelpers.ThrowExceptionForHR(Marshal.QueryInterface(inspectable.ThisPtr, in Unsafe.AsRef(in IID.IID_NullableString), out ppv)); ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)ppv) + (nint)6 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(ppv, &intPtr)); return new Nullable(MarshalString.FromAbi(intPtr)); } finally { MarshalString.DisposeAbi(intPtr); MarshalExtensions.ReleaseIfNotNull(ppv); } } } [Guid("e5198cc8-2873-55f5-b0a1-84ff9e4aad62")] internal static class Nullable_byte { [Guid("e5198cc8-2873-55f5-b0a1-84ff9e4aad62")] public struct Vftbl { internal IInspectable.Vftbl IInspectableVftbl; private unsafe void* _Get_Value_0; private static readonly Vftbl AbiToProjectionVftable; public static readonly IntPtr AbiToProjectionVftablePtr; public unsafe delegate* unmanaged[Stdcall] Get_Value_0 { get { return (delegate* unmanaged[Stdcall])_Get_Value_0; } set { _Get_Value_0 = value; } } unsafe static Vftbl() { AbiToProjectionVftable = new Vftbl { IInspectableVftbl = IInspectable.Vftbl.AbiToProjectionVftable, _Get_Value_0 = (delegate*)(&Do_Abi_get_Value_0) }; IntPtr* ptr = (IntPtr*)(void*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), sizeof(IInspectable.Vftbl) + sizeof(IntPtr)); *(Vftbl*)ptr = AbiToProjectionVftable; AbiToProjectionVftablePtr = (IntPtr)ptr; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_get_Value_0(IntPtr thisPtr, byte* __return_value__) { byte b = 0; *__return_value__ = 0; try { b = (byte)ComWrappersSupport.FindObject(thisPtr); *__return_value__ = b; } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } } public static string GetGuidSignature() { return "pinterface({61c17706-2d65-11e0-9ae8-d48564015472};u1)"; } } [Guid("95500129-fbf6-5afc-89df-70642d741990")] internal static class Nullable_sbyte { [Guid("95500129-fbf6-5afc-89df-70642d741990")] public struct Vftbl { internal IInspectable.Vftbl IInspectableVftbl; private unsafe void* _Get_Value_0; private static readonly Vftbl AbiToProjectionVftable; public static readonly IntPtr AbiToProjectionVftablePtr; public unsafe delegate* unmanaged[Stdcall] Get_Value_0 { get { return (delegate* unmanaged[Stdcall])_Get_Value_0; } set { _Get_Value_0 = value; } } unsafe static Vftbl() { AbiToProjectionVftable = new Vftbl { IInspectableVftbl = IInspectable.Vftbl.AbiToProjectionVftable, _Get_Value_0 = (delegate*)(&Do_Abi_get_Value_0) }; IntPtr* ptr = (IntPtr*)(void*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), sizeof(IInspectable.Vftbl) + sizeof(IntPtr)); *(Vftbl*)ptr = AbiToProjectionVftable; AbiToProjectionVftablePtr = (IntPtr)ptr; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_get_Value_0(IntPtr thisPtr, sbyte* __return_value__) { sbyte b = 0; *__return_value__ = 0; try { b = (sbyte)ComWrappersSupport.FindObject(thisPtr); *__return_value__ = b; } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } } public static string GetGuidSignature() { return "pinterface({61c17706-2d65-11e0-9ae8-d48564015472};i1)"; } } [Guid("6ec9e41b-6709-5647-9918-a1270110fc4e")] internal static class Nullable_short { [Guid("6ec9e41b-6709-5647-9918-a1270110fc4e")] public struct Vftbl { internal IInspectable.Vftbl IInspectableVftbl; private unsafe void* _Get_Value_0; private static readonly Vftbl AbiToProjectionVftable; public static readonly IntPtr AbiToProjectionVftablePtr; public unsafe delegate* unmanaged[Stdcall] Get_Value_0 { get { return (delegate* unmanaged[Stdcall])_Get_Value_0; } set { _Get_Value_0 = value; } } unsafe static Vftbl() { AbiToProjectionVftable = new Vftbl { IInspectableVftbl = IInspectable.Vftbl.AbiToProjectionVftable, _Get_Value_0 = (delegate*)(&Do_Abi_get_Value_0) }; IntPtr* ptr = (IntPtr*)(void*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), sizeof(IInspectable.Vftbl) + sizeof(IntPtr)); *(Vftbl*)ptr = AbiToProjectionVftable; AbiToProjectionVftablePtr = (IntPtr)ptr; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_get_Value_0(IntPtr thisPtr, short* __return_value__) { short num = 0; *__return_value__ = 0; try { num = (short)ComWrappersSupport.FindObject(thisPtr); *__return_value__ = num; } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } } public static string GetGuidSignature() { return "pinterface({61c17706-2d65-11e0-9ae8-d48564015472};i2)"; } } [Guid("5ab7d2c3-6b62-5e71-a4b6-2d49c4f238fd")] internal static class Nullable_ushort { [Guid("5ab7d2c3-6b62-5e71-a4b6-2d49c4f238fd")] public struct Vftbl { internal IInspectable.Vftbl IInspectableVftbl; private unsafe void* _Get_Value_0; private static readonly Vftbl AbiToProjectionVftable; public static readonly IntPtr AbiToProjectionVftablePtr; public unsafe delegate* unmanaged[Stdcall] Get_Value_0 { get { return (delegate* unmanaged[Stdcall])_Get_Value_0; } set { _Get_Value_0 = value; } } unsafe static Vftbl() { AbiToProjectionVftable = new Vftbl { IInspectableVftbl = IInspectable.Vftbl.AbiToProjectionVftable, _Get_Value_0 = (delegate*)(&Do_Abi_get_Value_0) }; IntPtr* ptr = (IntPtr*)(void*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), sizeof(IInspectable.Vftbl) + sizeof(IntPtr)); *(Vftbl*)ptr = AbiToProjectionVftable; AbiToProjectionVftablePtr = (IntPtr)ptr; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_get_Value_0(IntPtr thisPtr, ushort* __return_value__) { ushort num = 0; *__return_value__ = 0; try { num = (ushort)ComWrappersSupport.FindObject(thisPtr); *__return_value__ = num; } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } } public static string GetGuidSignature() { return "pinterface({61c17706-2d65-11e0-9ae8-d48564015472};u2)"; } } [Guid("513ef3af-e784-5325-a91e-97c2b8111cf3")] internal static class Nullable_uint { [Guid("513ef3af-e784-5325-a91e-97c2b8111cf3")] public struct Vftbl { internal IInspectable.Vftbl IInspectableVftbl; private unsafe void* _Get_Value_0; private static readonly Vftbl AbiToProjectionVftable; public static readonly IntPtr AbiToProjectionVftablePtr; public unsafe delegate* unmanaged[Stdcall] Get_Value_0 { get { return (delegate* unmanaged[Stdcall])_Get_Value_0; } set { _Get_Value_0 = value; } } unsafe static Vftbl() { AbiToProjectionVftable = new Vftbl { IInspectableVftbl = IInspectable.Vftbl.AbiToProjectionVftable, _Get_Value_0 = (delegate*)(&Do_Abi_get_Value_0) }; IntPtr* ptr = (IntPtr*)(void*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), sizeof(IInspectable.Vftbl) + sizeof(IntPtr)); *(Vftbl*)ptr = AbiToProjectionVftable; AbiToProjectionVftablePtr = (IntPtr)ptr; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_get_Value_0(IntPtr thisPtr, uint* __return_value__) { uint num = 0u; *__return_value__ = 0u; try { num = (uint)ComWrappersSupport.FindObject(thisPtr); *__return_value__ = num; } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } } public static string GetGuidSignature() { return "pinterface({61c17706-2d65-11e0-9ae8-d48564015472};u4)"; } } [Guid("4dda9e24-e69f-5c6a-a0a6-93427365af2a")] internal static class Nullable_long { [Guid("4dda9e24-e69f-5c6a-a0a6-93427365af2a")] public struct Vftbl { internal IInspectable.Vftbl IInspectableVftbl; private unsafe void* _Get_Value_0; private static readonly Vftbl AbiToProjectionVftable; public static readonly IntPtr AbiToProjectionVftablePtr; public unsafe delegate* unmanaged[Stdcall] Get_Value_0 { get { return (delegate* unmanaged[Stdcall])_Get_Value_0; } set { _Get_Value_0 = value; } } unsafe static Vftbl() { AbiToProjectionVftable = new Vftbl { IInspectableVftbl = IInspectable.Vftbl.AbiToProjectionVftable, _Get_Value_0 = (delegate*)(&Do_Abi_get_Value_0) }; IntPtr* ptr = (IntPtr*)(void*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), sizeof(IInspectable.Vftbl) + sizeof(IntPtr)); *(Vftbl*)ptr = AbiToProjectionVftable; AbiToProjectionVftablePtr = (IntPtr)ptr; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_get_Value_0(IntPtr thisPtr, long* __return_value__) { long num = 0L; *__return_value__ = 0L; try { num = (long)ComWrappersSupport.FindObject(thisPtr); *__return_value__ = num; } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } } public static string GetGuidSignature() { return "pinterface({61c17706-2d65-11e0-9ae8-d48564015472};i8)"; } } [Guid("6755e376-53bb-568b-a11d-17239868309e")] internal static class Nullable_ulong { [Guid("6755e376-53bb-568b-a11d-17239868309e")] public struct Vftbl { internal IInspectable.Vftbl IInspectableVftbl; private unsafe void* _Get_Value_0; private static readonly Vftbl AbiToProjectionVftable; public static readonly IntPtr AbiToProjectionVftablePtr; public unsafe delegate* unmanaged[Stdcall] Get_Value_0 { get { return (delegate* unmanaged[Stdcall])_Get_Value_0; } set { _Get_Value_0 = value; } } unsafe static Vftbl() { AbiToProjectionVftable = new Vftbl { IInspectableVftbl = IInspectable.Vftbl.AbiToProjectionVftable, _Get_Value_0 = (delegate*)(&Do_Abi_get_Value_0) }; IntPtr* ptr = (IntPtr*)(void*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), sizeof(IInspectable.Vftbl) + sizeof(IntPtr)); *(Vftbl*)ptr = AbiToProjectionVftable; AbiToProjectionVftablePtr = (IntPtr)ptr; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_get_Value_0(IntPtr thisPtr, ulong* __return_value__) { ulong num = 0uL; *__return_value__ = 0uL; try { num = (ulong)ComWrappersSupport.FindObject(thisPtr); *__return_value__ = num; } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } } public static string GetGuidSignature() { return "pinterface({61c17706-2d65-11e0-9ae8-d48564015472};u8)"; } } [Guid("719cc2ba-3e76-5def-9f1a-38d85a145ea8")] internal static class Nullable_float { [Guid("719cc2ba-3e76-5def-9f1a-38d85a145ea8")] public struct Vftbl { internal IInspectable.Vftbl IInspectableVftbl; private unsafe void* _Get_Value_0; private static readonly Vftbl AbiToProjectionVftable; public static readonly IntPtr AbiToProjectionVftablePtr; public unsafe delegate* unmanaged[Stdcall] Get_Value_0 { get { return (delegate* unmanaged[Stdcall])_Get_Value_0; } set { _Get_Value_0 = value; } } unsafe static Vftbl() { AbiToProjectionVftable = new Vftbl { IInspectableVftbl = IInspectable.Vftbl.AbiToProjectionVftable, _Get_Value_0 = (delegate*)(&Do_Abi_get_Value_0) }; IntPtr* ptr = (IntPtr*)(void*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), sizeof(IInspectable.Vftbl) + sizeof(IntPtr)); *(Vftbl*)ptr = AbiToProjectionVftable; AbiToProjectionVftablePtr = (IntPtr)ptr; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_get_Value_0(IntPtr thisPtr, float* __return_value__) { float num = 0f; *__return_value__ = 0f; try { num = (float)ComWrappersSupport.FindObject(thisPtr); *__return_value__ = num; } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } } public static string GetGuidSignature() { return "pinterface({61c17706-2d65-11e0-9ae8-d48564015472};f4)"; } } [Guid("2f2d6c29-5473-5f3e-92e7-96572bb990e2")] internal static class Nullable_double { [Guid("2f2d6c29-5473-5f3e-92e7-96572bb990e2")] public struct Vftbl { internal IInspectable.Vftbl IInspectableVftbl; private unsafe void* _Get_Value_0; private static readonly Vftbl AbiToProjectionVftable; public static readonly IntPtr AbiToProjectionVftablePtr; public unsafe delegate* unmanaged[Stdcall] Get_Value_0 { get { return (delegate* unmanaged[Stdcall])_Get_Value_0; } set { _Get_Value_0 = value; } } unsafe static Vftbl() { AbiToProjectionVftable = new Vftbl { IInspectableVftbl = IInspectable.Vftbl.AbiToProjectionVftable, _Get_Value_0 = (delegate*)(&Do_Abi_get_Value_0) }; IntPtr* ptr = (IntPtr*)(void*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), sizeof(IInspectable.Vftbl) + sizeof(IntPtr)); *(Vftbl*)ptr = AbiToProjectionVftable; AbiToProjectionVftablePtr = (IntPtr)ptr; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_get_Value_0(IntPtr thisPtr, double* __return_value__) { double num = 0.0; *__return_value__ = 0.0; try { num = (double)ComWrappersSupport.FindObject(thisPtr); *__return_value__ = num; } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } } public static string GetGuidSignature() { return "pinterface({61c17706-2d65-11e0-9ae8-d48564015472};f8)"; } } [Guid("fb393ef3-bbac-5bd5-9144-84f23576f415")] internal static class Nullable_char { [Guid("fb393ef3-bbac-5bd5-9144-84f23576f415")] public struct Vftbl { internal IInspectable.Vftbl IInspectableVftbl; private unsafe void* _Get_Value_0; private static readonly Vftbl AbiToProjectionVftable; public static readonly IntPtr AbiToProjectionVftablePtr; public unsafe delegate* unmanaged[Stdcall] Get_Value_0 { get { return (delegate* unmanaged[Stdcall])_Get_Value_0; } set { _Get_Value_0 = value; } } unsafe static Vftbl() { AbiToProjectionVftable = new Vftbl { IInspectableVftbl = IInspectable.Vftbl.AbiToProjectionVftable, _Get_Value_0 = (delegate*)(&Do_Abi_get_Value_0) }; IntPtr* ptr = (IntPtr*)(void*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), sizeof(IInspectable.Vftbl) + sizeof(IntPtr)); *(Vftbl*)ptr = AbiToProjectionVftable; AbiToProjectionVftablePtr = (IntPtr)ptr; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_get_Value_0(IntPtr thisPtr, char* __return_value__) { char c = '\0'; *__return_value__ = '\0'; try { c = (char)ComWrappersSupport.FindObject(thisPtr); *__return_value__ = c; } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } } public static string GetGuidSignature() { return "pinterface({61c17706-2d65-11e0-9ae8-d48564015472};c2)"; } } [Guid("3c00fd60-2950-5939-a21a-2d12c5a01b8a")] internal static class Nullable_bool { [Guid("3c00fd60-2950-5939-a21a-2d12c5a01b8a")] public struct Vftbl { internal IInspectable.Vftbl IInspectableVftbl; private unsafe void* _Get_Value_0; private static readonly Vftbl AbiToProjectionVftable; public static readonly IntPtr AbiToProjectionVftablePtr; public unsafe delegate* unmanaged[Stdcall] Get_Value_0 { get { return (delegate* unmanaged[Stdcall])_Get_Value_0; } set { _Get_Value_0 = value; } } unsafe static Vftbl() { AbiToProjectionVftable = new Vftbl { IInspectableVftbl = IInspectable.Vftbl.AbiToProjectionVftable, _Get_Value_0 = (delegate*)(&Do_Abi_get_Value_0) }; IntPtr* ptr = (IntPtr*)(void*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), sizeof(IInspectable.Vftbl) + sizeof(IntPtr)); *(Vftbl*)ptr = AbiToProjectionVftable; AbiToProjectionVftablePtr = (IntPtr)ptr; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_get_Value_0(IntPtr thisPtr, bool* __return_value__) { bool flag = false; *__return_value__ = false; try { flag = (bool)ComWrappersSupport.FindObject(thisPtr); *__return_value__ = flag; } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } } public static string GetGuidSignature() { return "pinterface({61c17706-2d65-11e0-9ae8-d48564015472};b1)"; } } [Guid("7d50f649-632c-51f9-849a-ee49428933ea")] internal static class Nullable_guid { [Guid("7d50f649-632c-51f9-849a-ee49428933ea")] public struct Vftbl { internal IInspectable.Vftbl IInspectableVftbl; private unsafe void* _Get_Value_0; private static readonly Vftbl AbiToProjectionVftable; public static readonly IntPtr AbiToProjectionVftablePtr; public unsafe delegate* unmanaged[Stdcall] Get_Value_0 { get { return (delegate* unmanaged[Stdcall])_Get_Value_0; } set { _Get_Value_0 = value; } } unsafe static Vftbl() { AbiToProjectionVftable = new Vftbl { IInspectableVftbl = IInspectable.Vftbl.AbiToProjectionVftable, _Get_Value_0 = (delegate*)(&Do_Abi_get_Value_0) }; IntPtr* ptr = (IntPtr*)(void*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), sizeof(IInspectable.Vftbl) + sizeof(IntPtr)); *(Vftbl*)ptr = AbiToProjectionVftable; AbiToProjectionVftablePtr = (IntPtr)ptr; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_get_Value_0(IntPtr thisPtr, Guid* __return_value__) { Guid guid = default(Guid); *__return_value__ = default(Guid); try { guid = (Guid)ComWrappersSupport.FindObject(thisPtr); *__return_value__ = guid; } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } } public static string GetGuidSignature() { return "pinterface({61c17706-2d65-11e0-9ae8-d48564015472};g16)"; } } [Guid("5541d8a7-497c-5aa4-86fc-7713adbf2a2c")] internal static class Nullable_DateTimeOffset { [Guid("5541d8a7-497c-5aa4-86fc-7713adbf2a2c")] public struct Vftbl { internal IInspectable.Vftbl IInspectableVftbl; private unsafe void* _Get_Value_0; private static readonly Vftbl AbiToProjectionVftable; public static readonly IntPtr AbiToProjectionVftablePtr; public unsafe delegate* unmanaged[Stdcall] Get_Value_0 { get { return (delegate* unmanaged[Stdcall])_Get_Value_0; } set { _Get_Value_0 = value; } } unsafe static Vftbl() { AbiToProjectionVftable = new Vftbl { IInspectableVftbl = IInspectable.Vftbl.AbiToProjectionVftable, _Get_Value_0 = (delegate*)(&Do_Abi_get_Value_0) }; IntPtr* ptr = (IntPtr*)(void*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), sizeof(IInspectable.Vftbl) + sizeof(IntPtr)); *(Vftbl*)ptr = AbiToProjectionVftable; AbiToProjectionVftablePtr = (IntPtr)ptr; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_get_Value_0(IntPtr thisPtr, DateTimeOffset* __return_value__) { global::System.DateTimeOffset dateTimeOffset = default(global::System.DateTimeOffset); *__return_value__ = default(DateTimeOffset); try { dateTimeOffset = (global::System.DateTimeOffset)ComWrappersSupport.FindObject(thisPtr); *__return_value__ = DateTimeOffset.FromManaged(dateTimeOffset); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } } public static string GetGuidSignature() { return "pinterface({61c17706-2d65-11e0-9ae8-d48564015472};struct(Windows.Foundation.DateTime;i8))"; } public unsafe static object GetValue(IInspectable inspectable) { IntPtr ppv = IntPtr.Zero; DateTimeOffset dateTimeOffset = default(DateTimeOffset); try { ExceptionHelpers.ThrowExceptionForHR(Marshal.QueryInterface(inspectable.ThisPtr, in Unsafe.AsRef(in IID.IID_NullableDateTimeOffset), out ppv)); ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)ppv) + (nint)6 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(ppv, &dateTimeOffset)); return DateTimeOffset.FromAbi(dateTimeOffset); } finally { DateTimeOffset.DisposeAbi(dateTimeOffset); MarshalExtensions.ReleaseIfNotNull(ppv); } } } [Guid("604d0c4c-91de-5c2a-935f-362f13eaf800")] internal static class Nullable_TimeSpan { [Guid("604d0c4c-91de-5c2a-935f-362f13eaf800")] public struct Vftbl { internal IInspectable.Vftbl IInspectableVftbl; private unsafe void* _Get_Value_0; private static readonly Vftbl AbiToProjectionVftable; public static readonly IntPtr AbiToProjectionVftablePtr; public unsafe delegate* unmanaged[Stdcall] Get_Value_0 { get { return (delegate* unmanaged[Stdcall])_Get_Value_0; } set { _Get_Value_0 = value; } } unsafe static Vftbl() { AbiToProjectionVftable = new Vftbl { IInspectableVftbl = IInspectable.Vftbl.AbiToProjectionVftable, _Get_Value_0 = (delegate*)(&Do_Abi_get_Value_0) }; IntPtr* ptr = (IntPtr*)(void*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), sizeof(IInspectable.Vftbl) + sizeof(IntPtr)); *(Vftbl*)ptr = AbiToProjectionVftable; AbiToProjectionVftablePtr = (IntPtr)ptr; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_get_Value_0(IntPtr thisPtr, TimeSpan* __return_value__) { global::System.TimeSpan timeSpan = default(global::System.TimeSpan); *__return_value__ = default(TimeSpan); try { timeSpan = (global::System.TimeSpan)ComWrappersSupport.FindObject(thisPtr); *__return_value__ = TimeSpan.FromManaged(timeSpan); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } } public static string GetGuidSignature() { return "pinterface({61c17706-2d65-11e0-9ae8-d48564015472};struct(Windows.Foundation.TimeSpan;i8))"; } public unsafe static object GetValue(IInspectable inspectable) { IntPtr ppv = IntPtr.Zero; TimeSpan timeSpan = default(TimeSpan); try { ExceptionHelpers.ThrowExceptionForHR(Marshal.QueryInterface(inspectable.ThisPtr, in Unsafe.AsRef(in IID.IID_NullableTimeSpan), out ppv)); ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)ppv) + (nint)6 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(ppv, &timeSpan)); return TimeSpan.FromAbi(timeSpan); } finally { TimeSpan.DisposeAbi(timeSpan); MarshalExtensions.ReleaseIfNotNull(ppv); } } } [Guid("06dccc90-a058-5c88-87b7-6f3360a2fc16")] internal static class Nullable_Object { [Guid("06dccc90-a058-5c88-87b7-6f3360a2fc16")] public struct Vftbl { internal IInspectable.Vftbl IInspectableVftbl; private unsafe void* _Get_Value_0; private static readonly Vftbl AbiToProjectionVftable; public static readonly IntPtr AbiToProjectionVftablePtr; public unsafe delegate* unmanaged[Stdcall] Get_Value_0 { get { return (delegate* unmanaged[Stdcall])_Get_Value_0; } set { _Get_Value_0 = value; } } unsafe static Vftbl() { AbiToProjectionVftable = new Vftbl { IInspectableVftbl = IInspectable.Vftbl.AbiToProjectionVftable, _Get_Value_0 = (delegate*)(&Do_Abi_get_Value_0) }; IntPtr* ptr = (IntPtr*)(void*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), sizeof(IInspectable.Vftbl) + sizeof(IntPtr)); *(Vftbl*)ptr = AbiToProjectionVftable; AbiToProjectionVftablePtr = (IntPtr)ptr; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_get_Value_0(IntPtr thisPtr, IntPtr* __return_value__) { object obj = null; *__return_value__ = default(IntPtr); try { obj = ComWrappersSupport.FindObject(thisPtr); *__return_value__ = MarshalInspectable.FromManaged(obj); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } } public static string GetGuidSignature() { return "pinterface({61c17706-2d65-11e0-9ae8-d48564015472};cinterface(IInspectable))"; } } [Guid("3830ad99-d8da-53f3-989b-fc92ad222778")] internal static class Nullable_Type { [Guid("3830ad99-d8da-53f3-989b-fc92ad222778")] public struct Vftbl { internal IInspectable.Vftbl IInspectableVftbl; private unsafe void* _Get_Value_0; private static readonly Vftbl AbiToProjectionVftable; public static readonly IntPtr AbiToProjectionVftablePtr; public unsafe delegate* unmanaged[Stdcall] Get_Value_0 { get { return (delegate* unmanaged[Stdcall])_Get_Value_0; } set { _Get_Value_0 = value; } } unsafe static Vftbl() { AbiToProjectionVftable = new Vftbl { IInspectableVftbl = IInspectable.Vftbl.AbiToProjectionVftable, _Get_Value_0 = (delegate*)(&Do_Abi_get_Value_0) }; IntPtr* ptr = (IntPtr*)(void*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), sizeof(IInspectable.Vftbl) + sizeof(IntPtr)); *(Vftbl*)ptr = AbiToProjectionVftable; AbiToProjectionVftablePtr = (IntPtr)ptr; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_get_Value_0(IntPtr thisPtr, Type* __return_value__) { global::System.Type type = null; *__return_value__ = default(Type); try { type = (global::System.Type)ComWrappersSupport.FindObject(thisPtr); *__return_value__ = Type.FromManaged(type); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } } public static string GetGuidSignature() { return "pinterface({61c17706-2d65-11e0-9ae8-d48564015472};struct(Windows.UI.Xaml.Interop.TypeName;string;enum(Windows.UI.Xaml.Interop.TypeKind;i4)))"; } public unsafe static Nullable GetValue(IInspectable inspectable) { IntPtr ppv = IntPtr.Zero; Type type = default(Type); try { ExceptionHelpers.ThrowExceptionForHR(Marshal.QueryInterface(inspectable.ThisPtr, in Unsafe.AsRef(in IID.IID_NullableType), out ppv)); ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)ppv) + (nint)6 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(ppv, &type)); return new Nullable(Type.FromAbi(type)); } finally { Type.DisposeAbi(type); MarshalExtensions.ReleaseIfNotNull(ppv); } } } [Guid("6ff27a1e-4b6a-59b7-b2c3-d1f2ee474593")] internal static class Nullable_Exception { [Guid("6ff27a1e-4b6a-59b7-b2c3-d1f2ee474593")] public struct Vftbl { internal IInspectable.Vftbl IInspectableVftbl; private unsafe void* _Get_Value_0; private static readonly Vftbl AbiToProjectionVftable; public static readonly IntPtr AbiToProjectionVftablePtr; public unsafe delegate* unmanaged[Stdcall] Get_Value_0 { get { return (delegate* unmanaged[Stdcall])_Get_Value_0; } set { _Get_Value_0 = value; } } unsafe static Vftbl() { AbiToProjectionVftable = new Vftbl { IInspectableVftbl = IInspectable.Vftbl.AbiToProjectionVftable, _Get_Value_0 = (delegate*)(&Do_Abi_get_Value_0) }; IntPtr* ptr = (IntPtr*)(void*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), sizeof(IInspectable.Vftbl) + sizeof(IntPtr)); *(Vftbl*)ptr = AbiToProjectionVftable; AbiToProjectionVftablePtr = (IntPtr)ptr; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_get_Value_0(IntPtr thisPtr, Exception* __return_value__) { global::System.Exception ex = null; *__return_value__ = default(Exception); try { ex = (global::System.Exception)ComWrappersSupport.FindObject(thisPtr); *__return_value__ = Exception.FromManaged(ex); } catch (global::System.Exception ex2) { ExceptionHelpers.SetErrorInfo(ex2); return ExceptionHelpers.GetHRForException(ex2); } return 0; } } public static string GetGuidSignature() { return "pinterface({61c17706-2d65-11e0-9ae8-d48564015472};struct(Windows.Foundation.HResult;i4))"; } public unsafe static Nullable GetValue(IInspectable inspectable) { IntPtr ppv = IntPtr.Zero; Exception ex = default(Exception); try { ExceptionHelpers.ThrowExceptionForHR(Marshal.QueryInterface(inspectable.ThisPtr, in Unsafe.AsRef(in IID.IID_NullableException), out ppv)); ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)ppv) + (nint)6 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(ppv, &ex)); return new Nullable(Exception.FromAbi(ex)); } finally { Exception.DisposeAbi(ex); MarshalExtensions.ReleaseIfNotNull(ppv); } } } [Guid("25230F05-B49C-57EE-8961-5373D98E1AB1")] internal static class Nullable_EventHandler { public static readonly IntPtr AbiToProjectionVftablePtr; unsafe static Nullable_EventHandler() { AbiToProjectionVftablePtr = ComWrappersSupport.AllocateVtableMemory(typeof(Nullable_EventHandler), sizeof(IInspectable.Vftbl) + sizeof(IntPtr)); *(IInspectable.Vftbl*)(void*)AbiToProjectionVftablePtr = IInspectable.Vftbl.AbiToProjectionVftable; *(IntPtr*)((byte*)(void*)AbiToProjectionVftablePtr + (nint)6 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)(delegate*)(&Do_Abi_get_Value_0); } [UnmanagedCallersOnly(CallConvs = new global::System.Type[] { typeof(CallConvStdcall) })] private unsafe static int Do_Abi_get_Value_0(IntPtr thisPtr, IntPtr* __return_value__) { global::System.EventHandler eventHandler = null; *__return_value__ = default(IntPtr); try { eventHandler = ComWrappersSupport.FindObject(thisPtr); *__return_value__ = EventHandler.FromManaged(eventHandler); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } public unsafe static Nullable GetValue(IInspectable inspectable) { IntPtr ppv = IntPtr.Zero; IntPtr intPtr = default(IntPtr); try { ExceptionHelpers.ThrowExceptionForHR(Marshal.QueryInterface(inspectable.ThisPtr, in Unsafe.AsRef(in IID.IID_NullableEventHandler), out ppv)); ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)ppv) + (nint)6 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(ppv, &intPtr)); return new Nullable(EventHandler.FromAbi(intPtr)); } finally { EventHandler.DisposeAbi(intPtr); MarshalExtensions.ReleaseIfNotNull(ppv); } } } [Guid("1eeae0cb-8f57-5c37-a087-a55d46e2fe3f")] internal static class Nullable_PropertyChangedEventHandler { public static readonly IntPtr AbiToProjectionVftablePtr; public static Guid IID { get { if (!FeatureSwitches.UseWindowsUIXamlProjections) { return global::WinRT.Interop.IID.IID_MUX_NullablePropertyChangedEventHandler; } return global::WinRT.Interop.IID.IID_WUX_NullablePropertyChangedEventHandler; } } unsafe static Nullable_PropertyChangedEventHandler() { AbiToProjectionVftablePtr = ComWrappersSupport.AllocateVtableMemory(typeof(Nullable_PropertyChangedEventHandler), sizeof(IInspectable.Vftbl) + sizeof(IntPtr)); *(IInspectable.Vftbl*)(void*)AbiToProjectionVftablePtr = IInspectable.Vftbl.AbiToProjectionVftable; *(IntPtr*)((byte*)(void*)AbiToProjectionVftablePtr + (nint)6 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)(delegate*)(&Do_Abi_get_Value_0); } [UnmanagedCallersOnly(CallConvs = new global::System.Type[] { typeof(CallConvStdcall) })] private unsafe static int Do_Abi_get_Value_0(IntPtr thisPtr, IntPtr* __return_value__) { global::System.ComponentModel.PropertyChangedEventHandler propertyChangedEventHandler = null; *__return_value__ = default(IntPtr); try { propertyChangedEventHandler = ComWrappersSupport.FindObject(thisPtr); *__return_value__ = ABI.System.ComponentModel.PropertyChangedEventHandler.FromManaged(propertyChangedEventHandler); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } public unsafe static Nullable GetValue(IInspectable inspectable) { Guid source = IID; IntPtr ppv = IntPtr.Zero; IntPtr intPtr = default(IntPtr); try { ExceptionHelpers.ThrowExceptionForHR(Marshal.QueryInterface(inspectable.ThisPtr, in Unsafe.AsRef(in source), out ppv)); ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)ppv) + (nint)6 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(ppv, &intPtr)); return new Nullable(ABI.System.ComponentModel.PropertyChangedEventHandler.FromAbi(intPtr)); } finally { ABI.System.ComponentModel.PropertyChangedEventHandler.DisposeAbi(intPtr); MarshalExtensions.ReleaseIfNotNull(ppv); } } } [Guid("779d5a21-0e7d-5476-bb90-27fa3b4b8de5")] internal static class Nullable_NotifyCollectionChangedEventHandler { public static readonly IntPtr AbiToProjectionVftablePtr; public static Guid IID { get { if (!FeatureSwitches.UseWindowsUIXamlProjections) { return global::WinRT.Interop.IID.IID_MUX_NotifyCollectionChangedEventHandler; } return global::WinRT.Interop.IID.IID_WUX_NotifyCollectionChangedEventHandler; } } unsafe static Nullable_NotifyCollectionChangedEventHandler() { AbiToProjectionVftablePtr = ComWrappersSupport.AllocateVtableMemory(typeof(Nullable_NotifyCollectionChangedEventHandler), sizeof(IInspectable.Vftbl) + sizeof(IntPtr)); *(IInspectable.Vftbl*)(void*)AbiToProjectionVftablePtr = IInspectable.Vftbl.AbiToProjectionVftable; *(IntPtr*)((byte*)(void*)AbiToProjectionVftablePtr + (nint)6 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)(delegate*)(&Do_Abi_get_Value_0); } [UnmanagedCallersOnly(CallConvs = new global::System.Type[] { typeof(CallConvStdcall) })] private unsafe static int Do_Abi_get_Value_0(IntPtr thisPtr, IntPtr* __return_value__) { global::System.Collections.Specialized.NotifyCollectionChangedEventHandler notifyCollectionChangedEventHandler = null; *__return_value__ = default(IntPtr); try { notifyCollectionChangedEventHandler = ComWrappersSupport.FindObject(thisPtr); *__return_value__ = ABI.System.Collections.Specialized.NotifyCollectionChangedEventHandler.FromManaged(notifyCollectionChangedEventHandler); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } public unsafe static Nullable GetValue(IInspectable inspectable) { Guid source = IID; IntPtr ppv = IntPtr.Zero; IntPtr intPtr = default(IntPtr); try { ExceptionHelpers.ThrowExceptionForHR(Marshal.QueryInterface(inspectable.ThisPtr, in Unsafe.AsRef(in source), out ppv)); ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)ppv) + (nint)6 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(ppv, &intPtr)); return new Nullable(ABI.System.Collections.Specialized.NotifyCollectionChangedEventHandler.FromAbi(intPtr)); } finally { ABI.System.Collections.Specialized.NotifyCollectionChangedEventHandler.DisposeAbi(intPtr); MarshalExtensions.ReleaseIfNotNull(ppv); } } } [Guid("61C17706-2D65-11E0-9AE8-D48564015472")] internal static class Nullable_Delegate where T : Delegate { public static readonly IntPtr AbiToProjectionVftablePtr; private static readonly Nullable_Delegates.GetValueDelegate _Get_Value_0; public static readonly Guid PIID; public static string GetGuidSignature() { return GuidGenerator.GetSignature(typeof(Nullable)); } unsafe static Nullable_Delegate() { PIID = Nullable.PIID; _Get_Value_0 = Do_Abi_get_Value_0; AbiToProjectionVftablePtr = ComWrappersSupport.AllocateVtableMemory(typeof(Nullable_Delegate), sizeof(IInspectable.Vftbl) + sizeof(IntPtr)); *(IInspectable.Vftbl*)(void*)AbiToProjectionVftablePtr = IInspectable.Vftbl.AbiToProjectionVftable; ((IntPtr*)(void*)AbiToProjectionVftablePtr)[6] = Marshal.GetFunctionPointerForDelegate(_Get_Value_0); } private unsafe static int Do_Abi_get_Value_0(IntPtr thisPtr, IntPtr* __return_value__) { T val = null; *__return_value__ = default(IntPtr); try { val = ComWrappersSupport.FindObject(thisPtr); *__return_value__ = (IntPtr)Marshaler.FromManaged(val); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } public unsafe static Nullable GetValue(IInspectable inspectable) { IntPtr ppv = IntPtr.Zero; IntPtr intPtr = default(IntPtr); try { ExceptionHelpers.ThrowExceptionForHR(Marshal.QueryInterface(inspectable.ThisPtr, in Unsafe.AsRef(in PIID), out ppv)); ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)ppv) + (nint)6 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(ppv, &intPtr)); return new Nullable(Marshaler.FromAbi(intPtr)); } finally { Marshaler.DisposeAbi(intPtr); MarshalExtensions.ReleaseIfNotNull(ppv); } } } internal static class Nullable_IntEnum { public static readonly IntPtr AbiToProjectionVftablePtr; unsafe static Nullable_IntEnum() { AbiToProjectionVftablePtr = ComWrappersSupport.AllocateVtableMemory(typeof(Nullable_IntEnum), sizeof(IInspectable.Vftbl) + sizeof(IntPtr)); *(IInspectable.Vftbl*)(void*)AbiToProjectionVftablePtr = IInspectable.Vftbl.AbiToProjectionVftable; *(IntPtr*)((byte*)(void*)AbiToProjectionVftablePtr + (nint)6 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)(delegate*)(&Do_Abi_get_Value_0); } [UnmanagedCallersOnly(CallConvs = new global::System.Type[] { typeof(CallConvStdcall) })] private unsafe static int Do_Abi_get_Value_0(IntPtr thisPtr, int* __return_value__) { *__return_value__ = 0; try { *__return_value__ = (int)ComWrappersSupport.FindObject(thisPtr); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } internal static Guid GetIID(global::System.Type enumType) { return GuidGenerator.CreateIIDForGenericType("pinterface({61c17706-2d65-11e0-9ae8-d48564015472};enum(" + enumType.FullName + ";i4))"); } internal unsafe static object GetValue(global::System.Type enumType, IInspectable inspectable) { Guid source = GetIID(enumType); IntPtr ppv = IntPtr.Zero; try { int value = 0; ExceptionHelpers.ThrowExceptionForHR(Marshal.QueryInterface(inspectable.ThisPtr, in Unsafe.AsRef(in source), out ppv)); ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)ppv) + (nint)6 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(ppv, &value)); return Enum.ToObject(enumType, value); } finally { MarshalExtensions.ReleaseIfNotNull(ppv); } } } internal static class Nullable_FlagsEnum { public static readonly IntPtr AbiToProjectionVftablePtr; unsafe static Nullable_FlagsEnum() { AbiToProjectionVftablePtr = ComWrappersSupport.AllocateVtableMemory(typeof(Nullable_FlagsEnum), sizeof(IInspectable.Vftbl) + sizeof(IntPtr)); *(IInspectable.Vftbl*)(void*)AbiToProjectionVftablePtr = IInspectable.Vftbl.AbiToProjectionVftable; *(IntPtr*)((byte*)(void*)AbiToProjectionVftablePtr + (nint)6 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)(delegate*)(&Do_Abi_get_Value_0); } [UnmanagedCallersOnly(CallConvs = new global::System.Type[] { typeof(CallConvStdcall) })] private unsafe static int Do_Abi_get_Value_0(IntPtr thisPtr, uint* __return_value__) { *__return_value__ = 0u; try { *__return_value__ = (uint)ComWrappersSupport.FindObject(thisPtr); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } internal static Guid GetIID(global::System.Type enumType) { return GuidGenerator.CreateIIDForGenericType("pinterface({61c17706-2d65-11e0-9ae8-d48564015472};enum(" + enumType.FullName + ";u4))"); } internal unsafe static object GetValue(global::System.Type enumType, IInspectable inspectable) { Guid source = GetIID(enumType); IntPtr ppv = IntPtr.Zero; try { uint value = 0u; ExceptionHelpers.ThrowExceptionForHR(Marshal.QueryInterface(inspectable.ThisPtr, in Unsafe.AsRef(in source), out ppv)); ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)ppv) + (nint)6 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(ppv, &value)); return Enum.ToObject(enumType, value); } finally { MarshalExtensions.ReleaseIfNotNull(ppv); } } } internal static class Nullable_Delegates { public unsafe delegate int GetValueDelegate(IntPtr thisPtr, IntPtr* value); public unsafe delegate int GetValueDelegateAbi(void* thisPtr, void* value); public unsafe delegate int GetValueDelegateAbiDateTimeOffset(void* ptr, DateTimeOffset* result); } internal static class NullableBlittable where T : unmanaged { private static readonly Guid IID = NullableType.GetIID(); public unsafe static object GetValue(IInspectable inspectable) { IntPtr ppv = IntPtr.Zero; try { T val = default(T); ExceptionHelpers.ThrowExceptionForHR(Marshal.QueryInterface(inspectable.ThisPtr, in Unsafe.AsRef(in IID), out ppv)); ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)ppv) + (nint)6 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(ppv, &val)); return val; } finally { MarshalExtensions.ReleaseIfNotNull(ppv); } } } internal static class NullableType { internal static Guid GetIID() { if (typeof(T) == typeof(int)) { return IID.IID_NullableInt; } if (typeof(T) == typeof(byte)) { return IID.IID_NullableByte; } if (typeof(T) == typeof(bool)) { return IID.IID_NullableBool; } if (typeof(T) == typeof(sbyte)) { return IID.IID_NullableSByte; } if (typeof(T) == typeof(short)) { return IID.IID_NullableShort; } if (typeof(T) == typeof(ushort)) { return IID.IID_NullableUShort; } if (typeof(T) == typeof(char)) { return IID.IID_NullableChar; } if (typeof(T) == typeof(uint)) { return IID.IID_NullableUInt; } if (typeof(T) == typeof(long)) { return IID.IID_NullableLong; } if (typeof(T) == typeof(ulong)) { return IID.IID_NullableULong; } if (typeof(T) == typeof(float)) { return IID.IID_NullableFloat; } if (typeof(T) == typeof(double)) { return IID.IID_NullableDouble; } if (typeof(T) == typeof(Guid)) { return IID.IID_NullableGuid; } if (typeof(T) == typeof(global::System.Type)) { return IID.IID_NullableType; } if (typeof(T) == typeof(global::System.TimeSpan)) { return IID.IID_NullableTimeSpan; } if (typeof(T) == typeof(global::System.DateTimeOffset)) { return IID.IID_NullableDateTimeOffset; } if (typeof(T) == typeof(global::Windows.Foundation.Point)) { return IID.IID_IReferenceOfPoint; } if (typeof(T) == typeof(global::Windows.Foundation.Size)) { return IID.IID_IReferenceOfSize; } if (typeof(T) == typeof(global::Windows.Foundation.Rect)) { return IID.IID_IReferenceOfRect; } if (typeof(T) == typeof(global::System.Numerics.Matrix3x2)) { return IID.IID_IReferenceMatrix3x2; } if (typeof(T) == typeof(global::System.Numerics.Matrix4x4)) { return IID.IID_IReferenceMatrix4x4; } if (typeof(T) == typeof(global::System.Numerics.Plane)) { return IID.IID_IReferencePlane; } if (typeof(T) == typeof(global::System.Numerics.Quaternion)) { return IID.IID_IReferenceQuaternion; } if (typeof(T) == typeof(global::System.Numerics.Vector2)) { return IID.IID_IReferenceVector2; } if (typeof(T) == typeof(global::System.Numerics.Vector3)) { return IID.IID_IReferenceVector3; } if (typeof(T) == typeof(global::System.Numerics.Vector4)) { return IID.IID_IReferenceVector4; } return GuidGenerator.CreateIIDUnsafe(typeof(Nullable)); } public static Func GetValueFactory(global::System.Type type) { if (!FeatureSwitches.EnableIReferenceSupport) { throw new NotSupportedException("Support for 'IReference' is not enabled."); } return ComWrappersSupport.CreateReferenceCachingFactory(GetValueFactoryInternal(type)); } private static Func GetValueFactoryInternal(global::System.Type type) { if (type == typeof(string)) { return Nullable_string.GetValue; } if (type == typeof(int)) { return NullableBlittable.GetValue; } if (type == typeof(byte)) { return NullableBlittable.GetValue; } if (type == typeof(bool)) { return NullableBlittable.GetValue; } if (type == typeof(sbyte)) { return NullableBlittable.GetValue; } if (type == typeof(short)) { return NullableBlittable.GetValue; } if (type == typeof(ushort)) { return NullableBlittable.GetValue; } if (type == typeof(char)) { return NullableBlittable.GetValue; } if (type == typeof(uint)) { return NullableBlittable.GetValue; } if (type == typeof(long)) { return NullableBlittable.GetValue; } if (type == typeof(ulong)) { return NullableBlittable.GetValue; } if (type == typeof(float)) { return NullableBlittable.GetValue; } if (type == typeof(double)) { return NullableBlittable.GetValue; } if (type == typeof(Guid)) { return NullableBlittable.GetValue; } if (type == typeof(global::System.Type)) { return Nullable_Type.GetValue; } if (type == typeof(global::System.TimeSpan)) { return Nullable_TimeSpan.GetValue; } if (type == typeof(global::System.Exception)) { return Nullable_Exception.GetValue; } if (type == typeof(global::System.DateTimeOffset)) { return Nullable_DateTimeOffset.GetValue; } if (type == typeof(global::Windows.Foundation.Point)) { return NullableBlittable.GetValue; } if (type == typeof(global::Windows.Foundation.Size)) { return NullableBlittable.GetValue; } if (type == typeof(global::Windows.Foundation.Rect)) { return NullableBlittable.GetValue; } if (type == typeof(global::System.Numerics.Matrix3x2)) { return NullableBlittable.GetValue; } if (type == typeof(global::System.Numerics.Matrix4x4)) { return NullableBlittable.GetValue; } if (type == typeof(global::System.Numerics.Plane)) { return NullableBlittable.GetValue; } if (type == typeof(global::System.Numerics.Quaternion)) { return NullableBlittable.GetValue; } if (type == typeof(global::System.Numerics.Vector2)) { return NullableBlittable.GetValue; } if (type == typeof(global::System.Numerics.Vector3)) { return NullableBlittable.GetValue; } if (type == typeof(global::System.Numerics.Vector4)) { return NullableBlittable.GetValue; } if (type == typeof(global::System.EventHandler)) { return Nullable_EventHandler.GetValue; } if (type == typeof(global::System.ComponentModel.PropertyChangedEventHandler)) { return Nullable_PropertyChangedEventHandler.GetValue; } if (type == typeof(global::System.Collections.Specialized.NotifyCollectionChangedEventHandler)) { return Nullable_NotifyCollectionChangedEventHandler.GetValue; } if (type.IsEnum && Enum.GetUnderlyingType(type) == typeof(int)) { return (IInspectable inspectable) => Nullable_IntEnum.GetValue(type, inspectable); } if (type.IsEnum && Enum.GetUnderlyingType(type) == typeof(uint)) { return (IInspectable inspectable) => Nullable_FlagsEnum.GetValue(type, inspectable); } WinRTExposedTypeAttribute customAttribute = type.GetCustomAttribute(inherit: false); if (customAttribute == null) { global::System.Type authoringMetadataType = type.GetAuthoringMetadataType(); if (authoringMetadataType != null) { customAttribute = authoringMetadataType.GetCustomAttribute(inherit: false); } } if (customAttribute != null && customAttribute.WinRTExposedTypeDetails != null && Activator.CreateInstance(customAttribute.WinRTExposedTypeDetails) is IWinRTNullableTypeDetails winRTNullableTypeDetails) { return winRTNullableTypeDetails.GetNullableValue; } if (!RuntimeFeature.IsDynamicCodeCompiled) { throw new NotSupportedException($"Failed to get the value from nullable with type '{type}'."); } if (type.IsDelegate()) { return ComWrappersSupport.CreateAbiNullableTFactory(typeof(Nullable_Delegate<>).MakeGenericType(type)); } return ComWrappersSupport.CreateNullableTFactory(typeof(global::System.Nullable<>).MakeGenericType(type)); } public static global::System.Type GetTypeAsNullableType(global::System.Type type) { if (!FeatureSwitches.EnableIReferenceSupport) { throw new NotSupportedException("Support for 'IReference' is not enabled."); } if (type == typeof(int)) { return typeof(int?); } if (type == typeof(byte)) { return typeof(byte?); } if (type == typeof(bool)) { return typeof(bool?); } if (type == typeof(sbyte)) { return typeof(sbyte?); } if (type == typeof(short)) { return typeof(short?); } if (type == typeof(ushort)) { return typeof(ushort?); } if (type == typeof(char)) { return typeof(char?); } if (type == typeof(uint)) { return typeof(uint?); } if (type == typeof(long)) { return typeof(long?); } if (type == typeof(ulong)) { return typeof(ulong?); } if (type == typeof(float)) { return typeof(float?); } if (type == typeof(double)) { return typeof(double?); } if (type == typeof(Guid)) { return typeof(Guid?); } if (type == typeof(global::System.TimeSpan)) { return typeof(global::System.TimeSpan?); } if (type == typeof(global::System.DateTimeOffset)) { return typeof(global::System.DateTimeOffset?); } if (type == typeof(global::Windows.Foundation.Point)) { return typeof(global::Windows.Foundation.Point?); } if (type == typeof(global::Windows.Foundation.Size)) { return typeof(global::Windows.Foundation.Size?); } if (type == typeof(global::Windows.Foundation.Rect)) { return typeof(global::Windows.Foundation.Rect?); } if (type == typeof(global::System.Numerics.Matrix3x2)) { return typeof(global::System.Numerics.Matrix3x2?); } if (type == typeof(global::System.Numerics.Matrix4x4)) { return typeof(global::System.Numerics.Matrix4x4?); } if (type == typeof(global::System.Numerics.Plane)) { return typeof(global::System.Numerics.Plane?); } if (type == typeof(global::System.Numerics.Quaternion)) { return typeof(global::System.Numerics.Quaternion?); } if (type == typeof(global::System.Numerics.Vector2)) { return typeof(global::System.Numerics.Vector2?); } if (type == typeof(global::System.Numerics.Vector3)) { return typeof(global::System.Numerics.Vector3?); } if (type == typeof(global::System.Numerics.Vector4)) { return typeof(global::System.Numerics.Vector4?); } WinRTExposedTypeAttribute customAttribute = type.GetCustomAttribute(inherit: false); if (customAttribute == null) { global::System.Type authoringMetadataType = type.GetAuthoringMetadataType(); if (authoringMetadataType != null) { customAttribute = authoringMetadataType.GetCustomAttribute(inherit: false); } } if (customAttribute != null && customAttribute.WinRTExposedTypeDetails != null && Activator.CreateInstance(customAttribute.WinRTExposedTypeDetails) is IWinRTNullableTypeDetails winRTNullableTypeDetails) { return winRTNullableTypeDetails.GetNullableType(); } if (!RuntimeFeature.IsDynamicCodeCompiled) { throw new NotSupportedException($"Failed to construct nullable with type '{type}'."); } return null; } } internal static class IReferenceSignatures { public const string Point = "pinterface({61c17706-2d65-11e0-9ae8-d48564015472};struct(Windows.Foundation.Point;f4;f4))"; public const string Size = "pinterface({61c17706-2d65-11e0-9ae8-d48564015472};struct(Windows.Foundation.Size;f4;f4))"; public const string Rect = "pinterface({61c17706-2d65-11e0-9ae8-d48564015472};struct(Windows.Foundation.Rect;f4;f4;f4;f4))"; public const string Matrix3x2 = "pinterface({61c17706-2d65-11e0-9ae8-d48564015472};struct(Windows.Foundation.Numerics.Matrix3x2;f4;f4;f4;f4;f4;f4))"; public const string Matrix4x4 = "pinterface({61c17706-2d65-11e0-9ae8-d48564015472};struct(Windows.Foundation.Numerics.Matrix4x4;f4;f4;f4;f4;f4;f4;f4;f4;f4;f4;f4;f4;f4;f4;f4;f4))"; public const string Plane = "pinterface({61c17706-2d65-11e0-9ae8-d48564015472};struct(Windows.Foundation.Numerics.Plane;struct(Windows.Foundation.Numerics.Vector3;f4;f4;f4);f4))"; public const string Quaternion = "pinterface({61c17706-2d65-11e0-9ae8-d48564015472};struct(Windows.Foundation.Numerics.Quaternion;f4;f4;f4;f4))"; public const string Vector2 = "pinterface({61c17706-2d65-11e0-9ae8-d48564015472};struct(Windows.Foundation.Numerics.Vector2;f4;f4))"; public const string Vector3 = "pinterface({61c17706-2d65-11e0-9ae8-d48564015472};struct(Windows.Foundation.Numerics.Vector3;f4;f4;f4))"; public const string Vector4 = "pinterface({61c17706-2d65-11e0-9ae8-d48564015472};struct(Windows.Foundation.Numerics.Vector4;f4;f4;f4;f4))"; } public struct TimeSpan { public struct Marshaler { public TimeSpan __abi; } public long Duration; public static Marshaler CreateMarshaler(global::System.TimeSpan value) { return new Marshaler { __abi = new TimeSpan { Duration = value.Ticks } }; } public static TimeSpan GetAbi(Marshaler m) { return m.__abi; } public static global::System.TimeSpan FromAbi(TimeSpan value) { return global::System.TimeSpan.FromTicks(value.Duration); } public unsafe static void CopyAbi(Marshaler arg, IntPtr dest) { *(TimeSpan*)dest.ToPointer() = GetAbi(arg); } public static TimeSpan FromManaged(global::System.TimeSpan value) { return new TimeSpan { Duration = value.Ticks }; } public unsafe static void CopyManaged(global::System.TimeSpan arg, IntPtr dest) { *(TimeSpan*)dest.ToPointer() = FromManaged(arg); } public static void DisposeMarshaler(Marshaler m) { } public static void DisposeAbi(TimeSpan abi) { } public static string GetGuidSignature() { return "struct(Windows.Foundation.TimeSpan;i8)"; } } public struct DateTimeOffset { public struct Marshaler { public DateTimeOffset __abi; } public long UniversalTime; private const long ManagedUtcTicksAtNativeZero = 504911232000000000L; public static Marshaler CreateMarshaler(global::System.DateTimeOffset value) { return new Marshaler { __abi = new DateTimeOffset { UniversalTime = value.UtcTicks - 504911232000000000L } }; } public static DateTimeOffset GetAbi(Marshaler m) { return m.__abi; } public static global::System.DateTimeOffset FromAbi(DateTimeOffset value) { global::System.DateTimeOffset dateTimeOffset = new global::System.DateTimeOffset(value.UniversalTime + 504911232000000000L, global::System.TimeSpan.Zero); global::System.TimeSpan utcOffset = TimeZoneInfo.Local.GetUtcOffset(dateTimeOffset); long num = dateTimeOffset.Ticks + utcOffset.Ticks; if (num < DateTime.MinValue.Ticks || num > DateTime.MaxValue.Ticks) { throw new ArgumentOutOfRangeException(); } return dateTimeOffset.ToLocalTime(); } public unsafe static void CopyAbi(Marshaler arg, IntPtr dest) { *(DateTimeOffset*)dest.ToPointer() = GetAbi(arg); } public static DateTimeOffset FromManaged(global::System.DateTimeOffset value) { return new DateTimeOffset { UniversalTime = value.UtcTicks - 504911232000000000L }; } public unsafe static void CopyManaged(global::System.DateTimeOffset arg, IntPtr dest) { *(DateTimeOffset*)dest.ToPointer() = FromManaged(arg); } public static void DisposeMarshaler(Marshaler m) { } public static void DisposeAbi(DateTimeOffset abi) { } public static string GetGuidSignature() { return "struct(Windows.Foundation.DateTime;i8)"; } } public struct Exception { public struct Marshaler { public Exception __abi; } public int hr; public static Marshaler CreateMarshaler(global::System.Exception value) { return new Marshaler { __abi = new Exception { hr = ((value != null) ? ExceptionHelpers.GetHRForException(value) : 0) } }; } public static Exception GetAbi(Marshaler m) { return m.__abi; } public static global::System.Exception FromAbi(Exception value) { return ExceptionHelpers.GetExceptionForHR(value.hr); } public unsafe static void CopyAbi(Marshaler arg, IntPtr dest) { *(Exception*)dest.ToPointer() = GetAbi(arg); } public static Exception FromManaged(global::System.Exception value) { return new Exception { hr = ((value != null) ? ExceptionHelpers.GetHRForException(value) : 0) }; } public unsafe static void CopyManaged(global::System.Exception arg, IntPtr dest) { *(Exception*)dest.ToPointer() = FromManaged(arg); } public static void DisposeMarshaler(Marshaler m) { } public static void DisposeAbi(Exception abi) { } public static string GetGuidSignature() { return "struct(Windows.Foundation.HResult;i4)"; } } public struct Type { internal struct MarshalerArray { public IntPtr _array; public object[] _marshalers; public void Dispose() { if (_marshalers != null) { object[] marshalers = _marshalers; foreach (object obj in marshalers) { DisposeMarshaler((Marshaler)obj); } } if (_array != IntPtr.Zero) { Marshal.FreeCoTaskMem(_array); } } } public struct Marshaler { internal MarshalString Name; internal TypeKind Kind; internal void Dispose() { MarshalString.DisposeMarshaler(Name); } } public ref struct Pinnable { internal MarshalString.Pinnable Name; internal TypeKind Kind; public Pinnable(global::System.Type type) { (string, TypeKind) tuple = ToAbi(type); Name = new MarshalString.Pinnable(tuple.Item1); Kind = tuple.Item2; } public ref readonly char GetPinnableReference() { return ref Name.GetPinnableReference(); } } private IntPtr Name; private TypeKind Kind; private static readonly ConcurrentDictionary typeNameCache = new ConcurrentDictionary(); internal unsafe static MarshalerArray CreateMarshalerArray(global::System.Type[] array) { MarshalerArray result = default(MarshalerArray); if (array == null) { return result; } bool flag = false; try { int num = array.Length; int num2 = sizeof(Type); int cb = num * num2; result._array = Marshal.AllocCoTaskMem(cb); result._marshalers = new object[num]; byte* ptr = (byte*)result._array.ToPointer(); for (int i = 0; i < num; i++) { result._marshalers[i] = CreateMarshaler(array[i]); CopyAbi((Marshaler)result._marshalers[i], (IntPtr)ptr); ptr += num2; } flag = true; return result; } finally { if (!flag) { result.Dispose(); } } } internal static (int length, IntPtr data) GetAbiArray(object box) { MarshalerArray marshalerArray = (MarshalerArray)box; object[] marshalers = marshalerArray._marshalers; return (length: (marshalers != null) ? marshalers.Length : 0, data: marshalerArray._array); } internal unsafe static global::System.Type[] FromAbiArray(object box) { if (box == null) { return null; } (int, IntPtr) tuple = ((int, IntPtr))box; if (tuple.Item2 == IntPtr.Zero) { return null; } global::System.Type[] array = new global::System.Type[tuple.Item1]; byte* ptr = (byte*)tuple.Item2.ToPointer(); int num = sizeof(Type); for (int i = 0; i < tuple.Item1; i++) { Type value = Unsafe.ReadUnaligned(ptr); array[i] = FromAbi(value); ptr += num; } return array; } internal unsafe static (int length, IntPtr data) FromManagedArray(global::System.Type[] array) { if (array == null) { return (length: 0, data: IntPtr.Zero); } IntPtr item = IntPtr.Zero; int i = 0; bool flag = false; try { int num = array.Length; int num2 = sizeof(Type); int cb = num * num2; item = Marshal.AllocCoTaskMem(cb); byte* ptr = (byte*)item.ToPointer(); for (i = 0; i < num; i++) { CopyManaged(array[i], (IntPtr)ptr); ptr += num2; } flag = true; return (length: i, data: item); } finally { if (!flag) { DisposeAbiArray((i, item)); } } } internal unsafe static void CopyManagedArray(global::System.Type[] array, IntPtr data) { if (array == null) { return; } DisposeAbiArrayElements((length: array.Length, data: data)); int i = 0; bool flag = false; try { int num = array.Length; int num2 = sizeof(Type); int num3 = num * num2; byte* ptr = (byte*)data.ToPointer(); for (i = 0; i < num; i++) { CopyManaged(array[i], (IntPtr)ptr); ptr += num2; } flag = true; } finally { if (!flag) { DisposeAbiArrayElements((length: i, data: data)); } } } internal static void DisposeMarshalerArray(object box) { ((MarshalerArray)box).Dispose(); } internal static void DisposeAbiArray(object box) { if (box != null) { (int, IntPtr) abi = ((int, IntPtr))box; if (!(abi.Item2 == IntPtr.Zero)) { DisposeAbiArrayElements(abi); Marshal.FreeCoTaskMem(abi.Item2); } } } private unsafe static void DisposeAbiArrayElements((int length, IntPtr data) abi) { byte* ptr = (byte*)abi.data.ToPointer(); int num = sizeof(Type); for (int i = 0; i < abi.length; i++) { Type abi2 = Unsafe.ReadUnaligned(ptr); DisposeAbi(abi2); ptr += num; } } private static (string Name, TypeKind Kind) ToAbi(global::System.Type value) { if (value is FakeMetadataType fakeMetadataType) { return (Name: fakeMetadataType.FullName, Kind: TypeKind.Metadata); } TypeKind typeKind = TypeKind.Custom; if ((object)value != null) { if (value.IsPrimitive) { typeKind = TypeKind.Primitive; } else if (value == typeof(object) || value == typeof(string) || value == typeof(Guid) || value == typeof(global::System.Type)) { typeKind = TypeKind.Metadata; } else if (Projections.IsTypeWindowsRuntimeType(value)) { typeKind = TypeKind.Metadata; } } return (Name: GetNameForTypeCached(value, typeKind == TypeKind.Custom), Kind: typeKind); } private static string GetNameForTypeCached(global::System.Type value, bool customKind) { if (customKind) { return typeNameCache.GetOrAdd(value, (global::System.Type type) => type.AssemblyQualifiedName); } return typeNameCache.GetOrAdd(value, (global::System.Type type) => TypeNameSupport.GetNameForType(type, TypeNameGenerationFlags.None)); } public static Marshaler CreateMarshaler(global::System.Type value) { (string, TypeKind) tuple = ToAbi(value); return new Marshaler { Name = MarshalString.CreateMarshaler(tuple.Item1), Kind = tuple.Item2 }; } public static Type GetAbi(ref Pinnable p) { return new Type { Name = MarshalString.GetAbi(ref p.Name), Kind = p.Kind }; } public static Type GetAbi(Marshaler m) { return new Type { Name = MarshalString.GetAbi(m.Name), Kind = m.Kind }; } [UnconditionalSuppressMessage("Trimming", "IL2057", Justification = "Any types which are trimmed are not used by managed user code and there is fallback logic to handle that.")] public static global::System.Type FromAbi(Type value) { string text = MarshalString.FromAbi(value.Name); if (string.IsNullOrEmpty(text)) { return null; } if (value.Kind == TypeKind.Custom) { return global::System.Type.GetType(text); } global::System.Type type = TypeNameSupport.FindTypeByNameCached(text); if (type == null && value.Kind == TypeKind.Metadata) { type = FakeMetadataType.GetFakeMetadataType(text); } return type; } public unsafe static void CopyAbi(Marshaler arg, IntPtr dest) { *(Type*)dest.ToPointer() = GetAbi(arg); } public static Type FromManaged(global::System.Type value) { (string, TypeKind) tuple = ToAbi(value); return new Type { Name = MarshalString.FromManaged(tuple.Item1), Kind = tuple.Item2 }; } public unsafe static void CopyManaged(global::System.Type arg, IntPtr dest) { *(Type*)dest.ToPointer() = FromManaged(arg); } public static void DisposeMarshaler(Marshaler m) { m.Dispose(); } public static void DisposeAbi(Type abi) { MarshalString.DisposeAbi(abi.Name); } public static string GetGuidSignature() { return "struct(Windows.UI.Xaml.Interop.TypeName;string;enum(Windows.UI.Xaml.Interop.TypeKind;i4))"; } } [WindowsRuntimeType("Windows.Foundation.UniversalApiContract")] internal enum TypeKind { Primitive, Metadata, Custom } internal sealed class FakeMetadataType : TypeInfo { private static readonly ConcurrentDictionary fakeMetadataTypeCache = new ConcurrentDictionary(StringComparer.Ordinal); private readonly string fullName; public override Assembly Assembly { get { throw new InvalidOperationException(); } } public override string AssemblyQualifiedName { get { throw new InvalidOperationException(); } } public override global::System.Type BaseType { get { throw new InvalidOperationException(); } } public override string FullName => fullName; public override Guid GUID { get { throw new InvalidOperationException(); } } public override Module Module { get { throw new InvalidOperationException(); } } public override string Namespace { get { throw new InvalidOperationException(); } } public override global::System.Type UnderlyingSystemType { get { throw new InvalidOperationException(); } } public override string Name { get { throw new InvalidOperationException(); } } private FakeMetadataType(string fullName) { this.fullName = fullName; } internal static FakeMetadataType GetFakeMetadataType(string name) { return fakeMetadataTypeCache.GetOrAdd(name, (string text) => new FakeMetadataType(text)); } [UnconditionalSuppressMessage("Trimming", "IL2094", Justification = "This method will always throw.")] public override ConstructorInfo[] GetConstructors(BindingFlags bindingAttr) { throw new InvalidOperationException(); } public override object[] GetCustomAttributes(bool inherit) { throw new InvalidOperationException(); } public override object[] GetCustomAttributes(global::System.Type attributeType, bool inherit) { throw new InvalidOperationException(); } public override global::System.Type GetElementType() { throw new InvalidOperationException(); } [UnconditionalSuppressMessage("Trimming", "IL2094", Justification = "This method will always throw.")] public override EventInfo GetEvent(string name, BindingFlags bindingAttr) { throw new InvalidOperationException(); } [UnconditionalSuppressMessage("Trimming", "IL2094", Justification = "This method will always throw.")] public override EventInfo[] GetEvents(BindingFlags bindingAttr) { throw new InvalidOperationException(); } [UnconditionalSuppressMessage("Trimming", "IL2094", Justification = "This method will always throw.")] public override FieldInfo GetField(string name, BindingFlags bindingAttr) { throw new InvalidOperationException(); } [UnconditionalSuppressMessage("Trimming", "IL2094", Justification = "This method will always throw.")] public override FieldInfo[] GetFields(BindingFlags bindingAttr) { throw new InvalidOperationException(); } [UnconditionalSuppressMessage("Trimming", "IL2093", Justification = "This method will always throw.")] [UnconditionalSuppressMessage("Trimming", "IL2094", Justification = "This method will always throw.")] public override global::System.Type GetInterface(string name, bool ignoreCase) { throw new InvalidOperationException(); } [UnconditionalSuppressMessage("Trimming", "IL2094", Justification = "This method will always throw.")] public override global::System.Type[] GetInterfaces() { throw new InvalidOperationException(); } [UnconditionalSuppressMessage("Trimming", "IL2094", Justification = "This method will always throw.")] public override MemberInfo[] GetMembers(BindingFlags bindingAttr) { throw new InvalidOperationException(); } [UnconditionalSuppressMessage("Trimming", "IL2094", Justification = "This method will always throw.")] public override MethodInfo[] GetMethods(BindingFlags bindingAttr) { throw new InvalidOperationException(); } [UnconditionalSuppressMessage("Trimming", "IL2094", Justification = "This method will always throw.")] public override global::System.Type GetNestedType(string name, BindingFlags bindingAttr) { throw new InvalidOperationException(); } [UnconditionalSuppressMessage("Trimming", "IL2094", Justification = "This method will always throw.")] public override global::System.Type[] GetNestedTypes(BindingFlags bindingAttr) { throw new InvalidOperationException(); } [UnconditionalSuppressMessage("Trimming", "IL2094", Justification = "This method will always throw.")] public override PropertyInfo[] GetProperties(BindingFlags bindingAttr) { throw new InvalidOperationException(); } [UnconditionalSuppressMessage("Trimming", "IL2094", Justification = "This method will always throw.")] public override object InvokeMember(string name, BindingFlags invokeAttr, Binder binder, object target, object[] args, ParameterModifier[] modifiers, CultureInfo culture, string[] namedParameters) { throw new InvalidOperationException(); } public override bool IsDefined(global::System.Type attributeType, bool inherit) { throw new InvalidOperationException(); } protected override TypeAttributes GetAttributeFlagsImpl() { throw new InvalidOperationException(); } [UnconditionalSuppressMessage("Trimming", "IL2094", Justification = "This method will always throw.")] protected override ConstructorInfo GetConstructorImpl(BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, global::System.Type[] types, ParameterModifier[] modifiers) { throw new InvalidOperationException(); } [UnconditionalSuppressMessage("Trimming", "IL2094", Justification = "This method will always throw.")] protected override MethodInfo GetMethodImpl(string name, BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, global::System.Type[] types, ParameterModifier[] modifiers) { throw new InvalidOperationException(); } [UnconditionalSuppressMessage("Trimming", "IL2094", Justification = "This method will always throw.")] protected override PropertyInfo GetPropertyImpl(string name, BindingFlags bindingAttr, Binder binder, global::System.Type returnType, global::System.Type[] types, ParameterModifier[] modifiers) { throw new InvalidOperationException(); } protected override bool HasElementTypeImpl() { throw new InvalidOperationException(); } protected override bool IsArrayImpl() { throw new InvalidOperationException(); } protected override bool IsByRefImpl() { throw new InvalidOperationException(); } protected override bool IsCOMObjectImpl() { throw new InvalidOperationException(); } protected override bool IsPointerImpl() { throw new InvalidOperationException(); } protected override bool IsPrimitiveImpl() { throw new InvalidOperationException(); } public override string ToString() { return fullName; } public override bool Equals(object o) { return this == o; } public override bool Equals(global::System.Type o) { return (object)this == o; } public override int GetHashCode() { return fullName.GetHashCode(); } } [Guid("44A9796F-723E-4FDF-A218-033E75B0C084")] internal sealed class WinRTUriRuntimeClassFactory { [Guid("44A9796F-723E-4FDF-A218-033E75B0C084")] public struct Vftbl { internal IInspectable.Vftbl IInspectableVftbl; private unsafe void* _CreateUri_0; public IntPtr _CreateWithRelativeUri; public unsafe delegate* unmanaged[Stdcall] CreateUri_0 => (delegate* unmanaged[Stdcall])_CreateUri_0; } private readonly ObjectReference _obj; public IntPtr ThisPtr => _obj.ThisPtr; public static ObjectReference FromAbi(IntPtr thisPtr) { return ObjectReference.FromAbi(thisPtr, IID.IID_UriRuntimeClassFactory); } public WinRTUriRuntimeClassFactory(IObjectReference obj) : this(obj.As(IID.IID_UriRuntimeClassFactory)) { } public WinRTUriRuntimeClassFactory(ObjectReference obj) { _obj = obj; } public unsafe IObjectReference CreateUri(string uri) { IntPtr thisPtr = default(IntPtr); MarshalString.Pinnable p = new MarshalString.Pinnable(uri); fixed (char* ptr = p) { void* ptr2 = ptr; ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)ThisPtr) + (nint)6 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(ThisPtr, MarshalString.GetAbi(ref p), &thisPtr)); GC.KeepAlive(_obj); return ObjectReference.Attach(ref thisPtr, IID.IID_IUnknown); } } public unsafe ObjectReferenceValue CreateUriForMarshaling(string uri) { IntPtr ptr = default(IntPtr); MarshalString.Pinnable p = new MarshalString.Pinnable(uri); fixed (char* ptr2 = p) { void* ptr3 = ptr2; ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)ThisPtr) + (nint)6 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(ThisPtr, MarshalString.GetAbi(ref p), &ptr)); GC.KeepAlive(_obj); return new ObjectReferenceValue(ptr); } } } public struct Uri { private static readonly WinRTUriRuntimeClassFactory Instance = new WinRTUriRuntimeClassFactory(ActivationFactory.Get("Windows.Foundation.Uri")); public static IObjectReference CreateMarshaler(global::System.Uri value) { if ((object)value == null) { return null; } return Instance.CreateUri(value.OriginalString); } public static ObjectReferenceValue CreateMarshaler2(global::System.Uri value) { if ((object)value == null) { return default(ObjectReferenceValue); } return Instance.CreateUriForMarshaling(value.OriginalString); } public static IntPtr GetAbi(IObjectReference m) { return m?.ThisPtr ?? IntPtr.Zero; } public unsafe static global::System.Uri FromAbi(IntPtr ptr) { if (ptr == IntPtr.Zero) { return null; } IntPtr zero = IntPtr.Zero; try { ExceptionHelpers.ThrowExceptionForHR(((IUriRuntimeClassVftbl*)(*(nint*)(void*)ptr))->get_RawUri_10(ptr, &zero)); return new global::System.Uri(MarshalString.FromAbi(zero)); } finally { MarshalString.DisposeAbi(zero); } } public static global::System.Uri[] FromAbiArray(object box) { return MarshalInterfaceHelper.FromAbiArray(box, FromAbi); } public unsafe static void CopyManaged(global::System.Uri o, IntPtr dest) { *(IntPtr*)dest.ToPointer() = CreateMarshaler2(o).Detach(); } public static IntPtr FromManaged(global::System.Uri value) { if ((object)value == null) { return IntPtr.Zero; } return CreateMarshaler2(value).Detach(); } public static MarshalInterfaceHelper.MarshalerArray CreateMarshalerArray(global::System.Uri[] array) { return MarshalInterfaceHelper.CreateMarshalerArray2(array, (global::System.Uri o) => CreateMarshaler2(o)); } public static (int length, IntPtr data) GetAbiArray(object box) { return MarshalInterfaceHelper.GetAbiArray(box); } public static void CopyAbiArray(global::System.Uri[] array, object box) { MarshalInterfaceHelper.CopyAbiArray(array, box, FromAbi); } public static (int length, IntPtr data) FromManagedArray(global::System.Uri[] array) { return MarshalInterfaceHelper.FromManagedArray(array, (global::System.Uri o) => FromManaged(o)); } public static void DisposeMarshalerArray(MarshalInterfaceHelper.MarshalerArray array) { MarshalInterfaceHelper.DisposeMarshalerArray(array); } public static void DisposeMarshaler(IObjectReference m) { m?.Dispose(); } public static void DisposeAbi(IntPtr abi) { MarshalInspectable.DisposeAbi(abi); } public static void DisposeAbiArray(object box) { MarshalInterfaceHelper.DisposeAbiArray(box); } public static string GetGuidSignature() { return "rc(Windows.Foundation.Uri;{9e365e57-48b2-4160-956f-c7385120bbfc})"; } } } namespace ABI.System.Numerics { public struct Matrix3x2 { public static string GetGuidSignature() { return "struct(Windows.Foundation.Numerics.Matrix3x2;f4;f4;f4;f4;f4;f4)"; } } public struct Matrix4x4 { public static string GetGuidSignature() { return "struct(Windows.Foundation.Numerics.Matrix4x4;f4;f4;f4;f4;f4;f4;f4;f4;f4;f4;f4;f4;f4;f4;f4;f4)"; } } public struct Plane { public static string GetGuidSignature() { return "struct(Windows.Foundation.Numerics.Plane;struct(Windows.Foundation.Numerics.Vector3;f4;f4;f4);f4)"; } } public struct Quaternion { public static string GetGuidSignature() { return "struct(Windows.Foundation.Numerics.Quaternion;f4;f4;f4;f4)"; } } public struct Vector2 { public static string GetGuidSignature() { return "struct(Windows.Foundation.Numerics.Vector2;f4;f4)"; } } public struct Vector3 { public static string GetGuidSignature() { return "struct(Windows.Foundation.Numerics.Vector3;f4;f4;f4)"; } } public struct Vector4 { public static string GetGuidSignature() { return "struct(Windows.Foundation.Numerics.Vector4;f4;f4;f4;f4)"; } } } namespace ABI.System.Windows.Input { public static class ICommandMethods { private static volatile ConditionalWeakTable _CanExecuteChanged; public static Guid IID => global::WinRT.Interop.IID.IID_ICommand; public static IntPtr AbiToProjectionVftablePtr => ICommand.Vftbl.AbiToProjectionVftablePtr; private static ConditionalWeakTable CanExecuteChanged => _CanExecuteChanged ?? MakeCanExecuteChangedTable(); public unsafe static bool CanExecute(IObjectReference obj, object parameter) { IntPtr thisPtr = obj.ThisPtr; ObjectReferenceValue value = default(ObjectReferenceValue); byte b = 0; try { value = MarshalInspectable.CreateMarshaler2(parameter); ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)8 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(thisPtr, MarshalInspectable.GetAbi(value), &b)); GC.KeepAlive(obj); return b != 0; } finally { MarshalInspectable.DisposeMarshaler(value); } } public unsafe static void Execute(IObjectReference obj, object parameter) { IntPtr thisPtr = obj.ThisPtr; ObjectReferenceValue value = default(ObjectReferenceValue); try { value = MarshalInspectable.CreateMarshaler2(parameter); ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)9 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(thisPtr, MarshalInspectable.GetAbi(value))); GC.KeepAlive(obj); } finally { MarshalInspectable.DisposeMarshaler(value); } } private static ConditionalWeakTable MakeCanExecuteChangedTable() { Interlocked.CompareExchange(ref _CanExecuteChanged, new ConditionalWeakTable(), null); return _CanExecuteChanged; } public unsafe static EventHandlerEventSource Get_CanExecuteChanged2(IObjectReference obj, object thisObj) { return CanExecuteChanged.GetValue(thisObj, delegate { IntPtr thisPtr = obj.ThisPtr; return new EventHandlerEventSource(obj, (delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)6 * (nint)sizeof(delegate* unmanaged[Stdcall]))), (delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)7 * (nint)sizeof(delegate* unmanaged[Stdcall])))); }); } } [EditorBrowsable(EditorBrowsableState.Never)] [Guid("E5AF3542-CA67-4081-995B-709DD13792DF")] [DynamicInterfaceCastableImplementation] internal interface ICommand : global::System.Windows.Input.ICommand { [Guid("E5AF3542-CA67-4081-995B-709DD13792DF")] public struct Vftbl { internal IInspectable.Vftbl IInspectableVftbl; private unsafe void* _add_CanExecuteChanged_0; private unsafe void* _remove_CanExecuteChanged_1; private unsafe void* _CanExecute_2; private unsafe void* _Execute_3; private static readonly Vftbl AbiToProjectionVftable; public static readonly IntPtr AbiToProjectionVftablePtr; private static volatile ConditionalWeakTable> _canExecuteChanged_TokenTables; public unsafe delegate* unmanaged[Stdcall] add_CanExecuteChanged_0 { get { return (delegate* unmanaged[Stdcall])_add_CanExecuteChanged_0; } set { _add_CanExecuteChanged_0 = value; } } public unsafe delegate* unmanaged[Stdcall] remove_CanExecuteChanged_1 { get { return (delegate* unmanaged[Stdcall])_remove_CanExecuteChanged_1; } set { _remove_CanExecuteChanged_1 = value; } } public unsafe delegate* unmanaged[Stdcall] CanExecute_2 { get { return (delegate* unmanaged[Stdcall])_CanExecute_2; } set { _CanExecute_2 = value; } } public unsafe delegate* unmanaged[Stdcall] Execute_3 { get { return (delegate* unmanaged[Stdcall])_Execute_3; } set { _Execute_3 = value; } } private static ConditionalWeakTable> _CanExecuteChanged_TokenTables => _canExecuteChanged_TokenTables ?? MakeConditionalWeakTable(); unsafe static Vftbl() { AbiToProjectionVftable = new Vftbl { IInspectableVftbl = IInspectable.Vftbl.AbiToProjectionVftable, _add_CanExecuteChanged_0 = (delegate*)(&Do_Abi_add_CanExecuteChanged_0), _remove_CanExecuteChanged_1 = (delegate*)(&Do_Abi_remove_CanExecuteChanged_1), _CanExecute_2 = (delegate*)(&Do_Abi_CanExecute_2), _Execute_3 = (delegate*)(&Do_Abi_Execute_3) }; IntPtr* ptr = (IntPtr*)(void*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), sizeof(IInspectable.Vftbl) + sizeof(IntPtr) * 4); *(Vftbl*)ptr = AbiToProjectionVftable; AbiToProjectionVftablePtr = (IntPtr)ptr; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_CanExecute_2(IntPtr thisPtr, IntPtr parameter, byte* result) { bool flag = false; *result = 0; try { flag = ComWrappersSupport.FindObject(thisPtr).CanExecute(MarshalInspectable.FromAbi(parameter)); *result = (flag ? ((byte)1) : ((byte)0)); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly] private static int Do_Abi_Execute_3(IntPtr thisPtr, IntPtr parameter) { try { ComWrappersSupport.FindObject(thisPtr).Execute(MarshalInspectable.FromAbi(parameter)); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } private static ConditionalWeakTable> MakeConditionalWeakTable() { Interlocked.CompareExchange(ref _canExecuteChanged_TokenTables, new ConditionalWeakTable>(), null); return _canExecuteChanged_TokenTables; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_add_CanExecuteChanged_0(IntPtr thisPtr, IntPtr handler, global::WinRT.EventRegistrationToken* token) { *token = default(global::WinRT.EventRegistrationToken); try { global::System.Windows.Input.ICommand command = ComWrappersSupport.FindObject(thisPtr); global::System.EventHandler eventHandler = EventHandler.FromAbi(handler); *token = _CanExecuteChanged_TokenTables.GetOrCreateValue(command).AddEventHandler(eventHandler); command.CanExecuteChanged += eventHandler; return 0; } catch (global::System.Exception ex) { return ex.HResult; } } [UnmanagedCallersOnly] private static int Do_Abi_remove_CanExecuteChanged_1(IntPtr thisPtr, global::WinRT.EventRegistrationToken token) { try { global::System.Windows.Input.ICommand command = ComWrappersSupport.FindObject(thisPtr); if (command != null && _CanExecuteChanged_TokenTables.TryGetValue(command, out var value) && value.RemoveEventHandler(token, out global::System.EventHandler handler)) { command.CanExecuteChanged -= handler; } return 0; } catch (global::System.Exception ex) { return ex.HResult; } } } event global::System.EventHandler global::System.Windows.Input.ICommand.CanExecuteChanged { add { _CanExecuteChanged((IWinRTObject)this).Subscribe(value); } remove { _CanExecuteChanged((IWinRTObject)this).Unsubscribe(value); } } static ObjectReference FromAbi(IntPtr thisPtr) { return ObjectReference.FromAbi(thisPtr, IID.IID_ICommand); } private static EventHandlerEventSource _CanExecuteChanged(IWinRTObject _this) { IObjectReference objectReferenceForType = _this.GetObjectReferenceForType(typeof(global::System.Windows.Input.ICommand).TypeHandle); return ICommandMethods.Get_CanExecuteChanged2(objectReferenceForType, _this); } bool global::System.Windows.Input.ICommand.CanExecute(object parameter) { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Windows.Input.ICommand).TypeHandle); return ICommandMethods.CanExecute(objectReferenceForType, parameter); } void global::System.Windows.Input.ICommand.Execute(object parameter) { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Windows.Input.ICommand).TypeHandle); ICommandMethods.Execute(objectReferenceForType, parameter); } } [EditorBrowsable(EditorBrowsableState.Never)] public static class ICommand_Delegates { public unsafe delegate int add_CanExecuteChanged_0(IntPtr thisPtr, IntPtr handler, global::WinRT.EventRegistrationToken* token); public unsafe delegate int CanExecute_2(IntPtr thisPtr, IntPtr parameter, byte* result); public delegate int Execute_3(IntPtr thisPtr, IntPtr parameter); } } namespace ABI.System.ComponentModel { [EditorBrowsable(EditorBrowsableState.Never)] public struct DataErrorsChangedEventArgs { private static readonly WinRTDataErrorsChangedEventArgsRuntimeClassFactory Instance = new WinRTDataErrorsChangedEventArgsRuntimeClassFactory(ActivationFactory.Get("Microsoft.UI.Xaml.Data.DataErrorsChangedEventArgs")); public static IObjectReference CreateMarshaler(global::System.ComponentModel.DataErrorsChangedEventArgs value) { if (value == null) { return null; } return Instance.CreateInstance(value.PropertyName); } public static ObjectReferenceValue CreateMarshaler2(global::System.ComponentModel.DataErrorsChangedEventArgs value) { if (value == null) { return default(ObjectReferenceValue); } return Instance.CreateInstanceForMarshaling(value.PropertyName); } public static IntPtr GetAbi(IObjectReference m) { return m?.ThisPtr ?? IntPtr.Zero; } public unsafe static global::System.ComponentModel.DataErrorsChangedEventArgs FromAbi(IntPtr ptr) { if (ptr == IntPtr.Zero) { return null; } IntPtr zero = IntPtr.Zero; try { ExceptionHelpers.ThrowExceptionForHR(((IDataErrorsChangedEventArgsVftbl*)(*(nint*)(void*)ptr))->get_PropertyName_0(ptr, &zero)); return new global::System.ComponentModel.DataErrorsChangedEventArgs(MarshalString.FromAbi(zero)); } finally { MarshalString.DisposeAbi(zero); } } public unsafe static void CopyManaged(global::System.ComponentModel.DataErrorsChangedEventArgs o, IntPtr dest) { *(IntPtr*)dest.ToPointer() = CreateMarshaler2(o).Detach(); } public static IntPtr FromManaged(global::System.ComponentModel.DataErrorsChangedEventArgs value) { if (value == null) { return IntPtr.Zero; } return CreateMarshaler2(value).Detach(); } public static void DisposeMarshaler(IObjectReference m) { m?.Dispose(); } public static void DisposeAbi(IntPtr abi) { MarshalInspectable.DisposeAbi(abi); } public static MarshalInterfaceHelper.MarshalerArray CreateMarshalerArray(global::System.ComponentModel.DataErrorsChangedEventArgs[] array) { return MarshalInterfaceHelper.CreateMarshalerArray2(array, CreateMarshaler2); } public static (int length, IntPtr data) GetAbiArray(object box) { return MarshalInterfaceHelper.GetAbiArray(box); } public static global::System.ComponentModel.DataErrorsChangedEventArgs[] FromAbiArray(object box) { return MarshalInterfaceHelper.FromAbiArray(box, FromAbi); } public static void CopyAbiArray(global::System.ComponentModel.DataErrorsChangedEventArgs[] array, object box) { MarshalInterfaceHelper.CopyAbiArray(array, box, FromAbi); } public static (int length, IntPtr data) FromManagedArray(global::System.ComponentModel.DataErrorsChangedEventArgs[] array) { return MarshalInterfaceHelper.FromManagedArray(array, FromManaged); } public static void DisposeMarshalerArray(MarshalInterfaceHelper.MarshalerArray array) { MarshalInterfaceHelper.DisposeMarshalerArray(array); } public static void DisposeAbiArray(object box) { MarshalInspectable.DisposeAbiArray(box); } public static string GetGuidSignature() { return "rc(Microsoft.UI.Xaml.Data.DataErrorsChangedEventArgs;{d026dd64-5f26-5f15-a86a-0dec8a431796})"; } } public static class INotifyDataErrorInfoMethods { private static volatile ConditionalWeakTable> _ErrorsChanged; public static Guid IID => global::WinRT.Interop.IID.IID_INotifyDataErrorInfo; public static IntPtr AbiToProjectionVftablePtr => INotifyDataErrorInfo.Vftbl.AbiToProjectionVftablePtr; private static ConditionalWeakTable> ErrorsChanged => _ErrorsChanged ?? MakeErrorsChangedTable(); public unsafe static bool get_HasErrors(IObjectReference obj) { IntPtr thisPtr = obj.ThisPtr; byte b = 0; ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)6 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(thisPtr, &b)); GC.KeepAlive(obj); return b != 0; } public unsafe static global::System.Collections.IEnumerable GetErrors(IObjectReference obj, string propertyName) { if (!FeatureSwitches.EnableIDynamicInterfaceCastableSupport) { throw new NotSupportedException("'INotifyDataErrorInfo.GetErrors' relies on 'IDynamicInterfaceCastable' support, which is not currently available. Make sure the 'EnableIDynamicInterfaceCastableSupport' property is not set to 'false'."); } IntPtr thisPtr = obj.ThisPtr; IntPtr intPtr = default(IntPtr); try { MarshalString.Pinnable p = new MarshalString.Pinnable(propertyName); fixed (char* ptr = p) { void* ptr2 = ptr; ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)9 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(thisPtr, MarshalString.GetAbi(ref p), &intPtr)); GC.KeepAlive(obj); return (ABI.System.Collections.Generic.IEnumerable)IInspectable.FromAbi(intPtr); } } finally { ABI.System.Collections.Generic.IEnumerable.DisposeAbi(intPtr); } } private static ConditionalWeakTable> MakeErrorsChangedTable() { Interlocked.CompareExchange(ref _ErrorsChanged, new ConditionalWeakTable>(), null); return _ErrorsChanged; } public unsafe static EventHandlerEventSource Get_ErrorsChanged2(IObjectReference obj, object thisObj) { return ErrorsChanged.GetValue(thisObj, delegate { IntPtr thisPtr = obj.ThisPtr; return new EventHandlerEventSource(obj, (delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)7 * (nint)sizeof(delegate* unmanaged[Stdcall]))), (delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)8 * (nint)sizeof(delegate* unmanaged[Stdcall]))), 0); }); } } [DynamicInterfaceCastableImplementation] [EditorBrowsable(EditorBrowsableState.Never)] [Guid("0EE6C2CC-273E-567D-BC0A-1DD87EE51EBA")] internal interface INotifyDataErrorInfo : global::System.ComponentModel.INotifyDataErrorInfo { [Guid("0EE6C2CC-273E-567D-BC0A-1DD87EE51EBA")] public struct Vftbl { internal IInspectable.Vftbl IInspectableVftbl; public unsafe delegate* unmanaged get_HasErrors_0; public unsafe delegate* unmanaged[Stdcall] add_ErrorsChanged_1; public unsafe delegate* unmanaged[Stdcall] remove_ErrorsChanged_2; public unsafe delegate* unmanaged GetErrors_3; public static readonly IntPtr AbiToProjectionVftablePtr; private static volatile ConditionalWeakTable>> _ErrorsChanged_TokenTablesLazy; private static ConditionalWeakTable>> _ErrorsChanged_TokenTables => _ErrorsChanged_TokenTablesLazy ?? MakeConditionalWeakTable(); unsafe static Vftbl() { AbiToProjectionVftablePtr = ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), sizeof(IInspectable.Vftbl) + sizeof(IntPtr) * 4); *(Vftbl*)(void*)AbiToProjectionVftablePtr = new Vftbl { IInspectableVftbl = IInspectable.Vftbl.AbiToProjectionVftable, get_HasErrors_0 = (delegate* unmanaged)(delegate*)(&Do_Abi_get_HasErrors_0), add_ErrorsChanged_1 = (delegate* unmanaged[Stdcall])(delegate*)(&Do_Abi_add_ErrorsChanged_1), remove_ErrorsChanged_2 = (delegate* unmanaged[Stdcall])(delegate*)(&Do_Abi_remove_ErrorsChanged_2), GetErrors_3 = (delegate* unmanaged)(delegate*)(&Do_Abi_GetErrors_3) }; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_GetErrors_3(IntPtr thisPtr, IntPtr propertyName, IntPtr* result) { global::System.Collections.Generic.IEnumerable enumerable = null; *result = default(IntPtr); try { enumerable = ComWrappersSupport.FindObject(thisPtr).GetErrors(MarshalString.FromAbi(propertyName)).OfType(); *result = ABI.System.Collections.Generic.IEnumerable.FromManaged(enumerable); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_get_HasErrors_0(IntPtr thisPtr, byte* value) { bool flag = false; *value = 0; try { flag = ComWrappersSupport.FindObject(thisPtr).HasErrors; *value = (flag ? ((byte)1) : ((byte)0)); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } private static ConditionalWeakTable>> MakeConditionalWeakTable() { Interlocked.CompareExchange(ref _ErrorsChanged_TokenTablesLazy, new ConditionalWeakTable>>(), null); return _ErrorsChanged_TokenTablesLazy; } [UnmanagedCallersOnly(CallConvs = new global::System.Type[] { typeof(CallConvStdcall) })] private unsafe static int Do_Abi_add_ErrorsChanged_1(IntPtr thisPtr, IntPtr handler, global::WinRT.EventRegistrationToken* token) { *token = default(global::WinRT.EventRegistrationToken); try { global::System.ComponentModel.INotifyDataErrorInfo notifyDataErrorInfo = ComWrappersSupport.FindObject(thisPtr); global::System.EventHandler eventHandler = EventHandler.FromAbi(handler); *token = _ErrorsChanged_TokenTables.GetOrCreateValue(notifyDataErrorInfo).AddEventHandler(eventHandler); notifyDataErrorInfo.ErrorsChanged += eventHandler; return 0; } catch (global::System.Exception ex) { return ex.HResult; } } [UnmanagedCallersOnly(CallConvs = new global::System.Type[] { typeof(CallConvStdcall) })] private static int Do_Abi_remove_ErrorsChanged_2(IntPtr thisPtr, global::WinRT.EventRegistrationToken token) { try { global::System.ComponentModel.INotifyDataErrorInfo notifyDataErrorInfo = ComWrappersSupport.FindObject(thisPtr); if (notifyDataErrorInfo != null && _ErrorsChanged_TokenTables.TryGetValue(notifyDataErrorInfo, out var value) && value.RemoveEventHandler(token, out global::System.EventHandler handler)) { notifyDataErrorInfo.ErrorsChanged -= handler; } return 0; } catch (global::System.Exception ex) { return ex.HResult; } } } bool global::System.ComponentModel.INotifyDataErrorInfo.HasErrors { get { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.ComponentModel.INotifyDataErrorInfo).TypeHandle); return INotifyDataErrorInfoMethods.get_HasErrors(objectReferenceForType); } } event global::System.EventHandler global::System.ComponentModel.INotifyDataErrorInfo.ErrorsChanged { add { _ErrorsChanged((IWinRTObject)this).Subscribe(value); } remove { _ErrorsChanged((IWinRTObject)this).Unsubscribe(value); } } internal static ObjectReference FromAbi(IntPtr thisPtr) { return ObjectReference.FromAbi(thisPtr, IID.IID_INotifyDataErrorInfo); } private static EventHandlerEventSource _ErrorsChanged(IWinRTObject _this) { IObjectReference objectReferenceForType = _this.GetObjectReferenceForType(typeof(global::System.ComponentModel.INotifyDataErrorInfo).TypeHandle); return INotifyDataErrorInfoMethods.Get_ErrorsChanged2(objectReferenceForType, _this); } global::System.Collections.IEnumerable global::System.ComponentModel.INotifyDataErrorInfo.GetErrors(string propertyName) { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.ComponentModel.INotifyDataErrorInfo).TypeHandle); return INotifyDataErrorInfoMethods.GetErrors(objectReferenceForType, propertyName); } } internal static class INotifyDataErrorInfo_Delegates { public unsafe delegate int get_HasErrors_0(IntPtr thisPtr, byte* value); public unsafe delegate int add_ErrorsChanged_1(IntPtr thisPtr, IntPtr handler, global::WinRT.EventRegistrationToken* token); public delegate int remove_ErrorsChanged_2(IntPtr thisPtr, global::WinRT.EventRegistrationToken token); public unsafe delegate int GetErrors_3(IntPtr thisPtr, IntPtr propertyName, IntPtr* result); } public static class INotifyPropertyChangedMethods { private static volatile ConditionalWeakTable _PropertyChanged; public static Guid IID { get { if (!FeatureSwitches.UseWindowsUIXamlProjections) { return global::WinRT.Interop.IID.IID_MUX_INotifyPropertyChanged; } return global::WinRT.Interop.IID.IID_WUX_INotifyPropertyChanged; } } public static IntPtr AbiToProjectionVftablePtr => INotifyPropertyChanged.Vftbl.AbiToProjectionVftablePtr; private static ConditionalWeakTable PropertyChanged => _PropertyChanged ?? MakePropertyChangedTable(); private static ConditionalWeakTable MakePropertyChangedTable() { Interlocked.CompareExchange(ref _PropertyChanged, new ConditionalWeakTable(), null); return _PropertyChanged; } public unsafe static EventSource Get_PropertyChanged2(IObjectReference obj, object thisObj) { return PropertyChanged.GetValue(thisObj, delegate { IntPtr thisPtr = obj.ThisPtr; return new PropertyChangedEventSource(obj, (delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)6 * (nint)sizeof(delegate* unmanaged[Stdcall]))), (delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)7 * (nint)sizeof(delegate* unmanaged[Stdcall])))); }); } } [DynamicInterfaceCastableImplementation] [Guid("90B17601-B065-586E-83D9-9ADC3A695284")] [WuxMuxProjectedType] internal interface INotifyPropertyChanged : global::System.ComponentModel.INotifyPropertyChanged { [Guid("90B17601-B065-586E-83D9-9ADC3A695284")] public struct Vftbl { internal IInspectable.Vftbl IInspectableVftbl; private unsafe delegate* unmanaged _add_PropertyChanged_0; private unsafe delegate* unmanaged _remove_PropertyChanged_1; private static readonly Vftbl AbiToProjectionVftable; public static readonly IntPtr AbiToProjectionVftablePtr; private static volatile ConditionalWeakTable> _PropertyChanged_TokenTablesLazy; public unsafe delegate* unmanaged[Stdcall] add_PropertyChanged_0 { get { return (delegate* unmanaged[Stdcall])_add_PropertyChanged_0; } set { _add_PropertyChanged_0 = (delegate* unmanaged)value; } } public unsafe delegate* unmanaged[Stdcall] remove_PropertyChanged_1 { get { return (delegate* unmanaged[Stdcall])_remove_PropertyChanged_1; } set { _remove_PropertyChanged_1 = (delegate* unmanaged)value; } } private static ConditionalWeakTable> _PropertyChanged_TokenTables => _PropertyChanged_TokenTablesLazy ?? MakeConditionalWeakTable(); unsafe static Vftbl() { AbiToProjectionVftable = new Vftbl { IInspectableVftbl = IInspectable.Vftbl.AbiToProjectionVftable, _add_PropertyChanged_0 = (delegate* unmanaged)(delegate*)(&Do_Abi_add_PropertyChanged_0), _remove_PropertyChanged_1 = (delegate* unmanaged)(delegate*)(&Do_Abi_remove_PropertyChanged_1) }; IntPtr* ptr = (IntPtr*)(void*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), sizeof(IInspectable.Vftbl) + sizeof(IntPtr) * 2); *(Vftbl*)ptr = AbiToProjectionVftable; AbiToProjectionVftablePtr = (IntPtr)ptr; } private static ConditionalWeakTable> MakeConditionalWeakTable() { Interlocked.CompareExchange(ref _PropertyChanged_TokenTablesLazy, new ConditionalWeakTable>(), null); return _PropertyChanged_TokenTablesLazy; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_add_PropertyChanged_0(IntPtr thisPtr, IntPtr handler, global::WinRT.EventRegistrationToken* token) { *token = default(global::WinRT.EventRegistrationToken); try { global::System.ComponentModel.INotifyPropertyChanged notifyPropertyChanged = ComWrappersSupport.FindObject(thisPtr); global::System.ComponentModel.PropertyChangedEventHandler propertyChangedEventHandler = PropertyChangedEventHandler.FromAbi(handler); *token = _PropertyChanged_TokenTables.GetOrCreateValue(notifyPropertyChanged).AddEventHandler(propertyChangedEventHandler); notifyPropertyChanged.PropertyChanged += propertyChangedEventHandler; return 0; } catch (global::System.Exception ex) { return ex.HResult; } } [UnmanagedCallersOnly] private static int Do_Abi_remove_PropertyChanged_1(IntPtr thisPtr, global::WinRT.EventRegistrationToken token) { try { global::System.ComponentModel.INotifyPropertyChanged notifyPropertyChanged = ComWrappersSupport.FindObject(thisPtr); if (notifyPropertyChanged != null && _PropertyChanged_TokenTables.TryGetValue(notifyPropertyChanged, out var value) && value.RemoveEventHandler(token, out global::System.ComponentModel.PropertyChangedEventHandler handler)) { notifyPropertyChanged.PropertyChanged -= handler; } return 0; } catch (global::System.Exception ex) { return ex.HResult; } } } event global::System.ComponentModel.PropertyChangedEventHandler global::System.ComponentModel.INotifyPropertyChanged.PropertyChanged { add { _PropertyChanged((IWinRTObject)this).Subscribe(value); } remove { _PropertyChanged((IWinRTObject)this).Unsubscribe(value); } } private static EventSource _PropertyChanged(IWinRTObject _this) { IObjectReference objectReferenceForType = _this.GetObjectReferenceForType(typeof(global::System.ComponentModel.INotifyPropertyChanged).TypeHandle); return INotifyPropertyChangedMethods.Get_PropertyChanged2(objectReferenceForType, _this); } } [EditorBrowsable(EditorBrowsableState.Never)] public struct PropertyChangedEventArgs { private static readonly PropertyChangedEventArgsRuntimeClassFactory Instance = new PropertyChangedEventArgsRuntimeClassFactory(); public static IObjectReference CreateMarshaler(global::System.ComponentModel.PropertyChangedEventArgs value) { if (value == null) { return null; } IObjectReference innerInterface; return Instance.CreateInstance(value.PropertyName, null, out innerInterface); } public static ObjectReferenceValue CreateMarshaler2(global::System.ComponentModel.PropertyChangedEventArgs value) { if (value == null) { return default(ObjectReferenceValue); } return Instance.CreateInstance(value.PropertyName); } public static IntPtr GetAbi(IObjectReference m) { return m?.ThisPtr ?? IntPtr.Zero; } public unsafe static global::System.ComponentModel.PropertyChangedEventArgs FromAbi(IntPtr ptr) { if (ptr == IntPtr.Zero) { return null; } IntPtr zero = IntPtr.Zero; try { ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)ptr) + (nint)6 * (nint)sizeof(void*))))(ptr, &zero)); return new global::System.ComponentModel.PropertyChangedEventArgs(MarshalString.FromAbi(zero)); } finally { MarshalString.DisposeAbi(zero); } } public unsafe static void CopyManaged(global::System.ComponentModel.PropertyChangedEventArgs o, IntPtr dest) { *(IntPtr*)dest.ToPointer() = CreateMarshaler2(o).Detach(); } public static IntPtr FromManaged(global::System.ComponentModel.PropertyChangedEventArgs value) { if (value == null) { return IntPtr.Zero; } return CreateMarshaler2(value).Detach(); } public static void DisposeMarshaler(IObjectReference m) { m?.Dispose(); } public static void DisposeAbi(IntPtr abi) { MarshalInspectable.DisposeAbi(abi); } public static MarshalInterfaceHelper.MarshalerArray CreateMarshalerArray(global::System.ComponentModel.PropertyChangedEventArgs[] array) { return MarshalInterfaceHelper.CreateMarshalerArray2(array, CreateMarshaler2); } public static (int length, IntPtr data) GetAbiArray(object box) { return MarshalInterfaceHelper.GetAbiArray(box); } public static global::System.ComponentModel.PropertyChangedEventArgs[] FromAbiArray(object box) { return MarshalInterfaceHelper.FromAbiArray(box, FromAbi); } public static void CopyAbiArray(global::System.ComponentModel.PropertyChangedEventArgs[] array, object box) { MarshalInterfaceHelper.CopyAbiArray(array, box, FromAbi); } public static (int length, IntPtr data) FromManagedArray(global::System.ComponentModel.PropertyChangedEventArgs[] array) { return MarshalInterfaceHelper.FromManagedArray(array, FromManaged); } public static void DisposeMarshalerArray(MarshalInterfaceHelper.MarshalerArray array) { MarshalInterfaceHelper.DisposeMarshalerArray(array); } public static void DisposeAbiArray(object box) { MarshalInspectable.DisposeAbiArray(box); } public static string GetGuidSignature() { if (FeatureSwitches.UseWindowsUIXamlProjections) { return "rc(Windows.UI.Xaml.Data.PropertyChangedEventArgs;{4f33a9a0-5cf4-47a4-b16f-d7faaf17457e})"; } return "rc(Microsoft.UI.Xaml.Data.PropertyChangedEventArgs;{63d0c952-396b-54f4-af8c-ba8724a427bf})"; } } [EditorBrowsable(EditorBrowsableState.Never)] [Guid("E3DE52F6-1E32-5DA6-BB2D-B5B6096C962D")] [WuxMuxProjectedType] public static class PropertyChangedEventHandler { private sealed class NativeDelegateWrapper : IWinRTObject, IDynamicInterfaceCastable { private readonly ObjectReference _nativeDelegate; private volatile ConcurrentDictionary _queryInterfaceCache; private volatile ConcurrentDictionary _additionalTypeData; IObjectReference IWinRTObject.NativeObject => _nativeDelegate; bool IWinRTObject.HasUnwrappableNativeObject => true; ConcurrentDictionary IWinRTObject.QueryInterfaceCache => _queryInterfaceCache ?? MakeQueryInterfaceCache(); ConcurrentDictionary IWinRTObject.AdditionalTypeData => _additionalTypeData ?? MakeAdditionalTypeData(); public NativeDelegateWrapper(ObjectReference nativeDelegate) { _nativeDelegate = nativeDelegate; } private ConcurrentDictionary MakeQueryInterfaceCache() { Interlocked.CompareExchange(ref _queryInterfaceCache, new ConcurrentDictionary(), null); return _queryInterfaceCache; } private ConcurrentDictionary MakeAdditionalTypeData() { Interlocked.CompareExchange(ref _additionalTypeData, new ConcurrentDictionary(), null); return _additionalTypeData; } public unsafe void Invoke(object sender, global::System.ComponentModel.PropertyChangedEventArgs e) { IntPtr thisPtr = _nativeDelegate.ThisPtr; delegate* unmanaged[Stdcall] delegate* = (delegate* unmanaged[Stdcall])(void*)_nativeDelegate.Vftbl.Invoke; ObjectReferenceValue value = default(ObjectReferenceValue); ObjectReferenceValue value2 = default(ObjectReferenceValue); try { value = MarshalInspectable.CreateMarshaler2(sender); value2 = PropertyChangedEventArgs.CreateMarshaler2(e); ExceptionHelpers.ThrowExceptionForHR(delegate*(thisPtr, MarshalInspectable.GetAbi(value), MarshalInspectable.GetAbi(value2))); GC.KeepAlive(_nativeDelegate); } finally { MarshalInspectable.DisposeMarshaler(value); MarshalInspectable.DisposeMarshaler(value2); } } } private static readonly IDelegateVftbl AbiToProjectionVftable; public static readonly IntPtr AbiToProjectionVftablePtr; public static Delegate AbiInvokeDelegate { get; } public static Guid IID { get { if (!FeatureSwitches.UseWindowsUIXamlProjections) { return global::WinRT.Interop.IID.IID_MUX_PropertyChangedEventHandler; } return global::WinRT.Interop.IID.IID_WUX_PropertyChangedEventHandler; } } unsafe static PropertyChangedEventHandler() { AbiToProjectionVftable = new IDelegateVftbl { IUnknownVftbl = IUnknownVftbl.AbiToProjectionVftbl, Invoke = (IntPtr)(delegate*)(&Do_Abi_Invoke) }; IntPtr intPtr = ComWrappersSupport.AllocateVtableMemory(typeof(PropertyChangedEventHandler), sizeof(IDelegateVftbl)); *(IDelegateVftbl*)(void*)intPtr = AbiToProjectionVftable; AbiToProjectionVftablePtr = intPtr; ComWrappersSupport.RegisterDelegateFactory(typeof(global::System.ComponentModel.PropertyChangedEventHandler), CreateRcw); } public static IObjectReference CreateMarshaler(global::System.ComponentModel.PropertyChangedEventHandler managedDelegate) { if (managedDelegate != null) { return MarshalDelegate.CreateMarshaler(managedDelegate, IID); } return null; } public static ObjectReferenceValue CreateMarshaler2(global::System.ComponentModel.PropertyChangedEventHandler managedDelegate) { return MarshalDelegate.CreateMarshaler2(managedDelegate, IID); } public static IntPtr GetAbi(IObjectReference value) { return MarshalInterfaceHelper.GetAbi(value); } public static global::System.ComponentModel.PropertyChangedEventHandler FromAbi(IntPtr nativeDelegate) { return MarshalDelegate.FromAbi(nativeDelegate); } public static global::System.ComponentModel.PropertyChangedEventHandler CreateRcw(IntPtr ptr) { return new NativeDelegateWrapper(ComWrappersSupport.GetObjectReferenceForInterface(ptr, IID)).Invoke; } public static IntPtr FromManaged(global::System.ComponentModel.PropertyChangedEventHandler managedDelegate) { return CreateMarshaler2(managedDelegate).Detach(); } public static void DisposeMarshaler(IObjectReference value) { MarshalInterfaceHelper.DisposeMarshaler(value); } public static void DisposeAbi(IntPtr abi) { MarshalInterfaceHelper.DisposeAbi(abi); } public static MarshalInterfaceHelper.MarshalerArray CreateMarshalerArray(global::System.ComponentModel.PropertyChangedEventHandler[] array) { return MarshalInterfaceHelper.CreateMarshalerArray2(array, CreateMarshaler2); } public static (int length, IntPtr data) GetAbiArray(object box) { return MarshalInterfaceHelper.GetAbiArray(box); } public static global::System.ComponentModel.PropertyChangedEventHandler[] FromAbiArray(object box) { return MarshalInterfaceHelper.FromAbiArray(box, FromAbi); } public static void CopyAbiArray(global::System.ComponentModel.PropertyChangedEventHandler[] array, object box) { MarshalInterfaceHelper.CopyAbiArray(array, box, FromAbi); } public static (int length, IntPtr data) FromManagedArray(global::System.ComponentModel.PropertyChangedEventHandler[] array) { return MarshalInterfaceHelper.FromManagedArray(array, FromManaged); } public static void DisposeMarshalerArray(MarshalInterfaceHelper.MarshalerArray array) { MarshalInterfaceHelper.DisposeMarshalerArray(array); } public static void DisposeAbiArray(object box) { MarshalInspectable.DisposeAbiArray(box); } [UnmanagedCallersOnly(CallConvs = new global::System.Type[] { typeof(CallConvStdcall) })] private static int Do_Abi_Invoke(IntPtr thisPtr, IntPtr sender, IntPtr e) { try { global::System.ComponentModel.PropertyChangedEventHandler propertyChangedEventHandler = ComWrappersSupport.FindObject(thisPtr); propertyChangedEventHandler(MarshalInspectable.FromAbi(sender), PropertyChangedEventArgs.FromAbi(e)); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [SkipLocalsInit] internal static ComWrappers.ComInterfaceEntry[] GetExposedInterfaces() { Span span = stackalloc ComWrappers.ComInterfaceEntry[3]; int length = 0; span[length++] = new ComWrappers.ComInterfaceEntry { IID = IID, Vtable = AbiToProjectionVftablePtr }; if (FeatureSwitches.EnableIReferenceSupport) { span[length++] = new ComWrappers.ComInterfaceEntry { IID = global::WinRT.Interop.IID.IID_IPropertyValue, Vtable = ManagedIPropertyValueImpl.AbiToProjectionVftablePtr }; span[length++] = new ComWrappers.ComInterfaceEntry { IID = Nullable_PropertyChangedEventHandler.IID, Vtable = Nullable_PropertyChangedEventHandler.AbiToProjectionVftablePtr }; } return span.Slice(0, length).ToArray(); } } internal sealed class PropertyChangedEventSource : EventSource { private sealed class EventState : EventSourceState { public EventState(IntPtr obj, int index) : base(obj, index) { } protected override global::System.ComponentModel.PropertyChangedEventHandler GetEventInvoke() { return delegate(object? obj, global::System.ComponentModel.PropertyChangedEventArgs e) { targetDelegate?.Invoke(obj, e); }; } } internal unsafe PropertyChangedEventSource(IObjectReference objectReference, delegate* unmanaged[Stdcall] addHandler, delegate* unmanaged[Stdcall] removeHandler) : base(objectReference, addHandler, removeHandler, 0) { } protected override ObjectReferenceValue CreateMarshaler(global::System.ComponentModel.PropertyChangedEventHandler del) { return PropertyChangedEventHandler.CreateMarshaler2(del); } protected override EventSourceState CreateEventSourceState() { return new EventState(base.ObjectReference.ThisPtr, base.Index); } } } namespace ABI.System.Collections { public static class IEnumerableMethods { public static Guid IID => global::WinRT.Interop.IID.IID_IEnumerable; public static IntPtr AbiToProjectionVftablePtr => IEnumerable.AbiToProjectionVftablePtr; } [DynamicInterfaceCastableImplementation] [Guid("036D2C08-DF29-41AF-8AA2-D774BE62BA6F")] internal interface IEnumerable : global::System.Collections.IEnumerable, global::Microsoft.UI.Xaml.Interop.IBindableIterable { public sealed class AdaptiveFromAbiHelper : FromAbiHelper, global::System.Collections.IEnumerable { private static readonly MethodInfo EnumerableOfTGetEnumerator = typeof(global::System.Collections.Generic.IEnumerable<>).GetMethod("GetEnumerator"); private readonly MethodInfo _enumerator; public AdaptiveFromAbiHelper(global::System.Type runtimeType, IWinRTObject winRTObject) : base(winRTObject) { _enumerator = (MethodInfo)(((!runtimeType.IsGenericType || !(runtimeType.GetGenericTypeDefinition() == typeof(global::System.Collections.Generic.IEnumerable<>))) ? GetEnumerableOfTInterface(runtimeType) : runtimeType)?.GetMemberWithSameMetadataDefinitionAs(EnumerableOfTGetEnumerator)); [MethodImpl(MethodImplOptions.NoInlining)] [UnconditionalSuppressMessage("Trimming", "IL2070", Justification = "'SomeType.GetInterfaces().Any(t => t.GetGenericTypeDefinition() == typeof(IEnumerable<>)' is safe,\r\nprovided you obtained someType from something like an analyzable 'Type.GetType' or 'object.GetType'\r\n(i.e. it is safe when the type you're asking about can exist on the GC heap as allocated).")] static global::System.Type GetEnumerableOfTInterface(global::System.Type type) { global::System.Type[] interfaces = type.GetInterfaces(); foreach (global::System.Type type2 in interfaces) { if (type2.IsGenericType && type2.GetGenericTypeDefinition() == typeof(global::System.Collections.Generic.IEnumerable<>)) { return type2; } } return null; } } public override IEnumerator GetEnumerator() { if ((object)_enumerator != null) { return Unsafe.As(_enumerator.Invoke(_winrtObject, null)); } return base.GetEnumerator(); } } public class FromAbiHelper : global::System.Collections.IEnumerable { private sealed class NonGenericToGenericIterator : IIterator { private readonly global::Microsoft.UI.Xaml.Interop.IBindableIterator iterator; public object _Current => iterator.Current; public bool HasCurrent => iterator.HasCurrent; public NonGenericToGenericIterator(global::Microsoft.UI.Xaml.Interop.IBindableIterator iterator) { this.iterator = iterator; } public bool _MoveNext() { return iterator.MoveNext(); } public uint GetMany(ref object[] items) { throw new NotSupportedException(); } } private readonly global::System.Collections.IEnumerable _iterable; protected readonly IWinRTObject _winrtObject; public FromAbiHelper(global::System.Collections.IEnumerable iterable) { _iterable = iterable; } protected FromAbiHelper(IWinRTObject winrtObject) { _iterable = null; _winrtObject = winrtObject; } private IWinRTObject GetIterable() { return ((IWinRTObject)_iterable) ?? _winrtObject; } public virtual IEnumerator GetEnumerator() { return new FromAbiEnumerator(new NonGenericToGenericIterator(((global::Microsoft.UI.Xaml.Interop.IBindableIterable)GetIterable()).First())); } } public sealed class ToAbiHelper : global::Microsoft.UI.Xaml.Interop.IBindableIterable { private sealed class NonGenericToGenericEnumerator : global::System.Collections.Generic.IEnumerator, IEnumerator, global::System.IDisposable { private readonly IEnumerator enumerator; public object Current => enumerator.Current; public NonGenericToGenericEnumerator(IEnumerator enumerator) { this.enumerator = enumerator; } public bool MoveNext() { return enumerator.MoveNext(); } public void Reset() { enumerator.Reset(); } public void Dispose() { } } private readonly IEnumerable m_enumerable; internal ToAbiHelper(IEnumerable enumerable) { m_enumerable = enumerable; } global::Microsoft.UI.Xaml.Interop.IBindableIterator global::Microsoft.UI.Xaml.Interop.IBindableIterable.First() { return MakeBindableIterator(m_enumerable.GetEnumerator()); } internal static global::Microsoft.UI.Xaml.Interop.IBindableIterator MakeBindableIterator(IEnumerator enumerator) { return new ABI.System.Collections.Generic.IEnumerator.ToAbiHelper(new NonGenericToGenericEnumerator(enumerator)); } } static readonly IntPtr AbiToProjectionVftablePtr; static string GetGuidSignature() { return GuidGenerator.GetSignature(typeof(IEnumerable)); } unsafe static IEnumerable() { AbiToProjectionVftablePtr = ComWrappersSupport.AllocateVtableMemory(typeof(IEnumerable), sizeof(IInspectable.Vftbl) + sizeof(IntPtr)); *(IInspectable.Vftbl*)(void*)AbiToProjectionVftablePtr = IInspectable.Vftbl.AbiToProjectionVftable; *(IntPtr*)((byte*)(void*)AbiToProjectionVftablePtr + (nint)6 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)(delegate*)(&Do_Abi_First_0); } [UnmanagedCallersOnly(CallConvs = new global::System.Type[] { typeof(CallConvStdcall) })] private unsafe static int Do_Abi_First_0(IntPtr thisPtr, IntPtr* result) { *result = default(IntPtr); try { global::System.Collections.IEnumerable enumerable = ComWrappersSupport.FindObject(thisPtr); global::Microsoft.UI.Xaml.Interop.IBindableIterator value = ToAbiHelper.MakeBindableIterator(enumerable.GetEnumerator()); *result = MarshalInterface.FromManaged(value); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } internal static ObjectReference ObjRefFromAbi(IntPtr thisPtr) { if (thisPtr == IntPtr.Zero) { return null; } return ObjectReference.FromAbi(thisPtr, IID.IID_IUnknown); } private static FromAbiHelper _AbiHelper(IWinRTObject _this) { return (FromAbiHelper)_this.AdditionalTypeData.GetOrAdd(typeof(global::System.Collections.IEnumerable).TypeHandle, (RuntimeTypeHandle _, IWinRTObject winRTObject) => new FromAbiHelper((global::System.Collections.IEnumerable)winRTObject), _this); } unsafe global::Microsoft.UI.Xaml.Interop.IBindableIterator global::Microsoft.UI.Xaml.Interop.IBindableIterable.First() { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.IEnumerable).TypeHandle); IntPtr thisPtr = objectReferenceForType.ThisPtr; IntPtr intPtr = default(IntPtr); try { ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)6 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(thisPtr, &intPtr)); GC.KeepAlive(objectReferenceForType); return MarshalInterface.FromAbi(intPtr); } finally { MarshalInterface.DisposeAbi(intPtr); } } IEnumerator global::System.Collections.IEnumerable.GetEnumerator() { return _AbiHelper((IWinRTObject)this).GetEnumerator(); } } [EditorBrowsable(EditorBrowsableState.Never)] public static class IEnumerable_Delegates { public unsafe delegate int First_0(IntPtr thisPtr, IntPtr* result); } public static class IListMethods { public static Guid IID => global::WinRT.Interop.IID.IID_IList; public static IntPtr AbiToProjectionVftablePtr => IList.AbiToProjectionVftablePtr; } [DynamicInterfaceCastableImplementation] [Guid("393DE7DE-6FD0-4C0D-BB71-47244A113E93")] internal interface IList : global::System.Collections.IList, global::System.Collections.ICollection, global::System.Collections.IEnumerable, IBindableVector { public sealed class FromAbiHelper : global::System.Collections.IList, global::System.Collections.ICollection, global::System.Collections.IEnumerable { private readonly IBindableVector _vector; public bool IsSynchronized => false; public object SyncRoot => this; public int Count { get { uint size = _vector.Size; if (int.MaxValue < size) { throw new InvalidOperationException(WinRTRuntimeErrorStrings.InvalidOperation_CollectionBackingListTooLarge); } return (int)size; } } public object this[int index] { get { return Indexer_Get(index); } set { Indexer_Set(index, value); } } public bool IsFixedSize => false; public bool IsReadOnly => false; public FromAbiHelper(IBindableVector vector) { _vector = vector; } public void CopyTo(Array array, int arrayIndex) { if (array == null) { throw new ArgumentNullException("array"); } if (array.Rank != 1) { throw new ArgumentException(WinRTRuntimeErrorStrings.Arg_RankMultiDimNotSupported); } int lowerBound = array.GetLowerBound(0); int count = Count; int length = array.GetLength(0); if (arrayIndex < lowerBound) { throw new ArgumentOutOfRangeException("arrayIndex"); } if (count > length - (arrayIndex - lowerBound)) { throw new ArgumentException(WinRTRuntimeErrorStrings.Argument_InsufficientSpaceToCopyCollection); } if (arrayIndex - lowerBound > length) { throw new ArgumentException(WinRTRuntimeErrorStrings.Argument_IndexOutOfArrayBounds); } for (uint num = 0u; num < count; num++) { array.SetValue(_vector.GetAt(num), num + arrayIndex); } } internal object Indexer_Get(int index) { if (index < 0) { throw new ArgumentOutOfRangeException("index"); } return GetAt(_vector, (uint)index); } internal void Indexer_Set(int index, object value) { if (index < 0) { throw new ArgumentOutOfRangeException("index"); } SetAt(_vector, (uint)index, value); } public int Add(object value) { _vector.Append(value); uint size = _vector.Size; if (int.MaxValue < size) { throw new InvalidOperationException(WinRTRuntimeErrorStrings.InvalidOperation_CollectionBackingListTooLarge); } return (int)(size - 1); } public bool Contains(object item) { uint index; return _vector.IndexOf(item, out index); } public void Clear() { _vector.Clear(); } public int IndexOf(object item) { if (!_vector.IndexOf(item, out var index)) { return -1; } if (int.MaxValue < index) { throw new InvalidOperationException(WinRTRuntimeErrorStrings.InvalidOperation_CollectionBackingListTooLarge); } return (int)index; } public void Insert(int index, object item) { if (index < 0) { throw new ArgumentOutOfRangeException("index"); } InsertAtHelper(_vector, (uint)index, item); } public void Remove(object item) { if (_vector.IndexOf(item, out var index)) { if (int.MaxValue < index) { throw new InvalidOperationException(WinRTRuntimeErrorStrings.InvalidOperation_CollectionBackingListTooLarge); } RemoveAtHelper(_vector, index); } } public void RemoveAt(int index) { if (index < 0) { throw new ArgumentOutOfRangeException("index"); } RemoveAtHelper(_vector, (uint)index); } private static object GetAt(IBindableVector _this, uint index) { try { return _this.GetAt(index); } catch (global::System.Exception ex) { if (-2147483637 == ex.HResult) { throw new ArgumentOutOfRangeException("index"); } throw; } } private static void SetAt(IBindableVector _this, uint index, object value) { try { _this.SetAt(index, value); } catch (global::System.Exception ex) { if (-2147483637 == ex.HResult) { throw new ArgumentOutOfRangeException("index"); } throw; } } private static void InsertAtHelper(IBindableVector _this, uint index, object item) { try { _this.InsertAt(index, item); } catch (global::System.Exception ex) { if (-2147483637 == ex.HResult) { throw new ArgumentOutOfRangeException("index"); } throw; } } private static void RemoveAtHelper(IBindableVector _this, uint index) { try { _this.RemoveAt(index); } catch (global::System.Exception ex) { if (-2147483637 == ex.HResult) { throw new ArgumentOutOfRangeException("index"); } throw; } } public IEnumerator GetEnumerator() { return ((IEnumerable)(IWinRTObject)_vector).GetEnumerator(); } } public sealed class ToAbiHelper : IBindableVector, global::System.Collections.IEnumerable { internal sealed class ListToBindableVectorViewAdapterTypeDetails : IWinRTExposedTypeDetails { public ComWrappers.ComInterfaceEntry[] GetExposedInterfaces() { return new ComWrappers.ComInterfaceEntry[2] { new ComWrappers.ComInterfaceEntry { IID = IID.IID_IBindableVectorView, Vtable = ABI.Microsoft.UI.Xaml.Interop.IBindableVectorView.AbiToProjectionVftablePtr }, new ComWrappers.ComInterfaceEntry { IID = IEnumerableMethods.IID, Vtable = IEnumerableMethods.AbiToProjectionVftablePtr } }; } } [WinRTExposedType(typeof(ListToBindableVectorViewAdapterTypeDetails))] internal sealed class ListToBindableVectorViewAdapter : global::Microsoft.UI.Xaml.Interop.IBindableVectorView, global::System.Collections.IEnumerable { private readonly global::System.Collections.IList list; public uint Size => (uint)list.Count; internal ListToBindableVectorViewAdapter(global::System.Collections.IList list) { if (list == null) { throw new ArgumentNullException("list"); } this.list = list; } private static void EnsureIndexInt32(uint index, int listCapacity) { if (int.MaxValue <= index || index >= (uint)listCapacity) { global::System.Exception ex = new ArgumentOutOfRangeException("index", WinRTRuntimeErrorStrings.ArgumentOutOfRange_IndexLargerThanMaxValue); ex.SetHResult(-2147483637); throw ex; } } public global::Microsoft.UI.Xaml.Interop.IBindableIterator First() { return IEnumerable.ToAbiHelper.MakeBindableIterator(list.GetEnumerator()); } public object GetAt(uint index) { EnsureIndexInt32(index, list.Count); try { return list[(int)index]; } catch (ArgumentOutOfRangeException innerException) { throw innerException.GetExceptionForHR(-2147483637, WinRTRuntimeErrorStrings.ArgumentOutOfRange_Index); } } public bool IndexOf(object value, out uint index) { int num = list.IndexOf(value); if (-1 == num) { index = 0u; return false; } index = (uint)num; return true; } public IEnumerator GetEnumerator() { return list.GetEnumerator(); } } private readonly global::System.Collections.IList _list; public uint Size => (uint)_list.Count; public ToAbiHelper(global::System.Collections.IList list) { _list = list; } public object GetAt(uint index) { EnsureIndexInt32(index, _list.Count); try { return _list[(int)index]; } catch (ArgumentOutOfRangeException innerException) { throw innerException.GetExceptionForHR(-2147483637, WinRTRuntimeErrorStrings.ArgumentOutOfRange_Index); } } global::Microsoft.UI.Xaml.Interop.IBindableVectorView IBindableVector.GetView() { return new ListToBindableVectorViewAdapter(_list); } public bool IndexOf(object value, out uint index) { int num = _list.IndexOf(value); if (-1 == num) { index = 0u; return false; } index = (uint)num; return true; } public void SetAt(uint index, object value) { EnsureIndexInt32(index, _list.Count); try { _list[(int)index] = value; } catch (ArgumentOutOfRangeException innerException) { throw innerException.GetExceptionForHR(-2147483637, WinRTRuntimeErrorStrings.ArgumentOutOfRange_Index); } } public void InsertAt(uint index, object value) { EnsureIndexInt32(index, _list.Count + 1); try { _list.Insert((int)index, value); } catch (ArgumentOutOfRangeException ex) { ex.SetHResult(-2147483637); throw; } } public void RemoveAt(uint index) { EnsureIndexInt32(index, _list.Count); try { _list.RemoveAt((int)index); } catch (ArgumentOutOfRangeException ex) { ex.SetHResult(-2147483637); throw; } } public void Append(object value) { _list.Add(value); } public void RemoveAtEnd() { if (_list.Count == 0) { global::System.Exception ex = new InvalidOperationException(WinRTRuntimeErrorStrings.InvalidOperation_CannotRemoveLastFromEmptyCollection); ex.SetHResult(-2147483637); throw ex; } uint count = (uint)_list.Count; RemoveAt(count - 1); } public void Clear() { _list.Clear(); } private static void EnsureIndexInt32(uint index, int listCapacity) { if (int.MaxValue <= index || index >= (uint)listCapacity) { global::System.Exception ex = new ArgumentOutOfRangeException("index", WinRTRuntimeErrorStrings.ArgumentOutOfRange_IndexLargerThanMaxValue); ex.SetHResult(-2147483637); throw ex; } } public IEnumerator GetEnumerator() { return _list.GetEnumerator(); } } static readonly IntPtr AbiToProjectionVftablePtr; private static readonly ConditionalWeakTable _adapterTable; unsafe uint IBindableVector.Size { get { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.IList).TypeHandle); IntPtr thisPtr = objectReferenceForType.ThisPtr; uint result = 0u; ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)7 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(thisPtr, &result)); GC.KeepAlive(objectReferenceForType); return result; } } object global::System.Collections.IList.this[int index] { get { return _VectorToList((IWinRTObject)this)[index]; } set { _VectorToList((IWinRTObject)this)[index] = value; } } bool global::System.Collections.IList.IsFixedSize => _VectorToList((IWinRTObject)this).IsFixedSize; bool global::System.Collections.IList.IsReadOnly => _VectorToList((IWinRTObject)this).IsReadOnly; int global::System.Collections.ICollection.Count => _VectorToList((IWinRTObject)this).Count; bool global::System.Collections.ICollection.IsSynchronized => _VectorToList((IWinRTObject)this).IsSynchronized; object global::System.Collections.ICollection.SyncRoot => _VectorToList((IWinRTObject)this).SyncRoot; static string GetGuidSignature() { return GuidGenerator.GetSignature(typeof(IList)); } unsafe static IList() { _adapterTable = new ConditionalWeakTable(); AbiToProjectionVftablePtr = ComWrappersSupport.AllocateVtableMemory(typeof(IList), sizeof(IInspectable.Vftbl) + sizeof(IntPtr) * 10); *(IInspectable.Vftbl*)(void*)AbiToProjectionVftablePtr = IInspectable.Vftbl.AbiToProjectionVftable; *(IntPtr*)((byte*)(void*)AbiToProjectionVftablePtr + (nint)6 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)(delegate*)(&Do_Abi_GetAt_0); *(IntPtr*)((byte*)(void*)AbiToProjectionVftablePtr + (nint)7 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)(delegate*)(&Do_Abi_get_Size_1); *(IntPtr*)((byte*)(void*)AbiToProjectionVftablePtr + (nint)8 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)(delegate*)(&Do_Abi_GetView_2); *(IntPtr*)((byte*)(void*)AbiToProjectionVftablePtr + (nint)9 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)(delegate*)(&Do_Abi_IndexOf_3); *(IntPtr*)((byte*)(void*)AbiToProjectionVftablePtr + (nint)10 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)(delegate*)(&Do_Abi_SetAt_4); *(IntPtr*)((byte*)(void*)AbiToProjectionVftablePtr + (nint)11 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)(delegate*)(&Do_Abi_InsertAt_5); *(IntPtr*)((byte*)(void*)AbiToProjectionVftablePtr + (nint)12 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)(delegate*)(&Do_Abi_RemoveAt_6); *(IntPtr*)((byte*)(void*)AbiToProjectionVftablePtr + (nint)13 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)(delegate*)(&Do_Abi_Append_7); *(IntPtr*)((byte*)(void*)AbiToProjectionVftablePtr + (nint)14 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)(delegate*)(&Do_Abi_RemoveAtEnd_8); *(IntPtr*)((byte*)(void*)AbiToProjectionVftablePtr + (nint)15 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)(delegate*)(&Do_Abi_Clear_9); } private static IBindableVector FindAdapter(IntPtr thisPtr) { global::System.Collections.IList key = ComWrappersSupport.FindObject(thisPtr); return _adapterTable.GetValue(key, (global::System.Collections.IList list) => new ToAbiHelper(list)); } [UnmanagedCallersOnly(CallConvs = new global::System.Type[] { typeof(CallConvStdcall) })] private unsafe static int Do_Abi_GetAt_0(IntPtr thisPtr, uint index, IntPtr* result) { object obj = null; *result = default(IntPtr); try { obj = FindAdapter(thisPtr).GetAt(index); *result = MarshalInspectable.FromManaged(obj); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly(CallConvs = new global::System.Type[] { typeof(CallConvStdcall) })] private unsafe static int Do_Abi_GetView_2(IntPtr thisPtr, IntPtr* result) { global::Microsoft.UI.Xaml.Interop.IBindableVectorView bindableVectorView = null; *result = default(IntPtr); try { bindableVectorView = FindAdapter(thisPtr).GetView(); *result = MarshalInterface.FromManaged(bindableVectorView); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly(CallConvs = new global::System.Type[] { typeof(CallConvStdcall) })] private unsafe static int Do_Abi_IndexOf_3(IntPtr thisPtr, IntPtr value, uint* index, byte* returnValue) { bool flag = false; *index = 0u; *returnValue = 0; uint index2 = 0u; try { flag = FindAdapter(thisPtr).IndexOf(MarshalInspectable.FromAbi(value), out index2); *index = index2; *returnValue = (flag ? ((byte)1) : ((byte)0)); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly(CallConvs = new global::System.Type[] { typeof(CallConvStdcall) })] private static int Do_Abi_SetAt_4(IntPtr thisPtr, uint index, IntPtr value) { try { FindAdapter(thisPtr).SetAt(index, MarshalInspectable.FromAbi(value)); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly(CallConvs = new global::System.Type[] { typeof(CallConvStdcall) })] private static int Do_Abi_InsertAt_5(IntPtr thisPtr, uint index, IntPtr value) { try { FindAdapter(thisPtr).InsertAt(index, MarshalInspectable.FromAbi(value)); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly(CallConvs = new global::System.Type[] { typeof(CallConvStdcall) })] private static int Do_Abi_RemoveAt_6(IntPtr thisPtr, uint index) { try { FindAdapter(thisPtr).RemoveAt(index); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly(CallConvs = new global::System.Type[] { typeof(CallConvStdcall) })] private static int Do_Abi_Append_7(IntPtr thisPtr, IntPtr value) { try { FindAdapter(thisPtr).Append(MarshalInspectable.FromAbi(value)); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly(CallConvs = new global::System.Type[] { typeof(CallConvStdcall) })] private static int Do_Abi_RemoveAtEnd_8(IntPtr thisPtr) { try { FindAdapter(thisPtr).RemoveAtEnd(); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly(CallConvs = new global::System.Type[] { typeof(CallConvStdcall) })] private static int Do_Abi_Clear_9(IntPtr thisPtr) { try { FindAdapter(thisPtr).Clear(); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly(CallConvs = new global::System.Type[] { typeof(CallConvStdcall) })] private unsafe static int Do_Abi_get_Size_1(IntPtr thisPtr, uint* value) { uint num = 0u; *value = 0u; try { num = FindAdapter(thisPtr).Size; *value = num; } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } internal static ObjectReference ObjRefFromAbi(IntPtr thisPtr) { if (thisPtr == IntPtr.Zero) { return null; } return ObjectReference.FromAbi(thisPtr, IID.IID_IUnknown); } internal static FromAbiHelper _VectorToList(IWinRTObject _this) { return (FromAbiHelper)_this.AdditionalTypeData.GetOrAdd(typeof(global::System.Collections.IList).TypeHandle, (RuntimeTypeHandle _, IWinRTObject winRTObject) => new FromAbiHelper((IBindableVector)winRTObject), _this); } unsafe object IBindableVector.GetAt(uint index) { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.IList).TypeHandle); IntPtr thisPtr = objectReferenceForType.ThisPtr; IntPtr ptr = default(IntPtr); try { ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)6 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(thisPtr, index, &ptr)); GC.KeepAlive(objectReferenceForType); return MarshalInspectable.FromAbi(ptr); } finally { MarshalInspectable.DisposeAbi(ptr); } } unsafe global::Microsoft.UI.Xaml.Interop.IBindableVectorView IBindableVector.GetView() { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.IList).TypeHandle); IntPtr thisPtr = objectReferenceForType.ThisPtr; IntPtr intPtr = default(IntPtr); try { ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)8 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(thisPtr, &intPtr)); GC.KeepAlive(objectReferenceForType); return MarshalInterface.FromAbi(intPtr); } finally { MarshalInterface.DisposeAbi(intPtr); } } unsafe bool IBindableVector.IndexOf(object value, out uint index) { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.IList).TypeHandle); IntPtr thisPtr = objectReferenceForType.ThisPtr; ObjectReferenceValue value2 = default(ObjectReferenceValue); uint num = 0u; byte b = 0; try { value2 = MarshalInspectable.CreateMarshaler2(value); ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)9 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(thisPtr, MarshalInspectable.GetAbi(value2), &num, &b)); GC.KeepAlive(objectReferenceForType); index = num; return b != 0; } finally { MarshalInspectable.DisposeMarshaler(value2); } } unsafe void IBindableVector.SetAt(uint index, object value) { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.IList).TypeHandle); IntPtr thisPtr = objectReferenceForType.ThisPtr; ObjectReferenceValue value2 = default(ObjectReferenceValue); try { value2 = MarshalInspectable.CreateMarshaler2(value); ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)10 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(thisPtr, index, MarshalInspectable.GetAbi(value2))); GC.KeepAlive(objectReferenceForType); } finally { MarshalInspectable.DisposeMarshaler(value2); } } unsafe void IBindableVector.InsertAt(uint index, object value) { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.IList).TypeHandle); IntPtr thisPtr = objectReferenceForType.ThisPtr; ObjectReferenceValue value2 = default(ObjectReferenceValue); try { value2 = MarshalInspectable.CreateMarshaler2(value); ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)11 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(thisPtr, index, MarshalInspectable.GetAbi(value2))); GC.KeepAlive(objectReferenceForType); } finally { MarshalInspectable.DisposeMarshaler(value2); } } unsafe void IBindableVector.RemoveAt(uint index) { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.IList).TypeHandle); IntPtr thisPtr = objectReferenceForType.ThisPtr; ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)12 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(thisPtr, index)); GC.KeepAlive(objectReferenceForType); } unsafe void IBindableVector.Append(object value) { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.IList).TypeHandle); IntPtr thisPtr = objectReferenceForType.ThisPtr; ObjectReferenceValue value2 = default(ObjectReferenceValue); try { value2 = MarshalInspectable.CreateMarshaler2(value); ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)13 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(thisPtr, MarshalInspectable.GetAbi(value2))); GC.KeepAlive(objectReferenceForType); } finally { MarshalInspectable.DisposeMarshaler(value2); } } unsafe void IBindableVector.RemoveAtEnd() { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.IList).TypeHandle); IntPtr thisPtr = objectReferenceForType.ThisPtr; ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)14 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(thisPtr)); GC.KeepAlive(objectReferenceForType); } unsafe void IBindableVector.Clear() { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.IList).TypeHandle); IntPtr thisPtr = objectReferenceForType.ThisPtr; ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)15 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(thisPtr)); GC.KeepAlive(objectReferenceForType); } int global::System.Collections.IList.Add(object value) { return _VectorToList((IWinRTObject)this).Add(value); } void global::System.Collections.IList.Clear() { _VectorToList((IWinRTObject)this).Clear(); } bool global::System.Collections.IList.Contains(object value) { return _VectorToList((IWinRTObject)this).Contains(value); } int global::System.Collections.IList.IndexOf(object value) { return _VectorToList((IWinRTObject)this).IndexOf(value); } void global::System.Collections.IList.Insert(int index, object value) { _VectorToList((IWinRTObject)this).Insert(index, value); } void global::System.Collections.IList.Remove(object value) { _VectorToList((IWinRTObject)this).Remove(value); } void global::System.Collections.IList.RemoveAt(int index) { _VectorToList((IWinRTObject)this).RemoveAt(index); } void global::System.Collections.ICollection.CopyTo(Array array, int index) { _VectorToList((IWinRTObject)this).CopyTo(array, index); } IEnumerator global::System.Collections.IEnumerable.GetEnumerator() { return _VectorToList((IWinRTObject)this).GetEnumerator(); } } internal static class IList_Delegates { public unsafe delegate int GetAt_0(IntPtr thisPtr, uint index, IntPtr* result); public unsafe delegate int get_Size_1(IntPtr thisPtr, uint* result); public unsafe delegate int GetView_2(IntPtr thisPtr, IntPtr* result); public unsafe delegate int IndexOf_3(IntPtr thisPtr, IntPtr value, uint* index, byte* returnValue); public delegate int SetAt_4(IntPtr thisPtr, uint index, IntPtr value); public delegate int InsertAt_5(IntPtr thisPtr, uint index, IntPtr value); public delegate int RemoveAt_6(IntPtr thisPtr, uint index); public delegate int Append_7(IntPtr thisPtr, IntPtr value); public delegate int RemoveAtEnd_8(IntPtr thisPtr); public delegate int Clear_9(IntPtr thisPtr); } [DynamicInterfaceCastableImplementation] internal interface ICollection : global::System.Collections.ICollection, global::System.Collections.IEnumerable { int global::System.Collections.ICollection.Count => GetHelper((IWinRTObject)this).Count; bool global::System.Collections.ICollection.IsSynchronized => GetHelper((IWinRTObject)this).IsSynchronized; object global::System.Collections.ICollection.SyncRoot => GetHelper((IWinRTObject)this).SyncRoot; private static global::System.Collections.ICollection CreateHelper(RuntimeTypeHandle type, IWinRTObject _this) { global::System.Type typeFromHandle = typeof(global::System.Collections.IList); if (_this.IsInterfaceImplemented(typeFromHandle.TypeHandle, throwIfNotImplemented: false)) { return IList._VectorToList(_this); } throw new InvalidOperationException("ICollection helper can not determine derived type."); } private static global::System.Collections.ICollection GetHelper(IWinRTObject _this) { return (global::System.Collections.ICollection)_this.AdditionalTypeData.GetOrAdd(typeof(global::System.Collections.ICollection).TypeHandle, CreateHelper, _this); } void global::System.Collections.ICollection.CopyTo(Array array, int arrayIndex) { GetHelper((IWinRTObject)this).CopyTo(array, arrayIndex); } IEnumerator global::System.Collections.IEnumerable.GetEnumerator() { return GetHelper((IWinRTObject)this).GetEnumerator(); } } } namespace ABI.System.Collections.Specialized { public static class INotifyCollectionChangedMethods { private static volatile ConditionalWeakTable _CollectionChanged; private static ConditionalWeakTable CollectionChanged => _CollectionChanged ?? MakeCollectionChangedTable(); public static Guid IID { get { if (!FeatureSwitches.UseWindowsUIXamlProjections) { return global::WinRT.Interop.IID.IID_MUX_INotifyCollectionChanged; } return global::WinRT.Interop.IID.IID_WUX_INotifyCollectionChanged; } } public static IntPtr AbiToProjectionVftablePtr => INotifyCollectionChanged.Vftbl.AbiToProjectionVftablePtr; private static ConditionalWeakTable MakeCollectionChangedTable() { Interlocked.CompareExchange(ref _CollectionChanged, new ConditionalWeakTable(), null); return _CollectionChanged; } public unsafe static EventSource Get_CollectionChanged2(IObjectReference obj, object thisObj) { return CollectionChanged.GetValue(thisObj, delegate { IntPtr thisPtr = obj.ThisPtr; return new NotifyCollectionChangedEventHandlerEventSource(obj, (delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)6 * (nint)sizeof(delegate* unmanaged[Stdcall]))), (delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)7 * (nint)sizeof(delegate* unmanaged[Stdcall])))); }); } } [DynamicInterfaceCastableImplementation] [EditorBrowsable(EditorBrowsableState.Never)] [Guid("530155E1-28A5-5693-87CE-30724D95A06D")] [WuxMuxProjectedType] internal interface INotifyCollectionChanged : global::System.Collections.Specialized.INotifyCollectionChanged { [Guid("530155E1-28A5-5693-87CE-30724D95A06D")] public struct Vftbl { internal IInspectable.Vftbl IInspectableVftbl; private unsafe delegate* unmanaged _add_CollectionChanged_0; private unsafe delegate* unmanaged _remove_CollectionChanged_1; private static readonly Vftbl AbiToProjectionVftable; public static readonly IntPtr AbiToProjectionVftablePtr; private static volatile ConditionalWeakTable> _collectionChanged_TokenTables; public unsafe delegate* unmanaged[Stdcall] add_CollectionChanged_0 { get { return (delegate* unmanaged[Stdcall])_add_CollectionChanged_0; } set { _add_CollectionChanged_0 = (delegate* unmanaged)value; } } public unsafe delegate* unmanaged[Stdcall] remove_CollectionChanged_1 { get { return (delegate* unmanaged[Stdcall])_remove_CollectionChanged_1; } set { _remove_CollectionChanged_1 = (delegate* unmanaged)value; } } private static ConditionalWeakTable> _CollectionChanged_TokenTables => _collectionChanged_TokenTables ?? MakeConditionalWeakTable(); unsafe static Vftbl() { AbiToProjectionVftable = new Vftbl { IInspectableVftbl = IInspectable.Vftbl.AbiToProjectionVftable, _add_CollectionChanged_0 = (delegate* unmanaged)(delegate*)(&Do_Abi_add_CollectionChanged_0), _remove_CollectionChanged_1 = (delegate* unmanaged)(delegate*)(&Do_Abi_remove_CollectionChanged_1) }; IntPtr* ptr = (IntPtr*)(void*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), sizeof(IInspectable.Vftbl) + sizeof(IntPtr) * 2); *(Vftbl*)ptr = AbiToProjectionVftable; AbiToProjectionVftablePtr = (IntPtr)ptr; } private static ConditionalWeakTable> MakeConditionalWeakTable() { Interlocked.CompareExchange(ref _collectionChanged_TokenTables, new ConditionalWeakTable>(), null); return _collectionChanged_TokenTables; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_add_CollectionChanged_0(IntPtr thisPtr, IntPtr handler, global::WinRT.EventRegistrationToken* token) { *token = default(global::WinRT.EventRegistrationToken); try { global::System.Collections.Specialized.INotifyCollectionChanged notifyCollectionChanged = ComWrappersSupport.FindObject(thisPtr); global::System.Collections.Specialized.NotifyCollectionChangedEventHandler notifyCollectionChangedEventHandler = NotifyCollectionChangedEventHandler.FromAbi(handler); *token = _CollectionChanged_TokenTables.GetOrCreateValue(notifyCollectionChanged).AddEventHandler(notifyCollectionChangedEventHandler); notifyCollectionChanged.CollectionChanged += notifyCollectionChangedEventHandler; return 0; } catch (global::System.Exception ex) { return ex.HResult; } } [UnmanagedCallersOnly] private static int Do_Abi_remove_CollectionChanged_1(IntPtr thisPtr, global::WinRT.EventRegistrationToken token) { try { global::System.Collections.Specialized.INotifyCollectionChanged notifyCollectionChanged = ComWrappersSupport.FindObject(thisPtr); if (notifyCollectionChanged != null && _CollectionChanged_TokenTables.TryGetValue(notifyCollectionChanged, out var value) && value.RemoveEventHandler(token, out global::System.Collections.Specialized.NotifyCollectionChangedEventHandler handler)) { notifyCollectionChanged.CollectionChanged -= handler; } return 0; } catch (global::System.Exception ex) { return ex.HResult; } } } event global::System.Collections.Specialized.NotifyCollectionChangedEventHandler global::System.Collections.Specialized.INotifyCollectionChanged.CollectionChanged { add { _CollectionChanged((IWinRTObject)this).Subscribe(value); } remove { _CollectionChanged((IWinRTObject)this).Unsubscribe(value); } } private static EventSource _CollectionChanged(IWinRTObject _this) { IObjectReference objectReferenceForType = _this.GetObjectReferenceForType(typeof(global::System.Collections.Specialized.INotifyCollectionChanged).TypeHandle); return INotifyCollectionChangedMethods.Get_CollectionChanged2(objectReferenceForType, _this); } } internal static class NotifyCollectionChangedAction { public static string GetGuidSignature() { if (!FeatureSwitches.UseWindowsUIXamlProjections) { return "enum(Microsoft.UI.Xaml.Interop.NotifyCollectionChangedAction;i4)"; } return "enum(Windows.UI.Xaml.Interop.NotifyCollectionChangedAction;i4)"; } } [EditorBrowsable(EditorBrowsableState.Never)] [WuxMuxProjectedType] public struct NotifyCollectionChangedEventArgs { private static ref readonly Guid Interface_IID { get { if (!FeatureSwitches.UseWindowsUIXamlProjections) { return ref IID.IID_MUX_INotifyCollectionChangedEventArgs; } return ref IID.IID_WUX_INotifyCollectionChangedEventArgs; } } public static IObjectReference CreateMarshaler(global::System.Collections.Specialized.NotifyCollectionChangedEventArgs value) { if (value == null) { return null; } ObjectReferenceValue objectReferenceValue = default(ObjectReferenceValue); try { objectReferenceValue = CreateMarshaler2(value); return ObjectReference.FromAbi(objectReferenceValue.GetAbi(), IID.IID_IUnknown); } finally { objectReferenceValue.Dispose(); } } public static ObjectReferenceValue CreateMarshaler2(global::System.Collections.Specialized.NotifyCollectionChangedEventArgs value) { if (value == null) { return default(ObjectReferenceValue); } return WinRTNotifyCollectionChangedEventArgsRuntimeClassFactory.Instance.CreateInstanceWithAllParameters(value.Action, value.NewItems, value.OldItems, value.NewStartingIndex, value.OldStartingIndex); } public static IntPtr GetAbi(IObjectReference m) { return m?.ThisPtr ?? IntPtr.Zero; } public static global::System.Collections.Specialized.NotifyCollectionChangedEventArgs FromAbi(IntPtr ptr) { if (ptr == IntPtr.Zero) { return null; } return CreateNotifyCollectionChangedEventArgs(ptr); } private unsafe static global::System.Collections.Specialized.NotifyCollectionChangedEventArgs CreateNotifyCollectionChangedEventArgs(IntPtr ptr) { IntPtr ppv = default(IntPtr); global::System.Collections.Specialized.NotifyCollectionChangedAction action = global::System.Collections.Specialized.NotifyCollectionChangedAction.Add; IntPtr intPtr = default(IntPtr); IntPtr intPtr2 = default(IntPtr); int newStartingIndex = 0; int oldStartingIndex = 0; try { ExceptionHelpers.ThrowExceptionForHR(Marshal.QueryInterface(ptr, in Unsafe.AsRef(in Interface_IID), out ppv)); ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)ppv) + (nint)6 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(ppv, &action)); ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)ppv) + (nint)7 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(ppv, &intPtr)); ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)ppv) + (nint)8 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(ppv, &intPtr2)); ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)ppv) + (nint)9 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(ppv, &newStartingIndex)); ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)ppv) + (nint)10 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(ppv, &oldStartingIndex)); return CreateNotifyCollectionChangedEventArgs(action, MarshalInterface.FromAbi(intPtr), MarshalInterface.FromAbi(intPtr2), newStartingIndex, oldStartingIndex); } finally { MarshalInterface.DisposeAbi(intPtr); MarshalInterface.DisposeAbi(intPtr2); MarshalExtensions.ReleaseIfNotNull(ppv); } } private static global::System.Collections.Specialized.NotifyCollectionChangedEventArgs CreateNotifyCollectionChangedEventArgs(global::System.Collections.Specialized.NotifyCollectionChangedAction action, global::System.Collections.IList newItems, global::System.Collections.IList oldItems, int newStartingIndex, int oldStartingIndex) { return action switch { global::System.Collections.Specialized.NotifyCollectionChangedAction.Add => new global::System.Collections.Specialized.NotifyCollectionChangedEventArgs(action, newItems, newStartingIndex), global::System.Collections.Specialized.NotifyCollectionChangedAction.Remove => new global::System.Collections.Specialized.NotifyCollectionChangedEventArgs(action, oldItems, oldStartingIndex), global::System.Collections.Specialized.NotifyCollectionChangedAction.Replace => new global::System.Collections.Specialized.NotifyCollectionChangedEventArgs(action, newItems, oldItems, newStartingIndex), global::System.Collections.Specialized.NotifyCollectionChangedAction.Move => new global::System.Collections.Specialized.NotifyCollectionChangedEventArgs(action, newItems, newStartingIndex, oldStartingIndex), global::System.Collections.Specialized.NotifyCollectionChangedAction.Reset => new global::System.Collections.Specialized.NotifyCollectionChangedEventArgs(global::System.Collections.Specialized.NotifyCollectionChangedAction.Reset), _ => throw new ArgumentException(), }; } public unsafe static void CopyManaged(global::System.Collections.Specialized.NotifyCollectionChangedEventArgs o, IntPtr dest) { *(IntPtr*)dest.ToPointer() = CreateMarshaler2(o).Detach(); } public static IntPtr FromManaged(global::System.Collections.Specialized.NotifyCollectionChangedEventArgs value) { if (value == null) { return IntPtr.Zero; } return CreateMarshaler2(value).Detach(); } public static void DisposeMarshaler(IObjectReference m) { m?.Dispose(); } public static void DisposeAbi(IntPtr abi) { MarshalInspectable.DisposeAbi(abi); } public static MarshalInterfaceHelper.MarshalerArray CreateMarshalerArray(global::System.Collections.Specialized.NotifyCollectionChangedEventArgs[] array) { return MarshalInterfaceHelper.CreateMarshalerArray2(array, CreateMarshaler2); } public static (int length, IntPtr data) GetAbiArray(object box) { return MarshalInterfaceHelper.GetAbiArray(box); } public static global::System.Collections.Specialized.NotifyCollectionChangedEventArgs[] FromAbiArray(object box) { return MarshalInterfaceHelper.FromAbiArray(box, FromAbi); } public static void CopyAbiArray(global::System.Collections.Specialized.NotifyCollectionChangedEventArgs[] array, object box) { MarshalInterfaceHelper.CopyAbiArray(array, box, FromAbi); } public static (int length, IntPtr data) FromManagedArray(global::System.Collections.Specialized.NotifyCollectionChangedEventArgs[] array) { return MarshalInterfaceHelper.FromManagedArray(array, FromManaged); } public static void DisposeMarshalerArray(MarshalInterfaceHelper.MarshalerArray array) { MarshalInterfaceHelper.DisposeMarshalerArray(array); } public static void DisposeAbiArray(object box) { MarshalInspectable.DisposeAbiArray(box); } public static string GetGuidSignature() { if (FeatureSwitches.UseWindowsUIXamlProjections) { return "rc(Windows.UI.Xaml.Interop.NotifyCollectionChangedEventArgs;{4cf68d33-e3f2-4964-b85e-945b4f7e2f21})"; } return "rc(Microsoft.UI.Xaml.Interop.NotifyCollectionChangedEventArgs;{da049ff2-d2e0-5fe8-8c7b-f87f26060b6f})"; } } [EditorBrowsable(EditorBrowsableState.Never)] [Guid("8B0909DC-2005-5D93-BF8A-725F017BAA8D")] [WuxMuxProjectedType] public static class NotifyCollectionChangedEventHandler { private sealed class NativeDelegateWrapper : IWinRTObject, IDynamicInterfaceCastable { private readonly ObjectReference _nativeDelegate; private volatile ConcurrentDictionary _queryInterfaceCache; private volatile ConcurrentDictionary _additionalTypeData; IObjectReference IWinRTObject.NativeObject => _nativeDelegate; bool IWinRTObject.HasUnwrappableNativeObject => true; ConcurrentDictionary IWinRTObject.QueryInterfaceCache => _queryInterfaceCache ?? MakeQueryInterfaceCache(); ConcurrentDictionary IWinRTObject.AdditionalTypeData => _additionalTypeData ?? MakeAdditionalTypeData(); public NativeDelegateWrapper(ObjectReference nativeDelegate) { _nativeDelegate = nativeDelegate; } private ConcurrentDictionary MakeQueryInterfaceCache() { Interlocked.CompareExchange(ref _queryInterfaceCache, new ConcurrentDictionary(), null); return _queryInterfaceCache; } private ConcurrentDictionary MakeAdditionalTypeData() { Interlocked.CompareExchange(ref _additionalTypeData, new ConcurrentDictionary(), null); return _additionalTypeData; } public unsafe void Invoke(object sender, global::System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { IntPtr thisPtr = _nativeDelegate.ThisPtr; delegate* unmanaged[Stdcall] delegate* = (delegate* unmanaged[Stdcall])(void*)_nativeDelegate.Vftbl.Invoke; ObjectReferenceValue value = default(ObjectReferenceValue); ObjectReferenceValue value2 = default(ObjectReferenceValue); try { value = MarshalInspectable.CreateMarshaler2(sender); value2 = NotifyCollectionChangedEventArgs.CreateMarshaler2(e); ExceptionHelpers.ThrowExceptionForHR(delegate*(thisPtr, MarshalInspectable.GetAbi(value), MarshalInspectable.GetAbi(value2))); GC.KeepAlive(_nativeDelegate); } finally { MarshalInspectable.DisposeMarshaler(value); MarshalInspectable.DisposeMarshaler(value2); } } } private static readonly IDelegateVftbl AbiToProjectionVftable; public static readonly IntPtr AbiToProjectionVftablePtr; public static Delegate AbiInvokeDelegate { get; } public static Guid IID { get { if (!FeatureSwitches.UseWindowsUIXamlProjections) { return global::WinRT.Interop.IID.IID_MUX_NotifyCollectionChangedEventHandler; } return global::WinRT.Interop.IID.IID_WUX_NotifyCollectionChangedEventHandler; } } unsafe static NotifyCollectionChangedEventHandler() { AbiToProjectionVftable = new IDelegateVftbl { IUnknownVftbl = IUnknownVftbl.AbiToProjectionVftbl, Invoke = (IntPtr)(delegate*)(&Do_Abi_Invoke) }; IntPtr intPtr = ComWrappersSupport.AllocateVtableMemory(typeof(NotifyCollectionChangedEventHandler), sizeof(IDelegateVftbl)); *(IDelegateVftbl*)(void*)intPtr = AbiToProjectionVftable; AbiToProjectionVftablePtr = intPtr; ComWrappersSupport.RegisterDelegateFactory(typeof(global::System.Collections.Specialized.NotifyCollectionChangedEventHandler), CreateRcw); } public static IObjectReference CreateMarshaler(global::System.Collections.Specialized.NotifyCollectionChangedEventHandler managedDelegate) { if (managedDelegate != null) { return MarshalDelegate.CreateMarshaler(managedDelegate, IID); } return null; } public static ObjectReferenceValue CreateMarshaler2(global::System.Collections.Specialized.NotifyCollectionChangedEventHandler managedDelegate) { return MarshalDelegate.CreateMarshaler2(managedDelegate, IID); } public static IntPtr GetAbi(IObjectReference value) { return MarshalInterfaceHelper.GetAbi(value); } public static global::System.Collections.Specialized.NotifyCollectionChangedEventHandler FromAbi(IntPtr nativeDelegate) { return MarshalDelegate.FromAbi(nativeDelegate); } public static global::System.Collections.Specialized.NotifyCollectionChangedEventHandler CreateRcw(IntPtr ptr) { return new NativeDelegateWrapper(ComWrappersSupport.GetObjectReferenceForInterface(ptr, IID)).Invoke; } public static IntPtr FromManaged(global::System.Collections.Specialized.NotifyCollectionChangedEventHandler managedDelegate) { return CreateMarshaler2(managedDelegate).Detach(); } public static void DisposeMarshaler(IObjectReference value) { MarshalInterfaceHelper.DisposeMarshaler(value); } public static void DisposeAbi(IntPtr abi) { MarshalInterfaceHelper.DisposeAbi(abi); } public static MarshalInterfaceHelper.MarshalerArray CreateMarshalerArray(global::System.Collections.Specialized.NotifyCollectionChangedEventHandler[] array) { return MarshalInterfaceHelper.CreateMarshalerArray2(array, CreateMarshaler2); } public static (int length, IntPtr data) GetAbiArray(object box) { return MarshalInterfaceHelper.GetAbiArray(box); } public static global::System.Collections.Specialized.NotifyCollectionChangedEventHandler[] FromAbiArray(object box) { return MarshalInterfaceHelper.FromAbiArray(box, FromAbi); } public static void CopyAbiArray(global::System.Collections.Specialized.NotifyCollectionChangedEventHandler[] array, object box) { MarshalInterfaceHelper.CopyAbiArray(array, box, FromAbi); } public static (int length, IntPtr data) FromManagedArray(global::System.Collections.Specialized.NotifyCollectionChangedEventHandler[] array) { return MarshalInterfaceHelper.FromManagedArray(array, FromManaged); } public static void DisposeMarshalerArray(MarshalInterfaceHelper.MarshalerArray array) { MarshalInterfaceHelper.DisposeMarshalerArray(array); } public static void DisposeAbiArray(object box) { MarshalInspectable.DisposeAbiArray(box); } [UnmanagedCallersOnly(CallConvs = new global::System.Type[] { typeof(CallConvStdcall) })] private static int Do_Abi_Invoke(IntPtr thisPtr, IntPtr sender, IntPtr e) { try { global::System.Collections.Specialized.NotifyCollectionChangedEventHandler notifyCollectionChangedEventHandler = ComWrappersSupport.FindObject(thisPtr); notifyCollectionChangedEventHandler(MarshalInspectable.FromAbi(sender), NotifyCollectionChangedEventArgs.FromAbi(e)); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [SkipLocalsInit] internal static ComWrappers.ComInterfaceEntry[] GetExposedInterfaces() { Span span = stackalloc ComWrappers.ComInterfaceEntry[3]; int length = 0; span[length++] = new ComWrappers.ComInterfaceEntry { IID = IID, Vtable = AbiToProjectionVftablePtr }; if (FeatureSwitches.EnableIReferenceSupport) { span[length++] = new ComWrappers.ComInterfaceEntry { IID = global::WinRT.Interop.IID.IID_IPropertyValue, Vtable = ManagedIPropertyValueImpl.AbiToProjectionVftablePtr }; span[length++] = new ComWrappers.ComInterfaceEntry { IID = Nullable_NotifyCollectionChangedEventHandler.IID, Vtable = Nullable_NotifyCollectionChangedEventHandler.AbiToProjectionVftablePtr }; } return span.Slice(0, length).ToArray(); } } internal sealed class NotifyCollectionChangedEventHandlerEventSource : EventSource { private sealed class EventState : EventSourceState { public EventState(IntPtr obj, int index) : base(obj, index) { } protected override global::System.Collections.Specialized.NotifyCollectionChangedEventHandler GetEventInvoke() { return delegate(object? obj, global::System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { targetDelegate?.Invoke(obj, e); }; } } internal unsafe NotifyCollectionChangedEventHandlerEventSource(IObjectReference objectReference, delegate* unmanaged[Stdcall] addHandler, delegate* unmanaged[Stdcall] removeHandler) : base(objectReference, addHandler, removeHandler, 0) { } protected override ObjectReferenceValue CreateMarshaler(global::System.Collections.Specialized.NotifyCollectionChangedEventHandler del) { return NotifyCollectionChangedEventHandler.CreateMarshaler2(del); } protected override EventSourceState CreateEventSourceState() { return new EventState(base.ObjectReference.ThisPtr, base.Index); } } } namespace ABI.System.Collections.Generic { [DynamicInterfaceCastableImplementation] internal interface IReadOnlyCollection : global::System.Collections.Generic.IReadOnlyCollection, global::System.Collections.Generic.IEnumerable, global::System.Collections.IEnumerable { int global::System.Collections.Generic.IReadOnlyCollection.Count => GetHelper((IWinRTObject)this).Count; private static global::System.Collections.Generic.IReadOnlyCollection CreateHelper(RuntimeTypeHandle type, IWinRTObject _this) { global::System.Type typeFromHandle = typeof(T); if (typeFromHandle.IsGenericType && typeFromHandle.GetGenericTypeDefinition() == typeof(global::System.Collections.Generic.KeyValuePair<, >)) { if (!RuntimeFeature.IsDynamicCodeCompiled) { throw new NotSupportedException($"'IDynamicInterfaceCastable' is not supported for generic type argument '{typeof(T)}'."); } global::System.Type type2 = typeof(global::System.Collections.Generic.IReadOnlyDictionary<, >).MakeGenericType(typeFromHandle.GetGenericArguments()); if (_this.IsInterfaceImplemented(type2.TypeHandle, throwIfNotImplemented: false)) { global::System.Type type3 = typeof(IReadOnlyDictionaryImpl<, >).MakeGenericType(typeFromHandle.GetGenericArguments()); return (global::System.Collections.Generic.IReadOnlyCollection)type3.GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic, null, new global::System.Type[1] { typeof(IObjectReference) }, null).Invoke(new object[1] { _this.NativeObject }); } } global::System.Type typeFromHandle2 = typeof(global::System.Collections.Generic.IReadOnlyList); if (_this.IsInterfaceImplemented(typeFromHandle2.TypeHandle, throwIfNotImplemented: false)) { return new IReadOnlyListImpl(_this.NativeObject); } throw new InvalidOperationException("IReadOnlyCollection<> helper can not determine derived type."); } private static global::System.Collections.Generic.IReadOnlyCollection GetHelper(IWinRTObject _this) { return (global::System.Collections.Generic.IReadOnlyCollection)_this.AdditionalTypeData.GetOrAdd(typeof(global::System.Collections.Generic.IReadOnlyCollection).TypeHandle, CreateHelper, _this); } IEnumerator global::System.Collections.IEnumerable.GetEnumerator() { return GetHelper((IWinRTObject)this).GetEnumerator(); } global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() { return GetHelper((IWinRTObject)this).GetEnumerator(); } } [DynamicInterfaceCastableImplementation] internal interface ICollection : global::System.Collections.Generic.ICollection, global::System.Collections.Generic.IEnumerable, global::System.Collections.IEnumerable { int global::System.Collections.Generic.ICollection.Count => GetHelper((IWinRTObject)this).Count; bool global::System.Collections.Generic.ICollection.IsReadOnly => GetHelper((IWinRTObject)this).IsReadOnly; private static global::System.Collections.Generic.ICollection CreateHelper(RuntimeTypeHandle type, IWinRTObject _this) { global::System.Type typeFromHandle = typeof(T); if (typeFromHandle.IsGenericType && typeFromHandle.GetGenericTypeDefinition() == typeof(global::System.Collections.Generic.KeyValuePair<, >)) { if (!RuntimeFeature.IsDynamicCodeCompiled) { throw new NotSupportedException($"'IDynamicInterfaceCastable' is not supported for generic type argument '{typeof(T)}'."); } global::System.Type type2 = typeof(global::System.Collections.Generic.IDictionary<, >).MakeGenericType(typeFromHandle.GetGenericArguments()); if (_this.IsInterfaceImplemented(type2.TypeHandle, throwIfNotImplemented: false)) { global::System.Type type3 = typeof(IDictionaryImpl<, >).MakeGenericType(typeFromHandle.GetGenericArguments()); return (global::System.Collections.Generic.ICollection)type3.GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic, null, new global::System.Type[1] { typeof(IObjectReference) }, null).Invoke(new object[1] { _this.NativeObject }); } } global::System.Type typeFromHandle2 = typeof(global::System.Collections.Generic.IList); if (_this.IsInterfaceImplemented(typeFromHandle2.TypeHandle, throwIfNotImplemented: false)) { return new IListImpl(_this.NativeObject); } throw new InvalidOperationException("ICollection<> helper can not determine derived type."); } private static global::System.Collections.Generic.ICollection GetHelper(IWinRTObject _this) { return (global::System.Collections.Generic.ICollection)_this.AdditionalTypeData.GetOrAdd(typeof(global::System.Collections.Generic.ICollection).TypeHandle, CreateHelper, _this); } void global::System.Collections.Generic.ICollection.Add(T item) { GetHelper((IWinRTObject)this).Add(item); } void global::System.Collections.Generic.ICollection.Clear() { GetHelper((IWinRTObject)this).Clear(); } bool global::System.Collections.Generic.ICollection.Contains(T item) { return GetHelper((IWinRTObject)this).Contains(item); } void global::System.Collections.Generic.ICollection.CopyTo(T[] array, int arrayIndex) { GetHelper((IWinRTObject)this).CopyTo(array, arrayIndex); } bool global::System.Collections.Generic.ICollection.Remove(T item) { return GetHelper((IWinRTObject)this).Remove(item); } IEnumerator global::System.Collections.IEnumerable.GetEnumerator() { return GetHelper((IWinRTObject)this).GetEnumerator(); } global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() { return GetHelper((IWinRTObject)this).GetEnumerator(); } } public static class IDictionaryMethods { private sealed class DictionaryKeyCollection : global::System.Collections.Generic.ICollection, global::System.Collections.Generic.IEnumerable, global::System.Collections.IEnumerable { private sealed class DictionaryKeyEnumerator : global::System.Collections.Generic.IEnumerator, IEnumerator, global::System.IDisposable { private readonly IObjectReference iEnumerableObjRef; private global::System.Collections.Generic.IEnumerator> enumeration; object IEnumerator.Current => Current; public K Current => enumeration.Current.Key; public DictionaryKeyEnumerator(IObjectReference iEnumerableObjRef) { this.iEnumerableObjRef = iEnumerableObjRef; enumeration = IEnumerableMethods>.GetEnumerator(iEnumerableObjRef); } public void Dispose() { enumeration.Dispose(); } public bool MoveNext() { return enumeration.MoveNext(); } public void Reset() { enumeration = IEnumerableMethods>.GetEnumerator(iEnumerableObjRef); } } private readonly IObjectReference iDictionaryObjRef; private volatile IObjectReference __iEnumerableObjRef; private IObjectReference iEnumerableObjRef => __iEnumerableObjRef ?? Make_IEnumerableObjRef(); public int Count => IDictionaryMethods.get_Count(iDictionaryObjRef); public bool IsReadOnly => true; public DictionaryKeyCollection(IObjectReference iDictionaryObjRef) { if (iDictionaryObjRef == null) { throw new ArgumentNullException("iDictionaryObjRef"); } this.iDictionaryObjRef = iDictionaryObjRef; } private IObjectReference Make_IEnumerableObjRef() { Interlocked.CompareExchange(ref __iEnumerableObjRef, iDictionaryObjRef.As(IEnumerableMethods>.PIID), null); return __iEnumerableObjRef; } public void CopyTo(K[] array, int index) { if (array == null) { throw new ArgumentNullException("array"); } if (index < 0) { throw new ArgumentOutOfRangeException("index"); } if (array.Length <= index && Count > 0) { throw new ArgumentException(WinRTRuntimeErrorStrings.Arg_IndexOutOfRangeException); } if (array.Length - index < IDictionaryMethods.get_Count(iDictionaryObjRef)) { throw new ArgumentException(WinRTRuntimeErrorStrings.Argument_InsufficientSpaceToCopyCollection); } int num = index; foreach (global::System.Collections.Generic.KeyValuePair item in new IEnumerableImpl>(iEnumerableObjRef)) { array[num++] = item.Key; } } void global::System.Collections.Generic.ICollection.Add(K item) { throw new NotSupportedException(WinRTRuntimeErrorStrings.NotSupported_KeyCollectionSet); } void global::System.Collections.Generic.ICollection.Clear() { throw new NotSupportedException(WinRTRuntimeErrorStrings.NotSupported_KeyCollectionSet); } public bool Contains(K item) { return IDictionaryMethods.ContainsKey(iDictionaryObjRef, item); } bool global::System.Collections.Generic.ICollection.Remove(K item) { throw new NotSupportedException(WinRTRuntimeErrorStrings.NotSupported_KeyCollectionSet); } IEnumerator global::System.Collections.IEnumerable.GetEnumerator() { return GetEnumerator(); } public global::System.Collections.Generic.IEnumerator GetEnumerator() { return new DictionaryKeyEnumerator(iEnumerableObjRef); } } private sealed class DictionaryValueCollection : global::System.Collections.Generic.ICollection, global::System.Collections.Generic.IEnumerable, global::System.Collections.IEnumerable { private sealed class DictionaryValueEnumerator : global::System.Collections.Generic.IEnumerator, IEnumerator, global::System.IDisposable { private readonly IObjectReference iEnumerableObjRef; private global::System.Collections.Generic.IEnumerator> enumeration; object IEnumerator.Current => Current; public V Current => enumeration.Current.Value; public DictionaryValueEnumerator(IObjectReference iEnumerableObjRef) { this.iEnumerableObjRef = iEnumerableObjRef; enumeration = IEnumerableMethods>.GetEnumerator(iEnumerableObjRef); } public void Dispose() { enumeration.Dispose(); } public bool MoveNext() { return enumeration.MoveNext(); } public void Reset() { enumeration = IEnumerableMethods>.GetEnumerator(iEnumerableObjRef); } } private readonly IObjectReference iDictionaryObjRef; private volatile IObjectReference __iEnumerableObjRef; private IObjectReference iEnumerableObjRef => __iEnumerableObjRef ?? Make_IEnumerableObjRef(); public int Count => IDictionaryMethods.get_Count(iDictionaryObjRef); public bool IsReadOnly => true; public DictionaryValueCollection(IObjectReference iDictionaryObjRef) { this.iDictionaryObjRef = iDictionaryObjRef; } private IObjectReference Make_IEnumerableObjRef() { Interlocked.CompareExchange(ref __iEnumerableObjRef, iDictionaryObjRef.As(IEnumerableMethods>.PIID), null); return __iEnumerableObjRef; } public void CopyTo(V[] array, int index) { if (array == null) { throw new ArgumentNullException("array"); } if (index < 0) { throw new ArgumentOutOfRangeException("index"); } if (array.Length <= index && Count > 0) { throw new ArgumentException(WinRTRuntimeErrorStrings.Arg_IndexOutOfRangeException); } if (array.Length - index < IDictionaryMethods.get_Count(iDictionaryObjRef)) { throw new ArgumentException(WinRTRuntimeErrorStrings.Argument_InsufficientSpaceToCopyCollection); } int num = index; foreach (global::System.Collections.Generic.KeyValuePair item in new IEnumerableImpl>(iEnumerableObjRef)) { array[num++] = item.Value; } } void global::System.Collections.Generic.ICollection.Add(V item) { throw new NotSupportedException(WinRTRuntimeErrorStrings.NotSupported_ValueCollectionSet); } void global::System.Collections.Generic.ICollection.Clear() { throw new NotSupportedException(WinRTRuntimeErrorStrings.NotSupported_ValueCollectionSet); } public bool Contains(V item) { EqualityComparer equalityComparer = EqualityComparer.Default; using (global::System.Collections.Generic.IEnumerator enumerator = GetEnumerator()) { while (enumerator.MoveNext()) { V current = enumerator.Current; if (equalityComparer.Equals(item, current)) { return true; } } } return false; } bool global::System.Collections.Generic.ICollection.Remove(V item) { throw new NotSupportedException(WinRTRuntimeErrorStrings.NotSupported_ValueCollectionSet); } IEnumerator global::System.Collections.IEnumerable.GetEnumerator() { return GetEnumerator(); } public global::System.Collections.Generic.IEnumerator GetEnumerator() { return new DictionaryValueEnumerator(iEnumerableObjRef); } } private static IntPtr abiToProjectionVftablePtr; internal static readonly Guid PIID; public static IntPtr AbiToProjectionVftablePtr => abiToProjectionVftablePtr; public static Guid IID => PIID; static IDictionaryMethods() { PIID = GuidGenerator.CreateIIDUnsafe(typeof(IDictionary)); ComWrappersSupport.RegisterHelperType(typeof(global::System.Collections.Generic.IDictionary), typeof(IDictionary)); if (RuntimeFeature.IsDynamicCodeCompiled) { InitRcwHelperFallbackIfNeeded(); } [MethodImpl(MethodImplOptions.NoInlining)] [UnconditionalSuppressMessage("Trimming", "IL2080", Justification = "All ABI types never have a constructor that would need to be accessed via reflection.")] static void InitRcwHelperFallbackIfNeeded() { if (!IMapMethods._RcwHelperInitialized) { Func func = (Func)typeof(IDictionaryMethods<, , , >).MakeGenericType(typeof(K), Marshaler.AbiType, typeof(V), Marshaler.AbiType).GetMethod("InitRcwHelperFallback", BindingFlags.Static | BindingFlags.NonPublic).CreateDelegate(typeof(Func)); func(); } } } public static int get_Count(IObjectReference obj) { uint num = IMapMethods.get_Size(obj); if (int.MaxValue < num) { throw new InvalidOperationException(WinRTRuntimeErrorStrings.InvalidOperation_CollectionBackingDictionaryTooLarge); } return (int)num; } public static bool get_IsReadOnly(IObjectReference _) { return false; } public static void Add(IObjectReference obj, global::System.Collections.Generic.KeyValuePair item) { IMapMethods.Insert(obj, item.Key, item.Value); } public static void Clear(IObjectReference obj) { IMapMethods.Clear(obj); } public static bool Contains(IObjectReference obj, Dictionary __lookupCache, global::System.Collections.Generic.KeyValuePair item) { if (!IMapMethods.HasKey(obj, item.Key)) { return false; } V x = IMapMethods.Lookup(obj, item.Key); return EqualityComparer.Default.Equals(x, item.Value); } public static void CopyTo(IObjectReference obj, IObjectReference iEnumerableObjRef, global::System.Collections.Generic.KeyValuePair[] array, int arrayIndex) { if (array == null) { throw new ArgumentNullException("array"); } if (arrayIndex < 0) { throw new ArgumentOutOfRangeException("arrayIndex"); } if (array.Length <= arrayIndex && get_Count(obj) > 0) { throw new ArgumentException(WinRTRuntimeErrorStrings.Argument_IndexOutOfArrayBounds); } if (array.Length - arrayIndex < get_Count(obj)) { throw new ArgumentException(WinRTRuntimeErrorStrings.Argument_InsufficientSpaceToCopyCollection); } foreach (global::System.Collections.Generic.KeyValuePair item in new IEnumerableImpl>(iEnumerableObjRef)) { array[arrayIndex++] = item; } } public static bool Remove(IObjectReference obj, global::System.Collections.Generic.KeyValuePair item) { IMapMethods.Remove(obj, item.Key); return true; } public static V Indexer_Get(IObjectReference obj, Dictionary __lookupCache, K key) { if (key == null) { throw new ArgumentNullException("key"); } return Lookup(obj, key); } public static void Indexer_Set(IObjectReference obj, K key, V value) { if (key == null) { throw new ArgumentNullException("key"); } Insert(obj, key, value); } public static global::System.Collections.Generic.ICollection get_Keys(IObjectReference obj) { return new DictionaryKeyCollection(obj); } public static global::System.Collections.Generic.ICollection get_Values(IObjectReference obj) { return new DictionaryValueCollection(obj); } public static bool ContainsKey(IObjectReference obj, K key) { if (key == null) { throw new ArgumentNullException("key"); } return IMapMethods.HasKey(obj, key); } public static void Add(IObjectReference obj, K key, V value) { if (key == null) { throw new ArgumentNullException("key"); } if (ContainsKey(obj, key)) { throw new ArgumentException(WinRTRuntimeErrorStrings.Argument_AddingDuplicate); } Insert(obj, key, value); } public static bool Remove(IObjectReference obj, K key) { if (key == null) { throw new ArgumentNullException("key"); } if (!IMapMethods.HasKey(obj, key)) { return false; } try { IMapMethods.Remove(obj, key); return true; } catch (global::System.Exception ex) { if (-2147483637 == ex.HResult) { return false; } throw; } } public static bool TryGetValue(IObjectReference obj, Dictionary __lookupCache, K key, out V value) { if (key == null) { throw new ArgumentNullException("key"); } if (!IMapMethods.HasKey(obj, key)) { value = default(V); return false; } try { value = Lookup(obj, key); return true; } catch (KeyNotFoundException) { value = default(V); return false; } } private static V Lookup(IObjectReference obj, K key) { try { return IMapMethods.Lookup(obj, key); } catch (global::System.Exception ex) { if (-2147483637 == ex.HResult) { throw new KeyNotFoundException(WinRTRuntimeErrorStrings.Arg_KeyNotFound); } throw; } } private static bool Insert(IObjectReference obj, K key, V value) { return IMapMethods.Insert(obj, key, value); } internal static bool TryInitCCWVtable(IntPtr ptr) { return Interlocked.CompareExchange(ref abiToProjectionVftablePtr, ptr, IntPtr.Zero) == IntPtr.Zero; } public static V Abi_Lookup_0(IntPtr thisPtr, K key) { return IDictionary.FindAdapter(thisPtr).Lookup(key); } public static bool Abi_HasKey_2(IntPtr thisPtr, K key) { return IDictionary.FindAdapter(thisPtr).HasKey(key); } public static global::System.Collections.Generic.IReadOnlyDictionary Abi_GetView_3(IntPtr thisPtr) { return IDictionary.FindAdapter(thisPtr).GetView(); } public static bool Abi_Insert_4(IntPtr thisPtr, K key, V value) { return IDictionary.FindAdapter(thisPtr).Insert(key, value); } public static void Abi_Remove_5(IntPtr thisPtr, K key) { IDictionary.FindAdapter(thisPtr)._Remove(key); } public static void Abi_Clear_6(IntPtr thisPtr) { IDictionary.FindAdapter(thisPtr).Clear(); } public static uint Abi_get_Size_1(IntPtr thisPtr) { return IDictionary.FindAdapter(thisPtr).Size; } } public static class IDictionaryMethods where KAbi : unmanaged where VAbi : unmanaged { private sealed class DelegateHelper { private readonly IntPtr _ptr; private Delegate _lookupDelegate; private Delegate _hasKeyDelegate; private Delegate _insertDelegate; private Delegate _removeDelegate; public Delegate Lookup => _lookupDelegate ?? GenericDelegateHelper.CreateDelegate(_ptr, ref _lookupDelegate, IDictionaryMethods.Lookup_0_Type, 6); public Delegate HasKey => _hasKeyDelegate ?? GenericDelegateHelper.CreateDelegate(_ptr, ref _hasKeyDelegate, IDictionaryMethods.HasKey_2_Type, 8); public Delegate Insert => _insertDelegate ?? GenericDelegateHelper.CreateDelegate(_ptr, ref _insertDelegate, IDictionaryMethods.Insert_4_Type, 10); public Delegate Remove => _removeDelegate ?? GenericDelegateHelper.CreateDelegate(_ptr, ref _removeDelegate, IDictionaryMethods.Remove_5_Type, 11); private DelegateHelper(IntPtr ptr) { _ptr = ptr; } public static DelegateHelper Get(IObjectReference obj) { return (DelegateHelper)GenericDelegateHelper.DelegateTable.GetValue(obj, (IObjectReference objRef) => new DelegateHelper(objRef.ThisPtr)); } } internal unsafe static delegate* _Lookup; internal unsafe static delegate* _HasKey; internal unsafe static delegate*> _GetView; internal unsafe static delegate* _Insert; internal unsafe static delegate* _Remove; private static Delegate[] DelegateCache; private static global::System.Type _lookup_0_type; private static global::System.Type _hasKey_2_type; private static global::System.Type _insert_4_type; private static global::System.Type _remove_5_type; private static global::System.Type Lookup_0_Type => _lookup_0_type ?? MakeLookupType(); private static global::System.Type HasKey_2_Type => _hasKey_2_type ?? MakeHasKeyType(); private static global::System.Type Insert_4_Type => _insert_4_type ?? MakeInsertType(); private static global::System.Type Remove_5_Type => _remove_5_type ?? MakeRemoveType(); public unsafe static bool InitRcwHelper(delegate* lookup, delegate* hasKey, delegate*> getView, delegate* insert, delegate* remove) { if (IMapMethods._RcwHelperInitialized) { return true; } IMapMethods._Lookup = lookup; IMapMethods._HasKey = hasKey; IMapMethods._GetView = getView; IMapMethods._Insert = insert; IMapMethods._Remove = remove; ComWrappersSupport.RegisterTypedRcwFactory(typeof(global::System.Collections.Generic.IDictionary), IDictionaryImpl.CreateRcw); ComWrappersSupport.RegisterHelperType(typeof(global::System.Collections.Generic.IDictionary), typeof(IDictionary)); IMapMethods._RcwHelperInitialized = true; return true; } private unsafe static bool InitRcwHelperFallback() { return InitRcwHelper((delegate*)(&LookupDynamic), (delegate*)(&HasKeyDynamic), (delegate*>)null, (delegate*)(&InsertDynamic), (delegate*)(&RemoveDynamic)); } private unsafe static V LookupDynamic(IObjectReference obj, K key) { IntPtr thisPtr = obj.ThisPtr; object obj2 = null; VAbi val = default(VAbi); object[] array = new object[3] { thisPtr, null, (IntPtr)(&val) }; try { obj2 = Marshaler.CreateMarshaler2(key); array[1] = Marshaler.GetAbi(obj2); DelegateHelper.Get(obj).Lookup.DynamicInvokeAbi(array); GC.KeepAlive(obj); GC.KeepAlive(array); return Marshaler.FromAbi(val); } finally { Marshaler.DisposeMarshaler(obj2); Marshaler.DisposeAbi(val); } } private unsafe static bool HasKeyDynamic(IObjectReference obj, K key) { IntPtr thisPtr = obj.ThisPtr; object obj2 = null; byte b = default(byte); object[] array = new object[3] { thisPtr, null, (IntPtr)(&b) }; try { obj2 = Marshaler.CreateMarshaler2(key); array[1] = Marshaler.GetAbi(obj2); DelegateHelper.Get(obj).HasKey.DynamicInvokeAbi(array); GC.KeepAlive(obj); GC.KeepAlive(array); return b != 0; } finally { Marshaler.DisposeMarshaler(obj2); } } private unsafe static bool InsertDynamic(IObjectReference obj, K key, V value) { IntPtr thisPtr = obj.ThisPtr; object obj2 = null; object obj3 = null; byte b = default(byte); object[] array = new object[4] { thisPtr, null, null, (IntPtr)(&b) }; try { obj2 = Marshaler.CreateMarshaler2(key); array[1] = Marshaler.GetAbi(obj2); obj3 = Marshaler.CreateMarshaler2(value); array[2] = Marshaler.GetAbi(obj3); DelegateHelper.Get(obj).Insert.DynamicInvokeAbi(array); GC.KeepAlive(obj); GC.KeepAlive(array); return b != 0; } finally { Marshaler.DisposeMarshaler(obj2); Marshaler.DisposeMarshaler(obj3); } } private static void RemoveDynamic(IObjectReference obj, K key) { IntPtr thisPtr = obj.ThisPtr; object obj2 = null; object[] array = new object[2] { thisPtr, null }; try { obj2 = Marshaler.CreateMarshaler2(key); array[1] = Marshaler.GetAbi(obj2); DelegateHelper.Get(obj).Remove.DynamicInvokeAbi(array); GC.KeepAlive(obj); GC.KeepAlive(array); } finally { Marshaler.DisposeMarshaler(obj2); } } public unsafe static bool InitCcw(delegate* unmanaged[Stdcall] lookup, delegate* unmanaged[Stdcall] getSize, delegate* unmanaged[Stdcall] hasKey, delegate* unmanaged[Stdcall] getView, delegate* unmanaged[Stdcall] insert, delegate* unmanaged[Stdcall] remove, delegate* unmanaged[Stdcall] clear) { if (IDictionaryMethods.AbiToProjectionVftablePtr != (IntPtr)0) { return false; } IntPtr intPtr = (IntPtr)NativeMemory.AllocZeroed((nuint)(sizeof(IInspectable.Vftbl) + sizeof(IntPtr) * 7)); *(IInspectable.Vftbl*)(void*)intPtr = IInspectable.Vftbl.AbiToProjectionVftable; *(IntPtr*)((byte*)(void*)intPtr + (nint)6 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)lookup; *(IntPtr*)((byte*)(void*)intPtr + (nint)7 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)getSize; *(IntPtr*)((byte*)(void*)intPtr + (nint)8 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)hasKey; *(IntPtr*)((byte*)(void*)intPtr + (nint)9 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)getView; *(IntPtr*)((byte*)(void*)intPtr + (nint)10 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)insert; *(IntPtr*)((byte*)(void*)intPtr + (nint)11 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)remove; *(IntPtr*)((byte*)(void*)intPtr + (nint)12 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)clear; if (!IDictionaryMethods.TryInitCCWVtable(intPtr)) { NativeMemory.Free((void*)intPtr); return false; } ComWrappersSupport.RegisterHelperType(typeof(global::System.Collections.Generic.IReadOnlyDictionary), typeof(IReadOnlyDictionary)); return true; } internal unsafe static void InitFallbackCCWVtable() { DelegateCache = new Delegate[7] { Delegate.CreateDelegate(Lookup_0_Type, typeof(IDictionaryMethods).GetMethod("Do_Abi_Lookup_0", BindingFlags.Static | BindingFlags.NonPublic)), new _get_PropertyAsUInt32_Abi(Do_Abi_get_Size_1), Delegate.CreateDelegate(HasKey_2_Type, typeof(IDictionaryMethods).GetMethod("Do_Abi_HasKey_2", BindingFlags.Static | BindingFlags.NonPublic)), new IDictionary_Delegates.GetView_3_Abi(Do_Abi_GetView_3), Delegate.CreateDelegate(Insert_4_Type, typeof(IDictionaryMethods).GetMethod("Do_Abi_Insert_4", BindingFlags.Static | BindingFlags.NonPublic)), Delegate.CreateDelegate(Remove_5_Type, typeof(IDictionaryMethods).GetMethod("Do_Abi_Remove_5", BindingFlags.Static | BindingFlags.NonPublic)), new IDictionary_Delegates.Clear_6(Do_Abi_Clear_6) }; InitCcw((delegate* unmanaged[Stdcall])(void*)Marshal.GetFunctionPointerForDelegate(DelegateCache[0]), (delegate* unmanaged[Stdcall])(void*)Marshal.GetFunctionPointerForDelegate(DelegateCache[1]), (delegate* unmanaged[Stdcall])(void*)Marshal.GetFunctionPointerForDelegate(DelegateCache[2]), (delegate* unmanaged[Stdcall])(void*)Marshal.GetFunctionPointerForDelegate(DelegateCache[3]), (delegate* unmanaged[Stdcall])(void*)Marshal.GetFunctionPointerForDelegate(DelegateCache[4]), (delegate* unmanaged[Stdcall])(void*)Marshal.GetFunctionPointerForDelegate(DelegateCache[5]), (delegate* unmanaged[Stdcall])(void*)Marshal.GetFunctionPointerForDelegate(DelegateCache[6])); } private unsafe static int Do_Abi_Lookup_0(void* thisPtr, KAbi key, VAbi* __return_value__) { V val = default(V); *__return_value__ = default(VAbi); try { val = IDictionary.FindAdapter(new IntPtr(thisPtr)).Lookup(Marshaler.FromAbi(key)); *__return_value__ = (VAbi)Marshaler.FromManaged(val); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } private unsafe static int Do_Abi_HasKey_2(void* thisPtr, KAbi key, byte* __return_value__) { bool flag = false; *__return_value__ = 0; try { flag = IDictionary.FindAdapter(new IntPtr(thisPtr)).HasKey(Marshaler.FromAbi(key)); *__return_value__ = (flag ? ((byte)1) : ((byte)0)); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } private unsafe static int Do_Abi_GetView_3(IntPtr thisPtr, IntPtr* __return_value__) { global::System.Collections.Generic.IReadOnlyDictionary readOnlyDictionary = null; *__return_value__ = default(IntPtr); try { readOnlyDictionary = IDictionary.FindAdapter(thisPtr).GetView(); *__return_value__ = MarshalInterface>.FromManaged(readOnlyDictionary); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } private unsafe static int Do_Abi_Insert_4(void* thisPtr, KAbi key, VAbi value, byte* __return_value__) { bool flag = false; *__return_value__ = 0; try { flag = IDictionary.FindAdapter(new IntPtr(thisPtr)).Insert(Marshaler.FromAbi(key), Marshaler.FromAbi(value)); *__return_value__ = (flag ? ((byte)1) : ((byte)0)); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } private unsafe static int Do_Abi_Remove_5(void* thisPtr, KAbi key) { try { IDictionary.FindAdapter(new IntPtr(thisPtr))._Remove(Marshaler.FromAbi(key)); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } private static int Do_Abi_Clear_6(IntPtr thisPtr) { try { IDictionary.FindAdapter(thisPtr).Clear(); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } private unsafe static int Do_Abi_get_Size_1(IntPtr thisPtr, uint* __return_value__) { uint num = 0u; *__return_value__ = 0u; try { num = IDictionary.FindAdapter(thisPtr).Size; *__return_value__ = num; } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } private unsafe static global::System.Type MakeLookupType() { Interlocked.CompareExchange(ref _lookup_0_type, Projections.GetAbiDelegateType(typeof(void*), typeof(KAbi), typeof(VAbi*), typeof(int)), null); return _lookup_0_type; } private unsafe static global::System.Type MakeHasKeyType() { Interlocked.CompareExchange(ref _hasKey_2_type, Projections.GetAbiDelegateType(typeof(void*), typeof(KAbi), typeof(byte*), typeof(int)), null); return _hasKey_2_type; } private unsafe static global::System.Type MakeInsertType() { Interlocked.CompareExchange(ref _insert_4_type, Projections.GetAbiDelegateType(typeof(void*), typeof(KAbi), typeof(VAbi), typeof(byte*), typeof(int)), null); return _insert_4_type; } private unsafe static global::System.Type MakeRemoveType() { Interlocked.CompareExchange(ref _remove_5_type, Projections.GetAbiDelegateType(typeof(void*), typeof(KAbi), typeof(int)), null); return _remove_5_type; } } [DynamicInterfaceCastableImplementation] [Guid("3C2925FE-8519-45C1-AA79-197B6718C1C1")] internal interface IDictionary : global::System.Collections.Generic.IDictionary, global::System.Collections.Generic.ICollection>, global::System.Collections.Generic.IEnumerable>, global::System.Collections.IEnumerable { public sealed class ToAbiHelper : IMap, global::Windows.Foundation.Collections.IIterable> { private readonly global::System.Collections.Generic.IDictionary _dictionary; public uint Size => (uint)_dictionary.Count; public ToAbiHelper(global::System.Collections.Generic.IDictionary dictionary) { _dictionary = dictionary; } global::System.Collections.Generic.IEnumerator> global::Windows.Foundation.Collections.IIterable>.First() { return new KeyValuePair.Enumerator(_dictionary.GetEnumerator()); } public V Lookup(K key) { if (!_dictionary.TryGetValue(key, out var value)) { global::System.Exception ex = new KeyNotFoundException(string.Format(WinRTRuntimeErrorStrings.Arg_KeyNotFoundWithKey, key.ToString())); ex.SetHResult(-2147483637); throw ex; } return value; } public bool HasKey(K key) { return _dictionary.ContainsKey(key); } global::System.Collections.Generic.IReadOnlyDictionary IMap.GetView() { global::System.Collections.Generic.IReadOnlyDictionary readOnlyDictionary = _dictionary as global::System.Collections.Generic.IReadOnlyDictionary; if (readOnlyDictionary == null) { readOnlyDictionary = new ReadOnlyDictionary(_dictionary); } return readOnlyDictionary; } public bool Insert(K key, V value) { bool result = _dictionary.ContainsKey(key); _dictionary[key] = value; return result; } public void _Remove(K key) { if (!_dictionary.Remove(key)) { global::System.Exception ex = new KeyNotFoundException(string.Format(WinRTRuntimeErrorStrings.Arg_KeyNotFoundWithKey, key.ToString())); ex.SetHResult(-2147483637); throw ex; } } public void Clear() { _dictionary.Clear(); } } [Guid("3C2925FE-8519-45C1-AA79-197B6718C1C1")] public struct Vftbl { internal IInspectable.Vftbl IInspectableVftbl; public static readonly IntPtr AbiToProjectionVftablePtr = IDictionary.AbiToProjectionVftablePtr; public static readonly Guid PIID = IDictionary.PIID; } static readonly IntPtr AbiToProjectionVftablePtr; private static readonly ConditionalWeakTable, ToAbiHelper> _adapterTable; static readonly Guid PIID; global::System.Collections.Generic.ICollection global::System.Collections.Generic.IDictionary.Keys { get { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.Generic.IDictionary).TypeHandle); return IDictionaryMethods.get_Keys(objectReferenceForType); } } global::System.Collections.Generic.ICollection global::System.Collections.Generic.IDictionary.Values { get { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.Generic.IDictionary).TypeHandle); return IDictionaryMethods.get_Values(objectReferenceForType); } } int global::System.Collections.Generic.ICollection>.Count { get { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.Generic.IDictionary).TypeHandle); return IDictionaryMethods.get_Count(objectReferenceForType); } } bool global::System.Collections.Generic.ICollection>.IsReadOnly { get { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.Generic.IDictionary).TypeHandle); return IDictionaryMethods.get_IsReadOnly(objectReferenceForType); } } V global::System.Collections.Generic.IDictionary.this[K key] { get { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.Generic.IDictionary).TypeHandle); return IDictionaryMethods.Indexer_Get(objectReferenceForType, null, key); } set { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.Generic.IDictionary).TypeHandle); IDictionaryMethods.Indexer_Set(objectReferenceForType, key, value); } } static IObjectReference CreateMarshaler(global::System.Collections.Generic.IDictionary obj) { if (obj != null) { return ComWrappersSupport.CreateCCWForObject(obj, PIID); } return null; } static ObjectReferenceValue CreateMarshaler2(global::System.Collections.Generic.IDictionary obj) { return ComWrappersSupport.CreateCCWForObjectForMarshaling(obj, PIID); } static IntPtr GetAbi(IObjectReference objRef) { return objRef?.ThisPtr ?? IntPtr.Zero; } static global::System.Collections.Generic.IDictionary FromAbi(IntPtr thisPtr) { if (thisPtr == IntPtr.Zero) { return null; } if (!FeatureSwitches.EnableIDynamicInterfaceCastableSupport) { throw new NotSupportedException("'IDictionary.FromAbi' relies on 'IDynamicInterfaceCastable' support, which is not currently available. Make sure the 'EnableIDynamicInterfaceCastableSupport' property is not set to 'false'."); } return (global::System.Collections.Generic.IDictionary)new IInspectable(ObjRefFromAbi(thisPtr)); } static IntPtr FromManaged(global::System.Collections.Generic.IDictionary value) { if (value != null) { return CreateMarshaler2(value).Detach(); } return IntPtr.Zero; } static void DisposeMarshaler(IObjectReference objRef) { objRef?.Dispose(); } static void DisposeAbi(IntPtr abi) { MarshalInterfaceHelper>.DisposeAbi(abi); } static string GetGuidSignature() { return GuidGenerator.GetSignature(typeof(IDictionary)); } static IDictionary() { _adapterTable = new ConditionalWeakTable, ToAbiHelper>(); PIID = IDictionaryMethods.PIID; if (RuntimeFeature.IsDynamicCodeCompiled) { InitFallbackCCWVTableIfNeeded(); } AbiToProjectionVftablePtr = IDictionaryMethods.AbiToProjectionVftablePtr; [MethodImpl(MethodImplOptions.NoInlining)] [UnconditionalSuppressMessage("Trimming", "IL2080", Justification = "All ABI types never have a constructor that would need to be accessed via reflection.")] internal static void InitFallbackCCWVTableIfNeeded() { if (IDictionaryMethods.AbiToProjectionVftablePtr == (IntPtr)0) { Action action = (Action)typeof(IDictionaryMethods<, , , >).MakeGenericType(typeof(K), Marshaler.AbiType, typeof(V), Marshaler.AbiType).GetMethod("InitFallbackCCWVtable", BindingFlags.Static | BindingFlags.NonPublic).CreateDelegate(typeof(Action)); action(); } } } internal static IMap FindAdapter(IntPtr thisPtr) { global::System.Collections.Generic.IDictionary key = ComWrappersSupport.FindObject>(thisPtr); return _adapterTable.GetValue(key, (global::System.Collections.Generic.IDictionary dictionary) => new ToAbiHelper(dictionary)); } static ObjectReference ObjRefFromAbi(IntPtr thisPtr) { if (thisPtr == IntPtr.Zero) { return null; } return ObjectReference.FromAbi(thisPtr, PIID); } void global::System.Collections.Generic.IDictionary.Add(K key, V value) { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.Generic.IDictionary).TypeHandle); IDictionaryMethods.Add(objectReferenceForType, key, value); } bool global::System.Collections.Generic.IDictionary.ContainsKey(K key) { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.Generic.IDictionary).TypeHandle); return IDictionaryMethods.ContainsKey(objectReferenceForType, key); } bool global::System.Collections.Generic.IDictionary.Remove(K key) { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.Generic.IDictionary).TypeHandle); return IDictionaryMethods.Remove(objectReferenceForType, key); } bool global::System.Collections.Generic.IDictionary.TryGetValue(K key, out V value) { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.Generic.IDictionary).TypeHandle); return IDictionaryMethods.TryGetValue(objectReferenceForType, null, key, out value); } void global::System.Collections.Generic.ICollection>.Add(global::System.Collections.Generic.KeyValuePair item) { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.Generic.IDictionary).TypeHandle); IDictionaryMethods.Add(objectReferenceForType, item); } bool global::System.Collections.Generic.ICollection>.Contains(global::System.Collections.Generic.KeyValuePair item) { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.Generic.IDictionary).TypeHandle); return IDictionaryMethods.Contains(objectReferenceForType, null, item); } void global::System.Collections.Generic.ICollection>.CopyTo(global::System.Collections.Generic.KeyValuePair[] array, int arrayIndex) { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.Generic.IDictionary).TypeHandle); ((IWinRTObject)this).IsInterfaceImplemented(typeof(global::System.Collections.Generic.IEnumerable>).TypeHandle, throwIfNotImplemented: true); IObjectReference objectReferenceForType2 = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.Generic.IEnumerable>).TypeHandle); IDictionaryMethods.CopyTo(objectReferenceForType, objectReferenceForType2, array, arrayIndex); } bool global::System.Collections.Generic.ICollection>.Remove(global::System.Collections.Generic.KeyValuePair item) { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.Generic.IDictionary).TypeHandle); return IDictionaryMethods.Remove(objectReferenceForType, item); } void global::System.Collections.Generic.ICollection>.Clear() { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.Generic.IDictionary).TypeHandle); IDictionaryMethods.Clear(objectReferenceForType); } global::System.Collections.Generic.IEnumerator> global::System.Collections.Generic.IEnumerable>.GetEnumerator() { ((IWinRTObject)this).IsInterfaceImplemented(typeof(global::System.Collections.Generic.IEnumerable>).TypeHandle, throwIfNotImplemented: true); IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.Generic.IEnumerable>).TypeHandle); return IEnumerableMethods>.GetEnumerator(objectReferenceForType); } IEnumerator global::System.Collections.IEnumerable.GetEnumerator() { return GetEnumerator(); } } public static class IDictionary_Delegates { public delegate int GetView_3(IntPtr thisPtr, out IntPtr __return_value__); internal unsafe delegate int GetView_3_Abi(IntPtr thisPtr, IntPtr* __return_value__); public delegate int Clear_6(IntPtr thisPtr); } public static class IEnumerableMethods { private static IntPtr abiToProjectionVftablePtr; internal static readonly Guid PIID; public static IntPtr AbiToProjectionVftablePtr => abiToProjectionVftablePtr; public static Guid IID => PIID; static IEnumerableMethods() { PIID = GuidGenerator.CreateIIDUnsafe(typeof(IEnumerable)); ComWrappersSupport.RegisterHelperType(typeof(global::System.Collections.Generic.IEnumerable), typeof(IEnumerable)); } public static global::System.Collections.Generic.IEnumerator GetEnumerator(IObjectReference obj) { global::System.Collections.Generic.IEnumerator enumerator = IIterableMethods.First(obj); if (enumerator is FromAbiEnumerator result) { return result; } if (enumerator is IEnumeratorImpl iterator) { return new FromAbiEnumerator(iterator); } if (enumerator is ToAbiEnumeratorAdapter toAbiEnumeratorAdapter) { return toAbiEnumeratorAdapter.m_enumerator; } if (enumerator is IWinRTObject winRTObject) { return new FromAbiEnumerator(winRTObject.NativeObject); } throw new InvalidOperationException("Unexpected type for enumerator"); } internal static bool TryInitCCWVtable(IntPtr ptr) { return Interlocked.CompareExchange(ref abiToProjectionVftablePtr, ptr, IntPtr.Zero) == IntPtr.Zero; } public static global::System.Collections.Generic.IEnumerator Abi_First_0(IntPtr thisPtr) { global::System.Collections.Generic.IEnumerable enumerable = ComWrappersSupport.FindObject>(thisPtr); return new ToAbiEnumeratorAdapter(enumerable.GetEnumerator()); } } public static class IEnumerableMethods where TAbi : unmanaged { private static IEnumerable_Delegates.First_0_Abi DelegateCache; public unsafe static bool InitRcwHelper(delegate*> first) { if (IIterableMethods._RcwHelperInitialized) { return true; } IIterableMethods._First = first; ComWrappersSupport.RegisterTypedRcwFactory(typeof(global::System.Collections.Generic.IEnumerable), IEnumerableImpl.CreateRcw); ComWrappersSupport.RegisterHelperType(typeof(global::System.Collections.Generic.IEnumerable), typeof(IEnumerable)); IIterableMethods._RcwHelperInitialized = true; return true; } public unsafe static bool InitCcw(delegate* unmanaged[Stdcall] first) { if (IEnumerableMethods.AbiToProjectionVftablePtr != (IntPtr)0) { return false; } IntPtr intPtr = (IntPtr)NativeMemory.AllocZeroed((nuint)(sizeof(IInspectable.Vftbl) + sizeof(IntPtr))); *(IInspectable.Vftbl*)(void*)intPtr = IInspectable.Vftbl.AbiToProjectionVftable; *(IntPtr*)((byte*)(void*)intPtr + (nint)6 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)first; if (!IEnumerableMethods.TryInitCCWVtable(intPtr)) { NativeMemory.Free((void*)intPtr); return false; } ComWrappersSupport.RegisterHelperType(typeof(global::System.Collections.Generic.IEnumerator), typeof(IEnumerator)); return true; } internal unsafe static void InitFallbackCCWVtable() { DelegateCache = Do_Abi_First_0; InitCcw((delegate* unmanaged[Stdcall])(void*)Marshal.GetFunctionPointerForDelegate(DelegateCache)); } private unsafe static int Do_Abi_First_0(IntPtr thisPtr, IntPtr* __return_value__) { *__return_value__ = default(IntPtr); try { *__return_value__ = MarshalInterface>.FromManaged(IEnumerableMethods.Abi_First_0(thisPtr)); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } } [DynamicInterfaceCastableImplementation] [Guid("FAA585EA-6214-4217-AFDA-7F46DE5869B3")] internal interface IEnumerable : global::System.Collections.Generic.IEnumerable, global::System.Collections.IEnumerable, global::Windows.Foundation.Collections.IIterable { internal sealed class ToAbiHelper : global::Windows.Foundation.Collections.IIterable { private readonly IEnumerable m_enumerable; internal ToAbiHelper(IEnumerable enumerable) { m_enumerable = enumerable; } public global::System.Collections.Generic.IEnumerator First() { return m_enumerable.GetEnumerator(); } } [Guid("FAA585EA-6214-4217-AFDA-7F46DE5869B3")] public struct Vftbl { internal IInspectable.Vftbl IInspectableVftbl; public static readonly IntPtr AbiToProjectionVftablePtr = IEnumerable.AbiToProjectionVftablePtr; public static readonly Guid PIID = IEnumerable.PIID; } static readonly IntPtr AbiToProjectionVftablePtr; static readonly Guid PIID; static IObjectReference CreateMarshaler(global::System.Collections.Generic.IEnumerable obj) { if (obj != null) { return ComWrappersSupport.CreateCCWForObject(obj, PIID); } return null; } static ObjectReferenceValue CreateMarshaler2(global::System.Collections.Generic.IEnumerable obj) { return ComWrappersSupport.CreateCCWForObjectForMarshaling(obj, PIID); } static IntPtr GetAbi(IObjectReference objRef) { return objRef?.ThisPtr ?? IntPtr.Zero; } static IntPtr FromManaged(global::System.Collections.Generic.IEnumerable value) { if (value != null) { return CreateMarshaler2(value).Detach(); } return IntPtr.Zero; } static void DisposeMarshaler(IObjectReference objRef) { objRef?.Dispose(); } static void DisposeAbi(IntPtr abi) { MarshalInterfaceHelper>.DisposeAbi(abi); } static string GetGuidSignature() { return GuidGenerator.GetSignature(typeof(IEnumerable)); } static IEnumerable() { PIID = IEnumerableMethods.PIID; if (RuntimeFeature.IsDynamicCodeCompiled) { InitFallbackCCWVTableIfNeeded(); } AbiToProjectionVftablePtr = IEnumerableMethods.AbiToProjectionVftablePtr; [MethodImpl(MethodImplOptions.NoInlining)] [UnconditionalSuppressMessage("Trimming", "IL2080", Justification = "All ABI types never have a constructor that would need to be accessed via reflection.")] internal static void InitFallbackCCWVTableIfNeeded() { if (IEnumerableMethods.AbiToProjectionVftablePtr == (IntPtr)0) { Action action = (Action)typeof(IEnumerableMethods<, >).MakeGenericType(typeof(T), Marshaler.AbiType).GetMethod("InitFallbackCCWVtable", BindingFlags.Static | BindingFlags.NonPublic).CreateDelegate(typeof(Action)); action(); } } } static ObjectReference ObjRefFromAbi(IntPtr thisPtr) { if (thisPtr == IntPtr.Zero) { return null; } return ObjectReference.FromAbi(thisPtr, PIID); } global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.Generic.IEnumerable).TypeHandle); return IEnumerableMethods.GetEnumerator(objectReferenceForType); } IEnumerator global::System.Collections.IEnumerable.GetEnumerator() { return GetEnumerator(); } } public static class IEnumerable_Delegates { public delegate int First_0(IntPtr thisPtr, out IntPtr __return_value__); internal unsafe delegate int First_0_Abi(IntPtr thisPtr, IntPtr* __return_value__); } internal static class IIteratorMethods { internal unsafe static volatile delegate* _GetCurrent; internal unsafe static volatile delegate* _GetMany; internal static volatile bool _RcwHelperInitialized; [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static void EnsureInitialized() { if (!RuntimeFeature.IsDynamicCodeCompiled && !_RcwHelperInitialized) { ThrowNotInitialized(); } [DoesNotReturn] static void ThrowNotInitialized() { throw new NotImplementedException($"'{typeof(global::System.Collections.Generic.IEnumerator)}' was called without initializing the RCW methods using 'IEnumeratorMethods.InitRcwHelper'. If using IDynamicInterfaceCastable support to do a dynamic cast to this interface, ensure InitRcwHelper is called."); } } public unsafe static bool MoveNext(IObjectReference obj) { IntPtr thisPtr = obj.ThisPtr; byte b = 0; ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)8 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(thisPtr, &b)); GC.KeepAlive(obj); return b != 0; } public unsafe static uint GetMany(IObjectReference obj, ref T[] items) { if (!RuntimeFeature.IsDynamicCodeCompiled) { EnsureInitialized(); return _GetMany(obj, items); } if (_GetMany != (delegate*)null) { return _GetMany(obj, items); } IntPtr thisPtr = obj.ThisPtr; object obj2 = null; int num = 0; IntPtr intPtr = default(IntPtr); uint result = 0u; try { obj2 = Marshaler.CreateMarshalerArray(items); (num, intPtr) = Marshaler.GetAbiArray(obj2); ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)9 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(thisPtr, num, intPtr, &result)); GC.KeepAlive(obj); items = Marshaler.FromAbiArray((num, intPtr)); return result; } finally { Marshaler.DisposeMarshalerArray(obj2); } } public unsafe static T get_Current(IObjectReference obj) { EnsureInitialized(); return _GetCurrent(obj); } public unsafe static bool get_HasCurrent(IObjectReference obj) { IntPtr thisPtr = obj.ThisPtr; byte b = 0; ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)7 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(thisPtr, &b)); GC.KeepAlive(obj); return b != 0; } } public static class IEnumeratorMethods { private static IntPtr abiToProjectionVftablePtr; internal static readonly Guid PIID; public static IntPtr AbiToProjectionVftablePtr => abiToProjectionVftablePtr; public static Guid IID => PIID; static IEnumeratorMethods() { PIID = GuidGenerator.CreateIIDUnsafe(typeof(IEnumerator)); ComWrappersSupport.RegisterHelperType(typeof(global::System.Collections.Generic.IEnumerator), typeof(IEnumerator)); if (RuntimeFeature.IsDynamicCodeCompiled) { InitRcwHelperFallbackIfNeeded(); } [MethodImpl(MethodImplOptions.NoInlining)] [UnconditionalSuppressMessage("Trimming", "IL2080", Justification = "All ABI types never have a constructor that would need to be accessed via reflection.")] static void InitRcwHelperFallbackIfNeeded() { if (!IIteratorMethods._RcwHelperInitialized) { Func func = (Func)typeof(IEnumeratorMethods<, >).MakeGenericType(typeof(T), Marshaler.AbiType).GetMethod("InitRcwHelperFallback", BindingFlags.Static | BindingFlags.NonPublic).CreateDelegate(typeof(Func)); func(); } } } public static T get_Current(IObjectReference obj) { return IIteratorMethods.get_Current(obj); } public static bool MoveNext(IObjectReference obj) { return IIteratorMethods.MoveNext(obj); } public static void Reset(IObjectReference obj) { throw new NotSupportedException(); } public static void Dispose(IObjectReference obj) { } internal static bool TryInitCCWVtable(IntPtr ptr) { return Interlocked.CompareExchange(ref abiToProjectionVftablePtr, ptr, IntPtr.Zero) == IntPtr.Zero; } public static bool Abi_MoveNext_2(IntPtr thisPtr) { return IEnumerator.FindAdapter(thisPtr)._MoveNext(); } public static uint Abi_GetMany_3(IntPtr thisPtr, ref T[] items) { return IEnumerator.FindAdapter(thisPtr).GetMany(ref items); } public static T Abi_get_Current_0(IntPtr thisPtr) { return IEnumerator.FindAdapter(thisPtr)._Current; } public static bool Abi_get_HasCurrent_1(IntPtr thisPtr) { return IEnumerator.FindAdapter(thisPtr).HasCurrent; } } public static class IEnumeratorMethods where TAbi : unmanaged { private static Delegate[] DelegateCache; public unsafe static bool InitRcwHelper(delegate* getCurrent, delegate* getMany) { if (IIteratorMethods._RcwHelperInitialized) { return true; } IIteratorMethods._GetCurrent = getCurrent; IIteratorMethods._GetMany = getMany; ComWrappersSupport.RegisterTypedRcwFactory(typeof(global::System.Collections.Generic.IEnumerator), IEnumeratorImpl.CreateRcw); ComWrappersSupport.RegisterHelperType(typeof(global::System.Collections.Generic.IEnumerator), typeof(IEnumerator)); IIteratorMethods._RcwHelperInitialized = true; return true; } private unsafe static bool InitRcwHelperFallback() { return InitRcwHelper((delegate*)(&get_Current), (delegate*)null); } private unsafe static T get_Current(IObjectReference obj) { IntPtr thisPtr = obj.ThisPtr; TAbi val = default(TAbi); try { ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)6 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(thisPtr, &val)); GC.KeepAlive(obj); return Marshaler.FromAbi(val); } finally { Marshaler.DisposeAbi(val); } } public unsafe static bool InitCcw(delegate* unmanaged[Stdcall] getCurrent, delegate* unmanaged[Stdcall] hasCurrent, delegate* unmanaged[Stdcall] moveNext, delegate* unmanaged[Stdcall] getMany) { if (IEnumeratorMethods.AbiToProjectionVftablePtr != (IntPtr)0) { return false; } IntPtr intPtr = (IntPtr)NativeMemory.AllocZeroed((nuint)(sizeof(IInspectable.Vftbl) + sizeof(IntPtr) * 4)); *(IInspectable.Vftbl*)(void*)intPtr = IInspectable.Vftbl.AbiToProjectionVftable; *(IntPtr*)((byte*)(void*)intPtr + (nint)6 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)getCurrent; *(IntPtr*)((byte*)(void*)intPtr + (nint)7 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)hasCurrent; *(IntPtr*)((byte*)(void*)intPtr + (nint)8 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)moveNext; *(IntPtr*)((byte*)(void*)intPtr + (nint)9 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)getMany; if (!IEnumeratorMethods.TryInitCCWVtable(intPtr)) { NativeMemory.Free((void*)intPtr); return false; } return true; } internal unsafe static void InitFallbackCCWVtable() { global::System.Type abiDelegateType = Projections.GetAbiDelegateType(typeof(IntPtr), typeof(TAbi*), typeof(int)); DelegateCache = new Delegate[4] { Delegate.CreateDelegate(abiDelegateType, typeof(IEnumeratorMethods).GetMethod("Do_Abi_get_Current_0", BindingFlags.Static | BindingFlags.NonPublic)), new _get_PropertyAsBoolean_Abi(Do_Abi_get_HasCurrent_1), new IEnumerator_Delegates.MoveNext_2_Abi(Do_Abi_MoveNext_2), new IEnumerator_Delegates.GetMany_3_Abi(Do_Abi_GetMany_3) }; InitCcw((delegate* unmanaged[Stdcall])(void*)Marshal.GetFunctionPointerForDelegate(DelegateCache[0]), (delegate* unmanaged[Stdcall])(void*)Marshal.GetFunctionPointerForDelegate(DelegateCache[1]), (delegate* unmanaged[Stdcall])(void*)Marshal.GetFunctionPointerForDelegate(DelegateCache[2]), (delegate* unmanaged[Stdcall])(void*)Marshal.GetFunctionPointerForDelegate(DelegateCache[3])); } private unsafe static int Do_Abi_MoveNext_2(IntPtr thisPtr, byte* __return_value__) { bool flag = false; *__return_value__ = 0; try { flag = IEnumerator.FindAdapter(thisPtr)._MoveNext(); *__return_value__ = (flag ? ((byte)1) : ((byte)0)); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } private unsafe static int Do_Abi_GetMany_3(IntPtr thisPtr, int __itemsSize, IntPtr items, uint* __return_value__) { uint num = 0u; *__return_value__ = 0u; T[] items2 = Marshaler.FromAbiArray((__itemsSize, items)); try { num = IEnumerator.FindAdapter(thisPtr).GetMany(ref items2); Marshaler.CopyManagedArray(items2, items); *__return_value__ = num; } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } private unsafe static int Do_Abi_get_Current_0(IntPtr thisPtr, TAbi* __return_value__) { T val = default(T); *__return_value__ = default(TAbi); try { val = IEnumerator.FindAdapter(thisPtr)._Current; *__return_value__ = (TAbi)Marshaler.FromManaged(val); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } private unsafe static int Do_Abi_get_HasCurrent_1(IntPtr thisPtr, byte* __return_value__) { bool flag = false; *__return_value__ = 0; try { flag = IEnumerator.FindAdapter(thisPtr).HasCurrent; *__return_value__ = (flag ? ((byte)1) : ((byte)0)); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } } internal sealed class FromAbiEnumerator : global::System.Collections.Generic.IEnumerator, IEnumerator, global::System.IDisposable { private readonly IIterator _iterator; private bool m_hadCurrent = true; private T m_current; private bool m_isInitialized; public T Current { get { if (!m_isInitialized) { throw new InvalidOperationException(WinRTRuntimeErrorStrings.InvalidOperation_EnumNotStarted); } if (!m_hadCurrent) { throw new InvalidOperationException(WinRTRuntimeErrorStrings.InvalidOperation_EnumEnded); } return m_current; } } object IEnumerator.Current { get { if (!m_isInitialized) { throw new InvalidOperationException(WinRTRuntimeErrorStrings.InvalidOperation_EnumNotStarted); } if (!m_hadCurrent) { throw new InvalidOperationException(WinRTRuntimeErrorStrings.InvalidOperation_EnumEnded); } return m_current; } } public FromAbiEnumerator(IObjectReference obj) : this((IIterator)new IEnumeratorImpl(obj)) { } internal FromAbiEnumerator(IIterator iterator) { _iterator = iterator; } public static global::System.Collections.Generic.IEnumerator FromAbi(IntPtr abi) { if (abi == IntPtr.Zero) { return null; } return new FromAbiEnumerator(ObjectReference.FromAbi(abi, IID.IID_IUnknown)); } public static void DisposeAbi(IntPtr abi) { MarshalInterfaceHelper>.DisposeAbi(abi); } public bool MoveNext() { if (!m_hadCurrent) { return false; } try { if (!m_isInitialized) { m_hadCurrent = _iterator.HasCurrent; m_isInitialized = true; } else { m_hadCurrent = _iterator._MoveNext(); } if (m_hadCurrent) { m_current = _iterator._Current; } } catch (global::System.Exception e) { if (Marshal.GetHRForException(e) == -2147483636) { throw new InvalidOperationException(WinRTRuntimeErrorStrings.InvalidOperation_EnumFailedVersion); } throw; } return m_hadCurrent; } public void Reset() { throw new NotSupportedException(); } public void Dispose() { } } internal sealed class IBindableIteratorTypeDetails : IWinRTExposedTypeDetails { public ComWrappers.ComInterfaceEntry[] GetExposedInterfaces() { return new ComWrappers.ComInterfaceEntry[2] { new ComWrappers.ComInterfaceEntry { IID = typeof(ABI.Microsoft.UI.Xaml.Interop.IBindableIterator).GUID, Vtable = ABI.Microsoft.UI.Xaml.Interop.IBindableIterator.AbiToProjectionVftablePtr }, new ComWrappers.ComInterfaceEntry { IID = IEnumeratorMethods.IID, Vtable = ABI.Microsoft.UI.Xaml.Interop.IBindableIterator.AbiToProjectionVftablePtr } }; } } public sealed class ToAbiEnumeratorAdapter : global::System.Collections.Generic.IEnumerator, IEnumerator, global::System.IDisposable { internal readonly global::System.Collections.Generic.IEnumerator m_enumerator; public T Current => m_enumerator.Current; object IEnumerator.Current => m_enumerator.Current; internal ToAbiEnumeratorAdapter(global::System.Collections.Generic.IEnumerator enumerator) { m_enumerator = enumerator; } public void Dispose() { m_enumerator.Dispose(); } public bool MoveNext() { return m_enumerator.MoveNext(); } public void Reset() { m_enumerator.Reset(); } } [DynamicInterfaceCastableImplementation] [Guid("6A79E863-4300-459A-9966-CBB660963EE1")] internal interface IEnumerator : global::System.Collections.Generic.IEnumerator, IEnumerator, global::System.IDisposable, IIterator { [WinRTExposedType(typeof(IBindableIteratorTypeDetails))] public sealed class ToAbiHelper : IIterator, global::Microsoft.UI.Xaml.Interop.IBindableIterator { private readonly global::System.Collections.Generic.IEnumerator m_enumerator; private bool m_firstItem = true; private bool m_hasCurrent; public T _Current { get { if (m_firstItem) { m_firstItem = false; _MoveNext(); } if (!m_hasCurrent) { ExceptionHelpers.ThrowExceptionForHR(-2147483637); } return m_enumerator.Current; } } public bool HasCurrent { get { if (m_firstItem) { m_firstItem = false; _MoveNext(); } return m_hasCurrent; } } public object Current => _Current; internal ToAbiHelper(global::System.Collections.Generic.IEnumerator enumerator) { m_enumerator = enumerator; } public bool _MoveNext() { try { m_hasCurrent = m_enumerator.MoveNext(); } catch (InvalidOperationException) { ExceptionHelpers.ThrowExceptionForHR(-2147483636); } return m_hasCurrent; } public uint GetMany(ref T[] items) { if (items == null) { return 0u; } int i; for (i = 0; i < items.Length; i++) { if (!HasCurrent) { break; } items[i] = _Current; _MoveNext(); } if (typeof(T) == typeof(string)) { string[] array = items as string[]; for (int j = i; j < items.Length; j++) { array[j] = string.Empty; } } return (uint)i; } public bool MoveNext() { return _MoveNext(); } uint global::Microsoft.UI.Xaml.Interop.IBindableIterator.GetMany(ref object[] items) { throw new NotImplementedException(); } } [Guid("6A79E863-4300-459A-9966-CBB660963EE1")] public struct Vftbl { internal IInspectable.Vftbl IInspectableVftbl; public static readonly IntPtr AbiToProjectionVftablePtr = IEnumerator.AbiToProjectionVftablePtr; public static readonly Guid PIID = IEnumerator.PIID; } static readonly IntPtr AbiToProjectionVftablePtr; private static readonly ConditionalWeakTable, ToAbiHelper> _adapterTable; static readonly Guid PIID; T global::System.Collections.Generic.IEnumerator.Current { get { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.Generic.IEnumerator).TypeHandle); return IEnumeratorMethods.get_Current(objectReferenceForType); } } object IEnumerator.Current => Current; static IObjectReference CreateMarshaler(global::System.Collections.Generic.IEnumerator obj) { if (obj != null) { return ComWrappersSupport.CreateCCWForObject(obj, PIID); } return null; } static ObjectReferenceValue CreateMarshaler2(global::System.Collections.Generic.IEnumerator obj) { return ComWrappersSupport.CreateCCWForObjectForMarshaling(obj, PIID); } static IntPtr GetAbi(IObjectReference objRef) { return objRef?.ThisPtr ?? IntPtr.Zero; } static IntPtr FromManaged(global::System.Collections.Generic.IEnumerator value) { if (value != null) { return CreateMarshaler2(value).Detach(); } return IntPtr.Zero; } static void DisposeMarshaler(IObjectReference objRef) { objRef?.Dispose(); } static void DisposeAbi(IntPtr abi) { MarshalInterfaceHelper>.DisposeAbi(abi); } static string GetGuidSignature() { return GuidGenerator.GetSignature(typeof(IEnumerator)); } static IEnumerator() { _adapterTable = new ConditionalWeakTable, ToAbiHelper>(); PIID = IEnumeratorMethods.PIID; if (RuntimeFeature.IsDynamicCodeCompiled) { InitFallbackCCWVTableIfNeeded(); } AbiToProjectionVftablePtr = IEnumeratorMethods.AbiToProjectionVftablePtr; [MethodImpl(MethodImplOptions.NoInlining)] [UnconditionalSuppressMessage("Trimming", "IL2080", Justification = "All ABI types never have a constructor that would need to be accessed via reflection.")] internal static void InitFallbackCCWVTableIfNeeded() { if (IEnumeratorMethods.AbiToProjectionVftablePtr == (IntPtr)0) { Action action = (Action)typeof(IEnumeratorMethods<, >).MakeGenericType(typeof(T), Marshaler.AbiType).GetMethod("InitFallbackCCWVtable", BindingFlags.Static | BindingFlags.NonPublic).CreateDelegate(typeof(Action)); action(); } } } internal static ToAbiHelper FindAdapter(IntPtr thisPtr) { global::System.Collections.Generic.IEnumerator key = ComWrappersSupport.FindObject>(thisPtr); return _adapterTable.GetValue(key, (global::System.Collections.Generic.IEnumerator enumerator) => new ToAbiHelper(enumerator)); } static ObjectReference ObjRefFromAbi(IntPtr thisPtr) { if (thisPtr == IntPtr.Zero) { return null; } return ObjectReference.FromAbi(thisPtr, PIID); } bool IEnumerator.MoveNext() { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.Generic.IEnumerator).TypeHandle); return IEnumeratorMethods.MoveNext(objectReferenceForType); } void IEnumerator.Reset() { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.Generic.IEnumerator).TypeHandle); IEnumeratorMethods.Reset(objectReferenceForType); } void global::System.IDisposable.Dispose() { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.Generic.IEnumerator).TypeHandle); IEnumeratorMethods.Dispose(objectReferenceForType); } } public static class IEnumerator_Delegates { public delegate int MoveNext_2(IntPtr thisPtr, out byte __return_value__); public delegate int GetMany_3(IntPtr thisPtr, int __itemsSize, IntPtr items, out uint __return_value__); internal unsafe delegate int MoveNext_2_Abi(IntPtr thisPtr, byte* __return_value__); internal unsafe delegate int GetMany_3_Abi(IntPtr thisPtr, int __itemsSize, IntPtr items, uint* __return_value__); } public static class IListMethods { private static IntPtr abiToProjectionVftablePtr; internal static readonly Guid PIID; public static IntPtr AbiToProjectionVftablePtr => abiToProjectionVftablePtr; public static Guid IID => PIID; static IListMethods() { PIID = GuidGenerator.CreateIIDUnsafe(typeof(IList)); ComWrappersSupport.RegisterHelperType(typeof(global::System.Collections.Generic.IList), typeof(IList)); if (RuntimeFeature.IsDynamicCodeCompiled) { InitRcwHelperFallbackIfNeeded(); } [MethodImpl(MethodImplOptions.NoInlining)] [UnconditionalSuppressMessage("Trimming", "IL2080", Justification = "All ABI types never have a constructor that would need to be accessed via reflection.")] static void InitRcwHelperFallbackIfNeeded() { if (!IVectorMethods._RcwHelperInitialized) { Func func = (Func)typeof(IListMethods<, >).MakeGenericType(typeof(T), Marshaler.AbiType).GetMethod("InitRcwHelperFallback", BindingFlags.Static | BindingFlags.NonPublic).CreateDelegate(typeof(Func)); func(); } } } public static int get_Count(IObjectReference obj) { uint num = IVectorMethods.get_Size(obj); if (int.MaxValue < num) { throw new InvalidOperationException(WinRTRuntimeErrorStrings.InvalidOperation_CollectionBackingListTooLarge); } return (int)num; } public static bool get_IsReadOnly(IObjectReference obj) { return false; } public static void Add(IObjectReference obj, T item) { IVectorMethods.Append(obj, item); } public static void Clear(IObjectReference obj) { IVectorMethods.Clear(obj); } public static bool Contains(IObjectReference obj, T item) { uint index; return IVectorMethods.IndexOf(obj, item, out index); } public static void CopyTo(IObjectReference obj, T[] array, int arrayIndex) { if (array == null) { throw new ArgumentNullException("array"); } if (arrayIndex < 0) { throw new ArgumentOutOfRangeException("arrayIndex"); } if (array.Length <= arrayIndex && get_Count(obj) > 0) { throw new ArgumentException(WinRTRuntimeErrorStrings.Argument_IndexOutOfArrayBounds); } if (array.Length - arrayIndex < get_Count(obj)) { throw new ArgumentException(WinRTRuntimeErrorStrings.Argument_InsufficientSpaceToCopyCollection); } int num = get_Count(obj); for (int i = 0; i < num; i++) { array[i + arrayIndex] = GetAtHelper(obj, (uint)i); } } public static bool Remove(IObjectReference obj, T item) { if (!IVectorMethods.IndexOf(obj, item, out var index)) { return false; } if (int.MaxValue < index) { throw new InvalidOperationException(WinRTRuntimeErrorStrings.InvalidOperation_CollectionBackingListTooLarge); } RemoveAtHelper(obj, index); return true; } public static T Indexer_Get(IObjectReference obj, int index) { if (index < 0) { throw new ArgumentOutOfRangeException("index"); } return GetAtHelper(obj, (uint)index); } public static void Indexer_Set(IObjectReference obj, int index, T value) { if (index < 0) { throw new ArgumentOutOfRangeException("index"); } SetAtHelper(obj, (uint)index, value); } public static int IndexOf(IObjectReference obj, T item) { if (!IVectorMethods.IndexOf(obj, item, out var index)) { return -1; } if (int.MaxValue < index) { throw new InvalidOperationException(WinRTRuntimeErrorStrings.InvalidOperation_CollectionBackingListTooLarge); } return (int)index; } public static void Insert(IObjectReference obj, int index, T item) { if (index < 0) { throw new ArgumentOutOfRangeException("index"); } InsertAtHelper(obj, (uint)index, item); } public static void RemoveAt(IObjectReference obj, int index) { if (index < 0) { throw new ArgumentOutOfRangeException("index"); } RemoveAtHelper(obj, (uint)index); } internal static T GetAtHelper(IObjectReference obj, uint index) { try { return IVectorMethods.GetAt(obj, index); } catch (global::System.Exception ex) { if (-2147483637 == ex.HResult) { throw new ArgumentOutOfRangeException("index"); } throw; } } private static void SetAtHelper(IObjectReference obj, uint index, T value) { try { IVectorMethods.SetAt(obj, index, value); } catch (global::System.Exception ex) { if (-2147483637 == ex.HResult) { throw new ArgumentOutOfRangeException("index"); } throw; } } private static void InsertAtHelper(IObjectReference obj, uint index, T item) { try { IVectorMethods.InsertAt(obj, index, item); } catch (global::System.Exception ex) { if (-2147483637 == ex.HResult) { throw new ArgumentOutOfRangeException("index"); } throw; } } internal static void RemoveAtHelper(IObjectReference obj, uint index) { try { IVectorMethods.RemoveAt(obj, index); } catch (global::System.Exception ex) { if (-2147483637 == ex.HResult) { throw new ArgumentOutOfRangeException("index"); } throw; } } internal static bool TryInitCCWVtable(IntPtr ptr) { return Interlocked.CompareExchange(ref abiToProjectionVftablePtr, ptr, IntPtr.Zero) == IntPtr.Zero; } public static T Abi_GetAt_0(IntPtr thisPtr, uint index) { return IList.FindAdapter(thisPtr).GetAt(index); } public static global::System.Collections.Generic.IReadOnlyList Abi_GetView_2(IntPtr thisPtr) { return IList.FindAdapter(thisPtr).GetView(); } public static bool Abi_IndexOf_3(IntPtr thisPtr, T value, out uint index) { return IList.FindAdapter(thisPtr).IndexOf(value, out index); } public static void Abi_SetAt_4(IntPtr thisPtr, uint index, T value) { IList.FindAdapter(thisPtr).SetAt(index, value); } public static void Abi_InsertAt_5(IntPtr thisPtr, uint index, T value) { IList.FindAdapter(thisPtr).InsertAt(index, value); } public static void Abi_RemoveAt_6(IntPtr thisPtr, uint index) { IList.FindAdapter(thisPtr).RemoveAt(index); } public static void Abi_Append_7(IntPtr thisPtr, T value) { IList.FindAdapter(thisPtr).Append(value); } public static void Abi_RemoveAtEnd_8(IntPtr thisPtr) { IList.FindAdapter(thisPtr).RemoveAtEnd(); } public static void Abi_Clear_9(IntPtr thisPtr) { IList.FindAdapter(thisPtr)._Clear(); } public static uint Abi_GetMany_10(IntPtr thisPtr, uint startIndex, ref T[] items) { return IList.FindAdapter(thisPtr).GetMany(startIndex, ref items); } public static void Abi_ReplaceAll_11(IntPtr thisPtr, T[] items) { IList.FindAdapter(thisPtr).ReplaceAll(items); } public static uint Abi_get_Size_1(IntPtr thisPtr) { return IList.FindAdapter(thisPtr).Size; } internal unsafe static bool EnsureEnumerableInitialized() { return IVectorMethods._EnsureEnumerableInitialized(); } } public static class IListMethods where TAbi : unmanaged { private sealed class DelegateHelper { private readonly IntPtr _ptr; private Delegate _indexOfDelegate; private Delegate _setAtDelegate; private Delegate _insertAtDelegate; private Delegate _appendDelegate; public Delegate IndexOf => _indexOfDelegate ?? GenericDelegateHelper.CreateDelegate(_ptr, ref _indexOfDelegate, IListMethods.IndexOf_3_Type, 9); public Delegate SetAt => _setAtDelegate ?? GenericDelegateHelper.CreateDelegate(_ptr, ref _setAtDelegate, IListMethods.SetAtInsertAt_Type, 10); public Delegate InsertAt => _insertAtDelegate ?? GenericDelegateHelper.CreateDelegate(_ptr, ref _insertAtDelegate, IListMethods.SetAtInsertAt_Type, 11); public Delegate Append => _appendDelegate ?? GenericDelegateHelper.CreateDelegate(_ptr, ref _appendDelegate, IListMethods.Append_7_Type, 13); private DelegateHelper(IntPtr ptr) { _ptr = ptr; } public static DelegateHelper Get(IObjectReference obj) { return (DelegateHelper)GenericDelegateHelper.DelegateTable.GetValue(obj, (IObjectReference objRef) => new DelegateHelper(objRef.ThisPtr)); } } private static Delegate[] DelegateCache; private static global::System.Type _indexOf_3_type; private static global::System.Type _setAtInsertAt_Type; private static global::System.Type _append_7_Type; private static global::System.Type IndexOf_3_Type => _indexOf_3_type ?? MakeIndexOfType(); private static global::System.Type SetAtInsertAt_Type => _setAtInsertAt_Type ?? MakeSetAtInsertAtType(); private static global::System.Type Append_7_Type => _append_7_Type ?? MakeAppendType(); public unsafe static bool InitRcwHelper(delegate* getAt, delegate*> getView, delegate* indexOf, delegate* setAt, delegate* insertAt, delegate* append, delegate* getMany, delegate* replaceAll) { if (IVectorMethods._RcwHelperInitialized) { return true; } IVectorMethods._GetAt = getAt; IVectorMethods._GetView = getView; IVectorMethods._IndexOf = indexOf; IVectorMethods._SetAt = setAt; IVectorMethods._InsertAt = insertAt; IVectorMethods._Append = append; IVectorMethods._GetMany = getMany; IVectorMethods._ReplaceAll = replaceAll; ComWrappersSupport.RegisterTypedRcwFactory(typeof(global::System.Collections.Generic.IList), IListImpl.CreateRcw); ComWrappersSupport.RegisterHelperType(typeof(global::System.Collections.Generic.IList), typeof(IList)); IVectorMethods._RcwHelperInitialized = true; return true; } private unsafe static bool InitRcwHelperFallback() { return InitRcwHelper((delegate*)(&GetAtDynamic), (delegate*>)null, (delegate*)(&IndexOfDynamic), (delegate*)(&SetAtDynamic), (delegate*)(&InsertAtDynamic), (delegate*)(&AppendDynamic), (delegate*)null, (delegate*)null); } private unsafe static T GetAtDynamic(IObjectReference obj, uint index) { IntPtr thisPtr = obj.ThisPtr; TAbi val = default(TAbi); try { ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)6 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(thisPtr, index, &val)); GC.KeepAlive(obj); return Marshaler.FromAbi(val); } finally { Marshaler.DisposeAbi(val); } } private unsafe static bool IndexOfDynamic(IObjectReference obj, T value, out uint index) { IntPtr thisPtr = obj.ThisPtr; object obj2 = null; uint num = default(uint); byte b = default(byte); object[] array = new object[4] { thisPtr, null, (IntPtr)(&num), (IntPtr)(&b) }; try { obj2 = Marshaler.CreateMarshaler2(value); array[1] = Marshaler.GetAbi(obj2); DelegateHelper.Get(obj).IndexOf.DynamicInvokeAbi(array); GC.KeepAlive(obj); GC.KeepAlive(array); index = num; return b != 0; } finally { Marshaler.DisposeMarshaler(obj2); } } private static void SetAtDynamic(IObjectReference obj, uint index, T value) { IntPtr thisPtr = obj.ThisPtr; object obj2 = null; object[] array = new object[3] { thisPtr, index, null }; try { obj2 = Marshaler.CreateMarshaler2(value); array[2] = Marshaler.GetAbi(obj2); DelegateHelper.Get(obj).SetAt.DynamicInvokeAbi(array); GC.KeepAlive(obj); GC.KeepAlive(array); } finally { Marshaler.DisposeMarshaler(obj2); } } private static void InsertAtDynamic(IObjectReference obj, uint index, T value) { IntPtr thisPtr = obj.ThisPtr; object obj2 = null; object[] array = new object[3] { thisPtr, index, null }; try { obj2 = Marshaler.CreateMarshaler2(value); array[2] = Marshaler.GetAbi(obj2); DelegateHelper.Get(obj).InsertAt.DynamicInvokeAbi(array); GC.KeepAlive(obj); GC.KeepAlive(array); } finally { Marshaler.DisposeMarshaler(obj2); } } private static void AppendDynamic(IObjectReference obj, T value) { IntPtr thisPtr = obj.ThisPtr; object obj2 = null; object[] array = new object[2] { thisPtr, null }; try { obj2 = Marshaler.CreateMarshaler2(value); array[1] = Marshaler.GetAbi(obj2); DelegateHelper.Get(obj).Append.DynamicInvokeAbi(array); GC.KeepAlive(obj); GC.KeepAlive(array); } finally { Marshaler.DisposeMarshaler(obj2); } } public unsafe static bool InitCcw(delegate* unmanaged[Stdcall] getAt, delegate* unmanaged[Stdcall] getSize, delegate* unmanaged[Stdcall] getView, delegate* unmanaged[Stdcall] indexOf, delegate* unmanaged[Stdcall] setAt, delegate* unmanaged[Stdcall] insertAt, delegate* unmanaged[Stdcall] removeAt, delegate* unmanaged[Stdcall] append, delegate* unmanaged[Stdcall] removeAtEnd, delegate* unmanaged[Stdcall] clear, delegate* unmanaged[Stdcall] getMany, delegate* unmanaged[Stdcall] replaceAll) { if (IListMethods.AbiToProjectionVftablePtr != (IntPtr)0) { return false; } IntPtr intPtr = (IntPtr)NativeMemory.AllocZeroed((nuint)(sizeof(IInspectable.Vftbl) + sizeof(IntPtr) * 12)); *(IInspectable.Vftbl*)(void*)intPtr = IInspectable.Vftbl.AbiToProjectionVftable; *(IntPtr*)((byte*)(void*)intPtr + (nint)6 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)getAt; *(IntPtr*)((byte*)(void*)intPtr + (nint)7 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)getSize; *(IntPtr*)((byte*)(void*)intPtr + (nint)8 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)getView; *(IntPtr*)((byte*)(void*)intPtr + (nint)9 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)indexOf; *(IntPtr*)((byte*)(void*)intPtr + (nint)10 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)setAt; *(IntPtr*)((byte*)(void*)intPtr + (nint)11 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)insertAt; *(IntPtr*)((byte*)(void*)intPtr + (nint)12 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)removeAt; *(IntPtr*)((byte*)(void*)intPtr + (nint)13 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)append; *(IntPtr*)((byte*)(void*)intPtr + (nint)14 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)removeAtEnd; *(IntPtr*)((byte*)(void*)intPtr + (nint)15 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)clear; *(IntPtr*)((byte*)(void*)intPtr + (nint)16 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)getMany; *(IntPtr*)((byte*)(void*)intPtr + (nint)17 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)replaceAll; if (!IListMethods.TryInitCCWVtable(intPtr)) { NativeMemory.Free((void*)intPtr); return false; } ComWrappersSupport.RegisterHelperType(typeof(global::System.Collections.Generic.IReadOnlyList), typeof(IReadOnlyList)); return true; } internal unsafe static void InitFallbackCCWVtable() { global::System.Type abiDelegateType = Projections.GetAbiDelegateType(typeof(void*), typeof(uint), typeof(TAbi*), typeof(int)); DelegateCache = new Delegate[12] { Delegate.CreateDelegate(abiDelegateType, typeof(IListMethods).GetMethod("Do_Abi_GetAt_0", BindingFlags.Static | BindingFlags.NonPublic)), new _get_PropertyAsUInt32_Abi(Do_Abi_get_Size_1), new IList_Delegates.GetView_2_Abi(Do_Abi_GetView_2), Delegate.CreateDelegate(IndexOf_3_Type, typeof(IListMethods).GetMethod("Do_Abi_IndexOf_3", BindingFlags.Static | BindingFlags.NonPublic)), Delegate.CreateDelegate(SetAtInsertAt_Type, typeof(IListMethods).GetMethod("Do_Abi_SetAt_4", BindingFlags.Static | BindingFlags.NonPublic)), Delegate.CreateDelegate(SetAtInsertAt_Type, typeof(IListMethods).GetMethod("Do_Abi_InsertAt_5", BindingFlags.Static | BindingFlags.NonPublic)), new IList_Delegates.RemoveAt_6(Do_Abi_RemoveAt_6), Delegate.CreateDelegate(Append_7_Type, typeof(IListMethods).GetMethod("Do_Abi_Append_7", BindingFlags.Static | BindingFlags.NonPublic)), new IList_Delegates.RemoveAtEnd_8(Do_Abi_RemoveAtEnd_8), new IList_Delegates.Clear_9(Do_Abi_Clear_9), new IList_Delegates.GetMany_10_Abi(Do_Abi_GetMany_10), new IList_Delegates.ReplaceAll_11(Do_Abi_ReplaceAll_11) }; InitCcw((delegate* unmanaged[Stdcall])(void*)Marshal.GetFunctionPointerForDelegate(DelegateCache[0]), (delegate* unmanaged[Stdcall])(void*)Marshal.GetFunctionPointerForDelegate(DelegateCache[1]), (delegate* unmanaged[Stdcall])(void*)Marshal.GetFunctionPointerForDelegate(DelegateCache[2]), (delegate* unmanaged[Stdcall])(void*)Marshal.GetFunctionPointerForDelegate(DelegateCache[3]), (delegate* unmanaged[Stdcall])(void*)Marshal.GetFunctionPointerForDelegate(DelegateCache[4]), (delegate* unmanaged[Stdcall])(void*)Marshal.GetFunctionPointerForDelegate(DelegateCache[5]), (delegate* unmanaged[Stdcall])(void*)Marshal.GetFunctionPointerForDelegate(DelegateCache[6]), (delegate* unmanaged[Stdcall])(void*)Marshal.GetFunctionPointerForDelegate(DelegateCache[7]), (delegate* unmanaged[Stdcall])(void*)Marshal.GetFunctionPointerForDelegate(DelegateCache[8]), (delegate* unmanaged[Stdcall])(void*)Marshal.GetFunctionPointerForDelegate(DelegateCache[9]), (delegate* unmanaged[Stdcall])(void*)Marshal.GetFunctionPointerForDelegate(DelegateCache[10]), (delegate* unmanaged[Stdcall])(void*)Marshal.GetFunctionPointerForDelegate(DelegateCache[11])); } private unsafe static int Do_Abi_GetAt_0(void* thisPtr, uint index, TAbi* __return_value__) { T val = default(T); *__return_value__ = default(TAbi); try { val = IList.FindAdapter(new IntPtr(thisPtr)).GetAt(index); *__return_value__ = (TAbi)Marshaler.FromManaged(val); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } private unsafe static int Do_Abi_GetView_2(IntPtr thisPtr, IntPtr* __return_value__) { global::System.Collections.Generic.IReadOnlyList readOnlyList = null; *__return_value__ = default(IntPtr); try { readOnlyList = IList.FindAdapter(thisPtr).GetView(); *__return_value__ = MarshalInterface>.FromManaged(readOnlyList); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } private unsafe static int Do_Abi_IndexOf_3(void* thisPtr, TAbi value, uint* index, byte* __return_value__) { bool flag = false; *index = 0u; *__return_value__ = 0; uint index2 = 0u; try { flag = IList.FindAdapter(new IntPtr(thisPtr)).IndexOf(Marshaler.FromAbi(value), out index2); *index = index2; *__return_value__ = (flag ? ((byte)1) : ((byte)0)); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } private unsafe static int Do_Abi_SetAt_4(void* thisPtr, uint index, TAbi value) { try { IList.FindAdapter(new IntPtr(thisPtr)).SetAt(index, Marshaler.FromAbi(value)); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } private unsafe static int Do_Abi_InsertAt_5(void* thisPtr, uint index, TAbi value) { try { IList.FindAdapter(new IntPtr(thisPtr)).InsertAt(index, Marshaler.FromAbi(value)); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } private static int Do_Abi_RemoveAt_6(IntPtr thisPtr, uint index) { try { IList.FindAdapter(thisPtr).RemoveAt(index); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } private unsafe static int Do_Abi_Append_7(void* thisPtr, TAbi value) { try { IList.FindAdapter(new IntPtr(thisPtr)).Append(Marshaler.FromAbi(value)); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } private static int Do_Abi_RemoveAtEnd_8(IntPtr thisPtr) { try { IList.FindAdapter(thisPtr).RemoveAtEnd(); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } private static int Do_Abi_Clear_9(IntPtr thisPtr) { try { IList.FindAdapter(thisPtr)._Clear(); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } private unsafe static int Do_Abi_GetMany_10(IntPtr thisPtr, uint startIndex, int __itemsSize, IntPtr items, uint* __return_value__) { uint num = 0u; *__return_value__ = 0u; T[] items2 = Marshaler.FromAbiArray((__itemsSize, items)); try { num = IList.FindAdapter(thisPtr).GetMany(startIndex, ref items2); Marshaler.CopyManagedArray(items2, items); *__return_value__ = num; } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } private static int Do_Abi_ReplaceAll_11(IntPtr thisPtr, int __itemsSize, IntPtr items) { try { IList.FindAdapter(thisPtr).ReplaceAll(Marshaler.FromAbiArray((__itemsSize, items))); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } private unsafe static int Do_Abi_get_Size_1(IntPtr thisPtr, uint* __return_value__) { uint num = 0u; *__return_value__ = 0u; try { num = IList.FindAdapter(thisPtr).Size; *__return_value__ = num; } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } private unsafe static global::System.Type MakeIndexOfType() { Interlocked.CompareExchange(ref _indexOf_3_type, Projections.GetAbiDelegateType(typeof(void*), typeof(TAbi), typeof(uint*), typeof(byte*), typeof(int)), null); return _indexOf_3_type; } private unsafe static global::System.Type MakeSetAtInsertAtType() { Interlocked.CompareExchange(ref _setAtInsertAt_Type, Projections.GetAbiDelegateType(typeof(void*), typeof(uint), typeof(TAbi), typeof(int)), null); return _setAtInsertAt_Type; } private unsafe static global::System.Type MakeAppendType() { Interlocked.CompareExchange(ref _append_7_Type, Projections.GetAbiDelegateType(typeof(void*), typeof(TAbi), typeof(int)), null); return _append_7_Type; } } internal static class IVectorMethods { internal unsafe static volatile delegate* _GetAt; internal unsafe static volatile delegate*> _GetView; internal unsafe static volatile delegate* _IndexOf; internal unsafe static volatile delegate* _SetAt; internal unsafe static volatile delegate* _InsertAt; internal unsafe static volatile delegate* _Append; internal unsafe static volatile delegate* _GetMany; internal unsafe static volatile delegate* _ReplaceAll; internal static volatile bool _RcwHelperInitialized; internal unsafe static volatile delegate* _EnsureEnumerableInitialized; [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static void EnsureInitialized() { if (!RuntimeFeature.IsDynamicCodeCompiled && !_RcwHelperInitialized) { ThrowNotInitialized(); } [DoesNotReturn] static void ThrowNotInitialized() { throw new NotImplementedException($"Type '{typeof(global::System.Collections.Generic.IList)}' was called without initializing the RCW methods using 'IListMethods.InitRcwHelper'. If using 'IDynamicInterfaceCastable' support to do a dynamic cast to this interface, ensure the 'InitRcwHelper' method is called."); } } public unsafe static uint get_Size(IObjectReference obj) { IntPtr thisPtr = obj.ThisPtr; uint result = 0u; ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)7 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(thisPtr, &result)); GC.KeepAlive(obj); return result; } public unsafe static T GetAt(IObjectReference obj, uint index) { EnsureInitialized(); return _GetAt(obj, index); } public unsafe static global::System.Collections.Generic.IReadOnlyList GetView(IObjectReference obj) { if (!RuntimeFeature.IsDynamicCodeCompiled) { EnsureInitialized(); return _GetView(obj); } if (_GetView != (delegate*>)null) { return _GetView(obj); } IntPtr thisPtr = obj.ThisPtr; IntPtr intPtr = default(IntPtr); try { ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)8 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(thisPtr, &intPtr)); GC.KeepAlive(obj); return MarshalInterface>.FromAbi(intPtr); } finally { MarshalInterface>.DisposeAbi(intPtr); } } public unsafe static bool IndexOf(IObjectReference obj, T value, out uint index) { EnsureInitialized(); return _IndexOf(obj, value, out index); } public unsafe static void SetAt(IObjectReference obj, uint index, T value) { EnsureInitialized(); _SetAt(obj, index, value); } public unsafe static void InsertAt(IObjectReference obj, uint index, T value) { EnsureInitialized(); _InsertAt(obj, index, value); } public unsafe static void RemoveAt(IObjectReference obj, uint index) { IntPtr thisPtr = obj.ThisPtr; ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)12 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(thisPtr, index)); GC.KeepAlive(obj); } public unsafe static void Append(IObjectReference obj, T value) { EnsureInitialized(); _Append(obj, value); } public unsafe static void RemoveAtEnd(IObjectReference obj) { IntPtr thisPtr = obj.ThisPtr; ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)14 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(thisPtr)); GC.KeepAlive(obj); } public unsafe static void Clear(IObjectReference obj) { IntPtr thisPtr = obj.ThisPtr; ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)15 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(thisPtr)); GC.KeepAlive(obj); } public unsafe static uint GetMany(IObjectReference obj, uint startIndex, ref T[] items) { if (!RuntimeFeature.IsDynamicCodeCompiled) { EnsureInitialized(); return _GetMany(obj, startIndex, items); } if (_GetMany != (delegate*)null) { return _GetMany(obj, startIndex, items); } IntPtr thisPtr = obj.ThisPtr; object obj2 = null; int num = 0; IntPtr intPtr = default(IntPtr); uint result = 0u; try { obj2 = Marshaler.CreateMarshalerArray(items); (num, intPtr) = Marshaler.GetAbiArray(obj2); ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)16 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(thisPtr, startIndex, num, intPtr, &result)); GC.KeepAlive(obj); items = Marshaler.FromAbiArray((num, intPtr)); return result; } finally { Marshaler.DisposeMarshalerArray(obj2); } } public unsafe static void ReplaceAll(IObjectReference obj, T[] items) { if (!RuntimeFeature.IsDynamicCodeCompiled) { EnsureInitialized(); _ReplaceAll(obj, items); return; } if (_ReplaceAll != (delegate*)null) { _ReplaceAll(obj, items); return; } IntPtr thisPtr = obj.ThisPtr; object obj2 = null; int num = 0; IntPtr intPtr = default(IntPtr); try { obj2 = Marshaler.CreateMarshalerArray(items); (num, intPtr) = Marshaler.GetAbiArray(obj2); ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)17 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(thisPtr, num, intPtr)); GC.KeepAlive(obj); } finally { Marshaler.DisposeMarshalerArray(obj2); } } } [DynamicInterfaceCastableImplementation] [Guid("913337E9-11A1-4345-A3A2-4E7F956E222D")] internal interface IList : global::System.Collections.Generic.IList, global::System.Collections.Generic.ICollection, global::System.Collections.Generic.IEnumerable, global::System.Collections.IEnumerable, IVector, global::Windows.Foundation.Collections.IIterable { public sealed class ToAbiHelper : IVector, global::Windows.Foundation.Collections.IIterable { private readonly global::System.Collections.Generic.IList _list; public uint Size => (uint)_list.Count; public ToAbiHelper(global::System.Collections.Generic.IList list) { _list = list; } global::System.Collections.Generic.IEnumerator global::Windows.Foundation.Collections.IIterable.First() { return _list.GetEnumerator(); } private static void EnsureIndexInt32(uint index, int limit = int.MaxValue) { if (int.MaxValue <= index || index >= (uint)limit) { global::System.Exception ex = new ArgumentOutOfRangeException("index", WinRTRuntimeErrorStrings.ArgumentOutOfRange_IndexLargerThanMaxValue); ex.SetHResult(-2147483637); throw ex; } } public T GetAt(uint index) { EnsureIndexInt32(index, _list.Count); try { return _list[(int)index]; } catch (ArgumentOutOfRangeException innerException) { throw innerException.GetExceptionForHR(-2147483637, WinRTRuntimeErrorStrings.ArgumentOutOfRange_Index); } } global::System.Collections.Generic.IReadOnlyList IVector.GetView() { global::System.Collections.Generic.IReadOnlyList readOnlyList = _list as global::System.Collections.Generic.IReadOnlyList; if (readOnlyList == null) { readOnlyList = new ReadOnlyCollection(_list); } return readOnlyList; } public bool IndexOf(T value, out uint index) { int num = _list.IndexOf(value); if (-1 == num) { index = 0u; return false; } index = (uint)num; return true; } public void SetAt(uint index, T value) { EnsureIndexInt32(index, _list.Count); try { _list[(int)index] = value; } catch (ArgumentOutOfRangeException innerException) { throw innerException.GetExceptionForHR(-2147483637, WinRTRuntimeErrorStrings.ArgumentOutOfRange_Index); } } public void InsertAt(uint index, T value) { EnsureIndexInt32(index, _list.Count + 1); try { _list.Insert((int)index, value); } catch (ArgumentOutOfRangeException ex) { ex.SetHResult(-2147483637); throw; } } public void RemoveAt(uint index) { EnsureIndexInt32(index, _list.Count); try { _list.RemoveAt((int)index); } catch (ArgumentOutOfRangeException ex) { ex.SetHResult(-2147483637); throw; } } public void Append(T value) { _list.Add(value); } public void RemoveAtEnd() { if (_list.Count == 0) { global::System.Exception ex = new InvalidOperationException(WinRTRuntimeErrorStrings.InvalidOperation_CannotRemoveLastFromEmptyCollection); ex.SetHResult(-2147483637); throw ex; } uint count = (uint)_list.Count; RemoveAt(count - 1); } public void _Clear() { _list.Clear(); } public uint GetMany(uint startIndex, ref T[] items) { return GetManyHelper(_list, startIndex, items); } public void ReplaceAll(T[] items) { _list.Clear(); if (items != null) { foreach (T item in items) { _list.Add(item); } } } private static uint GetManyHelper(global::System.Collections.Generic.IList sourceList, uint startIndex, T[] items) { if (startIndex == sourceList.Count) { return 0u; } EnsureIndexInt32(startIndex, sourceList.Count); if (items == null) { return 0u; } uint num = Math.Min((uint)items.Length, (uint)sourceList.Count - startIndex); for (uint num2 = 0u; num2 < num; num2++) { items[num2] = sourceList[(int)(num2 + startIndex)]; } if (typeof(T) == typeof(string)) { string[] array = items as string[]; for (uint num3 = num; num3 < items.Length; num3++) { array[num3] = string.Empty; } } return num; } } [Guid("913337E9-11A1-4345-A3A2-4E7F956E222D")] public struct Vftbl { internal IInspectable.Vftbl IInspectableVftbl; public static readonly IntPtr AbiToProjectionVftablePtr = IList.AbiToProjectionVftablePtr; public static readonly Guid PIID = IList.PIID; } static readonly IntPtr AbiToProjectionVftablePtr; private static readonly ConditionalWeakTable, ToAbiHelper> _adapterTable; static readonly Guid PIID; uint IVector.Size { get { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.Generic.IList).TypeHandle); return IVectorMethods.get_Size(objectReferenceForType); } } int global::System.Collections.Generic.ICollection.Count { get { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.Generic.IList).TypeHandle); return IListMethods.get_Count(objectReferenceForType); } } bool global::System.Collections.Generic.ICollection.IsReadOnly { get { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.Generic.IList).TypeHandle); return IListMethods.get_IsReadOnly(objectReferenceForType); } } T global::System.Collections.Generic.IList.this[int index] { get { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.Generic.IList).TypeHandle); return IListMethods.Indexer_Get(objectReferenceForType, index); } set { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.Generic.IList).TypeHandle); IListMethods.Indexer_Set(objectReferenceForType, index, value); } } static IObjectReference CreateMarshaler(global::System.Collections.Generic.IList obj) { if (obj != null) { return ComWrappersSupport.CreateCCWForObject(obj, PIID); } return null; } static ObjectReferenceValue CreateMarshaler2(global::System.Collections.Generic.IList obj) { return ComWrappersSupport.CreateCCWForObjectForMarshaling(obj, PIID); } static IntPtr GetAbi(IObjectReference objRef) { return objRef?.ThisPtr ?? IntPtr.Zero; } static IntPtr FromManaged(global::System.Collections.Generic.IList value) { if (value != null) { return CreateMarshaler2(value).Detach(); } return IntPtr.Zero; } static void DisposeMarshaler(IObjectReference objRef) { objRef?.Dispose(); } static void DisposeAbi(IntPtr abi) { MarshalInterfaceHelper>.DisposeAbi(abi); } static string GetGuidSignature() { return GuidGenerator.GetSignature(typeof(IList)); } static IList() { _adapterTable = new ConditionalWeakTable, ToAbiHelper>(); PIID = IListMethods.PIID; if (RuntimeFeature.IsDynamicCodeCompiled) { InitFallbackCCWVTableIfNeeded(); } AbiToProjectionVftablePtr = IListMethods.AbiToProjectionVftablePtr; [MethodImpl(MethodImplOptions.NoInlining)] [UnconditionalSuppressMessage("Trimming", "IL2080", Justification = "All ABI types never have a constructor that would need to be accessed via reflection.")] internal static void InitFallbackCCWVTableIfNeeded() { if (IListMethods.AbiToProjectionVftablePtr == (IntPtr)0) { Action action = (Action)typeof(IListMethods<, >).MakeGenericType(typeof(T), Marshaler.AbiType).GetMethod("InitFallbackCCWVtable", BindingFlags.Static | BindingFlags.NonPublic).CreateDelegate(typeof(Action)); action(); } } } internal static IVector FindAdapter(IntPtr thisPtr) { global::System.Collections.Generic.IList key = ComWrappersSupport.FindObject>(thisPtr); return _adapterTable.GetValue(key, (global::System.Collections.Generic.IList list) => new ToAbiHelper(list)); } static ObjectReference ObjRefFromAbi(IntPtr thisPtr) { if (thisPtr == IntPtr.Zero) { return null; } return ObjectReference.FromAbi(thisPtr, PIID); } T IVector.GetAt(uint index) { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.Generic.IList).TypeHandle); return IVectorMethods.GetAt(objectReferenceForType, index); } global::System.Collections.Generic.IReadOnlyList IVector.GetView() { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.Generic.IList).TypeHandle); return IVectorMethods.GetView(objectReferenceForType); } bool IVector.IndexOf(T value, out uint index) { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.Generic.IList).TypeHandle); return IVectorMethods.IndexOf(objectReferenceForType, value, out index); } void IVector.SetAt(uint index, T value) { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.Generic.IList).TypeHandle); IVectorMethods.SetAt(objectReferenceForType, index, value); } void IVector.InsertAt(uint index, T value) { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.Generic.IList).TypeHandle); IVectorMethods.InsertAt(objectReferenceForType, index, value); } void IVector.RemoveAt(uint index) { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.Generic.IList).TypeHandle); IVectorMethods.RemoveAt(objectReferenceForType, index); } void IVector.Append(T value) { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.Generic.IList).TypeHandle); IVectorMethods.Append(objectReferenceForType, value); } void IVector.RemoveAtEnd() { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.Generic.IList).TypeHandle); IVectorMethods.RemoveAtEnd(objectReferenceForType); } void IVector._Clear() { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.Generic.IList).TypeHandle); IVectorMethods.Clear(objectReferenceForType); } uint IVector.GetMany(uint startIndex, ref T[] items) { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.Generic.IList).TypeHandle); return IVectorMethods.GetMany(objectReferenceForType, startIndex, ref items); } void IVector.ReplaceAll(T[] items) { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.Generic.IList).TypeHandle); IVectorMethods.ReplaceAll(objectReferenceForType, items); } int global::System.Collections.Generic.IList.IndexOf(T item) { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.Generic.IList).TypeHandle); return IListMethods.IndexOf(objectReferenceForType, item); } void global::System.Collections.Generic.IList.Insert(int index, T item) { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.Generic.IList).TypeHandle); IListMethods.Insert(objectReferenceForType, index, item); } void global::System.Collections.Generic.IList.RemoveAt(int index) { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.Generic.IList).TypeHandle); IListMethods.RemoveAt(objectReferenceForType, index); } void global::System.Collections.Generic.ICollection.Add(T item) { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.Generic.IList).TypeHandle); IListMethods.Add(objectReferenceForType, item); } void global::System.Collections.Generic.ICollection.Clear() { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.Generic.IList).TypeHandle); IListMethods.Clear(objectReferenceForType); } bool global::System.Collections.Generic.ICollection.Contains(T item) { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.Generic.IList).TypeHandle); return IListMethods.Contains(objectReferenceForType, item); } void global::System.Collections.Generic.ICollection.CopyTo(T[] array, int arrayIndex) { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.Generic.IList).TypeHandle); IListMethods.CopyTo(objectReferenceForType, array, arrayIndex); } bool global::System.Collections.Generic.ICollection.Remove(T item) { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.Generic.IList).TypeHandle); return IListMethods.Remove(objectReferenceForType, item); } global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() { ((IWinRTObject)this).IsInterfaceImplemented(typeof(global::System.Collections.Generic.IEnumerable).TypeHandle, throwIfNotImplemented: true); IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.Generic.IEnumerable).TypeHandle); return IEnumerableMethods.GetEnumerator(objectReferenceForType); } IEnumerator global::System.Collections.IEnumerable.GetEnumerator() { return GetEnumerator(); } } public static class IList_Delegates { public delegate int GetView_2(IntPtr thisPtr, out IntPtr __return_value__); internal unsafe delegate int GetView_2_Abi(IntPtr thisPtr, IntPtr* __return_value__); public delegate int RemoveAt_6(IntPtr thisPtr, uint index); public delegate int RemoveAtEnd_8(IntPtr thisPtr); public delegate int Clear_9(IntPtr thisPtr); public delegate int GetMany_10(IntPtr thisPtr, uint startIndex, int __itemsSize, IntPtr items, out uint __return_value__); internal unsafe delegate int GetMany_10_Abi(IntPtr thisPtr, uint startIndex, int __itemsSize, IntPtr items, uint* __return_value__); public delegate int ReplaceAll_11(IntPtr thisPtr, int __itemsSize, IntPtr items); } public static class IReadOnlyDictionaryMethods { private sealed class ReadOnlyDictionaryKeyCollection : global::System.Collections.Generic.IEnumerable, global::System.Collections.IEnumerable { private sealed class ReadOnlyDictionaryKeyEnumerator : global::System.Collections.Generic.IEnumerator, IEnumerator, global::System.IDisposable { private readonly IObjectReference iEnumerableObjRef; private global::System.Collections.Generic.IEnumerator> enumeration; object IEnumerator.Current => Current; public K Current => enumeration.Current.Key; public ReadOnlyDictionaryKeyEnumerator(IObjectReference iEnumerableObjRef) { this.iEnumerableObjRef = iEnumerableObjRef; enumeration = IEnumerableMethods>.GetEnumerator(iEnumerableObjRef); } void global::System.IDisposable.Dispose() { enumeration.Dispose(); } public bool MoveNext() { return enumeration.MoveNext(); } public void Reset() { enumeration = IEnumerableMethods>.GetEnumerator(iEnumerableObjRef); } } private readonly IObjectReference iReadOnlyDictionaryObjRef; private volatile IObjectReference __iEnumerableObjRef; private IObjectReference iEnumerableObjRef => __iEnumerableObjRef ?? Make_IEnumerableObjRef(); public ReadOnlyDictionaryKeyCollection(IObjectReference iReadOnlyDictionaryObjRef) { if (iReadOnlyDictionaryObjRef == null) { throw new ArgumentNullException("iReadOnlyDictionaryObjRef"); } this.iReadOnlyDictionaryObjRef = iReadOnlyDictionaryObjRef; } private IObjectReference Make_IEnumerableObjRef() { Interlocked.CompareExchange(ref __iEnumerableObjRef, iReadOnlyDictionaryObjRef.As(IEnumerableMethods>.PIID), null); return __iEnumerableObjRef; } public global::System.Collections.Generic.IEnumerator GetEnumerator() { return new ReadOnlyDictionaryKeyEnumerator(iEnumerableObjRef); } IEnumerator global::System.Collections.IEnumerable.GetEnumerator() { return GetEnumerator(); } } private sealed class ReadOnlyDictionaryValueCollection : global::System.Collections.Generic.IEnumerable, global::System.Collections.IEnumerable { private sealed class ReadOnlyDictionaryValueEnumerator : global::System.Collections.Generic.IEnumerator, IEnumerator, global::System.IDisposable { private readonly IObjectReference iEnumerableObjRef; private global::System.Collections.Generic.IEnumerator> enumeration; object IEnumerator.Current => Current; public V Current => enumeration.Current.Value; public ReadOnlyDictionaryValueEnumerator(IObjectReference iEnumerableObjRef) { this.iEnumerableObjRef = iEnumerableObjRef; enumeration = IEnumerableMethods>.GetEnumerator(iEnumerableObjRef); } void global::System.IDisposable.Dispose() { enumeration.Dispose(); } public bool MoveNext() { return enumeration.MoveNext(); } public void Reset() { enumeration = IEnumerableMethods>.GetEnumerator(iEnumerableObjRef); } } private readonly IObjectReference iDictionaryObjRef; private volatile IObjectReference __iEnumerableObjRef; private IObjectReference iEnumerableObjRef => __iEnumerableObjRef ?? Make_IEnumerableObjRef(); public ReadOnlyDictionaryValueCollection(IObjectReference iDictionaryObjRef) { this.iDictionaryObjRef = iDictionaryObjRef; } private IObjectReference Make_IEnumerableObjRef() { Interlocked.CompareExchange(ref __iEnumerableObjRef, iDictionaryObjRef.As(IEnumerableMethods>.PIID), null); return __iEnumerableObjRef; } public global::System.Collections.Generic.IEnumerator GetEnumerator() { return new ReadOnlyDictionaryValueEnumerator(iEnumerableObjRef); } IEnumerator global::System.Collections.IEnumerable.GetEnumerator() { return GetEnumerator(); } } private static IntPtr abiToProjectionVftablePtr; internal static readonly Guid PIID; public static IntPtr AbiToProjectionVftablePtr => abiToProjectionVftablePtr; public static Guid IID => PIID; static IReadOnlyDictionaryMethods() { PIID = GuidGenerator.CreateIIDUnsafe(typeof(IReadOnlyDictionary)); ComWrappersSupport.RegisterHelperType(typeof(global::System.Collections.Generic.IReadOnlyDictionary), typeof(IReadOnlyDictionary)); ComWrappersSupport.RegisterHelperType(typeof(IMapView), typeof(IReadOnlyDictionary)); if (RuntimeFeature.IsDynamicCodeCompiled) { InitRcwHelperFallbackIfNeeded(); } [MethodImpl(MethodImplOptions.NoInlining)] [UnconditionalSuppressMessage("Trimming", "IL2080", Justification = "All ABI types never have a constructor that would need to be accessed via reflection.")] static void InitRcwHelperFallbackIfNeeded() { if (!IMapViewMethods._RcwHelperInitialized) { Func func = (Func)typeof(IReadOnlyDictionaryMethods<, , , >).MakeGenericType(typeof(K), Marshaler.AbiType, typeof(V), Marshaler.AbiType).GetMethod("InitRcwHelperFallback", BindingFlags.Static | BindingFlags.NonPublic).CreateDelegate(typeof(Func)); func(); } } } public static int get_Count(IObjectReference obj) { uint num = IMapViewMethods.get_Size(obj); if (int.MaxValue < num) { throw new InvalidOperationException(WinRTRuntimeErrorStrings.InvalidOperation_CollectionBackingDictionaryTooLarge); } return (int)num; } public static V Indexer_Get(IObjectReference obj, K key) { if (key == null) { throw new ArgumentNullException("key"); } return Lookup(obj, key); } public static global::System.Collections.Generic.IEnumerable get_Keys(IObjectReference obj) { return new ReadOnlyDictionaryKeyCollection(obj); } public static global::System.Collections.Generic.IEnumerable get_Values(IObjectReference obj) { return new ReadOnlyDictionaryValueCollection(obj); } public static bool ContainsKey(IObjectReference obj, K key) { if (key == null) { throw new ArgumentNullException("key"); } return IMapViewMethods.HasKey(obj, key); } public static bool TryGetValue(IObjectReference obj, K key, out V value) { if (key == null) { throw new ArgumentNullException("key"); } if (!IMapViewMethods.HasKey(obj, key)) { value = default(V); return false; } try { value = IMapViewMethods.Lookup(obj, key); return true; } catch (global::System.Exception ex) { if (-2147483637 == ex.HResult) { value = default(V); return false; } throw; } } public static V Lookup(IObjectReference obj, K key) { try { return IMapViewMethods.Lookup(obj, key); } catch (global::System.Exception ex) { if (-2147483637 == ex.HResult) { throw new KeyNotFoundException(string.Format(WinRTRuntimeErrorStrings.Arg_KeyNotFoundWithKey, key.ToString())); } throw; } } internal static bool TryInitCCWVtable(IntPtr ptr) { return Interlocked.CompareExchange(ref abiToProjectionVftablePtr, ptr, IntPtr.Zero) == IntPtr.Zero; } public static V Abi_Lookup_0(IntPtr thisPtr, K key) { return IReadOnlyDictionary.FindAdapter(thisPtr).Lookup(key); } public static bool Abi_HasKey_2(IntPtr thisPtr, K key) { return IReadOnlyDictionary.FindAdapter(thisPtr).HasKey(key); } public static void Abi_Split_3(IntPtr thisPtr, out IntPtr first, out IntPtr second) { IReadOnlyDictionary.FindAdapter(thisPtr).Split(out var first2, out var second2); first = MarshalInterface>.FromManaged(first2); second = MarshalInterface>.FromManaged(second2); } public static uint Abi_get_Size_1(IntPtr thisPtr) { return IReadOnlyDictionary.FindAdapter(thisPtr).Size; } } public static class IReadOnlyDictionaryMethods where KAbi : unmanaged where VAbi : unmanaged { private sealed class DelegateHelper { private readonly IntPtr _ptr; private Delegate _lookupDelegate; private Delegate _hasKeyDelegate; public Delegate Lookup => _lookupDelegate ?? GenericDelegateHelper.CreateDelegate(_ptr, ref _lookupDelegate, IReadOnlyDictionaryMethods.Lookup_0_Type, 6); public Delegate HasKey => _hasKeyDelegate ?? GenericDelegateHelper.CreateDelegate(_ptr, ref _hasKeyDelegate, IReadOnlyDictionaryMethods.HasKey_2_Type, 8); private DelegateHelper(IntPtr ptr) { _ptr = ptr; } public static DelegateHelper Get(IObjectReference obj) { return (DelegateHelper)GenericDelegateHelper.DelegateTable.GetValue(obj, (IObjectReference objRef) => new DelegateHelper(objRef.ThisPtr)); } } private static Delegate[] DelegateCache; private static global::System.Type _lookup_0_type; private static global::System.Type _hasKey_2_type; private static global::System.Type Lookup_0_Type => _lookup_0_type ?? MakeLookupType(); private static global::System.Type HasKey_2_Type => _hasKey_2_type ?? MakeHasKeyType(); public unsafe static bool InitRcwHelper(delegate* lookup, delegate* hasKey, delegate*, out global::System.Collections.Generic.IReadOnlyDictionary, void> _) { if (IMapViewMethods._RcwHelperInitialized) { return true; } IMapViewMethods._Lookup = lookup; IMapViewMethods._HasKey = hasKey; ComWrappersSupport.RegisterTypedRcwFactory(typeof(global::System.Collections.Generic.IReadOnlyDictionary), IReadOnlyDictionaryImpl.CreateRcw); ComWrappersSupport.RegisterHelperType(typeof(global::System.Collections.Generic.IReadOnlyDictionary), typeof(IReadOnlyDictionary)); ComWrappersSupport.RegisterHelperType(typeof(IMapView), typeof(IReadOnlyDictionary)); IMapViewMethods._RcwHelperInitialized = true; return true; } private unsafe static bool InitRcwHelperFallback() { return InitRcwHelper((delegate*)(&LookupDynamic), (delegate*)(&HasKeyDynamic), (delegate*, out global::System.Collections.Generic.IReadOnlyDictionary, void>)null); } private unsafe static V LookupDynamic(IObjectReference obj, K key) { IntPtr thisPtr = obj.ThisPtr; object obj2 = null; VAbi val = default(VAbi); object[] array = new object[3] { thisPtr, null, (IntPtr)(&val) }; try { obj2 = Marshaler.CreateMarshaler2(key); array[1] = Marshaler.GetAbi(obj2); DelegateHelper.Get(obj).Lookup.DynamicInvokeAbi(array); GC.KeepAlive(obj); GC.KeepAlive(array); return Marshaler.FromAbi(val); } finally { Marshaler.DisposeMarshaler(obj2); Marshaler.DisposeAbi(val); } } private unsafe static bool HasKeyDynamic(IObjectReference obj, K key) { IntPtr thisPtr = obj.ThisPtr; object obj2 = null; byte b = default(byte); object[] array = new object[3] { thisPtr, null, (IntPtr)(&b) }; try { obj2 = Marshaler.CreateMarshaler2(key); array[1] = Marshaler.GetAbi(obj2); DelegateHelper.Get(obj).HasKey.DynamicInvokeAbi(array); GC.KeepAlive(obj); GC.KeepAlive(array); return b != 0; } finally { Marshaler.DisposeMarshaler(obj2); } } public unsafe static bool InitCcw(delegate* unmanaged[Stdcall] lookup, delegate* unmanaged[Stdcall] getSize, delegate* unmanaged[Stdcall] hasKey, delegate* unmanaged[Stdcall] split) { if (IReadOnlyDictionaryMethods.AbiToProjectionVftablePtr != (IntPtr)0) { return false; } IntPtr intPtr = (IntPtr)NativeMemory.AllocZeroed((nuint)(sizeof(IInspectable.Vftbl) + sizeof(IntPtr) * 4)); *(IInspectable.Vftbl*)(void*)intPtr = IInspectable.Vftbl.AbiToProjectionVftable; *(IntPtr*)((byte*)(void*)intPtr + (nint)6 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)lookup; *(IntPtr*)((byte*)(void*)intPtr + (nint)7 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)getSize; *(IntPtr*)((byte*)(void*)intPtr + (nint)8 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)hasKey; *(IntPtr*)((byte*)(void*)intPtr + (nint)9 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)split; if (!IReadOnlyDictionaryMethods.TryInitCCWVtable(intPtr)) { NativeMemory.Free((void*)intPtr); return false; } return true; } internal unsafe static void InitFallbackCCWVtable() { DelegateCache = new Delegate[4] { Delegate.CreateDelegate(Lookup_0_Type, typeof(IReadOnlyDictionaryMethods).GetMethod("Do_Abi_Lookup_0", BindingFlags.Static | BindingFlags.NonPublic)), new _get_PropertyAsUInt32_Abi(Do_Abi_get_Size_1), Delegate.CreateDelegate(HasKey_2_Type, typeof(IReadOnlyDictionaryMethods).GetMethod("Do_Abi_HasKey_2", BindingFlags.Static | BindingFlags.NonPublic)), new IReadOnlyDictionary_Delegates.Split_3_Abi(Do_Abi_Split_3) }; InitCcw((delegate* unmanaged[Stdcall])(void*)Marshal.GetFunctionPointerForDelegate(DelegateCache[0]), (delegate* unmanaged[Stdcall])(void*)Marshal.GetFunctionPointerForDelegate(DelegateCache[1]), (delegate* unmanaged[Stdcall])(void*)Marshal.GetFunctionPointerForDelegate(DelegateCache[2]), (delegate* unmanaged[Stdcall])(void*)Marshal.GetFunctionPointerForDelegate(DelegateCache[3])); } private unsafe static int Do_Abi_Lookup_0(IntPtr thisPtr, KAbi key, VAbi* __return_value__) { V val = default(V); *__return_value__ = default(VAbi); try { val = IReadOnlyDictionary.FindAdapter(thisPtr).Lookup(Marshaler.FromAbi(key)); *__return_value__ = (VAbi)Marshaler.FromManaged(val); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } private unsafe static int Do_Abi_HasKey_2(IntPtr thisPtr, KAbi key, byte* __return_value__) { bool flag = false; *__return_value__ = 0; try { flag = IReadOnlyDictionary.FindAdapter(thisPtr).HasKey(Marshaler.FromAbi(key)); *__return_value__ = (flag ? ((byte)1) : ((byte)0)); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } private unsafe static int Do_Abi_Split_3(IntPtr thisPtr, IntPtr* first, IntPtr* second) { *first = default(IntPtr); *second = default(IntPtr); IMapView first2 = null; IMapView second2 = null; try { IReadOnlyDictionary.FindAdapter(thisPtr).Split(out first2, out second2); *first = MarshalInterface>.FromManaged(first2); *second = MarshalInterface>.FromManaged(second2); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } private unsafe static int Do_Abi_get_Size_1(IntPtr thisPtr, uint* __return_value__) { uint num = 0u; *__return_value__ = 0u; try { num = IReadOnlyDictionary.FindAdapter(thisPtr).Size; *__return_value__ = num; } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } private unsafe static global::System.Type MakeLookupType() { Interlocked.CompareExchange(ref _lookup_0_type, Projections.GetAbiDelegateType(typeof(IntPtr), typeof(KAbi), typeof(VAbi*), typeof(int)), null); return _lookup_0_type; } private unsafe static global::System.Type MakeHasKeyType() { Interlocked.CompareExchange(ref _hasKey_2_type, Projections.GetAbiDelegateType(typeof(IntPtr), typeof(KAbi), typeof(byte*), typeof(int)), null); return _hasKey_2_type; } } internal sealed class ConstantSplittableMap : IMapView, global::Windows.Foundation.Collections.IIterable>, global::System.Collections.Generic.IReadOnlyDictionary, global::System.Collections.Generic.IEnumerable>, global::System.Collections.IEnumerable, global::System.Collections.Generic.IReadOnlyCollection> { private sealed class KeyValuePairComparator : IComparer> { private static readonly IComparer keyComparator = Comparer.Default; public int Compare(global::System.Collections.Generic.KeyValuePair x, global::System.Collections.Generic.KeyValuePair y) { return keyComparator.Compare(x.Key, y.Key); } } private static readonly KeyValuePairComparator keyValuePairComparator = new KeyValuePairComparator(); private readonly global::System.Collections.Generic.KeyValuePair[] items; private readonly int firstItemIndex; private readonly int lastItemIndex; public uint Size => (uint)(lastItemIndex - firstItemIndex + 1); public global::System.Collections.Generic.IEnumerable Keys => new ReadOnlyDictionaryKeyCollection(this); public global::System.Collections.Generic.IEnumerable Values => new ReadOnlyDictionaryValueCollection(this); public int Count => lastItemIndex - firstItemIndex + 1; public V this[K key] => Lookup(key); internal ConstantSplittableMap(global::System.Collections.Generic.IReadOnlyDictionary data) { if (data == null) { throw new ArgumentNullException("data"); } firstItemIndex = 0; lastItemIndex = data.Count - 1; items = CreateKeyValueArray(data.Count, data.GetEnumerator()); } private ConstantSplittableMap(global::System.Collections.Generic.KeyValuePair[] items, int firstItemIndex, int lastItemIndex) { this.items = items; this.firstItemIndex = firstItemIndex; this.lastItemIndex = lastItemIndex; } private global::System.Collections.Generic.KeyValuePair[] CreateKeyValueArray(int count, global::System.Collections.Generic.IEnumerator> data) { global::System.Collections.Generic.KeyValuePair[] array = new global::System.Collections.Generic.KeyValuePair[count]; int num = 0; while (data.MoveNext()) { array[num++] = data.Current; } Array.Sort(array, keyValuePairComparator); return array; } public V Lookup(K key) { if (!TryGetValue(key, out var value)) { global::System.Exception ex = new KeyNotFoundException(string.Format(WinRTRuntimeErrorStrings.Arg_KeyNotFoundWithKey, key.ToString())); ex.SetHResult(-2147483637); throw ex; } return value; } public bool HasKey(K key) { V value; return TryGetValue(key, out value); } public global::System.Collections.Generic.IEnumerator> First() { return GetEnumerator(); } public void Split(out IMapView firstPartition, out IMapView secondPartition) { if (Count < 2) { firstPartition = null; secondPartition = null; } else { int num = (int)(((long)firstItemIndex + (long)lastItemIndex) / 2); firstPartition = new ConstantSplittableMap(items, firstItemIndex, num); secondPartition = new ConstantSplittableMap(items, num + 1, lastItemIndex); } } public bool TryGetValue(K key, out V value) { global::System.Collections.Generic.KeyValuePair value2 = new global::System.Collections.Generic.KeyValuePair(key, default(V)); int num = Array.BinarySearch(items, firstItemIndex, Count, value2, keyValuePairComparator); if (num < 0) { value = default(V); return false; } value = items[num].Value; return true; } public bool ContainsKey(K key) { return HasKey(key); } global::System.Collections.Generic.IEnumerator> global::Windows.Foundation.Collections.IIterable>.First() { IKeyValuePair[] array = new IKeyValuePair[items.Length]; for (int i = 0; i < items.Length; i++) { array[i] = new KeyValuePair.ToIKeyValuePair(ref items[i]); } return new ConstantSplittableMapEnumerator>(array, firstItemIndex, lastItemIndex); } public global::System.Collections.Generic.IEnumerator> GetEnumerator() { return new ConstantSplittableMapEnumerator>(items, firstItemIndex, lastItemIndex); } IEnumerator global::System.Collections.IEnumerable.GetEnumerator() { return new ConstantSplittableMapEnumerator>(items, firstItemIndex, lastItemIndex); } } internal struct ConstantSplittableMapEnumerator : global::System.Collections.Generic.IEnumerator, IEnumerator, global::System.IDisposable { private readonly T[] _array; private readonly int _start; private readonly int _end; private int _current; public T Current { get { if (_current < _start) { throw new InvalidOperationException(WinRTRuntimeErrorStrings.InvalidOperation_EnumNotStarted); } if (_current > _end) { throw new InvalidOperationException(WinRTRuntimeErrorStrings.InvalidOperation_EnumEnded); } return _array[_current]; } } object IEnumerator.Current => Current; internal ConstantSplittableMapEnumerator(T[] items, int first, int end) { _array = items; _start = first; _end = end; _current = _start - 1; } public bool MoveNext() { if (_current < _end) { _current++; return true; } return false; } void IEnumerator.Reset() { _current = _start - 1; } public void Dispose() { } } internal sealed class ReadOnlyDictionaryKeyCollection : global::System.Collections.Generic.IEnumerable, global::System.Collections.IEnumerable { private sealed class ReadOnlyDictionaryKeyEnumerator : global::System.Collections.Generic.IEnumerator, IEnumerator, global::System.IDisposable { private readonly global::System.Collections.Generic.IReadOnlyDictionary dictionary; private global::System.Collections.Generic.IEnumerator> enumeration; object IEnumerator.Current => Current; public K Current => enumeration.Current.Key; public ReadOnlyDictionaryKeyEnumerator(global::System.Collections.Generic.IReadOnlyDictionary dictionary) { this.dictionary = dictionary ?? throw new ArgumentNullException("dictionary"); enumeration = dictionary.GetEnumerator(); } void global::System.IDisposable.Dispose() { enumeration.Dispose(); } public bool MoveNext() { return enumeration.MoveNext(); } public void Reset() { enumeration = dictionary.GetEnumerator(); } } private readonly global::System.Collections.Generic.IReadOnlyDictionary dictionary; public ReadOnlyDictionaryKeyCollection(global::System.Collections.Generic.IReadOnlyDictionary dictionary) { this.dictionary = dictionary ?? throw new ArgumentNullException("dictionary"); } public global::System.Collections.Generic.IEnumerator GetEnumerator() { return new ReadOnlyDictionaryKeyEnumerator(dictionary); } IEnumerator global::System.Collections.IEnumerable.GetEnumerator() { return GetEnumerator(); } } internal sealed class ReadOnlyDictionaryValueCollection : global::System.Collections.Generic.IEnumerable, global::System.Collections.IEnumerable { private sealed class ReadOnlyDictionaryValueEnumerator : global::System.Collections.Generic.IEnumerator, IEnumerator, global::System.IDisposable { private readonly global::System.Collections.Generic.IReadOnlyDictionary dictionary; private global::System.Collections.Generic.IEnumerator> enumeration; object IEnumerator.Current => Current; public V Current => enumeration.Current.Value; public ReadOnlyDictionaryValueEnumerator(global::System.Collections.Generic.IReadOnlyDictionary dictionary) { this.dictionary = dictionary ?? throw new ArgumentNullException("dictionary"); enumeration = dictionary.GetEnumerator(); } void global::System.IDisposable.Dispose() { enumeration.Dispose(); } public bool MoveNext() { return enumeration.MoveNext(); } public void Reset() { enumeration = dictionary.GetEnumerator(); } } private readonly global::System.Collections.Generic.IReadOnlyDictionary dictionary; public ReadOnlyDictionaryValueCollection(global::System.Collections.Generic.IReadOnlyDictionary dictionary) { this.dictionary = dictionary ?? throw new ArgumentNullException("dictionary"); } public global::System.Collections.Generic.IEnumerator GetEnumerator() { return new ReadOnlyDictionaryValueEnumerator(dictionary); } IEnumerator global::System.Collections.IEnumerable.GetEnumerator() { return GetEnumerator(); } } [DynamicInterfaceCastableImplementation] [Guid("E480CE40-A338-4ADA-ADCF-272272E48CB9")] internal interface IReadOnlyDictionary : global::System.Collections.Generic.IReadOnlyDictionary, global::System.Collections.Generic.IEnumerable>, global::System.Collections.IEnumerable, global::System.Collections.Generic.IReadOnlyCollection>, IMapView, global::Windows.Foundation.Collections.IIterable> { public sealed class ToAbiHelper : IMapView, global::Windows.Foundation.Collections.IIterable> { private readonly global::System.Collections.Generic.IReadOnlyDictionary _dictionary; uint IMapView.Size => (uint)_dictionary.Count; internal ToAbiHelper(global::System.Collections.Generic.IReadOnlyDictionary dictionary) { _dictionary = dictionary; } global::System.Collections.Generic.IEnumerator> global::Windows.Foundation.Collections.IIterable>.First() { return new KeyValuePair.Enumerator(_dictionary.GetEnumerator()); } public V Lookup(K key) { if (!_dictionary.TryGetValue(key, out var value)) { global::System.Exception ex = new KeyNotFoundException(string.Format(WinRTRuntimeErrorStrings.Arg_KeyNotFoundWithKey, key.ToString())); ex.SetHResult(-2147483637); throw ex; } return value; } public uint Size() { return (uint)_dictionary.Count; } public bool HasKey(K key) { return _dictionary.ContainsKey(key); } void IMapView.Split(out IMapView first, out IMapView second) { if (_dictionary.Count < 2) { first = null; second = null; return; } ConstantSplittableMap constantSplittableMap = _dictionary as ConstantSplittableMap; if (constantSplittableMap == null) { constantSplittableMap = new ConstantSplittableMap(_dictionary); } constantSplittableMap.Split(out first, out second); } } [Guid("E480CE40-A338-4ADA-ADCF-272272E48CB9")] public struct Vftbl { internal IInspectable.Vftbl IInspectableVftbl; public static readonly IntPtr AbiToProjectionVftablePtr = IReadOnlyDictionary.AbiToProjectionVftablePtr; public static readonly Guid PIID = IReadOnlyDictionary.PIID; } static readonly IntPtr AbiToProjectionVftablePtr; private static readonly ConditionalWeakTable, ToAbiHelper> _adapterTable; static readonly Guid PIID; global::System.Collections.Generic.IEnumerable global::System.Collections.Generic.IReadOnlyDictionary.Keys { get { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.Generic.IReadOnlyDictionary).TypeHandle); return IReadOnlyDictionaryMethods.get_Keys(objectReferenceForType); } } global::System.Collections.Generic.IEnumerable global::System.Collections.Generic.IReadOnlyDictionary.Values { get { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.Generic.IReadOnlyDictionary).TypeHandle); return IReadOnlyDictionaryMethods.get_Values(objectReferenceForType); } } int global::System.Collections.Generic.IReadOnlyCollection>.Count { get { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.Generic.IReadOnlyDictionary).TypeHandle); return IReadOnlyDictionaryMethods.get_Count(objectReferenceForType); } } V global::System.Collections.Generic.IReadOnlyDictionary.this[K key] { get { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.Generic.IReadOnlyDictionary).TypeHandle); return IReadOnlyDictionaryMethods.Indexer_Get(objectReferenceForType, key); } } static IObjectReference CreateMarshaler(global::System.Collections.Generic.IReadOnlyDictionary obj) { if (obj != null) { return ComWrappersSupport.CreateCCWForObject(obj, PIID); } return null; } static ObjectReferenceValue CreateMarshaler2(global::System.Collections.Generic.IReadOnlyDictionary obj) { return ComWrappersSupport.CreateCCWForObjectForMarshaling(obj, PIID); } static IntPtr GetAbi(IObjectReference objRef) { return objRef?.ThisPtr ?? IntPtr.Zero; } static IntPtr FromManaged(global::System.Collections.Generic.IReadOnlyDictionary value) { if (value != null) { return CreateMarshaler2(value).Detach(); } return IntPtr.Zero; } static void DisposeMarshaler(IObjectReference objRef) { objRef?.Dispose(); } static void DisposeAbi(IntPtr abi) { MarshalInterfaceHelper>.DisposeAbi(abi); } static string GetGuidSignature() { return GuidGenerator.GetSignature(typeof(IReadOnlyDictionary)); } static IReadOnlyDictionary() { _adapterTable = new ConditionalWeakTable, ToAbiHelper>(); PIID = IReadOnlyDictionaryMethods.PIID; if (RuntimeFeature.IsDynamicCodeCompiled) { InitFallbackCCWVTableIfNeeded(); } AbiToProjectionVftablePtr = IReadOnlyDictionaryMethods.AbiToProjectionVftablePtr; [MethodImpl(MethodImplOptions.NoInlining)] [UnconditionalSuppressMessage("Trimming", "IL2080", Justification = "All ABI types never have a constructor that would need to be accessed via reflection.")] internal static void InitFallbackCCWVTableIfNeeded() { if (IReadOnlyDictionaryMethods.AbiToProjectionVftablePtr == (IntPtr)0) { Action action = (Action)typeof(IReadOnlyDictionaryMethods<, , , >).MakeGenericType(typeof(K), Marshaler.AbiType, typeof(V), Marshaler.AbiType).GetMethod("InitFallbackCCWVtable", BindingFlags.Static | BindingFlags.NonPublic).CreateDelegate(typeof(Action)); action(); } } } internal static IMapView FindAdapter(IntPtr thisPtr) { global::System.Collections.Generic.IReadOnlyDictionary key = ComWrappersSupport.FindObject>(thisPtr); return _adapterTable.GetValue(key, (global::System.Collections.Generic.IReadOnlyDictionary dictionary) => new ToAbiHelper(dictionary)); } static ObjectReference ObjRefFromAbi(IntPtr thisPtr) { if (thisPtr == IntPtr.Zero) { return null; } return ObjectReference.FromAbi(thisPtr, PIID); } bool global::System.Collections.Generic.IReadOnlyDictionary.ContainsKey(K key) { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.Generic.IReadOnlyDictionary).TypeHandle); return IReadOnlyDictionaryMethods.ContainsKey(objectReferenceForType, key); } bool global::System.Collections.Generic.IReadOnlyDictionary.TryGetValue(K key, out V value) { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.Generic.IReadOnlyDictionary).TypeHandle); return IReadOnlyDictionaryMethods.TryGetValue(objectReferenceForType, key, out value); } global::System.Collections.Generic.IEnumerator> global::System.Collections.Generic.IEnumerable>.GetEnumerator() { ((IWinRTObject)this).IsInterfaceImplemented(typeof(global::System.Collections.Generic.IEnumerable>).TypeHandle, throwIfNotImplemented: true); IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.Generic.IEnumerable>).TypeHandle); return IEnumerableMethods>.GetEnumerator(objectReferenceForType); } IEnumerator global::System.Collections.IEnumerable.GetEnumerator() { return GetEnumerator(); } } public static class IReadOnlyDictionary_Delegates { public delegate int Split_3(IntPtr thisPtr, out IntPtr first, out IntPtr second); internal unsafe delegate int Split_3_Abi(IntPtr thisPtr, IntPtr* first, IntPtr* second); } public static class IReadOnlyListMethods { private static IntPtr abiToProjectionVftablePtr; internal static readonly Guid PIID; public static IntPtr AbiToProjectionVftablePtr => abiToProjectionVftablePtr; public static Guid IID => PIID; static IReadOnlyListMethods() { PIID = GuidGenerator.CreateIIDUnsafe(typeof(IReadOnlyList)); ComWrappersSupport.RegisterHelperType(typeof(global::System.Collections.Generic.IReadOnlyList), typeof(IReadOnlyList)); } public static int get_Count(IObjectReference obj) { uint num = IVectorViewMethods.get_Size(obj); if (int.MaxValue < num) { throw new InvalidOperationException(WinRTRuntimeErrorStrings.InvalidOperation_CollectionBackingListTooLarge); } return (int)num; } public static T Indexer_Get(IObjectReference obj, int index) { if (index < 0) { throw new ArgumentOutOfRangeException("index"); } try { return IVectorViewMethods.GetAt(obj, (uint)index); } catch (global::System.Exception ex) { if (-2147483637 == ex.HResult) { throw new ArgumentOutOfRangeException("index"); } throw; } } internal static bool TryInitCCWVtable(IntPtr ptr) { return Interlocked.CompareExchange(ref abiToProjectionVftablePtr, ptr, IntPtr.Zero) == IntPtr.Zero; } public static T Abi_GetAt_0(IntPtr thisPtr, uint index) { return IReadOnlyList.FindAdapter(thisPtr).GetAt(index); } public static bool Abi_IndexOf_2(IntPtr thisPtr, T value, out uint index) { return IReadOnlyList.FindAdapter(thisPtr).IndexOf(value, out index); } public static uint Abi_GetMany_3(IntPtr thisPtr, uint startIndex, ref T[] items) { return IReadOnlyList.FindAdapter(thisPtr).GetMany(startIndex, ref items); } public static uint Abi_get_Size_1(IntPtr thisPtr) { return IReadOnlyList.FindAdapter(thisPtr).Size; } } public static class IReadOnlyListMethods where TAbi : unmanaged { private sealed class DelegateHelper { internal unsafe static global::System.Type IndexOf_2_Type = Projections.GetAbiDelegateType(typeof(IntPtr), typeof(TAbi), typeof(uint*), typeof(byte*), typeof(int)); private readonly IntPtr _ptr; private Delegate _indexOfDelegate; public Delegate IndexOf => _indexOfDelegate ?? GenericDelegateHelper.CreateDelegate(_ptr, ref _indexOfDelegate, IndexOf_2_Type, 8); private DelegateHelper(IntPtr ptr) { _ptr = ptr; } public static DelegateHelper Get(IObjectReference obj) { return (DelegateHelper)GenericDelegateHelper.DelegateTable.GetValue(obj, (IObjectReference objRef) => new DelegateHelper(objRef.ThisPtr)); } } private static Delegate[] DelegateCache; public unsafe static bool InitRcwHelper(delegate* getAt, delegate* indexOf, delegate* getMany) { if (IVectorViewMethods._RcwHelperInitialized) { return true; } IVectorViewMethods._GetAt = getAt; IVectorViewMethods._IndexOf = indexOf; IVectorViewMethods._GetMany = getMany; ComWrappersSupport.RegisterTypedRcwFactory(typeof(global::System.Collections.Generic.IReadOnlyList), IReadOnlyListImpl.CreateRcw); ComWrappersSupport.RegisterHelperType(typeof(global::System.Collections.Generic.IReadOnlyList), typeof(IReadOnlyList)); IVectorViewMethods._RcwHelperInitialized = true; return true; } private unsafe static bool InitRcwHelperFallback() { return InitRcwHelper((delegate*)(&GetAtDynamic), (delegate*)(&IndexOfDynamic), (delegate*)null); } private unsafe static T GetAtDynamic(IObjectReference obj, uint index) { IntPtr thisPtr = obj.ThisPtr; TAbi val = default(TAbi); try { ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)6 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(thisPtr, index, &val)); GC.KeepAlive(obj); return Marshaler.FromAbi(val); } finally { Marshaler.DisposeAbi(val); } } private unsafe static bool IndexOfDynamic(IObjectReference obj, T value, out uint index) { IntPtr thisPtr = obj.ThisPtr; object obj2 = null; uint num = default(uint); byte b = default(byte); object[] array = new object[4] { thisPtr, null, (IntPtr)(&num), (IntPtr)(&b) }; try { obj2 = Marshaler.CreateMarshaler2(value); array[1] = Marshaler.GetAbi(obj2); DelegateHelper.Get(obj).IndexOf.DynamicInvokeAbi(array); GC.KeepAlive(obj); GC.KeepAlive(array); index = num; return b != 0; } finally { Marshaler.DisposeMarshaler(obj2); } } public unsafe static bool InitCcw(delegate* unmanaged[Stdcall] getAt, delegate* unmanaged[Stdcall] getSize, delegate* unmanaged[Stdcall] indexOf, delegate* unmanaged[Stdcall] getMany) { if (IReadOnlyListMethods.AbiToProjectionVftablePtr != (IntPtr)0) { return false; } IntPtr intPtr = (IntPtr)NativeMemory.AllocZeroed((nuint)(sizeof(IInspectable.Vftbl) + sizeof(IntPtr) * 4)); *(IInspectable.Vftbl*)(void*)intPtr = IInspectable.Vftbl.AbiToProjectionVftable; *(IntPtr*)((byte*)(void*)intPtr + (nint)6 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)getAt; *(IntPtr*)((byte*)(void*)intPtr + (nint)7 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)getSize; *(IntPtr*)((byte*)(void*)intPtr + (nint)8 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)indexOf; *(IntPtr*)((byte*)(void*)intPtr + (nint)9 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)getMany; if (!IReadOnlyListMethods.TryInitCCWVtable(intPtr)) { NativeMemory.Free((void*)intPtr); return false; } return true; } internal unsafe static void InitFallbackCCWVtable() { global::System.Type abiDelegateType = Projections.GetAbiDelegateType(typeof(IntPtr), typeof(uint), typeof(TAbi*), typeof(int)); DelegateCache = new Delegate[4] { Delegate.CreateDelegate(abiDelegateType, typeof(IReadOnlyListMethods).GetMethod("Do_Abi_GetAt_0", BindingFlags.Static | BindingFlags.NonPublic)), new _get_PropertyAsUInt32_Abi(Do_Abi_get_Size_1), Delegate.CreateDelegate(DelegateHelper.IndexOf_2_Type, typeof(IReadOnlyListMethods).GetMethod("Do_Abi_IndexOf_2", BindingFlags.Static | BindingFlags.NonPublic)), new IReadOnlyList_Delegates.GetMany_3_Abi(Do_Abi_GetMany_3) }; InitCcw((delegate* unmanaged[Stdcall])(void*)Marshal.GetFunctionPointerForDelegate(DelegateCache[0]), (delegate* unmanaged[Stdcall])(void*)Marshal.GetFunctionPointerForDelegate(DelegateCache[1]), (delegate* unmanaged[Stdcall])(void*)Marshal.GetFunctionPointerForDelegate(DelegateCache[2]), (delegate* unmanaged[Stdcall])(void*)Marshal.GetFunctionPointerForDelegate(DelegateCache[3])); } private unsafe static int Do_Abi_GetAt_0(IntPtr thisPtr, uint index, TAbi* __return_value__) { T val = default(T); *__return_value__ = default(TAbi); try { val = IReadOnlyList.FindAdapter(thisPtr).GetAt(index); *__return_value__ = (TAbi)Marshaler.FromManaged(val); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } private unsafe static int Do_Abi_IndexOf_2(IntPtr thisPtr, TAbi value, uint* index, byte* __return_value__) { bool flag = false; *index = 0u; *__return_value__ = 0; uint index2 = 0u; try { flag = IReadOnlyList.FindAdapter(thisPtr).IndexOf(Marshaler.FromAbi(value), out index2); *index = index2; *__return_value__ = (flag ? ((byte)1) : ((byte)0)); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } private unsafe static int Do_Abi_GetMany_3(IntPtr thisPtr, uint startIndex, int __itemsSize, IntPtr items, uint* __return_value__) { uint num = 0u; *__return_value__ = 0u; T[] items2 = Marshaler.FromAbiArray((__itemsSize, items)); try { num = IReadOnlyList.FindAdapter(thisPtr).GetMany(startIndex, ref items2); Marshaler.CopyManagedArray(items2, items); *__return_value__ = num; } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } private unsafe static int Do_Abi_get_Size_1(IntPtr thisPtr, uint* __return_value__) { uint num = 0u; *__return_value__ = 0u; try { num = IReadOnlyList.FindAdapter(thisPtr).Size; *__return_value__ = num; } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } } [DynamicInterfaceCastableImplementation] [Guid("BBE1FA4C-B0E3-4583-BAEF-1F1B2E483E56")] internal interface IReadOnlyList : global::System.Collections.Generic.IReadOnlyList, global::System.Collections.Generic.IEnumerable, global::System.Collections.IEnumerable, global::System.Collections.Generic.IReadOnlyCollection, IVectorView, global::Windows.Foundation.Collections.IIterable { public sealed class ToAbiHelper : IVectorView, global::Windows.Foundation.Collections.IIterable { private readonly global::System.Collections.Generic.IReadOnlyList _list; public uint Size => (uint)_list.Count; internal ToAbiHelper(global::System.Collections.Generic.IReadOnlyList list) { _list = list; } global::System.Collections.Generic.IEnumerator global::Windows.Foundation.Collections.IIterable.First() { return _list.GetEnumerator(); } private static void EnsureIndexInt32(uint index, int limit = int.MaxValue) { if (int.MaxValue <= index || index >= (uint)limit) { global::System.Exception ex = new ArgumentOutOfRangeException("index", WinRTRuntimeErrorStrings.ArgumentOutOfRange_IndexLargerThanMaxValue); ex.SetHResult(-2147483637); throw ex; } } public T GetAt(uint index) { EnsureIndexInt32(index, _list.Count); try { return _list[(int)index]; } catch (ArgumentOutOfRangeException ex) { ex.SetHResult(-2147483637); throw; } } public bool IndexOf(T value, out uint index) { int num = -1; int count = _list.Count; for (int i = 0; i < count; i++) { if (EqualityComparer.Default.Equals(value, _list[i])) { num = i; break; } } if (-1 == num) { index = 0u; return false; } index = (uint)num; return true; } public uint GetMany(uint startIndex, ref T[] items) { if (startIndex == _list.Count) { return 0u; } EnsureIndexInt32(startIndex, _list.Count); if (items == null) { return 0u; } uint num = Math.Min((uint)items.Length, (uint)_list.Count - startIndex); for (uint num2 = 0u; num2 < num; num2++) { items[num2] = _list[(int)(num2 + startIndex)]; } if (typeof(T) == typeof(string)) { string[] array = items as string[]; for (uint num3 = num; num3 < items.Length; num3++) { array[num3] = string.Empty; } } return num; } } [Guid("BBE1FA4C-B0E3-4583-BAEF-1F1B2E483E56")] public struct Vftbl { internal IInspectable.Vftbl IInspectableVftbl; public static readonly IntPtr AbiToProjectionVftablePtr = IReadOnlyList.AbiToProjectionVftablePtr; public static readonly Guid PIID = IReadOnlyList.PIID; } static readonly IntPtr AbiToProjectionVftablePtr; private static readonly ConditionalWeakTable, ToAbiHelper> _adapterTable; static readonly Guid PIID; int global::System.Collections.Generic.IReadOnlyCollection.Count { get { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.Generic.IReadOnlyList).TypeHandle); return IReadOnlyListMethods.get_Count(objectReferenceForType); } } T global::System.Collections.Generic.IReadOnlyList.this[int index] { get { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.Generic.IReadOnlyList).TypeHandle); return IReadOnlyListMethods.Indexer_Get(objectReferenceForType, index); } } static IObjectReference CreateMarshaler(global::System.Collections.Generic.IReadOnlyList obj) { if (obj != null) { return ComWrappersSupport.CreateCCWForObject(obj, PIID); } return null; } static ObjectReferenceValue CreateMarshaler2(global::System.Collections.Generic.IReadOnlyList obj) { return ComWrappersSupport.CreateCCWForObjectForMarshaling(obj, PIID); } static IntPtr GetAbi(IObjectReference objRef) { return objRef?.ThisPtr ?? IntPtr.Zero; } static IntPtr FromManaged(global::System.Collections.Generic.IReadOnlyList value) { if (value != null) { return CreateMarshaler2(value).Detach(); } return IntPtr.Zero; } static void DisposeMarshaler(IObjectReference objRef) { objRef?.Dispose(); } static void DisposeAbi(IntPtr abi) { MarshalInterfaceHelper>.DisposeAbi(abi); } static string GetGuidSignature() { return GuidGenerator.GetSignature(typeof(IReadOnlyList)); } static IReadOnlyList() { _adapterTable = new ConditionalWeakTable, ToAbiHelper>(); PIID = IReadOnlyListMethods.PIID; if (RuntimeFeature.IsDynamicCodeCompiled) { InitFallbackCCWVTableIfNeeded(); } AbiToProjectionVftablePtr = IReadOnlyListMethods.AbiToProjectionVftablePtr; [MethodImpl(MethodImplOptions.NoInlining)] [UnconditionalSuppressMessage("Trimming", "IL2080", Justification = "All ABI types never have a constructor that would need to be accessed via reflection.")] internal static void InitFallbackCCWVTableIfNeeded() { if (IReadOnlyListMethods.AbiToProjectionVftablePtr == (IntPtr)0) { Action action = (Action)typeof(IReadOnlyListMethods<, >).MakeGenericType(typeof(T), Marshaler.AbiType).GetMethod("InitFallbackCCWVtable", BindingFlags.Static | BindingFlags.NonPublic).CreateDelegate(typeof(Action)); action(); } } } internal static ToAbiHelper FindAdapter(IntPtr thisPtr) { global::System.Collections.Generic.IReadOnlyList key = ComWrappersSupport.FindObject>(thisPtr); return _adapterTable.GetValue(key, (global::System.Collections.Generic.IReadOnlyList list) => new ToAbiHelper(list)); } static ObjectReference ObjRefFromAbi(IntPtr thisPtr) { if (thisPtr == IntPtr.Zero) { return null; } return ObjectReference.FromAbi(thisPtr, PIID); } global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() { ((IWinRTObject)this).IsInterfaceImplemented(typeof(global::System.Collections.Generic.IEnumerable).TypeHandle, throwIfNotImplemented: true); IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.Generic.IEnumerable).TypeHandle); return IEnumerableMethods.GetEnumerator(objectReferenceForType); } IEnumerator global::System.Collections.IEnumerable.GetEnumerator() { return GetEnumerator(); } } public static class IReadOnlyList_Delegates { public delegate int GetMany_3(IntPtr thisPtr, uint startIndex, int __itemsSize, IntPtr items, out uint __return_value__); internal unsafe delegate int GetMany_3_Abi(IntPtr thisPtr, uint startIndex, int __itemsSize, IntPtr items, uint* __return_value__); } public static class KeyValuePairMethods { internal unsafe static volatile delegate* _GetKey; internal unsafe static volatile delegate* _GetValue; internal static volatile bool _RcwHelperInitialized; internal static readonly Guid PIID; private static IntPtr abiToProjectionVftablePtr; public static Guid IID => PIID; public static IntPtr AbiToProjectionVftablePtr => abiToProjectionVftablePtr; static KeyValuePairMethods() { PIID = GuidGenerator.CreateIIDUnsafe(typeof(KeyValuePair)); ComWrappersSupport.RegisterHelperType(typeof(global::System.Collections.Generic.KeyValuePair), typeof(KeyValuePair)); } internal static void EnsureInitialized() { if (!RuntimeFeature.IsDynamicCodeCompiled) { if (!_RcwHelperInitialized) { ThrowNotInitialized(); } } else { InitRcwHelperFallbackIfNeeded(); } [MethodImpl(MethodImplOptions.NoInlining)] [UnconditionalSuppressMessage("Trimming", "IL2080", Justification = "All ABI types never have a constructor that would need to be accessed via reflection.")] static void InitRcwHelperFallbackIfNeeded() { if (!_RcwHelperInitialized) { Func func = (Func)typeof(KeyValuePairMethods<, , , >).MakeGenericType(typeof(K), Marshaler.AbiType, typeof(V), Marshaler.AbiType).GetMethod("InitRcwHelperFallback", BindingFlags.Static | BindingFlags.NonPublic).CreateDelegate(typeof(Func)); func(); } } [DoesNotReturn] static void ThrowNotInitialized() { throw new NotImplementedException($"Type '{typeof(global::System.Collections.Generic.KeyValuePair)}' was called without initializing the RCW methods using 'KeyValuePairMethods.InitRcwHelper'. Ensure the 'InitRcwHelper' method is called."); } } internal unsafe static K GetKey(IObjectReference obj) { EnsureInitialized(); return _GetKey(obj); } internal unsafe static V GetValue(IObjectReference obj) { EnsureInitialized(); return _GetValue(obj); } internal static bool TryInitCCWVtable(IntPtr ptr) { return Interlocked.CompareExchange(ref abiToProjectionVftablePtr, ptr, IntPtr.Zero) == IntPtr.Zero; } public static K Abi_get_Key_0(IntPtr thisPtr) { return KeyValuePair.FindAdapter(thisPtr).Key; } public static V Abi_get_Value_1(IntPtr thisPtr) { return KeyValuePair.FindAdapter(thisPtr).Value; } } public static class KeyValuePairMethods where KAbi : unmanaged where VAbi : unmanaged { private static Delegate[] DelegateCache; public unsafe static bool InitRcwHelper(delegate* getKey, delegate* getValue) { if (KeyValuePairMethods._RcwHelperInitialized) { return true; } KeyValuePairMethods._GetKey = getKey; KeyValuePairMethods._GetValue = getValue; ComWrappersSupport.RegisterTypedRcwFactory(typeof(global::System.Collections.Generic.KeyValuePair), KeyValuePair.CreateRcw); KeyValuePairMethods._RcwHelperInitialized = true; return true; } private unsafe static bool InitRcwHelperFallback() { return InitRcwHelper((delegate*)(&get_Key), (delegate*)(&get_Value)); } private unsafe static K get_Key(IObjectReference obj) { IntPtr thisPtr = obj.ThisPtr; KAbi val = default(KAbi); try { ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)6 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(thisPtr, &val)); GC.KeepAlive(obj); return Marshaler.FromAbi(val); } finally { Marshaler.DisposeAbi(val); } } private unsafe static V get_Value(IObjectReference obj) { IntPtr thisPtr = obj.ThisPtr; VAbi val = default(VAbi); try { ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)7 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(thisPtr, &val)); GC.KeepAlive(obj); return Marshaler.FromAbi(val); } finally { Marshaler.DisposeAbi(val); } } public unsafe static bool InitCcw(delegate* unmanaged[Stdcall] getKey, delegate* unmanaged[Stdcall] getValue) { if (KeyValuePairMethods.AbiToProjectionVftablePtr != (IntPtr)0) { return false; } IntPtr intPtr = (IntPtr)NativeMemory.AllocZeroed((nuint)(sizeof(IInspectable.Vftbl) + sizeof(IntPtr) * 2)); *(IInspectable.Vftbl*)(void*)intPtr = IInspectable.Vftbl.AbiToProjectionVftable; *(IntPtr*)((byte*)(void*)intPtr + (nint)6 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)getKey; *(IntPtr*)((byte*)(void*)intPtr + (nint)7 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)getValue; if (!KeyValuePairMethods.TryInitCCWVtable(intPtr)) { NativeMemory.Free((void*)intPtr); return false; } KeyValuePairHelper.TryAddKeyValuePairCCW(typeof(global::System.Collections.Generic.KeyValuePair), KeyValuePairMethods.PIID, KeyValuePairMethods.AbiToProjectionVftablePtr); return true; } internal unsafe static void InitFallbackCCWVtable() { InitRcwHelperFallback(); global::System.Type abiDelegateType = Projections.GetAbiDelegateType(typeof(IntPtr), typeof(KAbi*), typeof(int)); global::System.Type abiDelegateType2 = Projections.GetAbiDelegateType(typeof(IntPtr), typeof(VAbi*), typeof(int)); DelegateCache = new Delegate[2] { Delegate.CreateDelegate(abiDelegateType, typeof(KeyValuePairMethods).GetMethod("Do_Abi_get_Key_0", BindingFlags.Static | BindingFlags.NonPublic)), Delegate.CreateDelegate(abiDelegateType2, typeof(KeyValuePairMethods).GetMethod("Do_Abi_get_Value_1", BindingFlags.Static | BindingFlags.NonPublic)) }; InitCcw((delegate* unmanaged[Stdcall])(void*)Marshal.GetFunctionPointerForDelegate(DelegateCache[0]), (delegate* unmanaged[Stdcall])(void*)Marshal.GetFunctionPointerForDelegate(DelegateCache[1])); } private unsafe static int Do_Abi_get_Key_0(IntPtr thisPtr, KAbi* __return_value__) { K val = default(K); *__return_value__ = default(KAbi); try { val = KeyValuePair.FindAdapter(thisPtr).Key; *__return_value__ = (KAbi)Marshaler.FromManaged(val); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } private unsafe static int Do_Abi_get_Value_1(IntPtr thisPtr, VAbi* __return_value__) { V val = default(V); *__return_value__ = default(VAbi); try { val = KeyValuePair.FindAdapter(thisPtr).Value; *__return_value__ = (VAbi)Marshaler.FromManaged(val); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } } [Guid("02B51929-C1C4-4A7E-8940-0312B5C18500")] public class KeyValuePair : IKeyValuePair { internal sealed class ToIKeyValuePair : IKeyValuePair { private readonly global::System.Collections.Generic.KeyValuePair _pair; public K Key => _pair.Key; public V Value => _pair.Value; public ToIKeyValuePair([In] ref global::System.Collections.Generic.KeyValuePair pair) { _pair = pair; } } internal struct Enumerator : global::System.Collections.Generic.IEnumerator>, IEnumerator, global::System.IDisposable { private readonly global::System.Collections.Generic.IEnumerator> _enum; public IKeyValuePair Current { get { global::System.Collections.Generic.KeyValuePair pair = _enum.Current; return new ToIKeyValuePair(ref pair); } } object IEnumerator.Current => Current; internal Enumerator(global::System.Collections.Generic.IEnumerator> enumerator) { _enum = enumerator; } public bool MoveNext() { return _enum.MoveNext(); } void IEnumerator.Reset() { _enum.Reset(); } public void Dispose() { } } [Guid("02B51929-C1C4-4A7E-8940-0312B5C18500")] public struct Vftbl { internal IInspectable.Vftbl IInspectableVftbl; public static readonly IntPtr AbiToProjectionVftablePtr = KeyValuePair.AbiToProjectionVftablePtr; public static readonly Guid PIID = KeyValuePair.PIID; } public static readonly IntPtr AbiToProjectionVftablePtr; private static readonly ConditionalWeakTable _adapterTable; public static readonly Guid PIID; protected readonly ObjectReference _obj; public IObjectReference ObjRef => _obj; public IntPtr ThisPtr => _obj.ThisPtr; public K Key => KeyValuePairMethods.GetKey(_obj); public V Value => KeyValuePairMethods.GetValue(_obj); public static IObjectReference CreateMarshaler(global::System.Collections.Generic.KeyValuePair obj) { return MarshalInterface>.CreateMarshaler(obj); } public static ObjectReferenceValue CreateMarshaler2(global::System.Collections.Generic.KeyValuePair obj) { return MarshalInterface>.CreateMarshaler2(obj); } public static IntPtr GetAbi(IObjectReference objRef) { return objRef?.ThisPtr ?? IntPtr.Zero; } public static object CreateRcw(IInspectable obj) { KeyValuePair keyValuePair = new KeyValuePair(obj.ObjRef); return new global::System.Collections.Generic.KeyValuePair(keyValuePair.Key, keyValuePair.Value); } public static global::System.Collections.Generic.KeyValuePair FromAbi(IntPtr thisPtr) { if (thisPtr == IntPtr.Zero) { return default(global::System.Collections.Generic.KeyValuePair); } KeyValuePair keyValuePair = new KeyValuePair(_FromAbi(thisPtr)); return new global::System.Collections.Generic.KeyValuePair(keyValuePair.Key, keyValuePair.Value); } public static IntPtr FromManaged(global::System.Collections.Generic.KeyValuePair obj) { return CreateMarshaler2(obj).Detach(); } internal unsafe static void CopyManaged(global::System.Collections.Generic.KeyValuePair o, IntPtr dest) { *(IntPtr*)dest.ToPointer() = CreateMarshaler2(o).Detach(); } internal static MarshalInterfaceHelper>.MarshalerArray CreateMarshalerArray(global::System.Collections.Generic.KeyValuePair[] array) { return MarshalInterfaceHelper>.CreateMarshalerArray2(array, (global::System.Collections.Generic.KeyValuePair o) => CreateMarshaler2(o)); } internal static (int length, IntPtr data) GetAbiArray(object box) { return MarshalInterfaceHelper>.GetAbiArray(box); } internal static global::System.Collections.Generic.KeyValuePair[] FromAbiArray(object box) { return MarshalInterfaceHelper>.FromAbiArray(box, (IntPtr o) => FromAbi(o)); } public static (int length, IntPtr data) FromManagedArray(global::System.Collections.Generic.KeyValuePair[] array) { return MarshalInterfaceHelper>.FromManagedArray(array, (global::System.Collections.Generic.KeyValuePair o) => FromManaged(o)); } internal static void CopyManagedArray(global::System.Collections.Generic.KeyValuePair[] array, IntPtr data) { MarshalInterfaceHelper>.CopyManagedArray(array, data, delegate(global::System.Collections.Generic.KeyValuePair o, IntPtr dest) { CopyManaged(o, dest); }); } public static void CopyAbiArray(global::System.Collections.Generic.KeyValuePair[] array, object box) { MarshalInterfaceHelper>.CopyAbiArray(array, box, FromAbi); } public static void DisposeMarshaler(IObjectReference value) { MarshalInterfaceHelper>.DisposeMarshaler(value); } public static void DisposeAbi(IntPtr abi) { MarshalInterfaceHelper>.DisposeAbi(abi); } public static string GetGuidSignature() { return GuidGenerator.GetSignature(typeof(KeyValuePair)); } static KeyValuePair() { _adapterTable = new ConditionalWeakTable(); PIID = KeyValuePairMethods.IID; if (RuntimeFeature.IsDynamicCodeCompiled) { InitFallbackCCWVTableIfNeeded(); } AbiToProjectionVftablePtr = KeyValuePairMethods.AbiToProjectionVftablePtr; [MethodImpl(MethodImplOptions.NoInlining)] [UnconditionalSuppressMessage("Trimming", "IL2080", Justification = "All ABI types never have a constructor that would need to be accessed via reflection.")] static void InitFallbackCCWVTableIfNeeded() { if (KeyValuePairMethods.AbiToProjectionVftablePtr == (IntPtr)0) { Action action = (Action)typeof(KeyValuePairMethods<, , , >).MakeGenericType(typeof(K), Marshaler.AbiType, typeof(V), Marshaler.AbiType).GetMethod("InitFallbackCCWVtable", BindingFlags.Static | BindingFlags.NonPublic).CreateDelegate(typeof(Action)); action(); } } } internal static ToIKeyValuePair FindAdapter(IntPtr thisPtr) { global::System.Collections.Generic.KeyValuePair __this = (global::System.Collections.Generic.KeyValuePair)ComWrappersSupport.FindObject(thisPtr); return _adapterTable.GetValue(__this, (object pair) => new ToIKeyValuePair(ref __this)); } public static ObjectReference _FromAbi(IntPtr thisPtr) { if (thisPtr == IntPtr.Zero) { return null; } return ObjectReference.FromAbi(thisPtr, PIID); } public KeyValuePair(IObjectReference obj) : this(obj.As(PIID)) { } public KeyValuePair(ObjectReference obj) { _obj = obj; } } } namespace ABI.WinRT { internal static class EventRegistrationToken { public static string GetGuidSignature() { return "struct(Windows.Foundation.EventRegistrationToken;i8)"; } } } namespace ABI.WinRT.Interop { [EditorBrowsable(EditorBrowsableState.Never)] public sealed class EventHandlerEventSource : EventSource { private sealed class EventState : EventSourceState { public EventState(IntPtr obj, int index) : base(obj, index) { } protected override global::System.EventHandler GetEventInvoke() { return delegate(object? obj, EventArgs e) { targetDelegate?.Invoke(obj, e); }; } } public unsafe EventHandlerEventSource(IObjectReference objectReference, delegate* unmanaged[Stdcall] addHandler, delegate* unmanaged[Stdcall] removeHandler) : base(objectReference, addHandler, removeHandler, 0) { } protected override ObjectReferenceValue CreateMarshaler(global::System.EventHandler del) { return ABI.System.EventHandler.CreateMarshaler2(del); } protected override EventSourceState CreateEventSourceState() { return new EventState(base.ObjectReference.ThisPtr, base.Index); } } [EditorBrowsable(EditorBrowsableState.Never)] public sealed class EventHandlerEventSource : EventSource> { private sealed class EventState : EventSourceState> { public EventState(IntPtr obj, int index) : base(obj, index) { } protected override global::System.EventHandler GetEventInvoke() { return delegate(object? obj, T e) { targetDelegate?.Invoke(obj, e); }; } } public unsafe EventHandlerEventSource(IObjectReference objectReference, delegate* unmanaged[Stdcall] addHandler, delegate* unmanaged[Stdcall] removeHandler, int index) : base(objectReference, addHandler, removeHandler, index) { } protected override ObjectReferenceValue CreateMarshaler(global::System.EventHandler del) { return ABI.System.EventHandler.CreateMarshaler2(del); } protected override EventSourceState> CreateEventSourceState() { return new EventState(base.ObjectReference.ThisPtr, base.Index); } } internal sealed class EventSourceCache { private static readonly ReaderWriterLockSlim cachesLock = new ReaderWriterLockSlim(); private static readonly ConcurrentDictionary caches = new ConcurrentDictionary(); private readonly ConcurrentDictionary> states = new ConcurrentDictionary>(); private global::WinRT.Interop.IWeakReference target; private EventSourceCache(global::WinRT.Interop.IWeakReference target, int index, WeakReference state) { this.target = target; SetState(index, state); } private EventSourceCache Update(global::WinRT.Interop.IWeakReference target, int index, WeakReference state) { lock (this) { using IObjectReference objectReference = this.target.Resolve(IID.IID_IUnknown); if (objectReference == null) { this.target = target; states.Clear(); } } SetState(index, state); return this; } private WeakReference GetState(int index) { lock (this) { using IObjectReference objectReference = target.Resolve(IID.IID_IUnknown); if (objectReference == null) { return null; } } if (states.TryGetValue(index, out var value)) { return value; } return null; } private void SetState(int index, WeakReference state) { states[index] = state; } public static void Create(IObjectReference obj, int index, WeakReference state) { global::WinRT.Interop.IWeakReference target = null; if (obj.TryAs(IID.IID_IWeakReferenceSource, out ObjectReference objRef) != 0) { return; } target = IWeakReferenceSourceMethods.GetWeakReference(objRef); cachesLock.EnterReadLock(); try { caches.AddOrUpdate(obj.ThisPtr, (IntPtr ThisPtr) => new EventSourceCache(target, index, state), (IntPtr ThisPtr, EventSourceCache cache) => cache.Update(target, index, state)); } finally { cachesLock.ExitReadLock(); } } public static WeakReference GetState(IObjectReference obj, int index) { if (caches.TryGetValue(obj.ThisPtr, out var value)) { return value.GetState(index); } return null; } public static void Remove(IntPtr thisPtr, int index, WeakReference state) { if (!caches.TryGetValue(thisPtr, out var value)) { return; } value.states.TryRemove(new global::System.Collections.Generic.KeyValuePair>(index, state)); if (!value.states.IsEmpty) { return; } cachesLock.EnterWriteLock(); try { if (value.states.IsEmpty) { caches.TryRemove(thisPtr, out var _); } } finally { cachesLock.ExitWriteLock(); } } } [EditorBrowsable(EditorBrowsableState.Never)] public abstract class EventSourceState : global::System.IDisposable where TDelegate : class, MulticastDelegate { private bool disposedValue; private readonly IntPtr obj; private readonly int index; private readonly WeakReference cacheEntry; private IntPtr eventInvokePtr; private IntPtr referenceTrackerTargetPtr; internal global::WinRT.EventRegistrationToken token; internal TDelegate? targetDelegate; internal TDelegate eventInvoke; protected TDelegate? TargetDelegate => targetDelegate; protected EventSourceState(IntPtr thisPtr, int index) { obj = thisPtr; this.index = index; eventInvoke = GetEventInvoke(); cacheEntry = new WeakReference(this); } ~EventSourceState() { Dispose(disposing: false); } protected abstract TDelegate GetEventInvoke(); protected virtual void Dispose(bool disposing) { if (!disposedValue) { EventSourceCache.Remove(obj, index, cacheEntry); disposedValue = true; } } public void Dispose() { GC.SuppressFinalize(this); Dispose(disposing: true); } internal WeakReference GetWeakReferenceForCache() { return cacheEntry; } internal void InitalizeReferenceTracking(IntPtr ptr) { eventInvokePtr = ptr; if (Marshal.QueryInterface(ptr, in Unsafe.AsRef(in IID.IID_IReferenceTrackerTarget), out referenceTrackerTargetPtr) != 0) { referenceTrackerTargetPtr = default(IntPtr); } else { Marshal.Release(referenceTrackerTargetPtr); } } internal unsafe bool HasComReferences() { if (eventInvokePtr != (IntPtr)0) { IUnknownVftbl unknownVftbl = *(*(IUnknownVftbl**)(void*)eventInvokePtr); unknownVftbl.AddRef(eventInvokePtr); if (unknownVftbl.Release(eventInvokePtr) != 0) { return true; } } if (referenceTrackerTargetPtr != (IntPtr)0) { void** ptr = *(void***)(void*)referenceTrackerTargetPtr; ((delegate* unmanaged[Stdcall])ptr[3])(referenceTrackerTargetPtr); if (((delegate* unmanaged[Stdcall])ptr[4])(referenceTrackerTargetPtr) != 0) { return true; } } return false; } } [EditorBrowsable(EditorBrowsableState.Never)] public abstract class EventSource where TDelegate : class, MulticastDelegate { private readonly IObjectReference _objectReference; private readonly int _index; private unsafe readonly delegate* unmanaged[Stdcall] _addHandler; private unsafe readonly delegate* unmanaged[Stdcall] _removeHandler; private WeakReference? _state; protected IObjectReference ObjectReference => _objectReference; protected int Index => _index; protected unsafe EventSource(IObjectReference objectReference, delegate* unmanaged[Stdcall] addHandler, delegate* unmanaged[Stdcall] removeHandler, int index = 0) { _objectReference = objectReference; _addHandler = addHandler; _removeHandler = removeHandler; _index = index; _state = EventSourceCache.GetState(objectReference, index); } protected abstract ObjectReferenceValue CreateMarshaler(TDelegate handler); protected abstract EventSourceState CreateEventSourceState(); public unsafe void Subscribe(TDelegate handler) { lock (this) { EventSourceState state = null; bool flag = !TryGetStateUnsafe(out state) || !state.HasComReferences(); if (flag) { state = CreateEventSourceState(); _state = state.GetWeakReferenceForCache(); EventSourceCache.Create(_objectReference, _index, _state); } state.targetDelegate = (TDelegate)Delegate.Combine(state.targetDelegate, handler); if (flag) { TDelegate eventInvoke = state.eventInvoke; ObjectReferenceValue objectReferenceValue = CreateMarshaler(eventInvoke); try { IntPtr abi = objectReferenceValue.GetAbi(); state.InitalizeReferenceTracking(abi); global::WinRT.EventRegistrationToken token = default(global::WinRT.EventRegistrationToken); ExceptionHelpers.ThrowExceptionForHR(_addHandler(_objectReference.ThisPtr, abi, &token)); GC.KeepAlive(_objectReference); state.token = token; return; } finally { objectReferenceValue.Dispose(); } } } } public void Unsubscribe(TDelegate handler) { if (_state == null || !TryGetStateUnsafe(out EventSourceState state)) { return; } lock (this) { TDelegate targetDelegate = state.targetDelegate; state.targetDelegate = (TDelegate)Delegate.Remove(state.targetDelegate, handler); if ((object)targetDelegate != null && (object)state.targetDelegate == null) { UnsubscribeFromNative(state); } } } private unsafe void UnsubscribeFromNative(EventSourceState state) { ExceptionHelpers.ThrowExceptionForHR(_removeHandler(_objectReference.ThisPtr, state.token)); GC.KeepAlive(_objectReference); state.Dispose(); _state = null; } [MethodImpl(MethodImplOptions.AggressiveInlining)] [MemberNotNullWhen(true, "_state")] private bool TryGetStateUnsafe([NotNullWhen(true)] out EventSourceState? state) { if (_state != null && _state.TryGetTarget(out object target)) { state = Unsafe.As>(target); return true; } state = null; return false; } } internal static class IRestrictedErrorInfoMethods { public unsafe static void GetErrorDetails(IntPtr thisPtr, out string description, out int error, out string restrictedDescription, out string capabilitySid) { IntPtr zero = IntPtr.Zero; IntPtr zero2 = IntPtr.Zero; IntPtr zero3 = IntPtr.Zero; try { fixed (int* ptr = &error) { Marshal.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)3 * (nint)sizeof(void*))))(thisPtr, &zero, ptr, &zero2, &zero3)); } description = ((zero != IntPtr.Zero) ? Marshal.PtrToStringBSTR(zero) : string.Empty); restrictedDescription = ((zero2 != IntPtr.Zero) ? Marshal.PtrToStringBSTR(zero2) : string.Empty); capabilitySid = ((zero3 != IntPtr.Zero) ? Marshal.PtrToStringBSTR(zero3) : string.Empty); } finally { Marshal.FreeBSTR(zero); Marshal.FreeBSTR(zero2); Marshal.FreeBSTR(zero3); } } public unsafe static void GetErrorDetails(IntPtr thisPtr, out int error) { IntPtr zero = IntPtr.Zero; IntPtr zero2 = IntPtr.Zero; IntPtr zero3 = IntPtr.Zero; try { fixed (int* ptr = &error) { Marshal.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)3 * (nint)sizeof(void*))))(thisPtr, &zero, ptr, &zero2, &zero3)); } } finally { Marshal.FreeBSTR(zero); Marshal.FreeBSTR(zero2); Marshal.FreeBSTR(zero3); } } public unsafe static string GetReference(IntPtr thisPtr) { IntPtr intPtr = default(IntPtr); try { Marshal.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)4 * (nint)sizeof(void*))))(thisPtr, &intPtr)); return (intPtr != IntPtr.Zero) ? Marshal.PtrToStringBSTR(intPtr) : string.Empty; } finally { Marshal.FreeBSTR(intPtr); } } } internal static class ILanguageExceptionErrorInfoMethods { public unsafe static IntPtr GetLanguageException(IntPtr thisPtr) { IntPtr zero = IntPtr.Zero; Marshal.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)3 * (nint)sizeof(void*))))(thisPtr, &zero)); return zero; } } internal static class ILanguageExceptionErrorInfo2Methods { public unsafe static IntPtr GetPreviousLanguageExceptionErrorInfo(IntPtr thisPtr) { IntPtr result = default(IntPtr); Marshal.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)4 * (nint)sizeof(void*))))(thisPtr, &result)); return result; } public unsafe static void CapturePropagationContext(IntPtr thisPtr, global::System.Exception ex) { IntPtr intPtr = ComWrappersSupport.CreateCCWForObjectUnsafe(ex); try { Marshal.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)5 * (nint)sizeof(void*))))(thisPtr, intPtr)); } finally { Marshal.Release(intPtr); } } public unsafe static IntPtr GetPropagationContextHead(IntPtr thisPtr) { IntPtr result = default(IntPtr); Marshal.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)6 * (nint)sizeof(void*))))(thisPtr, &result)); return result; } } internal struct IErrorInfoVftbl { public IUnknownVftbl IUnknownVftbl; public unsafe delegate* unmanaged[Stdcall] GetGuid_0; public unsafe delegate* unmanaged[Stdcall] GetSource_1; public unsafe delegate* unmanaged[Stdcall] GetDescription_2; public unsafe delegate* unmanaged[Stdcall] GetHelpFile_3; public unsafe delegate* unmanaged[Stdcall] GetHelpFileContent_4; public static readonly IErrorInfoVftbl AbiToProjectionVftable; public static readonly IntPtr AbiToProjectionVftablePtr; unsafe static IErrorInfoVftbl() { AbiToProjectionVftable = new IErrorInfoVftbl { IUnknownVftbl = IUnknownVftbl.AbiToProjectionVftbl, GetGuid_0 = (delegate* unmanaged[Stdcall])(delegate*)(&Do_Abi_GetGuid_0), GetSource_1 = (delegate* unmanaged[Stdcall])(delegate*)(&Do_Abi_GetSource_1), GetDescription_2 = (delegate* unmanaged[Stdcall])(delegate*)(&Do_Abi_GetDescription_2), GetHelpFile_3 = (delegate* unmanaged[Stdcall])(delegate*)(&Do_Abi_GetHelpFile_3), GetHelpFileContent_4 = (delegate* unmanaged[Stdcall])(delegate*)(&Do_Abi_GetHelpFileContent_4) }; IntPtr* ptr = (IntPtr*)(void*)Marshal.AllocCoTaskMem(sizeof(IErrorInfoVftbl)); *(IErrorInfoVftbl*)ptr = AbiToProjectionVftable; AbiToProjectionVftablePtr = (IntPtr)ptr; } [UnmanagedCallersOnly(CallConvs = new global::System.Type[] { typeof(CallConvStdcall) })] private unsafe static int Do_Abi_GetGuid_0(IntPtr thisPtr, Guid* guid) { try { *guid = ComWrappersSupport.FindObject(thisPtr).GetGuid(); } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly(CallConvs = new global::System.Type[] { typeof(CallConvStdcall) })] private unsafe static int Do_Abi_GetSource_1(IntPtr thisPtr, IntPtr* source) { *source = IntPtr.Zero; try { string source2 = ComWrappersSupport.FindObject(thisPtr).GetSource(); *source = Marshal.StringToBSTR(source2); } catch (global::System.Exception ex) { Marshal.FreeBSTR(*source); ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly(CallConvs = new global::System.Type[] { typeof(CallConvStdcall) })] private unsafe static int Do_Abi_GetDescription_2(IntPtr thisPtr, IntPtr* description) { *description = IntPtr.Zero; try { string description2 = ComWrappersSupport.FindObject(thisPtr).GetDescription(); *description = Marshal.StringToBSTR(description2); } catch (global::System.Exception ex) { Marshal.FreeBSTR(*description); ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly(CallConvs = new global::System.Type[] { typeof(CallConvStdcall) })] private unsafe static int Do_Abi_GetHelpFile_3(IntPtr thisPtr, IntPtr* helpFile) { *helpFile = IntPtr.Zero; try { string helpFile2 = ComWrappersSupport.FindObject(thisPtr).GetHelpFile(); *helpFile = Marshal.StringToBSTR(helpFile2); } catch (global::System.Exception ex) { Marshal.FreeBSTR(*helpFile); ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } [UnmanagedCallersOnly(CallConvs = new global::System.Type[] { typeof(CallConvStdcall) })] private unsafe static int Do_Abi_GetHelpFileContent_4(IntPtr thisPtr, IntPtr* helpFileContent) { *helpFileContent = IntPtr.Zero; try { string helpFileContent2 = ComWrappersSupport.FindObject(thisPtr).GetHelpFileContent(); *helpFileContent = Marshal.StringToBSTR(helpFileContent2); } catch (global::System.Exception ex) { Marshal.FreeBSTR(*helpFileContent); ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } } internal struct ISupportErrorInfoVftbl { public IUnknownVftbl IUnknownVftbl; public unsafe delegate* unmanaged[Stdcall] InterfaceSupportsErrorInfo_0; public static readonly ISupportErrorInfoVftbl AbiToProjectionVftable; public static readonly IntPtr AbiToProjectionVftablePtr; unsafe static ISupportErrorInfoVftbl() { AbiToProjectionVftable = new ISupportErrorInfoVftbl { IUnknownVftbl = IUnknownVftbl.AbiToProjectionVftbl, InterfaceSupportsErrorInfo_0 = (delegate* unmanaged[Stdcall])(delegate*)(&Do_Abi_InterfaceSupportsErrorInfo_0) }; IntPtr* ptr = (IntPtr*)(void*)Marshal.AllocCoTaskMem(sizeof(ISupportErrorInfoVftbl)); *(ISupportErrorInfoVftbl*)ptr = AbiToProjectionVftable; AbiToProjectionVftablePtr = (IntPtr)ptr; } [UnmanagedCallersOnly(CallConvs = new global::System.Type[] { typeof(CallConvStdcall) })] private unsafe static int Do_Abi_InterfaceSupportsErrorInfo_0(IntPtr thisPtr, Guid* guid) { try { return (!ComWrappersSupport.FindObject(thisPtr).InterfaceSupportsErrorInfo(*guid)) ? 1 : 0; } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } } } public static class IActivationFactoryMethods { public static Guid IID => global::WinRT.Interop.IID.IID_IActivationFactory; public static IntPtr AbiToProjectionVftablePtr => IActivationFactory.Vftbl.AbiToProjectionVftablePtr; [EditorBrowsable(EditorBrowsableState.Never)] public unsafe static IObjectReference ActivateInstanceUnsafe(IObjectReference objectReference, Guid iid) { IntPtr thisPtr = objectReference.ThisPtr; IntPtr intPtr = default(IntPtr); ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)6 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(thisPtr, &intPtr)); GC.KeepAlive(objectReference); try { return ComWrappersSupport.GetObjectReferenceForInterface(intPtr, iid, requireQI: true); } finally { MarshalInspectable.DisposeAbi(intPtr); } } } [Guid("00000035-0000-0000-C000-000000000046")] public class IActivationFactory : global::WinRT.Interop.IActivationFactory { [Guid("00000035-0000-0000-C000-000000000046")] public struct Vftbl { internal IInspectable.Vftbl IInspectableVftbl; public unsafe delegate* unmanaged[Stdcall] ActivateInstance_0; public static readonly IntPtr AbiToProjectionVftablePtr; unsafe static Vftbl() { AbiToProjectionVftablePtr = ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), sizeof(IInspectable.Vftbl) + sizeof(IntPtr)); *(Vftbl*)(void*)AbiToProjectionVftablePtr = new Vftbl { IInspectableVftbl = IInspectable.Vftbl.AbiToProjectionVftable, ActivateInstance_0 = (delegate* unmanaged[Stdcall])(delegate*)(&Do_Abi_ActivateInstance_0) }; } [UnmanagedCallersOnly(CallConvs = new global::System.Type[] { typeof(CallConvStdcall) })] private unsafe static int Do_Abi_ActivateInstance_0(IntPtr thisPtr, IntPtr* result) { IntPtr intPtr = default(IntPtr); *result = default(IntPtr); try { intPtr = ComWrappersSupport.FindObject(thisPtr).ActivateInstance(); *result = intPtr; } catch (global::System.Exception ex) { ExceptionHelpers.SetErrorInfo(ex); return ExceptionHelpers.GetHRForException(ex); } return 0; } } protected readonly ObjectReference _obj; public IObjectReference ObjRef => _obj; public IntPtr ThisPtr => _obj.ThisPtr; public IActivationFactory(IObjectReference obj) { _obj = obj.As(IID.IID_IActivationFactory); } public unsafe IntPtr ActivateInstance() { IntPtr result = default(IntPtr); IntPtr thisPtr = ThisPtr; Marshal.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)6 * (nint)sizeof(void*))))(thisPtr, &result)); return result; } } internal static class IAgileReferenceMethods { public unsafe static IObjectReference Resolve(IObjectReference _obj, Guid riid) { if (_obj == null) { return null; } IntPtr thisPtr = _obj.ThisPtr; IntPtr zero = IntPtr.Zero; ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)3 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(thisPtr, &riid, &zero)); GC.KeepAlive(_obj); try { return ComWrappersSupport.GetObjectReferenceForInterface(zero, riid, requireQI: false); } finally { MarshalInspectable.DisposeAbi(zero); } } public unsafe static ObjectReference Resolve(IObjectReference _obj, Guid riid) { if (_obj == null) { return null; } IntPtr thisPtr = _obj.ThisPtr; IntPtr zero = IntPtr.Zero; ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)3 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(thisPtr, &riid, &zero)); GC.KeepAlive(_obj); try { return ComWrappersSupport.GetObjectReferenceForInterface(zero, riid, requireQI: false); } finally { MarshalInspectable.DisposeAbi(zero); } } } [DynamicInterfaceCastableImplementation] [Guid("C03F6A43-65A4-9818-987E-E0B810D2A6F2")] internal interface IAgileReference : global::WinRT.Interop.IAgileReference { static IntPtr AbiToProjectionVftablePtr; unsafe static IAgileReference() { AbiToProjectionVftablePtr = ComWrappersSupport.AllocateVtableMemory(typeof(IAgileReference), sizeof(IUnknownVftbl) + sizeof(IntPtr)); *(IUnknownVftbl*)(void*)AbiToProjectionVftablePtr = IUnknownVftbl.AbiToProjectionVftbl; *(IntPtr*)((byte*)(void*)AbiToProjectionVftablePtr + (nint)3 * (nint)sizeof(delegate* unmanaged)) = (nint)(delegate*)(&Do_Abi_Resolve); } [UnmanagedCallersOnly] private unsafe static int Do_Abi_Resolve(IntPtr thisPtr, Guid* riid, IntPtr* objectReference) { IObjectReference objectReference2 = null; *objectReference = default(IntPtr); try { *objectReference = ComWrappersSupport.FindObject(thisPtr).Resolve(*riid)?.GetRef() ?? IntPtr.Zero; } catch (global::System.Exception ex) { return ex.HResult; } return 0; } IObjectReference global::WinRT.Interop.IAgileReference.Resolve(Guid riid) { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::WinRT.Interop.IAgileReference).TypeHandle); return IAgileReferenceMethods.Resolve(objectReferenceForType, riid); } } [DynamicInterfaceCastableImplementation] [Guid("94ea2b94-e9cc-49e0-c0ff-ee64ca8f5b90")] internal interface IAgileObject : global::WinRT.Interop.IAgileObject { static IntPtr AbiToProjectionVftablePtr; unsafe static IAgileObject() { AbiToProjectionVftablePtr = ComWrappersSupport.AllocateVtableMemory(typeof(IAgileObject), sizeof(IUnknownVftbl)); *(IUnknownVftbl*)(void*)AbiToProjectionVftablePtr = IUnknownVftbl.AbiToProjectionVftbl; } } [Guid("00000146-0000-0000-C000-000000000046")] internal sealed class IGlobalInterfaceTable { private readonly ObjectReference _obj; public IntPtr ThisPtr => _obj.ThisPtr; public static ObjectReference FromAbi(IntPtr thisPtr) { return ObjectReference.FromAbi(thisPtr, IID.IID_IGlobalInterfaceTable); } public IGlobalInterfaceTable(IntPtr thisPtr) { _obj = ObjectReference.FromAbi(thisPtr, IID.IID_IGlobalInterfaceTable); } public unsafe IntPtr RegisterInterfaceInGlobal(IntPtr ptr, Guid riid) { IntPtr thisPtr = ThisPtr; IntPtr result = default(IntPtr); Marshal.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)3 * (nint)sizeof(void*))))(thisPtr, ptr, &riid, &result)); GC.KeepAlive(_obj); return result; } public unsafe void TryRevokeInterfaceFromGlobal(IntPtr cookie) { IntPtr thisPtr = ThisPtr; int num = ((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)4 * (nint)sizeof(void*))))(thisPtr, cookie); GC.KeepAlive(_obj); if (num != -2147024809) { Marshal.ThrowExceptionForHR(num); } } public unsafe IObjectReference GetInterfaceFromGlobal(IntPtr cookie, Guid riid) { IntPtr thisPtr = ThisPtr; IntPtr intPtr = default(IntPtr); Marshal.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)5 * (nint)sizeof(void*))))(thisPtr, cookie, &riid, &intPtr)); GC.KeepAlive(_obj); try { return ComWrappersSupport.GetObjectReferenceForInterface(intPtr, riid, requireQI: false); } finally { MarshalInspectable.DisposeAbi(intPtr); } } } internal struct ComCallData { public int dwDispid; public int dwReserved; public IntPtr pUserDefined; } internal struct CallbackData { public unsafe delegate* Callback; public object State; } internal struct IContextCallbackVftbl { private IUnknownVftbl IUnknownVftbl; private unsafe delegate* unmanaged[Stdcall] ContextCallback_4; public unsafe static void ContextCallback(IntPtr contextCallbackPtr, delegate* callback, delegate* onFailCallback, object state) { ComCallData comCallData = default(ComCallData); comCallData.dwDispid = 0; comCallData.dwReserved = 0; CallbackData callbackData = default(CallbackData); callbackData.Callback = callback; callbackData.State = state; comCallData.pUserDefined = (IntPtr)(&callbackData); Guid iID_ICallbackWithNoReentrancyToApplicationSTA = IID.IID_ICallbackWithNoReentrancyToApplicationSTA; int num = (*(IContextCallbackVftbl**)(void*)contextCallbackPtr)->ContextCallback_4(contextCallbackPtr, (IntPtr)(delegate*)(&InvokeCallback), &comCallData, &iID_ICallbackWithNoReentrancyToApplicationSTA, 5, IntPtr.Zero); if (num < 0 && onFailCallback != (delegate*)null) { onFailCallback(state); } [UnmanagedCallersOnly] static unsafe int InvokeCallback(ComCallData* ptr2) { try { CallbackData* ptr = (CallbackData*)(void*)ptr2->pUserDefined; ptr->Callback(ptr->State); return 0; } catch (global::System.Exception ex) { return ex.HResult; } } } } [Guid("00000003-0000-0000-c000-000000000046")] internal sealed class IMarshal { [Guid("00000003-0000-0000-c000-000000000046")] public struct Vftbl { internal IUnknownVftbl IUnknownVftbl; public unsafe delegate* unmanaged[Stdcall] GetUnmarshalClass_0; public unsafe delegate* unmanaged[Stdcall] GetMarshalSizeMax_1; public unsafe delegate* unmanaged[Stdcall] MarshalInterface_2; public unsafe delegate* unmanaged[Stdcall] UnmarshalInterface_3; public unsafe delegate* unmanaged[Stdcall] ReleaseMarshalData_4; public unsafe delegate* unmanaged[Stdcall] DisconnectObject_5; public static readonly IntPtr AbiToProjectionVftablePtr; [ThreadStatic] private static IMarshal t_freeThreadedMarshaler; unsafe static Vftbl() { AbiToProjectionVftablePtr = ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), sizeof(IUnknownVftbl) + sizeof(IntPtr) * 6); *(Vftbl*)(void*)AbiToProjectionVftablePtr = new Vftbl { IUnknownVftbl = IUnknownVftbl.AbiToProjectionVftbl, GetUnmarshalClass_0 = (delegate* unmanaged[Stdcall])(delegate*)(&Do_Abi_GetUnmarshalClass_0), GetMarshalSizeMax_1 = (delegate* unmanaged[Stdcall])(delegate*)(&Do_Abi_GetMarshalSizeMax_1), MarshalInterface_2 = (delegate* unmanaged[Stdcall])(delegate*)(&Do_Abi_MarshalInterface_2), UnmarshalInterface_3 = (delegate* unmanaged[Stdcall])(delegate*)(&Do_Abi_UnmarshalInterface_3), ReleaseMarshalData_4 = (delegate* unmanaged[Stdcall])(delegate*)(&Do_Abi_ReleaseMarshalData_4), DisconnectObject_5 = (delegate* unmanaged[Stdcall])(delegate*)(&Do_Abi_DisconnectObject_5) }; } private unsafe static void EnsureHasFreeThreadedMarshaler() { if (t_freeThreadedMarshaler != null) { return; } try { IntPtr thisPtr = default(IntPtr); Marshal.ThrowExceptionForHR(Platform.CoCreateFreeThreadedMarshaler(IntPtr.Zero, &thisPtr)); using ObjectReference obj = ObjectReference.Attach(ref thisPtr, IID.IID_IUnknown); IMarshal marshal = new IMarshal(obj); t_freeThreadedMarshaler = marshal; } catch (DllNotFoundException inner) { throw new NotImplementedException(string.Format("A native library routine was not found: {0}.", "CoCreateFreeThreadedMarshaler"), inner); } } internal unsafe static Guid GetInProcFreeThreadedMarshalerIID() { EnsureHasFreeThreadedMarshaler(); Guid iID_IUnknown = IID.IID_IUnknown; Guid result = default(Guid); t_freeThreadedMarshaler.GetUnmarshalClass(&iID_IUnknown, IntPtr.Zero, MSHCTX.InProc, IntPtr.Zero, MSHLFLAGS.Normal, &result); return result; } [UnmanagedCallersOnly(CallConvs = new global::System.Type[] { typeof(CallConvStdcall) })] private unsafe static int Do_Abi_GetUnmarshalClass_0(IntPtr thisPtr, Guid* riid, IntPtr pv, MSHCTX dwDestContext, IntPtr pvDestContext, MSHLFLAGS mshlFlags, Guid* pCid) { *pCid = default(Guid); try { EnsureHasFreeThreadedMarshaler(); t_freeThreadedMarshaler.GetUnmarshalClass(riid, pv, dwDestContext, pvDestContext, mshlFlags, pCid); } catch (global::System.Exception e) { return Marshal.GetHRForException(e); } return 0; } [UnmanagedCallersOnly(CallConvs = new global::System.Type[] { typeof(CallConvStdcall) })] private unsafe static int Do_Abi_GetMarshalSizeMax_1(IntPtr thisPtr, Guid* riid, IntPtr pv, MSHCTX dwDestContext, IntPtr pvDestContext, MSHLFLAGS mshlflags, uint* pSize) { *pSize = 0u; try { EnsureHasFreeThreadedMarshaler(); t_freeThreadedMarshaler.GetMarshalSizeMax(riid, pv, dwDestContext, pvDestContext, mshlflags, pSize); } catch (global::System.Exception e) { return Marshal.GetHRForException(e); } return 0; } [UnmanagedCallersOnly(CallConvs = new global::System.Type[] { typeof(CallConvStdcall) })] private unsafe static int Do_Abi_MarshalInterface_2(IntPtr thisPtr, IntPtr pStm, Guid* riid, IntPtr pv, MSHCTX dwDestContext, IntPtr pvDestContext, MSHLFLAGS mshlflags) { try { EnsureHasFreeThreadedMarshaler(); t_freeThreadedMarshaler.MarshalInterface(pStm, riid, pv, dwDestContext, pvDestContext, mshlflags); } catch (global::System.Exception e) { return Marshal.GetHRForException(e); } return 0; } [UnmanagedCallersOnly(CallConvs = new global::System.Type[] { typeof(CallConvStdcall) })] private unsafe static int Do_Abi_UnmarshalInterface_3(IntPtr thisPtr, IntPtr pStm, Guid* riid, IntPtr* ppv) { *ppv = default(IntPtr); try { EnsureHasFreeThreadedMarshaler(); t_freeThreadedMarshaler.UnmarshalInterface(pStm, riid, ppv); } catch (global::System.Exception e) { return Marshal.GetHRForException(e); } return 0; } [UnmanagedCallersOnly(CallConvs = new global::System.Type[] { typeof(CallConvStdcall) })] private static int Do_Abi_ReleaseMarshalData_4(IntPtr thisPtr, IntPtr pStm) { try { EnsureHasFreeThreadedMarshaler(); t_freeThreadedMarshaler.ReleaseMarshalData(pStm); } catch (global::System.Exception e) { return Marshal.GetHRForException(e); } return 0; } [UnmanagedCallersOnly(CallConvs = new global::System.Type[] { typeof(CallConvStdcall) })] private static int Do_Abi_DisconnectObject_5(IntPtr thisPtr, uint dwReserved) { try { EnsureHasFreeThreadedMarshaler(); t_freeThreadedMarshaler.DisconnectObject(dwReserved); } catch (global::System.Exception e) { return Marshal.GetHRForException(e); } return 0; } } private const string NotImplemented_NativeRoutineNotFound = "A native library routine was not found: {0}."; private static readonly object _IID_InProcFreeThreadedMarshalerLock = new object(); internal static volatile object _IID_InProcFreeThreadedMarshaler; private readonly ObjectReference _obj; internal static Guid IID_InProcFreeThreadedMarshaler { get { object iID_InProcFreeThreadedMarshaler = _IID_InProcFreeThreadedMarshaler; if (iID_InProcFreeThreadedMarshaler != null) { return (Guid)iID_InProcFreeThreadedMarshaler; } return IID_InProcFreeThreadedMarshaler_Slow(); [MethodImpl(MethodImplOptions.NoInlining)] static Guid IID_InProcFreeThreadedMarshaler_Slow() { lock (_IID_InProcFreeThreadedMarshalerLock) { return (Guid)(_IID_InProcFreeThreadedMarshaler ?? (_IID_InProcFreeThreadedMarshaler = Vftbl.GetInProcFreeThreadedMarshalerIID())); } } } } public IObjectReference ObjRef => _obj; public IntPtr ThisPtr => _obj.ThisPtr; public IMarshal(IObjectReference obj) { _obj = obj.As(IID.IID_IMarshal); } public unsafe void GetUnmarshalClass(Guid* riid, IntPtr pv, MSHCTX dwDestContext, IntPtr pvDestContext, MSHLFLAGS mshlFlags, Guid* pCid) { IntPtr thisPtr = ThisPtr; Marshal.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)3 * (nint)sizeof(void*))))(thisPtr, riid, pv, dwDestContext, pvDestContext, mshlFlags, pCid)); GC.KeepAlive(_obj); } public unsafe void GetMarshalSizeMax(Guid* riid, IntPtr pv, MSHCTX dwDestContext, IntPtr pvDestContext, MSHLFLAGS mshlflags, uint* pSize) { IntPtr thisPtr = ThisPtr; Marshal.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)4 * (nint)sizeof(void*))))(thisPtr, riid, pv, dwDestContext, pvDestContext, mshlflags, pSize)); GC.KeepAlive(_obj); } public unsafe void MarshalInterface(IntPtr pStm, Guid* riid, IntPtr pv, MSHCTX dwDestContext, IntPtr pvDestContext, MSHLFLAGS mshlflags) { IntPtr thisPtr = ThisPtr; Marshal.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)5 * (nint)sizeof(void*))))(thisPtr, pStm, riid, pv, dwDestContext, pvDestContext, mshlflags)); GC.KeepAlive(_obj); } public unsafe void UnmarshalInterface(IntPtr pStm, Guid* riid, IntPtr* ppv) { IntPtr thisPtr = ThisPtr; Marshal.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)6 * (nint)sizeof(void*))))(thisPtr, pStm, riid, ppv)); GC.KeepAlive(_obj); } public unsafe void ReleaseMarshalData(IntPtr pStm) { IntPtr thisPtr = ThisPtr; Marshal.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)7 * (nint)sizeof(void*))))(thisPtr, pStm)); GC.KeepAlive(_obj); } public unsafe void DisconnectObject(uint dwReserved) { IntPtr thisPtr = ThisPtr; Marshal.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)8 * (nint)sizeof(void*))))(thisPtr, dwReserved)); GC.KeepAlive(_obj); } } public static class IWeakReferenceSourceMethods { public unsafe static global::WinRT.Interop.IWeakReference GetWeakReference(IObjectReference _obj) { IntPtr thisPtr = _obj.ThisPtr; IntPtr zero = IntPtr.Zero; try { ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)3 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(thisPtr, &zero)); GC.KeepAlive(_obj); return MarshalInterface.FromAbi(zero); } finally { MarshalInspectable.DisposeAbi(zero); } } } [DynamicInterfaceCastableImplementation] [Guid("00000038-0000-0000-C000-000000000046")] internal interface IWeakReferenceSource : global::WinRT.Interop.IWeakReferenceSource { static IntPtr AbiToProjectionVftablePtr; unsafe static IWeakReferenceSource() { AbiToProjectionVftablePtr = ComWrappersSupport.AllocateVtableMemory(typeof(IWeakReferenceSource), sizeof(IUnknownVftbl) + sizeof(IntPtr)); *(IUnknownVftbl*)(void*)AbiToProjectionVftablePtr = IUnknownVftbl.AbiToProjectionVftbl; *(IntPtr*)((byte*)(void*)AbiToProjectionVftablePtr + (nint)3 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)(delegate*)(&Do_Abi_GetWeakReference); } [UnmanagedCallersOnly(CallConvs = new global::System.Type[] { typeof(CallConvStdcall) })] private unsafe static int Do_Abi_GetWeakReference(IntPtr thisPtr, IntPtr* weakReference) { *weakReference = default(IntPtr); try { *weakReference = ComWrappersSupport.CreateCCWForObjectForABI(new ManagedWeakReference(ComWrappersSupport.FindObject(thisPtr)), IID.IID_IWeakReference); } catch (global::System.Exception ex) { return ex.HResult; } return 0; } global::WinRT.Interop.IWeakReference global::WinRT.Interop.IWeakReferenceSource.GetWeakReference() { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::WinRT.Interop.IWeakReferenceSource).TypeHandle); return IWeakReferenceSourceMethods.GetWeakReference(objectReferenceForType); } } [DynamicInterfaceCastableImplementation] [Guid("00000037-0000-0000-C000-000000000046")] internal interface IWeakReference : global::WinRT.Interop.IWeakReference { static IntPtr AbiToProjectionVftablePtr; unsafe static IWeakReference() { AbiToProjectionVftablePtr = ComWrappersSupport.AllocateVtableMemory(typeof(IWeakReference), sizeof(IUnknownVftbl) + sizeof(IntPtr)); *(IUnknownVftbl*)(void*)AbiToProjectionVftablePtr = IUnknownVftbl.AbiToProjectionVftbl; *(IntPtr*)((byte*)(void*)AbiToProjectionVftablePtr + (nint)3 * (nint)sizeof(delegate* unmanaged[Stdcall])) = (nint)(delegate*)(&Do_Abi_Resolve); } [UnmanagedCallersOnly(CallConvs = new global::System.Type[] { typeof(CallConvStdcall) })] private unsafe static int Do_Abi_Resolve(IntPtr thisPtr, Guid* riid, IntPtr* objectReference) { *objectReference = default(IntPtr); try { global::WinRT.Interop.IWeakReference weakReference = ComWrappersSupport.FindObject(thisPtr); if (weakReference is ManagedWeakReference managedWeakReference) { *objectReference = managedWeakReference.ResolveForABI(*riid); } else { using IObjectReference objectReference2 = weakReference.Resolve(*riid); *objectReference = objectReference2?.GetRef() ?? IntPtr.Zero; } } catch (global::System.Exception ex) { return ex.HResult; } return 0; } unsafe IObjectReference global::WinRT.Interop.IWeakReference.Resolve(Guid riid) { IObjectReference objectReferenceForType = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::WinRT.Interop.IWeakReference).TypeHandle); IntPtr thisPtr = objectReferenceForType.ThisPtr; IntPtr intPtr = default(IntPtr); ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)3 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(thisPtr, &riid, &intPtr)); GC.KeepAlive(objectReferenceForType); try { return ComWrappersSupport.GetObjectReferenceForInterface(intPtr, riid, requireQI: false); } finally { MarshalInspectable.DisposeAbi(intPtr); } } } } namespace System.Collections.Generic { internal sealed class IDictionaryImpl : IDictionary, ICollection>, IEnumerable>, IEnumerable, IWinRTObject, IDynamicInterfaceCastable { private readonly IObjectReference _inner; private volatile IObjectReference __iDictionaryObjRef; private volatile IObjectReference __iEnumerableObjRef; private volatile ConcurrentDictionary _queryInterfaceCache; private volatile ConcurrentDictionary _additionalTypeData; private IObjectReference iDictionaryObjRef => __iDictionaryObjRef ?? Make_IDictionaryObjRef(); private IObjectReference iEnumerableObjRef => __iEnumerableObjRef ?? Make_IEnumerableObjRef(); IObjectReference IWinRTObject.NativeObject => _inner; bool IWinRTObject.HasUnwrappableNativeObject => true; ConcurrentDictionary IWinRTObject.QueryInterfaceCache => _queryInterfaceCache ?? MakeQueryInterfaceCache(); ConcurrentDictionary IWinRTObject.AdditionalTypeData => _additionalTypeData ?? MakeAdditionalTypeData(); public V this[K key] { get { return IDictionaryMethods.Indexer_Get(iDictionaryObjRef, null, key); } set { IDictionaryMethods.Indexer_Set(iDictionaryObjRef, key, value); } } public ICollection Keys => IDictionaryMethods.get_Keys(iDictionaryObjRef); public ICollection Values => IDictionaryMethods.get_Values(iDictionaryObjRef); public int Count => IDictionaryMethods.get_Count(iDictionaryObjRef); public bool IsReadOnly => IDictionaryMethods.get_IsReadOnly(iDictionaryObjRef); internal IDictionaryImpl(IObjectReference _inner) { this._inner = _inner; } public static IDictionaryImpl CreateRcw(IInspectable obj) { return new IDictionaryImpl(obj.ObjRef); } private IObjectReference Make_IDictionaryObjRef() { Interlocked.CompareExchange(ref __iDictionaryObjRef, _inner.As(IDictionaryMethods.PIID), null); return __iDictionaryObjRef; } private IObjectReference Make_IEnumerableObjRef() { Interlocked.CompareExchange(ref __iEnumerableObjRef, _inner.As(IEnumerableMethods>.PIID), null); return __iEnumerableObjRef; } private ConcurrentDictionary MakeQueryInterfaceCache() { Interlocked.CompareExchange(ref _queryInterfaceCache, new ConcurrentDictionary(), null); return _queryInterfaceCache; } private ConcurrentDictionary MakeAdditionalTypeData() { Interlocked.CompareExchange(ref _additionalTypeData, new ConcurrentDictionary(), null); return _additionalTypeData; } public void Add(K key, V value) { IDictionaryMethods.Add(iDictionaryObjRef, key, value); } public void Add(KeyValuePair item) { IDictionaryMethods.Add(iDictionaryObjRef, item); } public void Clear() { IDictionaryMethods.Clear(iDictionaryObjRef); } public bool Contains(KeyValuePair item) { return IDictionaryMethods.Contains(iDictionaryObjRef, null, item); } public bool ContainsKey(K key) { return IDictionaryMethods.ContainsKey(iDictionaryObjRef, key); } public void CopyTo(KeyValuePair[] array, int arrayIndex) { IDictionaryMethods.CopyTo(iDictionaryObjRef, iEnumerableObjRef, array, arrayIndex); } public IEnumerator> GetEnumerator() { return IEnumerableMethods>.GetEnumerator(iEnumerableObjRef); } public bool Remove(K key) { return IDictionaryMethods.Remove(iDictionaryObjRef, key); } public bool Remove(KeyValuePair item) { return IDictionaryMethods.Remove(iDictionaryObjRef, item); } public bool TryGetValue(K key, [MaybeNullWhen(false)] out V value) { return IDictionaryMethods.TryGetValue(iDictionaryObjRef, null, key, out value); } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } } internal sealed class IEnumerableImpl : IEnumerable, IEnumerable, IWinRTObject, IDynamicInterfaceCastable { private readonly IObjectReference _inner; private volatile IObjectReference __iEnumerableObjRef; private volatile ConcurrentDictionary _queryInterfaceCache; private volatile ConcurrentDictionary _additionalTypeData; private IObjectReference iEnumerableObjRef => __iEnumerableObjRef ?? Make_IEnumerableObjRef(); IObjectReference IWinRTObject.NativeObject => _inner; bool IWinRTObject.HasUnwrappableNativeObject => true; ConcurrentDictionary IWinRTObject.QueryInterfaceCache => _queryInterfaceCache ?? MakeQueryInterfaceCache(); ConcurrentDictionary IWinRTObject.AdditionalTypeData => _additionalTypeData ?? MakeAdditionalTypeData(); internal IEnumerableImpl(IObjectReference _inner) { this._inner = _inner; } public static IEnumerableImpl CreateRcw(IInspectable obj) { return new IEnumerableImpl(obj.ObjRef); } private IObjectReference Make_IEnumerableObjRef() { Interlocked.CompareExchange(ref __iEnumerableObjRef, _inner.As(IEnumerableMethods.PIID), null); return __iEnumerableObjRef; } private ConcurrentDictionary MakeQueryInterfaceCache() { Interlocked.CompareExchange(ref _queryInterfaceCache, new ConcurrentDictionary(), null); return _queryInterfaceCache; } private ConcurrentDictionary MakeAdditionalTypeData() { Interlocked.CompareExchange(ref _additionalTypeData, new ConcurrentDictionary(), null); return _additionalTypeData; } public IEnumerator GetEnumerator() { return IEnumerableMethods.GetEnumerator(iEnumerableObjRef); } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } } internal sealed class IEnumeratorImpl : IEnumerator, IEnumerator, IDisposable, IIterator, IWinRTObject, IDynamicInterfaceCastable { private readonly IObjectReference _inner; private volatile IObjectReference __iEnumeratorObjRef; private volatile ConcurrentDictionary _queryInterfaceCache; private volatile ConcurrentDictionary _additionalTypeData; private IObjectReference iEnumeratorObjRef => __iEnumeratorObjRef ?? Make_IEnumeratorObjRef(); IObjectReference IWinRTObject.NativeObject => _inner; bool IWinRTObject.HasUnwrappableNativeObject => true; ConcurrentDictionary IWinRTObject.QueryInterfaceCache => _queryInterfaceCache ?? MakeQueryInterfaceCache(); ConcurrentDictionary IWinRTObject.AdditionalTypeData => _additionalTypeData ?? MakeAdditionalTypeData(); public T Current => IEnumeratorMethods.get_Current(iEnumeratorObjRef); object IEnumerator.Current => Current; T IIterator._Current => IIteratorMethods.get_Current(iEnumeratorObjRef); bool IIterator.HasCurrent => IIteratorMethods.get_HasCurrent(iEnumeratorObjRef); internal IEnumeratorImpl(IObjectReference _inner) { this._inner = _inner; } public static IEnumeratorImpl CreateRcw(IInspectable obj) { return new IEnumeratorImpl(obj.ObjRef); } private IObjectReference Make_IEnumeratorObjRef() { Interlocked.CompareExchange(ref __iEnumeratorObjRef, _inner.As(IEnumeratorMethods.PIID), null); return __iEnumeratorObjRef; } private ConcurrentDictionary MakeQueryInterfaceCache() { Interlocked.CompareExchange(ref _queryInterfaceCache, new ConcurrentDictionary(), null); return _queryInterfaceCache; } private ConcurrentDictionary MakeAdditionalTypeData() { Interlocked.CompareExchange(ref _additionalTypeData, new ConcurrentDictionary(), null); return _additionalTypeData; } bool IEnumerator.MoveNext() { return IEnumeratorMethods.MoveNext(iEnumeratorObjRef); } void IEnumerator.Reset() { IEnumeratorMethods.Reset(iEnumeratorObjRef); } void IDisposable.Dispose() { IEnumeratorMethods.Dispose(iEnumeratorObjRef); } bool IIterator._MoveNext() { return IIteratorMethods.MoveNext(iEnumeratorObjRef); } uint IIterator.GetMany(ref T[] items) { return IIteratorMethods.GetMany(iEnumeratorObjRef, ref items); } } internal sealed class IListImpl : IList, ICollection, IEnumerable, IEnumerable, IWinRTObject, IDynamicInterfaceCastable { private readonly IObjectReference _inner; private volatile IObjectReference __iListObjRef; private volatile IObjectReference __iEnumerableObjRef; private volatile ConcurrentDictionary _queryInterfaceCache; private volatile ConcurrentDictionary _additionalTypeData; private IObjectReference iListObjRef => __iListObjRef ?? Make_IListObjRef(); private IObjectReference iEnumerableObjRef => __iEnumerableObjRef ?? Make_IEnumerableObjRef(); public T this[int index] { get { return IListMethods.Indexer_Get(iListObjRef, index); } set { IListMethods.Indexer_Set(iListObjRef, index, value); } } public int Count => IListMethods.get_Count(iListObjRef); public bool IsReadOnly => IListMethods.get_IsReadOnly(iListObjRef); IObjectReference IWinRTObject.NativeObject => _inner; bool IWinRTObject.HasUnwrappableNativeObject => true; ConcurrentDictionary IWinRTObject.QueryInterfaceCache => _queryInterfaceCache ?? MakeQueryInterfaceCache(); ConcurrentDictionary IWinRTObject.AdditionalTypeData => _additionalTypeData ?? MakeAdditionalTypeData(); private IObjectReference Make_IListObjRef() { Interlocked.CompareExchange(ref __iListObjRef, _inner.As(IListMethods.PIID), null); return __iListObjRef; } private IObjectReference Make_IEnumerableObjRef() { Interlocked.CompareExchange(ref __iEnumerableObjRef, _inner.As(IEnumerableMethods.PIID), null); return __iEnumerableObjRef; } internal IListImpl(IObjectReference _inner) { this._inner = _inner; } public static IListImpl CreateRcw(IInspectable obj) { return new IListImpl(obj.ObjRef); } private ConcurrentDictionary MakeQueryInterfaceCache() { Interlocked.CompareExchange(ref _queryInterfaceCache, new ConcurrentDictionary(), null); return _queryInterfaceCache; } private ConcurrentDictionary MakeAdditionalTypeData() { Interlocked.CompareExchange(ref _additionalTypeData, new ConcurrentDictionary(), null); return _additionalTypeData; } public void Add(T item) { IListMethods.Add(iListObjRef, item); } public void Clear() { IListMethods.Clear(iListObjRef); } public bool Contains(T item) { return IListMethods.Contains(iListObjRef, item); } public void CopyTo(T[] array, int arrayIndex) { IListMethods.CopyTo(iListObjRef, array, arrayIndex); } public IEnumerator GetEnumerator() { return IEnumerableMethods.GetEnumerator(iEnumerableObjRef); } public int IndexOf(T item) { return IListMethods.IndexOf(iListObjRef, item); } public void Insert(int index, T item) { IListMethods.Insert(iListObjRef, index, item); } public bool Remove(T item) { return IListMethods.Remove(iListObjRef, item); } public void RemoveAt(int index) { IListMethods.RemoveAt(iListObjRef, index); } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } } internal sealed class IReadOnlyDictionaryImpl : IReadOnlyDictionary, IEnumerable>, IEnumerable, IReadOnlyCollection>, IWinRTObject, IDynamicInterfaceCastable { private readonly IObjectReference _inner; private volatile IObjectReference __iReadOnlyDictionaryObjRef; private volatile IObjectReference __iEnumerableObjRef; private volatile ConcurrentDictionary _queryInterfaceCache; private volatile ConcurrentDictionary _additionalTypeData; private IObjectReference iReadOnlyDictionaryObjRef => __iReadOnlyDictionaryObjRef ?? Make_IDictionaryObjRef(); private IObjectReference iEnumerableObjRef => __iEnumerableObjRef ?? Make_IEnumerableObjRef(); IObjectReference IWinRTObject.NativeObject => _inner; bool IWinRTObject.HasUnwrappableNativeObject => true; ConcurrentDictionary IWinRTObject.QueryInterfaceCache => _queryInterfaceCache ?? MakeQueryInterfaceCache(); ConcurrentDictionary IWinRTObject.AdditionalTypeData => _additionalTypeData ?? MakeAdditionalTypeData(); public V this[K key] => IReadOnlyDictionaryMethods.Indexer_Get(iReadOnlyDictionaryObjRef, key); public IEnumerable Keys => IReadOnlyDictionaryMethods.get_Keys(iReadOnlyDictionaryObjRef); public IEnumerable Values => IReadOnlyDictionaryMethods.get_Values(iReadOnlyDictionaryObjRef); public int Count => IReadOnlyDictionaryMethods.get_Count(iReadOnlyDictionaryObjRef); internal IReadOnlyDictionaryImpl(IObjectReference _inner) { this._inner = _inner; } public static IReadOnlyDictionaryImpl CreateRcw(IInspectable obj) { return new IReadOnlyDictionaryImpl(obj.ObjRef); } private IObjectReference Make_IDictionaryObjRef() { Interlocked.CompareExchange(ref __iReadOnlyDictionaryObjRef, _inner.As(IReadOnlyDictionaryMethods.PIID), null); return __iReadOnlyDictionaryObjRef; } private IObjectReference Make_IEnumerableObjRef() { Interlocked.CompareExchange(ref __iEnumerableObjRef, _inner.As(IEnumerableMethods>.PIID), null); return __iEnumerableObjRef; } private ConcurrentDictionary MakeQueryInterfaceCache() { Interlocked.CompareExchange(ref _queryInterfaceCache, new ConcurrentDictionary(), null); return _queryInterfaceCache; } private ConcurrentDictionary MakeAdditionalTypeData() { Interlocked.CompareExchange(ref _additionalTypeData, new ConcurrentDictionary(), null); return _additionalTypeData; } public bool ContainsKey(K key) { return IReadOnlyDictionaryMethods.ContainsKey(iReadOnlyDictionaryObjRef, key); } public IEnumerator> GetEnumerator() { return IEnumerableMethods>.GetEnumerator(iEnumerableObjRef); } public bool TryGetValue(K key, [MaybeNullWhen(false)] out V value) { return IReadOnlyDictionaryMethods.TryGetValue(iReadOnlyDictionaryObjRef, key, out value); } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } } internal sealed class IReadOnlyListImpl : IReadOnlyList, IEnumerable, IEnumerable, IReadOnlyCollection, IWinRTObject, IDynamicInterfaceCastable { private readonly IObjectReference _inner; private volatile IObjectReference __iReadOnlyListObjRef; private volatile IObjectReference __iEnumerableObjRef; private volatile ConcurrentDictionary _queryInterfaceCache; private volatile ConcurrentDictionary _additionalTypeData; private IObjectReference iReadOnlyListObjRef => __iReadOnlyListObjRef ?? Make_IListObjRef(); private IObjectReference iEnumerableObjRef => __iEnumerableObjRef ?? Make_IEnumerableObjRef(); IObjectReference IWinRTObject.NativeObject => _inner; bool IWinRTObject.HasUnwrappableNativeObject => true; ConcurrentDictionary IWinRTObject.QueryInterfaceCache => _queryInterfaceCache ?? MakeQueryInterfaceCache(); ConcurrentDictionary IWinRTObject.AdditionalTypeData => _additionalTypeData ?? MakeAdditionalTypeData(); public T this[int index] => IReadOnlyListMethods.Indexer_Get(iReadOnlyListObjRef, index); public int Count => IReadOnlyListMethods.get_Count(iReadOnlyListObjRef); private IObjectReference Make_IListObjRef() { Interlocked.CompareExchange(ref __iReadOnlyListObjRef, _inner.As(IReadOnlyListMethods.PIID), null); return __iReadOnlyListObjRef; } private IObjectReference Make_IEnumerableObjRef() { Interlocked.CompareExchange(ref __iEnumerableObjRef, _inner.As(IEnumerableMethods.PIID), null); return __iEnumerableObjRef; } internal IReadOnlyListImpl(IObjectReference _inner) { this._inner = _inner; } public static IReadOnlyListImpl CreateRcw(IInspectable obj) { return new IReadOnlyListImpl(obj.ObjRef); } private ConcurrentDictionary MakeQueryInterfaceCache() { Interlocked.CompareExchange(ref _queryInterfaceCache, new ConcurrentDictionary(), null); return _queryInterfaceCache; } private ConcurrentDictionary MakeAdditionalTypeData() { Interlocked.CompareExchange(ref _additionalTypeData, new ConcurrentDictionary(), null); return _additionalTypeData; } public IEnumerator GetEnumerator() { return IEnumerableMethods.GetEnumerator(iEnumerableObjRef); } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } } } namespace System.Numerics { public static class VectorExtensions { public static global::Windows.Foundation.Point ToPoint(this Vector2 vector) { return new global::Windows.Foundation.Point(vector.X, vector.Y); } public static global::Windows.Foundation.Size ToSize(this Vector2 vector) { return new global::Windows.Foundation.Size(vector.X, vector.Y); } public static Vector2 ToVector2(this global::Windows.Foundation.Point point) { return new Vector2((float)point.X, (float)point.Y); } public static Vector2 ToVector2(this global::Windows.Foundation.Size size) { return new Vector2((float)size.Width, (float)size.Height); } } } namespace System.Runtime.InteropServices.WindowsRuntime { [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] public sealed class ReadOnlyArrayAttribute : Attribute { } [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] public sealed class WriteOnlyArrayAttribute : Attribute { } } namespace WinRT { internal sealed class DllModule { private static readonly string _currentModuleDirectory = AppContext.BaseDirectory; private static readonly Dictionary _cache = new Dictionary(StringComparer.Ordinal); private readonly string _fileName; private readonly IntPtr _moduleHandle; private unsafe readonly delegate* unmanaged[Stdcall] _GetActivationFactory; private unsafe readonly delegate* unmanaged[Stdcall] _CanUnloadNow; public static bool TryLoad(string fileName, out DllModule module) { lock (_cache) { if (_cache.TryGetValue(fileName, out module)) { return true; } if (TryCreate(fileName, out module)) { _cache[fileName] = module; return true; } return false; } } private unsafe static bool TryCreate(string fileName, out DllModule module) { IntPtr zero = IntPtr.Zero; zero = Platform.LoadLibraryExW(Path.Combine(_currentModuleDirectory, fileName), IntPtr.Zero, 8u); if (zero == IntPtr.Zero) { NativeLibrary.TryLoad(fileName, typeof(DllModule).Assembly, null, out zero); } if (zero == IntPtr.Zero) { module = null; return false; } void* ptr = null; ReadOnlySpan functionName = "DllGetActivationFactory"u8; ptr = (void*)Platform.TryGetProcAddress(zero, functionName); if (ptr == null) { module = null; return false; } module = new DllModule(fileName, zero, ptr); return true; } private unsafe DllModule(string fileName, IntPtr moduleHandle, void* getActivationFactory) { _fileName = fileName; _moduleHandle = moduleHandle; _GetActivationFactory = (delegate* unmanaged[Stdcall])getActivationFactory; void* ptr = null; ReadOnlySpan functionName = "DllCanUnloadNow"u8; ptr = (void*)Platform.TryGetProcAddress(_moduleHandle, functionName); if (ptr != null) { _CanUnloadNow = (delegate* unmanaged[Stdcall])ptr; } } public unsafe (ObjectReference obj, int hr) GetActivationFactory(string runtimeClassId) { IntPtr thisPtr = IntPtr.Zero; try { MarshalString.Pinnable p = new MarshalString.Pinnable(runtimeClassId); fixed (char* ptr = p) { void* ptr2 = ptr; int num = _GetActivationFactory(MarshalString.GetAbi(ref p), &thisPtr); if (num == 0) { ObjectReference item = ObjectReference.Attach(ref thisPtr, IID.IID_IActivationFactory); return (obj: item, hr: num); } return (obj: null, hr: num); } } finally { MarshalInspectable.DisposeAbi(thisPtr); } } ~DllModule() { lock (_cache) { _cache.Remove(_fileName); } if (_moduleHandle != IntPtr.Zero && !Platform.FreeLibrary(_moduleHandle)) { Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); } } } internal sealed class WinRTModule { private static volatile WinRTModule _instance; private readonly IntPtr _mtaCookie; public static WinRTModule Instance => _instance ?? MakeWinRTModule(); private static WinRTModule MakeWinRTModule() { Interlocked.CompareExchange(ref _instance, new WinRTModule(), null); return _instance; } public unsafe WinRTModule() { IntPtr mtaCookie = default(IntPtr); Marshal.ThrowExceptionForHR(Platform.CoIncrementMTAUsage(&mtaCookie)); _mtaCookie = mtaCookie; } public unsafe static (ObjectReference obj, int hr) GetActivationFactory(string runtimeClassId, Guid iid) { WinRTModule instance = Instance; IntPtr thisPtr = IntPtr.Zero; try { MarshalString.Pinnable p = new MarshalString.Pinnable(runtimeClassId); fixed (char* ptr = p) { void* ptr2 = ptr; int num = Platform.RoGetActivationFactory(MarshalString.GetAbi(ref p), &iid, &thisPtr); if (num == 0) { ObjectReference item = ObjectReference.Attach(ref thisPtr, iid); return (obj: item, hr: num); } return (obj: null, hr: num); } } finally { MarshalInspectable.DisposeAbi(thisPtr); } } ~WinRTModule() { Marshal.ThrowExceptionForHR(Platform.CoDecrementMTAUsage(_mtaCookie)); } } public static class ActivationFactory { public static Func ActivationHandler { get; set; } public static IObjectReference Get(string typeName) { if (ActivationHandler != null) { IObjectReference fromActivationHandler = GetFromActivationHandler(typeName, IID.IID_IActivationFactory); if (fromActivationHandler != null) { return fromActivationHandler; } } int errorCode; ObjectReference objectReference; (objectReference, errorCode) = WinRTModule.GetActivationFactory(typeName, IID.IID_IActivationFactory); if (objectReference != null) { return objectReference; } string text = typeName; while (true) { int num = text.LastIndexOf(".", StringComparison.Ordinal); if (num <= 0) { Marshal.ThrowExceptionForHR(errorCode); } text = text.Remove(num); DllModule module = null; if (DllModule.TryLoad(text + ".dll", out module)) { (objectReference, errorCode) = module.GetActivationFactory(typeName); if (objectReference != null) { break; } } } return objectReference; } public static IObjectReference Get(string typeName, Guid iid) { if (ActivationHandler != null) { IObjectReference fromActivationHandler = GetFromActivationHandler(typeName, iid); if (fromActivationHandler != null) { return fromActivationHandler; } } var (objectReference, errorCode) = WinRTModule.GetActivationFactory(typeName, iid); if (objectReference != null) { return objectReference; } string text = typeName; ObjectReference objectReference2; while (true) { int num = text.LastIndexOf(".", StringComparison.Ordinal); if (num <= 0) { Marshal.ThrowExceptionForHR(errorCode); } text = text.Remove(num); DllModule module = null; if (DllModule.TryLoad(text + ".dll", out module)) { (objectReference2, errorCode) = module.GetActivationFactory(typeName); if (objectReference2 != null) { break; } } } using (objectReference2) { return objectReference2.As(iid); } } private static IObjectReference GetFromActivationHandler(string typeName, Guid iid) { Func activationHandler = ActivationHandler; if (activationHandler != null) { IntPtr thisPtr = IntPtr.Zero; try { thisPtr = activationHandler(typeName, iid); if (thisPtr != IntPtr.Zero) { return ObjectReference.Attach(ref thisPtr, iid); } } finally { MarshalInspectable.DisposeAbi(thisPtr); } } return null; } } public class AgileReference : System.IDisposable { private static readonly Guid CLSID_StdGlobalInterfaceTable = new Guid(803, 0, 0, 192, 0, 0, 0, 0, 0, 0, 70); private static readonly object _lock = new object(); private static volatile IGlobalInterfaceTable _git; private readonly IObjectReference _agileReference; private readonly IntPtr _cookie; private bool disposed; internal static IGlobalInterfaceTable Git { get { return _git ?? Git_Slow(); [MethodImpl(MethodImplOptions.NoInlining)] static IGlobalInterfaceTable Git_Slow() { lock (_lock) { return _git ?? (_git = GetGitTable()); } } } } public AgileReference(IObjectReference instance) : this(instance?.ThisPtr ?? IntPtr.Zero) { } internal AgileReference(in ObjectReferenceValue instance) : this(instance.GetAbi()) { } internal unsafe AgileReference(IntPtr thisPtr) { if (thisPtr == IntPtr.Zero) { return; } IntPtr thisPtr2 = default(IntPtr); Guid iID_IUnknown = IID.IID_IUnknown; try { Marshal.ThrowExceptionForHR(Platform.RoGetAgileReference(0u, &iID_IUnknown, thisPtr, &thisPtr2)); _agileReference = ObjectReference.Attach(ref thisPtr2, IID.IID_IUnknown); } catch (TypeLoadException) { _cookie = Git.RegisterInterfaceInGlobal(thisPtr, iID_IUnknown); } finally { MarshalInterface.DisposeAbi(thisPtr2); } } public IObjectReference Get() { if (!(_cookie == IntPtr.Zero)) { return Git.GetInterfaceFromGlobal(_cookie, IID.IID_IUnknown); } return IAgileReferenceMethods.Resolve(_agileReference, IID.IID_IUnknown); } internal ObjectReference Get(Guid iid) { if (!(_cookie == IntPtr.Zero)) { return Git.GetInterfaceFromGlobal(_cookie, IID.IID_IUnknown)?.As(iid); } return IAgileReferenceMethods.Resolve(_agileReference, iid); } protected virtual void Dispose(bool disposing) { if (!disposed) { if (_cookie != IntPtr.Zero) { Git.TryRevokeInterfaceFromGlobal(_cookie); } disposed = true; } } private unsafe static IGlobalInterfaceTable GetGitTable() { Guid cLSID_StdGlobalInterfaceTable = CLSID_StdGlobalInterfaceTable; Guid iID_IGlobalInterfaceTable = IID.IID_IGlobalInterfaceTable; IntPtr intPtr = default(IntPtr); try { Marshal.ThrowExceptionForHR(Platform.CoCreateInstance(&cLSID_StdGlobalInterfaceTable, IntPtr.Zero, 1u, &iID_IGlobalInterfaceTable, &intPtr)); return new IGlobalInterfaceTable(intPtr); } finally { MarshalExtensions.ReleaseIfNotNull(intPtr); } } ~AgileReference() { Dispose(disposing: false); } public void Dispose() { Dispose(disposing: true); GC.SuppressFinalize(this); } } public sealed class AgileReference : AgileReference where T : class { public AgileReference(IObjectReference instance) : base(instance) { } internal AgileReference(in ObjectReferenceValue instance) : base(in instance) { } public new T Get() { using IObjectReference objectReference = base.Get(); return ComWrappersSupport.CreateRcwForComObject(objectReference?.ThisPtr ?? IntPtr.Zero); } } internal static class AttributeMessages { public const string GenericDeprecatedMessage = "This method is deprecated and will be removed in a future release."; public const string GenericRequiresUnreferencedCodeMessage = "This method is not trim-safe, and is only supported for use when not using trimming (or AOT)."; public const string MarshallingOrGenericInstantiationsRequiresDynamicCode = "The necessary marshalling code or generic instantiations might not be available."; public const string AbiTypesNeverHaveConstructors = "All ABI types never have a constructor that would need to be accessed via reflection."; } [EditorBrowsable(EditorBrowsableState.Never)] [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)] public sealed class ProjectedRuntimeClassAttribute : Attribute { public string DefaultInterfaceProperty { get; } public System.Type DefaultInterface { get; } public ProjectedRuntimeClassAttribute(string defaultInterfaceProp) { DefaultInterfaceProperty = defaultInterfaceProp; } public ProjectedRuntimeClassAttribute(System.Type defaultInterface) { DefaultInterface = defaultInterface; } } [Obsolete("This attribute is only used for the .NET Standard 2.0 projections.")] [EditorBrowsable(EditorBrowsableState.Never)] [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)] public sealed class ObjectReferenceWrapperAttribute : Attribute { public string ObjectReferenceField { get; } public ObjectReferenceWrapperAttribute(string objectReferenceField) { ObjectReferenceField = objectReferenceField; } } [EditorBrowsable(EditorBrowsableState.Never)] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Interface | AttributeTargets.Delegate, Inherited = false, AllowMultiple = false)] public sealed class WindowsRuntimeTypeAttribute : Attribute { public string SourceMetadata { get; } public string GuidSignature { get; } public WindowsRuntimeTypeAttribute(string sourceMetadata = null) { SourceMetadata = sourceMetadata; } public WindowsRuntimeTypeAttribute(string sourceMetadata, string guidSignature) : this(sourceMetadata) { GuidSignature = guidSignature; } } [EditorBrowsable(EditorBrowsableState.Never)] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Interface | AttributeTargets.Delegate, Inherited = false, AllowMultiple = false)] public sealed class WindowsRuntimeHelperTypeAttribute : Attribute { [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicFields)] public System.Type HelperType { get; } public WindowsRuntimeHelperTypeAttribute() { } public WindowsRuntimeHelperTypeAttribute([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicFields)] System.Type helperType) { HelperType = helperType; } } public interface IWinRTExposedTypeDetails { ComWrappers.ComInterfaceEntry[] GetExposedInterfaces(); } [EditorBrowsable(EditorBrowsableState.Never)] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Interface | AttributeTargets.Delegate, Inherited = false, AllowMultiple = false)] public sealed class WinRTExposedTypeAttribute : Attribute { [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] internal System.Type WinRTExposedTypeDetails { get; } public WinRTExposedTypeAttribute() { } public WinRTExposedTypeAttribute([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] System.Type winrtExposedTypeDetails) { WinRTExposedTypeDetails = winrtExposedTypeDetails; } public ComWrappers.ComInterfaceEntry[] GetExposedInterfaces() { if ((object)WinRTExposedTypeDetails == null) { return Array.Empty(); } return ((IWinRTExposedTypeDetails)Activator.CreateInstance(WinRTExposedTypeDetails)).GetExposedInterfaces(); } } [EditorBrowsable(EditorBrowsableState.Never)] [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)] public abstract class WinRTImplementationTypeRcwFactoryAttribute : Attribute { public abstract object CreateInstance(IInspectable inspectable); } [EditorBrowsable(EditorBrowsableState.Never)] [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)] public sealed class WinRTRuntimeClassNameAttribute : Attribute { public string RuntimeClassName { get; } public WinRTRuntimeClassNameAttribute(string runtimeClassName) { RuntimeClassName = runtimeClassName; } } [EditorBrowsable(EditorBrowsableState.Never)] [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] public sealed class WinRTAssemblyExportsTypeAttribute : Attribute { public System.Type Type { get; } public WinRTAssemblyExportsTypeAttribute(System.Type type) { Type = type; } } [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)] public sealed class GeneratedBindableCustomPropertyAttribute : Attribute { internal string[] PropertyNames { get; } internal System.Type[] IndexerPropertyTypes { get; } public GeneratedBindableCustomPropertyAttribute() { } public GeneratedBindableCustomPropertyAttribute(string[] propertyNames, System.Type[] indexerPropertyTypes) { PropertyNames = propertyNames; IndexerPropertyTypes = indexerPropertyTypes; } } public static class CastExtensions { public static TInterface As(this object value) { if (typeof(TInterface) == typeof(object) && TryGetRefForObject(value, allowComposed: false, out var reference)) { using (reference) { return ComWrappersSupport.CreateRcwForComObject(reference.ThisPtr); } } if (value is TInterface) { return (TInterface)value; } if (TryGetRefForObject(value, allowComposed: true, out reference)) { using (reference) { return reference.AsInterface(); } } throw GetArgumentExceptionForFailedCast(value); [MethodImpl(MethodImplOptions.NoInlining)] static System.Exception GetArgumentExceptionForFailedCast(object obj) { if (obj == null) { return new ArgumentNullException("value", $"The source object being cast to type '{typeof(TInterface)}' is 'null'."); } return new ArgumentException($"The source object type ('{obj.GetType()}') being cast to type '{typeof(TInterface)}' is not a projected type, nor does it inherit from a projected type.", "value"); } } public static AgileReference AsAgile(this T value) where T : class { if (value == null) { return new AgileReference(null); } object obj = Marshaler.CreateMarshaler2(value); try { if (obj is IObjectReference instance) { return new AgileReference(instance); } if (obj is ObjectReferenceValue instance2) { return new AgileReference(in instance2); } } finally { Marshaler.DisposeMarshaler(obj); } throw new InvalidOperationException("Object type is not a projected type: value."); } private static bool TryGetRefForObject(object value, bool allowComposed, out IObjectReference reference) { if (ComWrappersSupport.TryUnwrapObject(value, out var objRef)) { reference = objRef.As(IID.IID_IUnknown); return true; } if (allowComposed && TryGetComposedRefForQI(value, out objRef)) { reference = objRef.As(IID.IID_IUnknown); return true; } reference = null; return false; } private static bool TryGetComposedRefForQI(object value, out IObjectReference objRef) { if (value is IWinRTObject winRTObject) { objRef = winRTObject.NativeObject; return true; } objRef = null; return false; } } internal static class KeyValuePairHelper { internal static readonly ConcurrentDictionary KeyValuePairCCW = new ConcurrentDictionary(); internal static void TryAddKeyValuePairCCW(System.Type keyValuePairType, Guid iid, IntPtr abiToProjectionVftablePtr) { KeyValuePairCCW.TryAdd(keyValuePairType, new ComWrappers.ComInterfaceEntry { IID = iid, Vtable = abiToProjectionVftablePtr }); } } public static class ComWrappersSupport { internal sealed class InspectableInfo { private readonly System.Type _type; private volatile string _runtimeClassName; public Guid[] IIDs { get; } public string RuntimeClassName => _runtimeClassName ?? MakeRuntimeClassName(); private string MakeRuntimeClassName() { Interlocked.CompareExchange(ref _runtimeClassName, TypeNameSupport.GetNameForType(_type, TypeNameGenerationFlags.GenerateBoxedName | TypeNameGenerationFlags.ForGetRuntimeClassName), null); return _runtimeClassName; } internal InspectableInfo(System.Type type, Guid[] iids) { _type = type; IIDs = iids; } } internal const int GC_PRESSURE_BASE = 1000; private static readonly ConcurrentDictionary> TypedObjectFactoryCacheForType = new ConcurrentDictionary>(); private static readonly ConcurrentDictionary> DelegateFactoryCache = new ConcurrentDictionary>(); internal static readonly ConditionalWeakTable BoxedValueReferenceCache = new ConditionalWeakTable(); private static DefaultComWrappers _instance; internal static readonly ConditionalWeakTable InspectableInfoTable = new ConditionalWeakTable(); [ThreadStatic] internal static System.Type CreateRCWType; private static ComWrappers _comWrappers; private static readonly object _comWrappersLock = new object(); private static readonly List> ComInterfaceEntriesLookup = new List>(); private static readonly List> RuntimeClassNameForNonWinRTTypeLookup = new List>(); private static readonly ConcurrentDictionary ComInterfaceEntriesForType = new ConcurrentDictionary(); private static ComWrappers.ComInterfaceEntry IPropertyValueEntry { get { if (!FeatureSwitches.EnableIReferenceSupport) { throw new NotSupportedException("Support for 'IPropertyValue' is not enabled (it depends on the support for 'IReference')."); } return new ComWrappers.ComInterfaceEntry { IID = IID.IID_IPropertyValue, Vtable = ManagedIPropertyValueImpl.AbiToProjectionVftablePtr }; } } private static DefaultComWrappers DefaultComWrappersInstance { get { if (_instance == null) { _instance = new DefaultComWrappers(); } return _instance; } } private static ComWrappers ComWrappers { get { if (_comWrappers == null) { lock (_comWrappersLock) { if (_comWrappers == null) { DefaultComWrappers defaultComWrappersInstance = DefaultComWrappersInstance; ComWrappers.RegisterForTrackerSupport(defaultComWrappersInstance); _comWrappers = defaultComWrappersInstance; } } } return _comWrappers; } set { lock (_comWrappersLock) { if (value != null || _comWrappers != DefaultComWrappersInstance) { ComWrappers comWrappers = value ?? DefaultComWrappersInstance; ComWrappers.RegisterForTrackerSupport(comWrappers); _comWrappers = comWrappers; } } } } public static IUnknownVftbl IUnknownVftbl => DefaultComWrappers.IUnknownVftbl; public static IntPtr IUnknownVftblPtr => DefaultComWrappers.IUnknownVftblPtr; public static TReturn MarshalDelegateInvoke(IntPtr thisPtr, Func invoke) where TDelegate : class, Delegate { TDelegate val = FindObject(thisPtr); if (val != null) { return invoke(val); } return default(TReturn); } public static void MarshalDelegateInvoke(IntPtr thisPtr, Action invoke) where T : class, Delegate { T val = FindObject(thisPtr); if (val != null) { invoke(val); } } internal unsafe static bool IsFreeThreaded(IntPtr iUnknown) { if (Marshal.QueryInterface(iUnknown, in Unsafe.AsRef(in IID.IID_IAgileObject), out var ppv) >= 0) { Marshal.Release(ppv); return true; } if (Marshal.QueryInterface(iUnknown, in Unsafe.AsRef(in IID.IID_IMarshal), out var ppv2) >= 0) { try { Guid iID_IUnknown = IID.IID_IUnknown; Guid guid = default(Guid); Marshal.ThrowExceptionForHR((*(IMarshal.Vftbl**)(void*)ppv2)->GetUnmarshalClass_0(ppv2, &iID_IUnknown, IntPtr.Zero, MSHCTX.InProc, IntPtr.Zero, MSHLFLAGS.Normal, &guid)); if (guid == IMarshal.IID_InProcFreeThreadedMarshaler) { return true; } } finally { Marshal.Release(ppv2); } } return false; } internal static bool IsFreeThreaded(IObjectReference objRef) { bool result = IsFreeThreaded(objRef.ThisPtr); GC.KeepAlive(objRef); return result; } public static IObjectReference GetObjectReferenceForInterface(IntPtr externalComObject) { return GetObjectReferenceForInterface(externalComObject, IID.IID_IUnknown, requireQI: false); } [RequiresUnreferencedCode("This method is not trim-safe, and is only supported for use when not using trimming (or AOT).")] public static ObjectReference GetObjectReferenceForInterface(IntPtr externalComObject) { if (externalComObject == IntPtr.Zero) { return null; } return ObjectReference.FromAbi(externalComObject); } public static ObjectReference GetObjectReferenceForInterface(IntPtr externalComObject, Guid iid) { return GetObjectReferenceForInterface(externalComObject, iid, requireQI: true); } public static IObjectReference GetObjectReferenceForInterface(IntPtr externalComObject, Guid iid, bool requireQI) { return GetObjectReferenceForInterface(externalComObject, iid, requireQI); } internal static ObjectReference GetObjectReferenceForInterface(IntPtr externalComObject, Guid iid, bool requireQI) { if (externalComObject == IntPtr.Zero) { return null; } if (requireQI) { Marshal.ThrowExceptionForHR(Marshal.QueryInterface(externalComObject, in iid, out var ppv)); return ObjectReference.Attach(ref ppv, iid); } return ObjectReference.FromAbi(externalComObject, iid); } public static void RegisterProjectionAssembly(Assembly assembly) { TypeNameSupport.RegisterProjectionAssembly(assembly); } public static void RegisterProjectionTypeBaseTypeMapping(System.Collections.Generic.IDictionary typeNameToBaseTypeNameMapping) { TypeNameSupport.RegisterProjectionTypeBaseTypeMapping(typeNameToBaseTypeNameMapping); } public static void RegisterAuthoringMetadataTypeLookup(Func authoringMetadataTypeLookup) { TypeExtensions.RegisterAuthoringMetadataTypeLookup(authoringMetadataTypeLookup); } public static void RegisterHelperType(System.Type type, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicFields)] System.Type helperType) { TypeExtensions.HelperTypeCache.TryAdd(type, helperType); } internal static List GetInterfaceTableEntries(System.Type type) { List list = new List(); bool hasUserImplementedIMarshalInterface = false; bool hasUserImplementedICustomPropertyProviderInterface = false; bool flag = false; WinRTExposedTypeAttribute customAttribute = type.GetCustomAttribute(inherit: false); if (customAttribute == null) { System.Type cCWType = type.GetCCWType(); if (cCWType != null) { customAttribute = cCWType.GetCustomAttribute(inherit: false); } } ComWrappers.ComInterfaceEntry[] value; if (customAttribute != null) { flag = true; list.AddRange(customAttribute.GetExposedInterfaces()); if (type.IsClass) { hasUserImplementedIMarshalInterface = GetHasCustomIMarshalInterface(list); hasUserImplementedICustomPropertyProviderInterface = GetHasICustomPropertyProviderInterface(list); } } else if (type == typeof(System.EventHandler)) { flag = true; list.AddRange(Projections.GetAbiEventHandlerExposedInterfaces()); } else if (type == typeof(System.ComponentModel.PropertyChangedEventHandler)) { flag = true; list.AddRange(Projections.GetAbiPropertyChangedEventHandlerExposedInterfaces()); } else if (type == typeof(System.Collections.Specialized.NotifyCollectionChangedEventHandler)) { flag = true; list.AddRange(Projections.GetAbiNotifyCollectionChangedEventHandlerExposedInterfaces()); } else if (ComInterfaceEntriesForType.TryGetValue(type, out value)) { flag = true; list.AddRange(value); } else { if (!type.IsEnum) { ComWrappers.ComInterfaceEntry[] comInterfaceEntriesForTypeFromLookupTable = GetComInterfaceEntriesForTypeFromLookupTable(type); if (comInterfaceEntriesForTypeFromLookupTable != null) { flag = true; list.AddRange(comInterfaceEntriesForTypeFromLookupTable); goto IL_0119; } } if (RuntimeFeature.IsDynamicCodeCompiled) { GetInterfaceTableEntriesForJitEnvironment(type, list, ref hasUserImplementedIMarshalInterface, ref hasUserImplementedICustomPropertyProviderInterface); } } goto IL_0119; IL_0119: if (type.IsSZArray) { System.Type elementType = type.GetElementType(); if (elementType.ShouldProvideIReference()) { list.Add(IPropertyValueEntry); list.Add(ProvideIReferenceArray(type)); } } else if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(System.Collections.Generic.KeyValuePair<, >)) { if (KeyValuePairHelper.KeyValuePairCCW.TryGetValue(type, out var value2)) { list.Add(value2); } else { System.Type type2 = type.FindHelperType(); list.Add(new ComWrappers.ComInterfaceEntry { IID = GuidGenerator.GetIID(type2), Vtable = type2.GetAbiToProjectionVftblPtr() }); } } else if (!flag && type.ShouldProvideIReference()) { list.Add(IPropertyValueEntry); list.Add(ProvideIReference(type)); } list.Add(new ComWrappers.ComInterfaceEntry { IID = IID.IID_IStringable, Vtable = ManagedIStringableVftbl.AbiToProjectionVftablePtr }); if (FeatureSwitches.EnableICustomPropertyProviderSupport && !hasUserImplementedICustomPropertyProviderInterface) { list.Add(new ComWrappers.ComInterfaceEntry { IID = IID.IID_ICustomPropertyProvider, Vtable = ManagedCustomPropertyProviderVftbl.AbiToProjectionVftablePtr }); } list.Add(new ComWrappers.ComInterfaceEntry { IID = IID.IID_IWeakReferenceSource, Vtable = ABI.WinRT.Interop.IWeakReferenceSource.AbiToProjectionVftablePtr }); if (!hasUserImplementedIMarshalInterface) { list.Add(new ComWrappers.ComInterfaceEntry { IID = IID.IID_IMarshal, Vtable = IMarshal.Vftbl.AbiToProjectionVftablePtr }); } list.Add(new ComWrappers.ComInterfaceEntry { IID = IID.IID_IAgileObject, Vtable = IUnknownVftbl.AbiToProjectionVftblPtr }); list.Add(new ComWrappers.ComInterfaceEntry { IID = IID.IID_IInspectable, Vtable = IInspectable.Vftbl.AbiToProjectionVftablePtr }); list.Add(new ComWrappers.ComInterfaceEntry { IID = IID.IID_IUnknown, Vtable = IUnknownVftbl.AbiToProjectionVftblPtr }); return list; static void AddInterfaceToVtable(System.Type iface, List entries, ref bool reference, ref bool reference2) { System.Type type3 = iface.FindHelperType(); Guid iID = GuidGenerator.GetIID(type3); entries.Add(new ComWrappers.ComInterfaceEntry { IID = GuidGenerator.GetIID(type3), Vtable = type3.GetAbiToProjectionVftblPtr() }); if (!reference && iID == IID.IID_IMarshal) { reference = true; } if (!reference2 && iID == IID.IID_ICustomPropertyProvider) { reference2 = true; } } static bool GetHasCustomIMarshalInterface(List entries) { Span span = CollectionsMarshal.AsSpan(entries); for (int i = 0; i < span.Length; i++) { if (span[i].IID == IID.IID_IMarshal) { return true; } } return false; } static bool GetHasICustomPropertyProviderInterface(List entries) { Span span = CollectionsMarshal.AsSpan(entries); for (int i = 0; i < span.Length; i++) { if (span[i].IID == IID.IID_ICustomPropertyProvider) { return true; } } return false; } [MethodImpl(MethodImplOptions.NoInlining)] [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Fallback method for JIT environments that is not trim-safe by design.")] [UnconditionalSuppressMessage("Trimming", "IL2067", Justification = "Fallback method for JIT environments that is not trim-safe by design.")] [UnconditionalSuppressMessage("Trimming", "IL2070", Justification = "Fallback method for JIT environments that is not trim-safe by design.")] [UnconditionalSuppressMessage("Trimming", "IL2075", Justification = "Fallback method for JIT environments that is not trim-safe by design.")] static void GetInterfaceTableEntriesForJitEnvironment(System.Type type3, List entries, ref bool hasUserImplementedIMarshalInterface2, ref bool hasUserImplementedICustomPropertyProviderInterface2) { if (type3.IsDelegate()) { System.Type type4 = type3.FindHelperType(); if ((object)type4 != null) { entries.Add(new ComWrappers.ComInterfaceEntry { IID = GuidGenerator.GetIID(type3), Vtable = type4.GetAbiToProjectionVftblPtr() }); } if (type3.ShouldProvideIReference()) { entries.Add(IPropertyValueEntry); entries.Add(ProvideIReference(type3)); } } else { System.Type type5 = type3.GetRuntimeClassCCWType() ?? type3; System.Type[] interfaces = type5.GetInterfaces(); System.Type[] array = interfaces; foreach (System.Type type6 in array) { if (Projections.IsTypeWindowsRuntimeType(type6)) { AddInterfaceToVtable(type6, entries, ref hasUserImplementedIMarshalInterface2, ref hasUserImplementedICustomPropertyProviderInterface2); } if (type6.IsConstructedGenericType && Projections.TryGetCompatibleWindowsRuntimeTypesForVariantType(type6, null, out var compatibleTypes)) { foreach (System.Type item in compatibleTypes) { AddInterfaceToVtable(item, entries, ref hasUserImplementedIMarshalInterface2, ref hasUserImplementedICustomPropertyProviderInterface2); } } } } } } [UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", Justification = "The existence of the ABI type implies the non-ABI type exists, as in authoring scenarios the ABI type is constructed from the non-ABI type.")] internal static (InspectableInfo inspectableInfo, List interfaceTableEntries) PregenerateNativeTypeInformation(System.Type type) { List interfaceTableEntries = GetInterfaceTableEntries(type); Guid[] array = new Guid[interfaceTableEntries.Count]; for (int i = 0; i < interfaceTableEntries.Count; i++) { array[i] = interfaceTableEntries[i].IID; } if (type.FullName.StartsWith("ABI.", StringComparison.Ordinal)) { type = Projections.FindCustomPublicTypeForAbiType(type) ?? type.Assembly.GetType(type.FullName.Substring("ABI.".Length)) ?? type; } return (inspectableInfo: new InspectableInfo(type, array), interfaceTableEntries: interfaceTableEntries); } private static Func CreateKeyValuePairFactory(System.Type type) { return (Func)type.GetHelperType().GetMethod("CreateRcw", BindingFlags.Static | BindingFlags.Public).CreateDelegate(typeof(Func)); } internal static Func GetOrCreateDelegateFactory(System.Type type) { return DelegateFactoryCache.GetOrAdd(type, CreateDelegateFactory); } [UnconditionalSuppressMessage("Trimming", "IL2067", Justification = "The type is a delegate type, so 'GuidGenerator.GetIID' doesn't need to access public fields from it (it uses the helper type).")] private static Func CreateDelegateFactory(System.Type type) { Func createRcwFunc = (Func)type.GetHelperType().GetMethod("CreateRcw", BindingFlags.Static | BindingFlags.Public).CreateDelegate(typeof(Func)); Guid iid = GuidGenerator.GetIID(type); return delegate(IntPtr externalComObject) { Marshal.ThrowExceptionForHR(Marshal.QueryInterface(externalComObject, in iid, out var ppv)); try { return createRcwFunc(ppv); } finally { Marshal.Release(ppv); } }; } public static bool RegisterDelegateFactory(System.Type implementationType, Func delegateFactory) { return DelegateFactoryCache.TryAdd(implementationType, delegateFactory); } internal static Func CreateNullableTFactory(System.Type implementationType) { MethodInfo getValueMethod = implementationType.GetHelperType().GetMethod("GetValue", BindingFlags.Static | BindingFlags.Public); return delegate(IInspectable obj) { MethodInfo methodInfo = getValueMethod; object[] parameters = new IInspectable[1] { obj }; return methodInfo.Invoke(null, parameters); }; } internal static Func CreateAbiNullableTFactory([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] System.Type implementationType) { MethodInfo method = implementationType.GetMethod("GetValue", BindingFlags.Static | BindingFlags.Public); return (Func)method.CreateDelegate(typeof(Func)); } private static Func CreateArrayFactory(System.Type implementationType) { MethodInfo method = implementationType.GetHelperType().GetMethod("GetValue", BindingFlags.Static | BindingFlags.Public); return (Func)method.CreateDelegate(typeof(Func)); } internal static Func CreateReferenceCachingFactory(Func internalFactory) { return internalFactory.InvokeWithBoxedValueReferenceCacheInsertion; } private static Func CreateCustomTypeMappingFactory([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] System.Type customTypeHelperType) { MethodInfo method = customTypeHelperType.GetMethod("FromAbi", BindingFlags.Static | BindingFlags.Public); if ((object)method == null) { throw new MissingMethodException(); } Func fromAbiMethodFunc = (Func)method.CreateDelegate(typeof(Func)); return delegate(IInspectable obj) { object result = fromAbiMethodFunc(obj.ThisPtr); GC.KeepAlive(obj); return result; }; } internal static Func CreateTypedRcwFactory(System.Type implementationType) { return CreateTypedRcwFactory(implementationType, null); } internal static Func CreateTypedRcwFactory(System.Type implementationType, string runtimeClassName) { if (implementationType == null || implementationType == typeof(object)) { return (IInspectable obj) => obj; } if (implementationType == typeof(string) || implementationType == typeof(System.Type) || implementationType == typeof(System.Exception) || implementationType.IsDelegate()) { return NullableType.GetValueFactory(implementationType); } if (implementationType.IsValueType) { if (implementationType.IsGenericType && implementationType.GetGenericTypeDefinition() == typeof(System.Collections.Generic.KeyValuePair<, >)) { return CreateReferenceCachingFactory(CreateKeyValuePairFactory(implementationType)); } if (implementationType.IsNullableT()) { return NullableType.GetValueFactory(implementationType.GetGenericArguments()[0]); } return NullableType.GetValueFactory(implementationType); } System.Type type = Projections.FindCustomHelperTypeMapping(implementationType, filterToRuntimeClass: true); if (type != null) { return CreateReferenceCachingFactory(CreateCustomTypeMappingFactory(type)); } if (implementationType.IsIReferenceArray()) { return CreateReferenceCachingFactory(CreateArrayFactory(implementationType)); } return CreateFactoryForImplementationType(runtimeClassName, implementationType); } internal static System.Type GetRuntimeClassForTypeCreation(IInspectable inspectable, System.Type staticallyDeterminedType) { string runtimeClassName = inspectable.GetRuntimeClassName(noThrow: true); System.Type type = null; if (!string.IsNullOrEmpty(runtimeClassName)) { if (runtimeClassName.StartsWith("Windows.Foundation.IReference`1<", StringComparison.Ordinal)) { return TypeNameSupport.FindRcwTypeByNameCached(runtimeClassName.Substring(32, runtimeClassName.Length - 33)); } type = TypeNameSupport.FindRcwTypeByNameCached(runtimeClassName); } if (staticallyDeterminedType != null && staticallyDeterminedType != typeof(object) && (!(type != null) || (!(staticallyDeterminedType == type) && !staticallyDeterminedType.IsAssignableFrom(type)))) { return staticallyDeterminedType; } if (!RuntimeFeature.IsDynamicCodeCompiled && type != null && type.IsInterface && type.IsGenericType && !TypedObjectFactoryCacheForType.ContainsKey(type)) { return staticallyDeterminedType; } return type; } private static ComWrappers.ComInterfaceEntry ProvideIReference(System.Type type) { if (!FeatureSwitches.EnableIReferenceSupport) { throw new NotSupportedException("Support for 'IReference' is not enabled."); } if (type == typeof(int)) { return new ComWrappers.ComInterfaceEntry { IID = IID.IID_NullableInt, Vtable = Nullable_int.Vftbl.AbiToProjectionVftablePtr }; } if (type == typeof(string)) { return new ComWrappers.ComInterfaceEntry { IID = IID.IID_NullableString, Vtable = Nullable_string.Vftbl.AbiToProjectionVftablePtr }; } if (type == typeof(byte)) { return new ComWrappers.ComInterfaceEntry { IID = IID.IID_NullableByte, Vtable = Nullable_byte.Vftbl.AbiToProjectionVftablePtr }; } if (type == typeof(short)) { return new ComWrappers.ComInterfaceEntry { IID = IID.IID_NullableShort, Vtable = Nullable_short.Vftbl.AbiToProjectionVftablePtr }; } if (type == typeof(ushort)) { return new ComWrappers.ComInterfaceEntry { IID = IID.IID_NullableUShort, Vtable = Nullable_ushort.Vftbl.AbiToProjectionVftablePtr }; } if (type == typeof(uint)) { return new ComWrappers.ComInterfaceEntry { IID = IID.IID_NullableUInt, Vtable = Nullable_uint.Vftbl.AbiToProjectionVftablePtr }; } if (type == typeof(long)) { return new ComWrappers.ComInterfaceEntry { IID = IID.IID_NullableLong, Vtable = Nullable_long.Vftbl.AbiToProjectionVftablePtr }; } if (type == typeof(ulong)) { return new ComWrappers.ComInterfaceEntry { IID = IID.IID_NullableULong, Vtable = Nullable_ulong.Vftbl.AbiToProjectionVftablePtr }; } if (type == typeof(float)) { return new ComWrappers.ComInterfaceEntry { IID = IID.IID_NullableFloat, Vtable = Nullable_float.Vftbl.AbiToProjectionVftablePtr }; } if (type == typeof(double)) { return new ComWrappers.ComInterfaceEntry { IID = IID.IID_NullableDouble, Vtable = Nullable_double.Vftbl.AbiToProjectionVftablePtr }; } if (type == typeof(char)) { return new ComWrappers.ComInterfaceEntry { IID = IID.IID_NullableChar, Vtable = Nullable_char.Vftbl.AbiToProjectionVftablePtr }; } if (type == typeof(bool)) { return new ComWrappers.ComInterfaceEntry { IID = IID.IID_NullableBool, Vtable = Nullable_bool.Vftbl.AbiToProjectionVftablePtr }; } if (type == typeof(Guid)) { return new ComWrappers.ComInterfaceEntry { IID = IID.IID_NullableGuid, Vtable = Nullable_guid.Vftbl.AbiToProjectionVftablePtr }; } if (type == typeof(System.DateTimeOffset)) { return new ComWrappers.ComInterfaceEntry { IID = IID.IID_NullableDateTimeOffset, Vtable = Nullable_DateTimeOffset.Vftbl.AbiToProjectionVftablePtr }; } if (type == typeof(System.TimeSpan)) { return new ComWrappers.ComInterfaceEntry { IID = IID.IID_NullableTimeSpan, Vtable = Nullable_TimeSpan.Vftbl.AbiToProjectionVftablePtr }; } if (type == typeof(object)) { return new ComWrappers.ComInterfaceEntry { IID = IID.IID_NullableObject, Vtable = Nullable_Object.Vftbl.AbiToProjectionVftablePtr }; } if (type.IsTypeOfType()) { return new ComWrappers.ComInterfaceEntry { IID = IID.IID_NullableType, Vtable = Nullable_Type.Vftbl.AbiToProjectionVftablePtr }; } if (type == typeof(sbyte)) { return new ComWrappers.ComInterfaceEntry { IID = IID.IID_NullableSByte, Vtable = Nullable_sbyte.Vftbl.AbiToProjectionVftablePtr }; } if (type.IsEnum) { if (type.IsDefined(typeof(FlagsAttribute))) { return new ComWrappers.ComInterfaceEntry { IID = Nullable_FlagsEnum.GetIID(type), Vtable = Nullable_FlagsEnum.AbiToProjectionVftablePtr }; } return new ComWrappers.ComInterfaceEntry { IID = Nullable_IntEnum.GetIID(type), Vtable = Nullable_IntEnum.AbiToProjectionVftablePtr }; } if (type == typeof(System.EventHandler)) { return new ComWrappers.ComInterfaceEntry { IID = IID.IID_NullableEventHandler, Vtable = Nullable_EventHandler.AbiToProjectionVftablePtr }; } if (type.IsDelegate()) { if (!RuntimeFeature.IsDynamicCodeCompiled) { throw new NotSupportedException($"Cannot provide IReference`1 support for delegate type '{type}'."); } System.Type type2 = typeof(Nullable_Delegate<>).MakeGenericType(type); return new ComWrappers.ComInterfaceEntry { IID = GuidGenerator.GetIID(type2), Vtable = type2.GetAbiToProjectionVftblPtr() }; } if (type == typeof(System.Numerics.Matrix3x2)) { return new ComWrappers.ComInterfaceEntry { IID = IID.IID_IReferenceMatrix3x2, Vtable = BoxedValueIReferenceImpl.AbiToProjectionVftablePtr }; } if (type == typeof(System.Numerics.Matrix4x4)) { return new ComWrappers.ComInterfaceEntry { IID = IID.IID_IReferenceMatrix4x4, Vtable = BoxedValueIReferenceImpl.AbiToProjectionVftablePtr }; } if (type == typeof(System.Numerics.Plane)) { return new ComWrappers.ComInterfaceEntry { IID = IID.IID_IReferencePlane, Vtable = BoxedValueIReferenceImpl.AbiToProjectionVftablePtr }; } if (type == typeof(System.Numerics.Quaternion)) { return new ComWrappers.ComInterfaceEntry { IID = IID.IID_IReferenceQuaternion, Vtable = BoxedValueIReferenceImpl.AbiToProjectionVftablePtr }; } if (type == typeof(System.Numerics.Vector2)) { return new ComWrappers.ComInterfaceEntry { IID = IID.IID_IReferenceVector2, Vtable = BoxedValueIReferenceImpl.AbiToProjectionVftablePtr }; } if (type == typeof(System.Numerics.Vector3)) { return new ComWrappers.ComInterfaceEntry { IID = IID.IID_IReferenceVector3, Vtable = BoxedValueIReferenceImpl.AbiToProjectionVftablePtr }; } if (type == typeof(System.Numerics.Vector4)) { return new ComWrappers.ComInterfaceEntry { IID = IID.IID_IReferenceVector4, Vtable = BoxedValueIReferenceImpl.AbiToProjectionVftablePtr }; } if (type.IsTypeOfException()) { return new ComWrappers.ComInterfaceEntry { IID = IID.IID_NullableException, Vtable = Nullable_Exception.Vftbl.AbiToProjectionVftablePtr }; } if (!RuntimeFeature.IsDynamicCodeCompiled) { throw new NotSupportedException($"Cannot provide IReference`1 support for type '{type}'."); } return new ComWrappers.ComInterfaceEntry { IID = GuidGenerator.GetIID(typeof(ABI.System.Nullable<>).MakeGenericType(type)), Vtable = typeof(BoxedValueIReferenceImpl<>).MakeGenericType(type).GetAbiToProjectionVftblPtr() }; } private static ComWrappers.ComInterfaceEntry ProvideIReferenceArray(System.Type arrayType) { if (!FeatureSwitches.EnableIReferenceSupport) { throw new NotSupportedException("Support for 'IReferenceArray' is not enabled."); } System.Type elementType = arrayType.GetElementType(); if (elementType == typeof(int)) { return new ComWrappers.ComInterfaceEntry { IID = IID.IID_IReferenceArrayOfInt32, Vtable = BoxedArrayIReferenceArrayImpl.AbiToProjectionVftablePtr }; } if (elementType == typeof(string)) { return new ComWrappers.ComInterfaceEntry { IID = IID.IID_IReferenceArrayOfString, Vtable = BoxedArrayIReferenceArrayImpl.AbiToProjectionVftablePtr }; } if (elementType == typeof(byte)) { return new ComWrappers.ComInterfaceEntry { IID = IID.IID_IReferenceArrayOfByte, Vtable = BoxedArrayIReferenceArrayImpl.AbiToProjectionVftablePtr }; } if (elementType == typeof(short)) { return new ComWrappers.ComInterfaceEntry { IID = IID.IID_IReferenceArrayOfInt16, Vtable = BoxedArrayIReferenceArrayImpl.AbiToProjectionVftablePtr }; } if (elementType == typeof(ushort)) { return new ComWrappers.ComInterfaceEntry { IID = IID.IID_IReferenceArrayOfUInt16, Vtable = BoxedArrayIReferenceArrayImpl.AbiToProjectionVftablePtr }; } if (elementType == typeof(uint)) { return new ComWrappers.ComInterfaceEntry { IID = IID.IID_IReferenceArrayOfUInt32, Vtable = BoxedArrayIReferenceArrayImpl.AbiToProjectionVftablePtr }; } if (elementType == typeof(long)) { return new ComWrappers.ComInterfaceEntry { IID = IID.IID_IReferenceArrayOfInt64, Vtable = BoxedArrayIReferenceArrayImpl.AbiToProjectionVftablePtr }; } if (elementType == typeof(ulong)) { return new ComWrappers.ComInterfaceEntry { IID = IID.IID_IReferenceArrayOfUInt64, Vtable = BoxedArrayIReferenceArrayImpl.AbiToProjectionVftablePtr }; } if (elementType == typeof(float)) { return new ComWrappers.ComInterfaceEntry { IID = IID.IID_IReferenceArrayOfSingle, Vtable = BoxedArrayIReferenceArrayImpl.AbiToProjectionVftablePtr }; } if (elementType == typeof(double)) { return new ComWrappers.ComInterfaceEntry { IID = IID.IID_IReferenceArrayOfDouble, Vtable = BoxedArrayIReferenceArrayImpl.AbiToProjectionVftablePtr }; } if (elementType == typeof(char)) { return new ComWrappers.ComInterfaceEntry { IID = IID.IID_IReferenceArrayOfChar, Vtable = BoxedArrayIReferenceArrayImpl.AbiToProjectionVftablePtr }; } if (elementType == typeof(bool)) { return new ComWrappers.ComInterfaceEntry { IID = IID.IID_IReferenceArrayOfBoolean, Vtable = BoxedArrayIReferenceArrayImpl.AbiToProjectionVftablePtr }; } if (elementType == typeof(Guid)) { return new ComWrappers.ComInterfaceEntry { IID = IID.IID_IReferenceArrayOfGuid, Vtable = BoxedArrayIReferenceArrayImpl.AbiToProjectionVftablePtr }; } if (elementType == typeof(System.DateTimeOffset)) { return new ComWrappers.ComInterfaceEntry { IID = IID.IID_IReferenceArrayOfDateTimeOffset, Vtable = BoxedArrayIReferenceArrayImpl.AbiToProjectionVftablePtr }; } if (elementType == typeof(System.TimeSpan)) { return new ComWrappers.ComInterfaceEntry { IID = IID.IID_IReferenceArrayOfTimeSpan, Vtable = BoxedArrayIReferenceArrayImpl.AbiToProjectionVftablePtr }; } if (elementType == typeof(object)) { return new ComWrappers.ComInterfaceEntry { IID = IID.IID_IReferenceArrayOfObject, Vtable = BoxedArrayIReferenceArrayImpl.AbiToProjectionVftablePtr }; } if (elementType.IsTypeOfType()) { return new ComWrappers.ComInterfaceEntry { IID = IID.IID_IReferenceArrayOfType, Vtable = BoxedArrayIReferenceArrayImpl.AbiToProjectionVftablePtr }; } if (elementType == typeof(System.Numerics.Matrix3x2)) { return new ComWrappers.ComInterfaceEntry { IID = IID.IID_IReferenceArrayOfMatrix3x2, Vtable = BoxedArrayIReferenceArrayImpl.AbiToProjectionVftablePtr }; } if (elementType == typeof(System.Numerics.Matrix4x4)) { return new ComWrappers.ComInterfaceEntry { IID = IID.IID_IReferenceArrayOfMatrix4x4, Vtable = BoxedArrayIReferenceArrayImpl.AbiToProjectionVftablePtr }; } if (elementType == typeof(System.Numerics.Plane)) { return new ComWrappers.ComInterfaceEntry { IID = IID.IID_IReferenceArrayOfPlane, Vtable = BoxedArrayIReferenceArrayImpl.AbiToProjectionVftablePtr }; } if (elementType == typeof(System.Numerics.Quaternion)) { return new ComWrappers.ComInterfaceEntry { IID = IID.IID_IReferenceArrayOfQuaternion, Vtable = BoxedArrayIReferenceArrayImpl.AbiToProjectionVftablePtr }; } if (elementType == typeof(System.Numerics.Vector2)) { return new ComWrappers.ComInterfaceEntry { IID = IID.IID_IReferenceArrayOfVector2, Vtable = BoxedArrayIReferenceArrayImpl.AbiToProjectionVftablePtr }; } if (elementType == typeof(System.Numerics.Vector3)) { return new ComWrappers.ComInterfaceEntry { IID = IID.IID_IReferenceArrayOfVector3, Vtable = BoxedArrayIReferenceArrayImpl.AbiToProjectionVftablePtr }; } if (elementType == typeof(System.Numerics.Vector4)) { return new ComWrappers.ComInterfaceEntry { IID = IID.IID_IReferenceArrayOfVector4, Vtable = BoxedArrayIReferenceArrayImpl.AbiToProjectionVftablePtr }; } if (elementType.IsTypeOfException()) { return new ComWrappers.ComInterfaceEntry { IID = IID.IID_IReferenceArrayOfException, Vtable = BoxedArrayIReferenceArrayImpl.AbiToProjectionVftablePtr }; } if (!RuntimeFeature.IsDynamicCodeCompiled) { throw new NotSupportedException($"Cannot provide IReferenceArray`1 support for element type '{elementType}'."); } return new ComWrappers.ComInterfaceEntry { IID = GuidGenerator.GetIID(typeof(ABI.Windows.Foundation.IReferenceArray<>).MakeGenericType(elementType)), Vtable = typeof(BoxedArrayIReferenceArrayImpl<>).MakeGenericType(elementType).GetAbiToProjectionVftblPtr() }; } internal static ObjectReference CreateCCWForObject(object obj, Guid iid) { IntPtr thisPtr = CreateCCWForObjectForABI(obj, iid); return ObjectReference.Attach(ref thisPtr, iid); } internal static ObjectReferenceValue CreateCCWForObjectForMarshaling(object obj, Guid iid) { IntPtr ptr = CreateCCWForObjectForABI(obj, iid); return new ObjectReferenceValue(ptr); } internal static InspectableInfo GetInspectableInfo(IntPtr pThis) { object obj = FindObject(pThis); return InspectableInfoTable.GetValue(obj.GetType(), (System.Type o) => PregenerateNativeTypeInformation(o).inspectableInfo); } public static T CreateRcwForComObject(IntPtr ptr) { return CreateRcwForComObject(ptr, tryUseCache: true); } private static T CreateRcwForComObject(IntPtr ptr, bool tryUseCache) { if (ptr == IntPtr.Zero) { return default(T); } CreateRCWType = typeof(T); CreateObjectFlags flags = (tryUseCache ? CreateObjectFlags.TrackerObject : (CreateObjectFlags.TrackerObject | CreateObjectFlags.UniqueInstance)); object orCreateObjectForComInstance = ComWrappers.GetOrCreateObjectForComInstance(ptr, flags); CreateRCWType = null; object obj = orCreateObjectForComInstance; if (!(obj is ABI.System.Nullable nullable)) { if (obj is T result) { return result; } if (tryUseCache) { return CreateRcwForComObject(ptr, tryUseCache: false); } throw new ArgumentException($"Unable to create a wrapper object. The WinRT object {ptr} has type {orCreateObjectForComInstance.GetType()} which cannot be assigned to type {typeof(T)}"); } return (T)nullable.Value; } public static bool TryUnwrapObject(object o, out IObjectReference objRef) { if (o is Delegate obj) { return TryUnwrapObject(obj.Target, out objRef); } if (o is IWinRTObject { HasUnwrappableNativeObject: not false } winRTObject) { objRef = winRTObject.NativeObject; return true; } objRef = null; return false; } public static void RegisterObjectForInterface(object obj, IntPtr thisPtr, CreateObjectFlags createObjectFlags) { ComWrappers.GetOrRegisterObjectForComInstance(thisPtr, createObjectFlags, obj); } internal static void RegisterObjectForInterface(object obj, IntPtr thisPtr, IntPtr inner, CreateObjectFlags createObjectFlags) { ComWrappers.GetOrRegisterObjectForComInstance(thisPtr, createObjectFlags, obj, inner); } public static void RegisterObjectForInterface(object obj, IntPtr thisPtr) { TryRegisterObjectForInterface(obj, thisPtr); } public static object TryRegisterObjectForInterface(object obj, IntPtr thisPtr) { return ComWrappers.GetOrRegisterObjectForComInstance(thisPtr, CreateObjectFlags.TrackerObject, obj); } internal static IntPtr CreateCCWForObjectUnsafe(object obj) { return ComWrappers.GetOrCreateComInterfaceForObject(obj, CreateComInterfaceFlags.TrackerSupport); } public static IObjectReference CreateCCWForObject(object obj) { IntPtr thisPtr = ComWrappers.GetOrCreateComInterfaceForObject(obj, CreateComInterfaceFlags.TrackerSupport); return ObjectReference.Attach(ref thisPtr, IID.IID_IUnknown); } internal static IntPtr CreateCCWForObjectForABI(object obj, Guid iid) { IntPtr orCreateComInterfaceForObject = ComWrappers.GetOrCreateComInterfaceForObject(obj, CreateComInterfaceFlags.TrackerSupport); IntPtr ppv; int num = Marshal.QueryInterface(orCreateComInterfaceForObject, in iid, out ppv); Marshal.Release(orCreateComInterfaceForObject); if (num < 0) { ThrowException(obj, iid, num); } return ppv; [MethodImpl(MethodImplOptions.NoInlining)] static void ThrowException(object obj2, Guid guid, int hr) { if (hr == -2147467262) { throw new InvalidCastException($"Failed to create a CCW for object of type '{obj2.GetType()}' for interface with IID '{guid.ToString().ToUpperInvariant()}': the specified cast is not valid."); } ExceptionHelpers.ThrowExceptionForHR(hr); } } public unsafe static T FindObject(IntPtr ptr) where T : class { return ComWrappers.ComInterfaceDispatch.GetInstance((ComWrappers.ComInterfaceDispatch*)(void*)ptr); } public static IntPtr AllocateVtableMemory(System.Type vtableType, int size) { return RuntimeHelpers.AllocateTypeAssociatedMemory(vtableType, size); } public static void InitializeComWrappers(ComWrappers wrappers = null) { ComWrappers = wrappers; } internal static Func GetTypedRcwFactory(System.Type implementationType) { return TypedObjectFactoryCacheForType.GetOrAdd(implementationType, CreateTypedRcwFactory); } public static bool RegisterTypedRcwFactory(System.Type implementationType, Func rcwFactory) { return TypedObjectFactoryCacheForType.TryAdd(implementationType, rcwFactory); } private static Func CreateFactoryForImplementationType(string runtimeClassName, System.Type implementationType) { if (implementationType.IsGenericType) { if (!RuntimeFeature.IsDynamicCodeCompiled) { throw new NotSupportedException($"Cannot create an RCW factory for implementation type '{implementationType}'."); } System.Type type = GetGenericImplType(implementationType); if (type != null) { MethodInfo method = type.GetMethod("CreateRcw", BindingFlags.Static | BindingFlags.Public, null, new System.Type[1] { typeof(IInspectable) }, null); return (Func)method.CreateDelegate(typeof(Func)); } } if (implementationType.IsInterface) { return (IInspectable obj) => obj; } WinRTImplementationTypeRcwFactoryAttribute customAttribute = implementationType.GetCustomAttribute(inherit: false); if (customAttribute != null) { return customAttribute.CreateInstance; } if (!RuntimeFeature.IsDynamicCodeCompiled) { throw new NotSupportedException($"Cannot create an RCW factory for implementation type '{implementationType}', because it doesn't have " + "a [WinRTImplementationTypeRcwFactory] derived attribute on it. The fallback path for older projections is not trim-safe, and isn't supported in AOT environments. Make sure to reference updated projections."); } return CreateRcwFallback(implementationType); [UnconditionalSuppressMessage("Trimming", "IL2070", Justification = "This fallback path is not trim-safe by design (to avoid annotations).")] static Func CreateRcwFallback(System.Type type2) { ConstructorInfo constructor = type2.GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.CreateInstance, null, new System.Type[1] { typeof(IObjectReference) }, null); return delegate(IInspectable obj) { ConstructorInfo constructorInfo = constructor; object[] parameters = new IObjectReference[1] { obj.ObjRef }; return constructorInfo.Invoke(parameters); }; } [return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] static System.Type GetGenericImplType(System.Type type2) { System.Type genericTypeDefinition = type2.GetGenericTypeDefinition(); System.Type type3 = null; if (genericTypeDefinition == typeof(System.Collections.Generic.IList<>)) { type3 = typeof(IListImpl<>); } else if (genericTypeDefinition == typeof(System.Collections.Generic.IDictionary<, >)) { type3 = typeof(IDictionaryImpl<, >); } else if (genericTypeDefinition == typeof(System.Collections.Generic.IReadOnlyDictionary<, >)) { type3 = typeof(IReadOnlyDictionaryImpl<, >); } else if (genericTypeDefinition == typeof(System.Collections.Generic.IReadOnlyList<>)) { type3 = typeof(IReadOnlyListImpl<>); } else if (genericTypeDefinition == typeof(System.Collections.Generic.IEnumerable<>)) { type3 = typeof(IEnumerableImpl<>); } else { if (!(genericTypeDefinition == typeof(System.Collections.Generic.IEnumerator<>))) { return null; } type3 = typeof(IEnumeratorImpl<>); } return type3.MakeGenericType(type2.GetGenericArguments()); } } public static void RegisterTypeComInterfaceEntriesLookup(Func comInterfaceEntriesLookup) { ComInterfaceEntriesLookup.Add(comInterfaceEntriesLookup); } internal static ComWrappers.ComInterfaceEntry[] GetComInterfaceEntriesForTypeFromLookupTable(System.Type type) { int count = ComInterfaceEntriesLookup.Count; for (int i = 0; i < count; i++) { ComWrappers.ComInterfaceEntry[] array = ComInterfaceEntriesLookup[i](type); if (array != null) { return array; } } return null; } public static void RegisterTypeRuntimeClassNameLookup(Func runtimeClassNameLookup) { RuntimeClassNameForNonWinRTTypeLookup.Add(runtimeClassNameLookup); } internal static string GetRuntimeClassNameForNonWinRTTypeFromLookupTable(System.Type type) { int count = RuntimeClassNameForNonWinRTTypeLookup.Count; for (int i = 0; i < count; i++) { string text = RuntimeClassNameForNonWinRTTypeLookup[i](type); if (!string.IsNullOrEmpty(text)) { return text; } } return null; } public static void RegisterComInterfaceEntries(System.Type implementationType, ComWrappers.ComInterfaceEntry[] comInterfaceEntries) { ComInterfaceEntriesForType.TryAdd(implementationType, comInterfaceEntries); } } public class ComWrappersHelper { public static void Init(bool isAggregation, object thisInstance, IntPtr newInstance, IntPtr inner, out IObjectReference objRef) { Init(isAggregation, thisInstance, newInstance, inner, IID.IID_IUnknown, out objRef); } public static void Init(bool isAggregation, object thisInstance, IntPtr newInstance, IntPtr inner, Guid iidForNewInstance, out IObjectReference objRef) { objRef = ComWrappersSupport.GetObjectReferenceForInterface(isAggregation ? inner : newInstance, isAggregation ? IID.IID_IInspectable : iidForNewInstance, requireQI: false); if (Marshal.QueryInterface(objRef.ThisPtr, in Unsafe.AsRef(in IID.IID_IReferenceTracker), out var ppv) != 0) { ppv = default(IntPtr); } CreateObjectFlags createObjectFlags = CreateObjectFlags.None; if (ppv != (IntPtr)0) { createObjectFlags |= CreateObjectFlags.TrackerObject; } if (isAggregation) { createObjectFlags |= CreateObjectFlags.Aggregation; if (ppv != (IntPtr)0) { Marshal.Release(ppv); ComWrappersSupport.RegisterObjectForInterface(thisInstance, newInstance, inner, createObjectFlags); } else { ComWrappersSupport.RegisterObjectForInterface(thisInstance, newInstance, createObjectFlags); } } else { ComWrappersSupport.RegisterObjectForInterface(thisInstance, newInstance, createObjectFlags); } if (isAggregation) { objRef.IsAggregated = true; objRef.PreventReleaseOnDispose = ppv != (IntPtr)0; return; } if (ppv != (IntPtr)0) { objRef.ReferenceTrackerPtr = ppv; objRef.PreventReleaseFromTrackerSourceOnDispose = true; Marshal.Release(ppv); } Marshal.Release(newInstance); } public static void Init(IObjectReference objRef, bool addRefFromTrackerSource = true) { if (objRef.ReferenceTrackerPtr == IntPtr.Zero && Marshal.QueryInterface(objRef.ThisPtr, in Unsafe.AsRef(in IID.IID_IReferenceTracker), out var ppv) == 0) { objRef.ReferenceTrackerPtr = ppv; if (addRefFromTrackerSource) { objRef.AddRefFromTrackerSource(); } else { objRef.PreventReleaseFromTrackerSourceOnDispose = true; } Marshal.Release(ppv); } } } public class DefaultComWrappers : ComWrappers { private sealed class VtableEntries { public unsafe ComInterfaceEntry* Data { get; } public int Count { get; } public unsafe VtableEntries() { Data = null; Count = 0; } public unsafe VtableEntries(List entries, System.Type type) { Data = (ComInterfaceEntry*)(void*)RuntimeHelpers.AllocateTypeAssociatedMemory(type, sizeof(ComInterfaceEntry) * entries.Count); CollectionsMarshal.AsSpan(entries).CopyTo(new Span(Data, entries.Count)); Count = entries.Count; } } private static readonly ConditionalWeakTable TypeVtableEntryTable; public unsafe static IUnknownVftbl IUnknownVftbl => Unsafe.AsRef(IUnknownVftblPtr.ToPointer()); internal static IntPtr IUnknownVftblPtr { get; } unsafe static DefaultComWrappers() { TypeVtableEntryTable = new ConditionalWeakTable(); ComWrappers.GetIUnknownImpl(out var fpQueryInterface, out var fpAddRef, out var fpRelease); IUnknownVftblPtr = RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(IUnknownVftbl), sizeof(IUnknownVftbl)); *(IUnknownVftbl*)(void*)IUnknownVftblPtr = new IUnknownVftbl { QueryInterface = (delegate* unmanaged[Stdcall])(void*)fpQueryInterface, AddRef = (delegate* unmanaged[Stdcall])(void*)fpAddRef, Release = (delegate* unmanaged[Stdcall])(void*)fpRelease }; } protected unsafe override ComInterfaceEntry* ComputeVtables(object obj, CreateComInterfaceFlags flags, out int count) { VtableEntries value = TypeVtableEntryTable.GetValue(obj.GetType(), (System.Type type) => IsRuntimeImplementedRCW(type) ? new VtableEntries() : new VtableEntries(ComWrappersSupport.GetInterfaceTableEntries(type), type)); count = value.Count; if (count != 0 && !flags.HasFlag(CreateComInterfaceFlags.CallerDefinedIUnknown)) { count--; } return value.Data; } private static bool IsRuntimeImplementedRCW(System.Type objType) { if (!RuntimeFeature.IsDynamicCodeCompiled) { return false; } bool result = objType.IsCOMObject; if (objType.IsGenericType) { System.Type[] genericArguments = objType.GetGenericArguments(); foreach (System.Type type in genericArguments) { if (type.IsCOMObject) { result = true; break; } } } return result; } private static object CreateObject(IntPtr externalComObject) { Guid iid = IID.IID_IInspectable; Guid iid2 = IID.IID_IWeakReference; IntPtr ppv = IntPtr.Zero; try { if (ComWrappersSupport.CreateRCWType != null && ComWrappersSupport.CreateRCWType.IsDelegate()) { return ComWrappersSupport.GetOrCreateDelegateFactory(ComWrappersSupport.CreateRCWType)(externalComObject); } if (Marshal.QueryInterface(externalComObject, in iid, out ppv) == 0) { ObjectReference objectReferenceForInterface = ComWrappersSupport.GetObjectReferenceForInterface(ppv, IID.IID_IInspectable, requireQI: false); ComWrappersHelper.Init(objectReferenceForInterface); IInspectable inspectable = new IInspectable(objectReferenceForInterface); if (ComWrappersSupport.CreateRCWType != null && ComWrappersSupport.CreateRCWType.IsSealed) { return ComWrappersSupport.GetTypedRcwFactory(ComWrappersSupport.CreateRCWType)(inspectable); } System.Type runtimeClassForTypeCreation = ComWrappersSupport.GetRuntimeClassForTypeCreation(inspectable, ComWrappersSupport.CreateRCWType); if (runtimeClassForTypeCreation == null) { return inspectable; } return ComWrappersSupport.GetTypedRcwFactory(runtimeClassForTypeCreation)(inspectable); } if (Marshal.QueryInterface(externalComObject, in iid2, out ppv) == 0) { ObjectReference objectReferenceForInterface2 = ComWrappersSupport.GetObjectReferenceForInterface(ppv, iid2, requireQI: false); ComWrappersHelper.Init(objectReferenceForInterface2); return new SingleInterfaceOptimizedObject(typeof(WinRT.Interop.IWeakReference), objectReferenceForInterface2, requireQI: false); } return null; } finally { MarshalExtensions.ReleaseIfNotNull(ppv); } } protected override object CreateObject(IntPtr externalComObject, CreateObjectFlags flags) { object obj = CreateObject(externalComObject); if (obj is IWinRTObject { HasUnwrappableNativeObject: not false, NativeObject: not null } winRTObject) { winRTObject.NativeObject.ReleaseFromTrackerSource(); winRTObject.NativeObject.PreventReleaseFromTrackerSourceOnDispose = true; } return obj; } protected override void ReleaseObjects(System.Collections.IEnumerable objects) { foreach (object @object in objects) { if (ComWrappersSupport.TryUnwrapObject(@object, out var objRef)) { objRef.Dispose(); continue; } throw new InvalidOperationException("Cannot release objects that are not runtime wrappers of native WinRT objects."); } } } internal static class FeatureSwitches { private const string EnableDynamicObjectsSupportPropertyName = "CSWINRT_ENABLE_DYNAMIC_OBJECTS_SUPPORT"; private const string UseExceptionResourceKeysPropertyName = "CSWINRT_USE_EXCEPTION_RESOURCE_KEYS"; private const string EnableDefaultCustomTypeMappingsPropertyName = "CSWINRT_ENABLE_DEFAULT_CUSTOM_TYPE_MAPPINGS"; private const string EnableICustomPropertyProviderSupportPropertyName = "CSWINRT_ENABLE_ICUSTOMPROPERTYPROVIDER_SUPPORT"; private const string EnableIReferenceSupportPropertyName = "CSWINRT_ENABLE_IREFERENCE_SUPPORT"; private const string EnableIDynamicInterfaceCastableSupportPropertyName = "CSWINRT_ENABLE_IDYNAMICINTERFACECASTABLE"; private const string UseWindowsUIXamlProjectionsPropertyName = "CSWINRT_USE_WINDOWS_UI_XAML_PROJECTIONS"; private static int _enableDynamicObjectsSupport; private static int _useExceptionResourceKeys; private static int _enableDefaultCustomTypeMappings; private static int _enableICustomPropertyProviderSupport; private static int _enableIReferenceSupport; private static int _enableIDynamicInterfaceCastableSupport; private static int _useWindowsUIXamlProjections; public static bool EnableDynamicObjectsSupport { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return GetConfigurationValue("CSWINRT_ENABLE_DYNAMIC_OBJECTS_SUPPORT", ref _enableDynamicObjectsSupport, defaultValue: true); } } public static bool UseExceptionResourceKeys { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return GetConfigurationValue("CSWINRT_USE_EXCEPTION_RESOURCE_KEYS", ref _useExceptionResourceKeys, defaultValue: false); } } public static bool EnableDefaultCustomTypeMappings { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return GetConfigurationValue("CSWINRT_ENABLE_DEFAULT_CUSTOM_TYPE_MAPPINGS", ref _enableDefaultCustomTypeMappings, defaultValue: true); } } public static bool EnableICustomPropertyProviderSupport { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return GetConfigurationValue("CSWINRT_ENABLE_ICUSTOMPROPERTYPROVIDER_SUPPORT", ref _enableICustomPropertyProviderSupport, defaultValue: true); } } public static bool EnableIReferenceSupport { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return GetConfigurationValue("CSWINRT_ENABLE_IREFERENCE_SUPPORT", ref _enableIReferenceSupport, defaultValue: true); } } public static bool EnableIDynamicInterfaceCastableSupport { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return GetConfigurationValue("CSWINRT_ENABLE_IDYNAMICINTERFACECASTABLE", ref _enableIDynamicInterfaceCastableSupport, defaultValue: true); } } public static bool UseWindowsUIXamlProjections { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return GetConfigurationValue("CSWINRT_USE_WINDOWS_UI_XAML_PROJECTIONS", ref _useWindowsUIXamlProjections, defaultValue: false); } } private static bool GetConfigurationValue(string propertyName, ref int cachedResult, bool defaultValue) { if (cachedResult < 0) { return false; } if (cachedResult > 0) { return true; } if (!AppContext.TryGetSwitch(propertyName, out var isEnabled)) { isEnabled = defaultValue; } cachedResult = (isEnabled ? 1 : (-1)); return isEnabled; } } internal static class Context { public unsafe static IntPtr GetContextToken() { IntPtr result = default(IntPtr); Marshal.ThrowExceptionForHR(Platform.CoGetContextToken(&result)); return result; } public unsafe static IntPtr GetContextCallback() { Guid iID_IContextCallback = IID.IID_IContextCallback; IntPtr result = default(IntPtr); Marshal.ThrowExceptionForHR(Platform.CoGetObjectContext(&iID_IContextCallback, &result)); return result; } public unsafe static void CallInContext(IntPtr contextCallbackPtr, IntPtr contextToken, delegate* callback, delegate* onFailCallback, object state) { if (contextCallbackPtr == IntPtr.Zero || GetContextToken() == contextToken) { callback(state); } else { IContextCallbackVftbl.ContextCallback(contextCallbackPtr, callback, onFailCallback, state); } } public static void DisposeContextCallback(IntPtr contextCallbackPtr) { MarshalInspectable.DisposeAbi(contextCallbackPtr); } } internal static class DelegateExtensions { public static void DynamicInvokeAbi(this Delegate del, object[] invoke_params) { Marshal.ThrowExceptionForHR((int)del.DynamicInvoke(invoke_params)); } public static Func WithMarshaler2Support(this Func function) { return function.InvokeWithMarshaler2Support; } public static Action WithMarshaler2Support(this Action action) { return action.InvokeWithMarshaler2Support; } public static Action WithTypedT1(this Action action) { return action.InvokeWithTypedT1; } public static Func WithObjectT(this Func function) { return function.InvokeWithObjectT; } public static Func WithObjectTResult(this Func function) { return function.InvokeWithObjectTResult; } public static Action WithObjectParams(this Action action) { return action.InvokeWithObjectParams; } private static object InvokeWithMarshaler2Support(this Func func, object arg) { if (arg is ObjectReferenceValue objectReferenceValue) { return objectReferenceValue.GetAbi(); } return func((IObjectReference)arg); } private static void InvokeWithMarshaler2Support(this Action action, object arg) { if (arg is ObjectReferenceValue objectReferenceValue) { objectReferenceValue.Dispose(); } else { action((IObjectReference)arg); } } private static object InvokeWithObjectTResult(this Func func, T arg) { return func(arg); } private static TResult InvokeWithObjectT(this Func func, object arg) { return func((T)arg); } private static void InvokeWithObjectParams(this Action func, object arg) { func((T)arg); } private static void InvokeWithTypedT1(this Action action, T arg1, IntPtr arg2) { action(arg1, arg2); } public static object InvokeWithBoxedValueReferenceCacheInsertion(this Func factory, IInspectable inspectable) { object obj = factory(inspectable); ComWrappersSupport.BoxedValueReferenceCache.Add(obj, inspectable); return obj; } } [EditorBrowsable(EditorBrowsableState.Never)] public class DerivedComposed { public static readonly DerivedComposed Instance = new DerivedComposed(); private DerivedComposed() { } } [WindowsRuntimeType("Windows.Foundation.FoundationContract")] [WindowsRuntimeHelperType(typeof(ABI.WinRT.EventRegistrationToken))] [WinRTExposedType(typeof(StructTypeDetails))] public struct EventRegistrationToken : IEquatable { public long Value; public EventRegistrationToken(long _Value) { Value = _Value; } public static bool operator ==(EventRegistrationToken x, EventRegistrationToken y) { return x.Value == y.Value; } public static bool operator !=(EventRegistrationToken x, EventRegistrationToken y) { return !(x == y); } public bool Equals(EventRegistrationToken other) { return this == other; } public override bool Equals(object obj) { if (obj is EventRegistrationToken eventRegistrationToken) { return this == eventRegistrationToken; } return false; } public override int GetHashCode() { return Value.GetHashCode(); } } public sealed class EventRegistrationTokenTable where T : Delegate { private static readonly int TypeOfTHashCode = GetTypeOfTHashCode(); private readonly Dictionary m_tokens = new Dictionary(); private int m_low32Bits = Random.Shared.Next(int.MinValue, int.MaxValue); private static int GetTypeOfTHashCode() { int hashCode = typeof(T).GetHashCode(); if (hashCode == 0) { return 1606893974; } return hashCode; } public EventRegistrationToken AddEventHandler(T handler) { if ((object)handler == null) { return default(EventRegistrationToken); } lock (m_tokens) { int num; do { num = m_low32Bits++; } while (!m_tokens.TryAdd(num, handler)); return new EventRegistrationToken { Value = (long)(((ulong)(uint)TypeOfTHashCode << 32) | (uint)num) }; } } public bool RemoveEventHandler(EventRegistrationToken token, [NotNullWhen(true)] out T? handler) { if ((int)(token.Value >>> 32) != TypeOfTHashCode) { handler = null; return false; } lock (m_tokens) { if (m_tokens.Remove((int)token.Value, out object value)) { handler = Unsafe.As(value); return true; } } handler = null; return false; } } public static class ExceptionHelpers { private const int COR_E_OBJECTDISPOSED = -2146232798; private const int COR_E_OPERATIONCANCELED = -2146233029; private const int COR_E_ARGUMENTOUTOFRANGE = -2146233086; private const int COR_E_INDEXOUTOFRANGE = -2146233080; private const int COR_E_TIMEOUT = -2146233083; private const int RO_E_CLOSED = -2147483629; internal const int E_BOUNDS = -2147483637; internal const int E_CHANGED_STATE = -2147483636; private const int E_ILLEGAL_STATE_CHANGE = -2147483635; private const int E_ILLEGAL_METHOD_CALL = -2147483634; private const int E_ILLEGAL_DELEGATE_ASSIGNMENT = -2147483624; private const int APPMODEL_ERROR_NO_PACKAGE = -2147009196; internal const int E_XAMLPARSEFAILED = -2144665590; internal const int E_LAYOUTCYCLE = -2144665580; internal const int E_ELEMENTNOTENABLED = -2144665570; internal const int E_ELEMENTNOTAVAILABLE = -2144665569; internal const int ERROR_INVALID_WINDOW_HANDLE = -2147023496; private const int E_POINTER = -2147467261; private const int E_NOTIMPL = -2147467263; private const int E_ACCESSDENIED = -2147024891; internal const int E_INVALIDARG = -2147024809; internal const int E_NOINTERFACE = -2147467262; private const int E_OUTOFMEMORY = -2147024882; private const int ERROR_ARITHMETIC_OVERFLOW = -2147024362; private const int ERROR_FILENAME_EXCED_RANGE = -2147024690; private const int ERROR_FILE_NOT_FOUND = -2147024894; private const int ERROR_HANDLE_EOF = -2147024858; private const int ERROR_PATH_NOT_FOUND = -2147024893; private const int ERROR_STACK_OVERFLOW = -2147023895; private const int ERROR_BAD_FORMAT = -2147024885; private const int ERROR_CANCELLED = -2147023673; private const int ERROR_TIMEOUT = -2147023436; private unsafe static delegate* unmanaged[Stdcall] getRestrictedErrorInfo; private unsafe static delegate* unmanaged[Stdcall] setRestrictedErrorInfo; private unsafe static delegate* unmanaged[Stdcall] roOriginateLanguageException; private unsafe static delegate* unmanaged[Stdcall] roReportUnhandledError; private static readonly bool initialized = Initialize(); private unsafe static bool Initialize() { IntPtr intPtr = Platform.LoadLibraryExW("api-ms-win-core-winrt-error-l1-1-1.dll", IntPtr.Zero, 2048u); if (intPtr != IntPtr.Zero) { ReadOnlySpan functionName = "RoOriginateLanguageException"u8; ReadOnlySpan functionName2 = "RoReportUnhandledError"u8; roOriginateLanguageException = (delegate* unmanaged[Stdcall])(void*)Platform.GetProcAddress(intPtr, functionName); roReportUnhandledError = (delegate* unmanaged[Stdcall])(void*)Platform.GetProcAddress(intPtr, functionName2); } else { intPtr = Platform.LoadLibraryExW("api-ms-win-core-winrt-error-l1-1-0.dll", IntPtr.Zero, 2048u); } if (intPtr != IntPtr.Zero) { ReadOnlySpan functionName3 = "GetRestrictedErrorInfo"u8; ReadOnlySpan functionName4 = "SetRestrictedErrorInfo"u8; getRestrictedErrorInfo = (delegate* unmanaged[Stdcall])(void*)Platform.GetProcAddress(intPtr, functionName3); setRestrictedErrorInfo = (delegate* unmanaged[Stdcall])(void*)Platform.GetProcAddress(intPtr, functionName4); } return true; } public static void ThrowExceptionForHR(int hr) { if (hr < 0) { Throw(hr); } [MethodImpl(MethodImplOptions.NoInlining)] static void Throw(int hr2) { bool restoredExceptionFromGlobalState; System.Exception exceptionForHR = GetExceptionForHR(hr2, useGlobalErrorState: true, associateErrorInfo: true, out restoredExceptionFromGlobalState); if (restoredExceptionFromGlobalState) { ExceptionDispatchInfo.Capture(exceptionForHR).Throw(); return; } throw exceptionForHR; } } private unsafe static ObjectReferenceValue BorrowRestrictedErrorInfo() { if (getRestrictedErrorInfo == (delegate* unmanaged[Stdcall])null) { return default(ObjectReferenceValue); } IntPtr thisPtr = IntPtr.Zero; Marshal.ThrowExceptionForHR(getRestrictedErrorInfo(&thisPtr)); if (thisPtr == IntPtr.Zero) { return default(ObjectReferenceValue); } if (setRestrictedErrorInfo != (delegate* unmanaged[Stdcall])null) { setRestrictedErrorInfo(thisPtr); } return ObjectReferenceValue.Attach(ref thisPtr); } public static System.Exception GetExceptionForHR(int hr) { bool restoredExceptionFromGlobalState; if (hr < 0) { return GetExceptionForHR(hr, useGlobalErrorState: true, associateErrorInfo: false, out restoredExceptionFromGlobalState); } return null; } private static System.Exception GetExceptionForHR(int hr, bool useGlobalErrorState, bool associateErrorInfo, out bool restoredExceptionFromGlobalState) { restoredExceptionFromGlobalState = false; ObjectReference restrictedErrorObject = null; string description = null; string restrictedDescription = null; string restrictedErrorReference = null; string capabilitySid = null; string text = string.Empty; System.Exception internalGetGlobalErrorStateException = null; System.Exception languageException; if (useGlobalErrorState) { ObjectReferenceValue objectReferenceValue = default(ObjectReferenceValue); try { objectReferenceValue = BorrowRestrictedErrorInfo(); IntPtr abi = objectReferenceValue.GetAbi(); if (abi != (IntPtr)0) { if (Marshal.QueryInterface(abi, in Unsafe.AsRef(in IID.IID_ILanguageExceptionErrorInfo), out var ppv) >= 0) { try { languageException = GetLanguageException(ppv, hr); if (languageException != null) { restoredExceptionFromGlobalState = true; if (associateErrorInfo) { languageException.AddExceptionDataForRestrictedErrorInfo(ObjectReference.FromAbi(abi, IID.IID_IRestrictedErrorInfo), hasRestrictedLanguageErrorObject: true); } return languageException; } } finally { Marshal.Release(ppv); } } restrictedErrorObject = ObjectReference.FromAbi(abi, IID.IID_IRestrictedErrorInfo); IRestrictedErrorInfoMethods.GetErrorDetails(abi, out description, out var error, out restrictedDescription, out capabilitySid); restrictedErrorReference = IRestrictedErrorInfoMethods.GetReference(abi); if (hr == error) { if (!string.IsNullOrEmpty(description)) { text += description; if (!string.IsNullOrEmpty(restrictedDescription)) { text += Environment.NewLine; } } if (!string.IsNullOrEmpty(restrictedDescription)) { text += restrictedDescription; } } } } catch (System.Exception ex) { internalGetGlobalErrorStateException = ex; } finally { objectReferenceValue.Dispose(); } } switch (hr) { case -2147483636: case -2147483635: case -2147483634: case -2147483624: case -2147009196: languageException = ((!string.IsNullOrEmpty(text)) ? new InvalidOperationException(text) : new InvalidOperationException()); break; case -2144665590: languageException = ((!FeatureSwitches.UseWindowsUIXamlProjections) ? ((System.Exception)((!string.IsNullOrEmpty(text)) ? new Microsoft.UI.Xaml.Markup.XamlParseException(text) : new Microsoft.UI.Xaml.Markup.XamlParseException())) : ((System.Exception)((!string.IsNullOrEmpty(text)) ? new Windows.UI.Xaml.Markup.XamlParseException(text) : new Windows.UI.Xaml.Markup.XamlParseException()))); break; case -2144665580: languageException = ((!FeatureSwitches.UseWindowsUIXamlProjections) ? ((System.Exception)((!string.IsNullOrEmpty(text)) ? new Microsoft.UI.Xaml.LayoutCycleException(text) : new Microsoft.UI.Xaml.LayoutCycleException())) : ((System.Exception)((!string.IsNullOrEmpty(text)) ? new Windows.UI.Xaml.LayoutCycleException(text) : new Windows.UI.Xaml.LayoutCycleException()))); break; case -2144665569: languageException = ((!FeatureSwitches.UseWindowsUIXamlProjections) ? ((System.Exception)((!string.IsNullOrEmpty(text)) ? new Microsoft.UI.Xaml.Automation.ElementNotAvailableException(text) : new Microsoft.UI.Xaml.Automation.ElementNotAvailableException())) : ((System.Exception)((!string.IsNullOrEmpty(text)) ? new Windows.UI.Xaml.Automation.ElementNotAvailableException(text) : new Windows.UI.Xaml.Automation.ElementNotAvailableException()))); break; case -2144665570: languageException = ((!FeatureSwitches.UseWindowsUIXamlProjections) ? ((System.Exception)((!string.IsNullOrEmpty(text)) ? new Microsoft.UI.Xaml.Automation.ElementNotEnabledException(text) : new Microsoft.UI.Xaml.Automation.ElementNotEnabledException())) : ((System.Exception)((!string.IsNullOrEmpty(text)) ? new Windows.UI.Xaml.Automation.ElementNotEnabledException(text) : new Windows.UI.Xaml.Automation.ElementNotEnabledException()))); break; case -2147023496: languageException = new COMException("Invalid window handle. (0x80070578)\r\nConsider WindowNative, InitializeWithWindow\r\nSee https://aka.ms/cswinrt/interop#windows-sdk", -2147023496); break; case -2147483629: languageException = ((!string.IsNullOrEmpty(text)) ? new ObjectDisposedException(string.Empty, text) : new ObjectDisposedException(string.Empty)); break; case -2147467261: languageException = ((!string.IsNullOrEmpty(text)) ? new NullReferenceException(text) : new NullReferenceException()); break; case -2147467263: languageException = ((!string.IsNullOrEmpty(text)) ? new NotImplementedException(text) : new NotImplementedException()); break; case -2147024891: languageException = ((!string.IsNullOrEmpty(text)) ? new UnauthorizedAccessException(text) : new UnauthorizedAccessException()); break; case -2147024809: languageException = ((!string.IsNullOrEmpty(text)) ? new ArgumentException(text) : new ArgumentException()); break; case -2147467262: languageException = ((!string.IsNullOrEmpty(text)) ? new InvalidCastException(text) : new InvalidCastException()); break; case -2147024882: languageException = ((!string.IsNullOrEmpty(text)) ? new OutOfMemoryException(text) : new OutOfMemoryException()); break; case -2147483637: languageException = ((!string.IsNullOrEmpty(text)) ? new ArgumentOutOfRangeException(text) : new ArgumentOutOfRangeException()); break; case -2147024362: languageException = ((!string.IsNullOrEmpty(text)) ? new ArithmeticException(text) : new ArithmeticException()); break; case -2147024690: languageException = ((!string.IsNullOrEmpty(text)) ? new PathTooLongException(text) : new PathTooLongException()); break; case -2147024894: languageException = ((!string.IsNullOrEmpty(text)) ? new FileNotFoundException(text) : new FileNotFoundException()); break; case -2147024858: languageException = ((!string.IsNullOrEmpty(text)) ? new EndOfStreamException(text) : new EndOfStreamException()); break; case -2147024893: languageException = ((!string.IsNullOrEmpty(text)) ? new DirectoryNotFoundException(text) : new DirectoryNotFoundException()); break; case -2147023895: languageException = ((!string.IsNullOrEmpty(text)) ? new StackOverflowException(text) : new StackOverflowException()); break; case -2147024885: languageException = ((!string.IsNullOrEmpty(text)) ? new BadImageFormatException(text) : new BadImageFormatException()); break; case -2147023673: languageException = ((!string.IsNullOrEmpty(text)) ? new OperationCanceledException(text) : new OperationCanceledException()); break; case -2147023436: languageException = ((!string.IsNullOrEmpty(text)) ? new TimeoutException(text) : new TimeoutException()); break; default: languageException = new COMException(text, hr); break; } languageException.SetHResult(hr); if (useGlobalErrorState) { languageException.AddExceptionDataForRestrictedErrorInfo(description, restrictedDescription, restrictedErrorReference, capabilitySid, restrictedErrorObject, hasRestrictedLanguageErrorObject: false, internalGetGlobalErrorStateException); } return languageException; } private static System.Exception GetLanguageException(IntPtr languageErrorInfoPtr, int hr) { System.Exception ex = GetLanguageExceptionInternal(languageErrorInfoPtr, hr); if (ex != null) { return ex; } if (Marshal.QueryInterface(languageErrorInfoPtr, in Unsafe.AsRef(in IID.IID_ILanguageExceptionErrorInfo2), out var ppv) >= 0) { IntPtr intPtr = default(IntPtr); try { intPtr = ILanguageExceptionErrorInfo2Methods.GetPropagationContextHead(ppv); while (intPtr != (IntPtr)0) { System.Exception ex2 = GetLanguageExceptionInternal(intPtr, hr); if (ex2 != null) { return ex2; } IntPtr pUnk = intPtr; intPtr = ILanguageExceptionErrorInfo2Methods.GetPreviousLanguageExceptionErrorInfo(intPtr); Marshal.Release(pUnk); } } finally { MarshalExtensions.ReleaseIfNotNull(intPtr); Marshal.Release(ppv); } } return null; static System.Exception GetLanguageExceptionInternal(IntPtr thisPtr, int num) { IntPtr languageException = ILanguageExceptionErrorInfoMethods.GetLanguageException(thisPtr); if (languageException != (IntPtr)0) { try { if (IUnknownVftbl.IsReferenceToManagedObject(languageException)) { System.Exception ex3 = ComWrappersSupport.FindObject(languageException); if (GetHRForException(ex3) == num) { return ex3; } } } finally { Marshal.Release(languageException); } } return null; } } public unsafe static void SetErrorInfo(System.Exception ex) { try { if (getRestrictedErrorInfo != (delegate* unmanaged[Stdcall])null && setRestrictedErrorInfo != (delegate* unmanaged[Stdcall])null && roOriginateLanguageException != (delegate* unmanaged[Stdcall])null) { if (ex.TryGetRestrictedLanguageErrorInfo(out var restrictedErrorObject, out var isLanguageException)) { if (!isLanguageException && Marshal.QueryInterface(restrictedErrorObject.ThisPtr, in Unsafe.AsRef(in IID.IID_ILanguageExceptionErrorInfo2), out var ppv) >= 0) { try { ILanguageExceptionErrorInfo2Methods.CapturePropagationContext(ppv, ex); } finally { Marshal.Release(ppv); } } else if (isLanguageException) { ex.Data.Remove("__RestrictedErrorObjectReference"); ex.Data.Remove("__HasRestrictedLanguageErrorObject"); } setRestrictedErrorInfo(restrictedErrorObject.ThisPtr); GC.KeepAlive(restrictedErrorObject); return; } string text = ex.Message; if (string.IsNullOrEmpty(text)) { text = ex.GetType().FullName; } MarshalString.HSTRING_HEADER hSTRING_HEADER = default(MarshalString.HSTRING_HEADER); IntPtr intPtr = default(IntPtr); fixed (char* sourceString = text) { if (Platform.WindowsCreateStringReference((ushort*)sourceString, text.Length, (IntPtr*)(&hSTRING_HEADER), &intPtr) != 0) { intPtr = IntPtr.Zero; } IntPtr intPtr2 = ComWrappersSupport.CreateCCWForObjectUnsafe(ex); try { roOriginateLanguageException(GetHRForException(ex), intPtr, intPtr2); return; } finally { Marshal.Release(intPtr2); } } } using IObjectReference objectReference = ComWrappersSupport.CreateCCWForObject(new ManagedExceptionErrorInfo(ex)); Platform.SetErrorInfo(0u, objectReference.ThisPtr); } catch (System.Exception) { } } public unsafe static void ReportUnhandledError(System.Exception ex) { SetErrorInfo(ex); if (roReportUnhandledError != (delegate* unmanaged[Stdcall])null) { ObjectReferenceValue objectReferenceValue = BorrowRestrictedErrorInfo(); IntPtr abi = objectReferenceValue.GetAbi(); if (abi != (IntPtr)0) { roReportUnhandledError(abi); objectReferenceValue.Dispose(); } } } public static int GetHRForException(System.Exception ex) { int error = ex.HResult; try { if (ex.TryGetRestrictedLanguageErrorInfo(out var restrictedErrorObject, out var _)) { IRestrictedErrorInfoMethods.GetErrorDetails(restrictedErrorObject.ThisPtr, out error); GC.KeepAlive(restrictedErrorObject); } } catch (System.Exception) { } switch (error) { case -2146232798: return -2147483629; case -2146233029: return -2147023673; case -2146233086: case -2146233080: return -2147483637; case -2146233083: return -2147023436; default: return error; } } internal static void AddExceptionDataForRestrictedErrorInfo(this System.Exception ex, string description, string restrictedError, string restrictedErrorReference, string restrictedCapabilitySid, ObjectReference restrictedErrorObject, bool hasRestrictedLanguageErrorObject = false, System.Exception internalGetGlobalErrorStateException = null) { IDictionary data = ex.Data; if (data != null) { data["Description"] = description; data["RestrictedDescription"] = restrictedError; data["RestrictedErrorReference"] = restrictedErrorReference; data["RestrictedCapabilitySid"] = restrictedCapabilitySid; data["__RestrictedErrorObjectReference"] = restrictedErrorObject; data["__HasRestrictedLanguageErrorObject"] = hasRestrictedLanguageErrorObject; if (internalGetGlobalErrorStateException != null) { data["_InternalCsWinRTException"] = internalGetGlobalErrorStateException; } } } internal static void AddExceptionDataForRestrictedErrorInfo(this System.Exception ex, ObjectReference restrictedErrorObject, bool hasRestrictedLanguageErrorObject) { IDictionary data = ex.Data; if (data != null) { data["__RestrictedErrorObjectReference"] = restrictedErrorObject; data["__HasRestrictedLanguageErrorObject"] = hasRestrictedLanguageErrorObject; } } internal static bool TryGetRestrictedLanguageErrorInfo(this System.Exception ex, out ObjectReference restrictedErrorObject, out bool isLanguageException) { restrictedErrorObject = null; isLanguageException = false; IDictionary data = ex.Data; if (data != null) { if (data.Contains("__RestrictedErrorObjectReference")) { restrictedErrorObject = (ObjectReference)data["__RestrictedErrorObjectReference"]; } if (data.Contains("__HasRestrictedLanguageErrorObject")) { isLanguageException = (bool)data["__HasRestrictedLanguageErrorObject"]; } return restrictedErrorObject != null; } return false; } public unsafe static System.Exception AttachRestrictedErrorInfo(System.Exception e) { if (e != null) { IntPtr thisPtr = IntPtr.Zero; try { Marshal.ThrowExceptionForHR(getRestrictedErrorInfo(&thisPtr)); if (thisPtr != IntPtr.Zero) { IRestrictedErrorInfoMethods.GetErrorDetails(thisPtr, out var description, out var error, out var restrictedDescription, out var capabilitySid); if (e.HResult == error) { string reference = IRestrictedErrorInfoMethods.GetReference(thisPtr); e.AddExceptionDataForRestrictedErrorInfo(description, restrictedDescription, reference, capabilitySid, ObjectReference.Attach(ref thisPtr, IID.IID_IRestrictedErrorInfo)); } } } catch { } finally { MarshalExtensions.ReleaseIfNotNull(thisPtr); } } return e; } } public static class ExceptionExtensions { public static void SetHResult(this System.Exception ex, int value) { ex.HResult = value; } internal static System.Exception GetExceptionForHR(this System.Exception innerException, int hresult, string messageResource) { System.Exception ex; if (innerException != null) { string message = innerException.Message ?? messageResource; ex = new System.Exception(message, innerException); } else { ex = new System.Exception(messageResource); } ex.SetHResult(hresult); return ex; } } public static class GuidGenerator { private static readonly Guid wrt_pinterface_namespace = new Guid(3581604881u, 29563, 49218, 171, 174, 135, 139, 30, 22, 173, 238); [UnconditionalSuppressMessage("Trimming", "IL2067", Justification = "This method only accesses 'Type.GUID', no fields are ever needed.")] public static Guid GetGUID(System.Type type) { type = type.GetGuidType(); if (FeatureSwitches.UseWindowsUIXamlProjections && TryGetWindowsUIXamlIID(type, out var iid)) { return iid; } return type.GUID; } public static Guid GetIID([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] System.Type type) { type = type.GetGuidType(); if (FeatureSwitches.UseWindowsUIXamlProjections && TryGetWindowsUIXamlIID(type, out var iid)) { return iid; } if (!type.IsGenericType) { return type.GUID; } return (Guid)type.GetField("PIID").GetValue(null); } internal static bool TryGetWindowsUIXamlIID(System.Type type, out Guid iid) { if (type == typeof(ABI.System.Collections.Specialized.INotifyCollectionChanged)) { iid = IID.IID_WUX_INotifyCollectionChanged; return true; } if (type == typeof(ABI.System.ComponentModel.INotifyPropertyChanged)) { iid = IID.IID_WUX_INotifyPropertyChanged; return true; } if (type == typeof(ABI.System.Collections.Specialized.NotifyCollectionChangedEventArgs)) { iid = IID.IID_WUX_INotifyCollectionChangedEventArgs; return true; } if (type == typeof(ABI.System.Collections.Specialized.NotifyCollectionChangedEventHandler)) { iid = IID.IID_WUX_NotifyCollectionChangedEventHandler; return true; } if (type == typeof(ABI.System.ComponentModel.PropertyChangedEventHandler)) { iid = IID.IID_WUX_PropertyChangedEventHandler; return true; } iid = default(Guid); return false; } public static string GetSignature([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] System.Type type) { if (type == typeof(object)) { return "cinterface(IInspectable)"; } if (type == typeof(string)) { return "string"; } if (type == typeof(System.Type)) { return ABI.System.Type.GetGuidSignature(); } if (type.IsGenericType) { string[] value = SelectSignaturesForTypes(type.GetGenericArguments()); System.Type type2 = type.GetGenericTypeDefinition().FindHelperType() ?? type; return "pinterface({" + type2.GUID.ToString() + "};" + string.Join(";", value) + ")"; } System.Type type3 = type.FindHelperType(); if (type3 != null) { MethodInfo method = type3.GetMethod("GetGuidSignature", BindingFlags.Static | BindingFlags.Public); if (method != null) { return (string)method.Invoke(null, null); } } if (type.IsValueType) { switch (type.Name) { case "SByte": return "i1"; case "Byte": return "u1"; case "Int16": return "i2"; case "UInt16": return "u2"; case "Int32": return "i4"; case "UInt32": return "u4"; case "Int64": return "i8"; case "UInt64": return "u8"; case "Single": return "f4"; case "Double": return "f8"; case "Boolean": return "b1"; case "Char": return "c2"; case "Guid": return "g16"; default: if (type.IsEnum) { bool flag = type.IsDefined(typeof(FlagsAttribute)); return "enum(" + type.FullName + ";" + (flag ? "u4" : "i4") + ")"; } if (!type.IsPrimitive) { WindowsRuntimeTypeAttribute customAttribute = type.GetCustomAttribute(); if (customAttribute != null && !string.IsNullOrEmpty(customAttribute.GuidSignature)) { return customAttribute.GuidSignature; } if (customAttribute == null && (customAttribute = type.GetAuthoringMetadataType()?.GetCustomAttribute()) != null && !string.IsNullOrEmpty(customAttribute.GuidSignature)) { return customAttribute.GuidSignature; } if (!RuntimeFeature.IsDynamicCodeCompiled) { throw new InvalidOperationException($"Cannot compute signature for type '{type}', as doing so requires a fallback path that is not trim/AOT compatible. Using AOT requires all referenced projections to be up to date. Make sure to only reference WinRT projections that have been generated by a version of CsWinRT supported for AOT."); } string[] value2 = SelectSignaturesForFields(type.GetFields(BindingFlags.Instance | BindingFlags.Public)); return "struct(" + type.FullName + ";" + string.Join(";", value2) + ")"; } throw new InvalidOperationException("Unsupported value type."); } } type = (type.IsInterface ? (type3 ?? type) : type); if (type.IsDelegate()) { return "delegate({" + GetGUID(type).ToString() + "})"; } if (TryGetSignatureFromDefaultInterfaceTypeForRuntimeClassType(type, out var signature)) { return signature; } return "{" + type.GUID.ToString() + "}"; [UnconditionalSuppressMessage("Trimming", "IL2072", Justification = "Fallback path for old projections, not trim-safe by design.")] static string[] SelectSignaturesForFields(FieldInfo[] fields) { string[] array = new string[fields.Length]; for (int i = 0; i < fields.Length; i++) { array[i] = GetSignature(fields[i].FieldType); } return array; } [UnconditionalSuppressMessage("Trimming", "IL2062", Justification = "Fallback path for old projections, not trim-safe by design.")] static string[] SelectSignaturesForTypes(System.Type[] types) { string[] array = new string[types.Length]; for (int i = 0; i < types.Length; i++) { array[i] = GetSignature(types[i]); } return array; } [UnconditionalSuppressMessage("Trimming", "IL2067", Justification = "'GetSignature' will only actually use reflection when using old projections.")] static bool TryGetSignatureFromDefaultInterfaceTypeForRuntimeClassType(System.Type type4, out string reference) { if (type4.IsClass && Projections.TryGetDefaultInterfaceTypeForRuntimeClassType(type4, out var defaultInterface)) { reference = "rc(" + type4.FullName + ";" + GetSignature(defaultInterface) + ")"; return true; } reference = null; return false; } } private static Guid encode_guid(Span data) { if (BitConverter.IsLittleEndian) { byte b = data[0]; data[0] = data[3]; data[3] = b; b = data[1]; data[1] = data[2]; data[2] = b; b = data[4]; data[4] = data[5]; data[5] = b; b = data[6]; data[6] = data[7]; data[7] = (byte)((b & 0xF) | 0x50); data[8] = (byte)((data[8] & 0x3F) | 0x80); } return new Guid(data.Slice(0, 16)); } public static Guid CreateIID([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] System.Type type) { string signature = GetSignature(type); if (!type.IsGenericType) { return new Guid(signature); } return CreateIIDForGenericType(signature); } [UnconditionalSuppressMessage("Trimming", "IL2067", Justification = "This method is only used for types (eg. generics) where fields aren't needed.")] internal static Guid CreateIIDUnsafe(System.Type type) { return CreateIID(type); } internal static Guid CreateIIDForGenericType(string signature) { int maxByteCount = Encoding.UTF8.GetMaxByteCount(signature.Length); byte[] array = new byte[16 + maxByteCount]; Span destination = array; wrt_pinterface_namespace.TryWriteBytes(destination); int bytes = Encoding.UTF8.GetBytes(signature, destination.Slice(16, destination.Length - 16)); array = array[..(16 + bytes)]; return encode_guid(SHA1.HashData(array)); } } public enum TrustLevel { BaseTrust, PartialTrust, FullTrust } [Guid("AF86E2E0-B12D-4c6a-9C5A-D7AA65101E90")] public class IInspectable : IWinRTObject, IDynamicInterfaceCastable { [Guid("AF86E2E0-B12D-4c6a-9C5A-D7AA65101E90")] public struct Vftbl { public IUnknownVftbl IUnknownVftbl; private unsafe void* _GetIids; private unsafe void* _GetRuntimeClassName; private unsafe void* _GetTrustLevel; public static readonly Vftbl AbiToProjectionVftable; public static readonly IntPtr AbiToProjectionVftablePtr; public unsafe delegate* unmanaged[Stdcall] GetIids { get { return (delegate* unmanaged[Stdcall])_GetIids; } set { _GetIids = value; } } public unsafe delegate* unmanaged[Stdcall] GetRuntimeClassName { get { return (delegate* unmanaged[Stdcall])_GetRuntimeClassName; } set { _GetRuntimeClassName = value; } } public unsafe delegate* unmanaged[Stdcall] GetTrustLevel { get { return (delegate* unmanaged[Stdcall])_GetTrustLevel; } set { _GetTrustLevel = value; } } unsafe static Vftbl() { AbiToProjectionVftable = new Vftbl { IUnknownVftbl = IUnknownVftbl.AbiToProjectionVftbl, _GetIids = (delegate*)(&Do_Abi_GetIids), _GetRuntimeClassName = (delegate*)(&Do_Abi_GetRuntimeClassName), _GetTrustLevel = (delegate*)(&Do_Abi_GetTrustLevel) }; AbiToProjectionVftablePtr = Marshal.AllocHGlobal(sizeof(Vftbl)); *(Vftbl*)(void*)AbiToProjectionVftablePtr = AbiToProjectionVftable; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_GetIids(IntPtr pThis, int* iidCount, IntPtr* iids) { *iidCount = 0; *iids = IntPtr.Zero; try { ref IntPtr reference = ref *iids; (int, IntPtr) tuple = MarshalBlittable.FromManagedArray(ComWrappersSupport.GetInspectableInfo(pThis).IIDs); *iidCount = tuple.Item1; reference = tuple.Item2; } catch (System.Exception ex) { return ex.HResult; } return 0; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_GetRuntimeClassName(IntPtr pThis, IntPtr* className) { *className = default(IntPtr); try { string runtimeClassName = ComWrappersSupport.GetInspectableInfo(pThis).RuntimeClassName; *className = MarshalString.FromManaged(runtimeClassName); } catch (System.Exception ex) { return ex.HResult; } return 0; } [UnmanagedCallersOnly] private unsafe static int Do_Abi_GetTrustLevel(IntPtr pThis, TrustLevel* trustLevel) { *trustLevel = TrustLevel.BaseTrust; return 0; } } private readonly ObjectReference _obj; private volatile ConcurrentDictionary _queryInterfaceCache; private volatile ConcurrentDictionary _additionalTypeData; public IntPtr ThisPtr => _obj.ThisPtr; public IObjectReference ObjRef => _obj; IObjectReference IWinRTObject.NativeObject => _obj; bool IWinRTObject.HasUnwrappableNativeObject => true; ConcurrentDictionary IWinRTObject.QueryInterfaceCache => _queryInterfaceCache ?? MakeQueryInterfaceCache(); ConcurrentDictionary IWinRTObject.AdditionalTypeData => _additionalTypeData ?? MakeAdditionalTypeData(); public static IInspectable FromAbi(IntPtr thisPtr) { return new IInspectable(ObjectReference.FromAbi(thisPtr, IID.IID_IInspectable)); } [RequiresUnreferencedCode("This method is not trim-safe, and is only supported for use when not using trimming (or AOT).")] [Obsolete("This method is deprecated and will be removed in a future release.")] [EditorBrowsable(EditorBrowsableState.Never)] public ObjectReference As() { return _obj.As(); } public IInspectable(IObjectReference obj) : this(obj.As(IID.IID_IInspectable)) { } [Obsolete("This method is deprecated and will be removed in a future release.")] [EditorBrowsable(EditorBrowsableState.Never)] public IInspectable(ObjectReference obj) : this(obj.As(IID.IID_IInspectable)) { } internal IInspectable(ObjectReference obj) { _obj = obj; } public unsafe string GetRuntimeClassName(bool noThrow = false) { IntPtr hstring = default(IntPtr); try { IntPtr thisPtr = ThisPtr; int num = ((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)thisPtr) + (nint)4 * (nint)sizeof(void*))))(thisPtr, &hstring); GC.KeepAlive(_obj); if (num != 0) { if (noThrow) { return null; } Marshal.ThrowExceptionForHR(num); } uint length = default(uint); char* value = Platform.WindowsGetStringRawBuffer(hstring, &length); return new string(value, 0, (int)length); } finally { Platform.WindowsDeleteString(hstring); } } private ConcurrentDictionary MakeQueryInterfaceCache() { Interlocked.CompareExchange(ref _queryInterfaceCache, new ConcurrentDictionary(), null); return _queryInterfaceCache; } private ConcurrentDictionary MakeAdditionalTypeData() { Interlocked.CompareExchange(ref _additionalTypeData, new ConcurrentDictionary(), null); return _additionalTypeData; } } public interface IWinRTObject : IDynamicInterfaceCastable { IObjectReference NativeObject { get; } bool HasUnwrappableNativeObject { get; } protected ConcurrentDictionary QueryInterfaceCache { get; } ConcurrentDictionary AdditionalTypeData { get; } bool IDynamicInterfaceCastable.IsInterfaceImplemented(RuntimeTypeHandle interfaceType, bool throwIfNotImplemented) { if (!FeatureSwitches.EnableIDynamicInterfaceCastableSupport) { return false; } return IsInterfaceImplementedFallback(interfaceType, throwIfNotImplemented); } internal sealed bool IsInterfaceImplementedFallback(RuntimeTypeHandle interfaceType, bool throwIfNotImplemented) { if (!FeatureSwitches.EnableIDynamicInterfaceCastableSupport) { if (!throwIfNotImplemented) { return false; } throw new NotSupportedException("Support for 'IDynamicInterfaceCastable' is disabled (make sure that the 'CsWinRTEnableIDynamicInterfaceCastableSupport' property is not set to 'false')."); } if (QueryInterfaceCache.ContainsKey(interfaceType)) { return true; } System.Type type = System.Type.GetTypeFromHandle(interfaceType); if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(System.Collections.Generic.IReadOnlyCollection<>)) { if (!RuntimeFeature.IsDynamicCodeCompiled) { if (!throwIfNotImplemented) { return false; } throw new NotSupportedException($"'IDynamicInterfaceCastable' is not supported for generic type '{type}'."); } System.Type type2 = type.GetGenericArguments()[0]; if (type2.IsGenericType && type2.GetGenericTypeDefinition() == typeof(System.Collections.Generic.KeyValuePair<, >)) { System.Type type3 = typeof(System.Collections.Generic.IReadOnlyDictionary<, >).MakeGenericType(type2.GetGenericArguments()); if (IsInterfaceImplemented(type3.TypeHandle, throwIfNotImplemented: false)) { if (QueryInterfaceCache.TryGetValue(type3.TypeHandle, out var value) && !QueryInterfaceCache.TryAdd(interfaceType, value)) { value.Dispose(); } return true; } } System.Type type4 = typeof(System.Collections.Generic.IReadOnlyList<>).MakeGenericType(type2); if (IsInterfaceImplemented(type4.TypeHandle, throwIfNotImplemented)) { if (QueryInterfaceCache.TryGetValue(type4.TypeHandle, out var value2) && !QueryInterfaceCache.TryAdd(interfaceType, value2)) { value2.Dispose(); } return true; } return false; } if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(System.Collections.Generic.ICollection<>)) { if (!RuntimeFeature.IsDynamicCodeCompiled) { if (!throwIfNotImplemented) { return false; } throw new NotSupportedException($"'IDynamicInterfaceCastable' is not supported for generic type '{type}'."); } System.Type type5 = type.GetGenericArguments()[0]; if (type5.IsGenericType && type5.GetGenericTypeDefinition() == typeof(System.Collections.Generic.KeyValuePair<, >)) { System.Type type6 = typeof(System.Collections.Generic.IDictionary<, >).MakeGenericType(type5.GetGenericArguments()); if (IsInterfaceImplemented(type6.TypeHandle, throwIfNotImplemented: false)) { if (QueryInterfaceCache.TryGetValue(type6.TypeHandle, out var value3) && !QueryInterfaceCache.TryAdd(interfaceType, value3)) { value3.Dispose(); } return true; } } System.Type type7 = typeof(System.Collections.Generic.IList<>).MakeGenericType(type5); if (IsInterfaceImplemented(type7.TypeHandle, throwIfNotImplemented)) { if (QueryInterfaceCache.TryGetValue(type7.TypeHandle, out var value4) && !QueryInterfaceCache.TryAdd(interfaceType, value4)) { value4.Dispose(); } return true; } return false; } if (type == typeof(System.Collections.IEnumerable)) { System.Type typeFromHandle = typeof(System.Collections.Generic.IEnumerable); if (IsInterfaceImplemented(typeFromHandle.TypeHandle, throwIfNotImplemented: false)) { if (QueryInterfaceCache.TryGetValue(typeFromHandle.TypeHandle, out var value5) && !QueryInterfaceCache.TryAdd(interfaceType, value5)) { value5.Dispose(); } return true; } } else if (type == typeof(System.Collections.ICollection)) { System.Type typeFromHandle2 = typeof(System.Collections.IList); if (IsInterfaceImplemented(typeFromHandle2.TypeHandle, throwIfNotImplemented: false)) { if (QueryInterfaceCache.TryGetValue(typeFromHandle2.TypeHandle, out var value6) && !QueryInterfaceCache.TryAdd(interfaceType, value6)) { value6.Dispose(); } return true; } } if (!Projections.IsTypeWindowsRuntimeType(type)) { return false; } System.Type type8 = type.FindHelperType(throwIfNotImplemented); if ((object)type8 == null || !type8.IsInterface) { return false; } ObjectReference objRef; int num = NativeObject.TryAs(GuidGenerator.GetIID(type8), out objRef); if (num < 0) { if (throwIfNotImplemented) { ExceptionHelpers.ThrowExceptionForHR(num); } return false; } if (typeof(System.Collections.IEnumerable).IsAssignableFrom(type)) { RuntimeTypeHandle typeHandle = typeof(System.Collections.IEnumerable).TypeHandle; AdditionalTypeData.GetOrAdd(typeHandle, (RuntimeTypeHandle _) => new ABI.System.Collections.IEnumerable.AdaptiveFromAbiHelper(type, this)); } bool flag = false; try { System.Type type9 = type8.FindVftblType(); if ((object)type9 == null) { flag = QueryInterfaceCache.TryAdd(interfaceType, objRef); return true; } if (!RuntimeFeature.IsDynamicCodeCompiled) { if (!throwIfNotImplemented) { return false; } throw new NotSupportedException($"Cannot construct an object reference for vtable type '{type9}'."); } IObjectReference objectReference = GetObjectReferenceViaVftbl(objRef, type9); if (!QueryInterfaceCache.TryAdd(interfaceType, objectReference)) { objectReference.Dispose(); } return true; } finally { if (!flag) { objRef.Dispose(); } } [MethodImpl(MethodImplOptions.NoInlining)] [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "If the 'Vftbl' type is kept, we can assume all its metadata will also have been rooted.")] internal static IObjectReference GetObjectReferenceViaVftbl(IObjectReference obj, System.Type vftblType) { return (IObjectReference)typeof(IObjectReference).GetMethod("As", System.Type.EmptyTypes).MakeGenericMethod(vftblType).Invoke(obj, null); } } RuntimeTypeHandle IDynamicInterfaceCastable.GetInterfaceImplementation(RuntimeTypeHandle interfaceType) { System.Type typeFromHandle = System.Type.GetTypeFromHandle(interfaceType); System.Type helperType = typeFromHandle.GetHelperType(); if (helperType.IsInterface) { return helperType.TypeHandle; } return default(RuntimeTypeHandle); } IObjectReference GetObjectReferenceForType(RuntimeTypeHandle type) { return GetObjectReferenceForTypeFallback(type); } internal sealed IObjectReference GetObjectReferenceForTypeFallback(RuntimeTypeHandle type) { if (IsInterfaceImplemented(type, throwIfNotImplemented: true)) { return QueryInterfaceCache[type]; } throw new System.Exception("Interface '" + System.Type.GetTypeFromHandle(type)?.ToString() + "' is not implemented."); } } internal static class MarshalExtensions { [MethodImpl(MethodImplOptions.AggressiveInlining)] public unsafe static void ReleaseIfNotNull(IntPtr pUnk) { if ((void*)pUnk != null) { ((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)pUnk) + (nint)2 * (nint)sizeof(void*))))(pUnk); } } public static void Dispose(this GCHandle handle) { if (handle.IsAllocated) { handle.Free(); } } } public class MarshalString { internal struct HSTRING_HEADER { private IntPtr reserved1; private int reserved2; private int reserved3; private int reserved4; private int reserved5; } public ref struct Pinnable { private readonly HSTRING_HEADER _header; private readonly string _value; public Pinnable(string value) { _value = value ?? ""; _header = default(HSTRING_HEADER); } public ref readonly char GetPinnableReference() { return ref _value.GetPinnableReference(); } public unsafe IntPtr GetAbi() { if (_value == "") { return IntPtr.Zero; } IntPtr result = default(IntPtr); Marshal.ThrowExceptionForHR(Platform.WindowsCreateStringReference((ushort*)Unsafe.AsPointer(ref Unsafe.AsRef(in GetPinnableReference())), _value.Length, (IntPtr*)Unsafe.AsPointer(ref Unsafe.AsRef(in _header)), &result)); return result; } } public struct MarshalerArray { public IntPtr _array; public MarshalString[] _marshalers; public void Dispose() { if (_marshalers != null) { MarshalString[] marshalers = _marshalers; for (int i = 0; i < marshalers.Length; i++) { marshalers[i]?.Dispose(); } } if (_array != IntPtr.Zero) { Marshal.FreeCoTaskMem(_array); } } } private IntPtr _header; private GCHandle _gchandle; public static Pinnable CreatePinnable(string value) { return new Pinnable(value); } public static IntPtr GetAbi(ref Pinnable p) { return p.GetAbi(); } public MarshalString(string value) { _gchandle = GCHandle.Alloc(value, GCHandleType.Pinned); _header = IntPtr.Zero; } public void Dispose() { _gchandle.Dispose(); _gchandle = default(GCHandle); Marshal.FreeHGlobal(_header); _header = IntPtr.Zero; } public static MarshalString CreateMarshaler(string value) { if (!string.IsNullOrEmpty(value)) { return new MarshalString(value); } return null; } public unsafe IntPtr GetAbi() { string text = (string)_gchandle.Target; fixed (char* sourceString = text) { _header = Marshal.AllocHGlobal(sizeof(HSTRING_HEADER)); IntPtr result = default(IntPtr); Marshal.ThrowExceptionForHR(Platform.WindowsCreateStringReference((ushort*)sourceString, text.Length, (IntPtr*)(void*)_header, &result)); return result; } } public static IntPtr GetAbi(MarshalString m) { return m?.GetAbi() ?? IntPtr.Zero; } public static IntPtr GetAbi(object box) { if (box != null) { return GetAbi((MarshalString)box); } return IntPtr.Zero; } public static void DisposeMarshaler(MarshalString m) { m?.Dispose(); } public static void DisposeMarshaler(object box) { if (box != null) { DisposeMarshaler((MarshalString)box); } } public static void DisposeAbi(IntPtr hstring) { if (hstring != IntPtr.Zero) { Platform.WindowsDeleteString(hstring); } } public static void DisposeAbi(object abi) { if (abi != null) { DisposeAbi((IntPtr)abi); } } public unsafe static string FromAbi(IntPtr value) { if (value == IntPtr.Zero) { return ""; } uint length = default(uint); char* value2 = Platform.WindowsGetStringRawBuffer(value, &length); return new string(value2, 0, (int)length); } public unsafe static ReadOnlySpan FromAbiUnsafe(IntPtr value) { if (value == IntPtr.Zero) { return "".AsSpan(); } uint length = default(uint); char* pointer = Platform.WindowsGetStringRawBuffer(value, &length); return new ReadOnlySpan(pointer, (int)length); } public unsafe static IntPtr FromManaged(string value) { if (value == null) { return IntPtr.Zero; } IntPtr result = default(IntPtr); fixed (char* sourceString = value) { Marshal.ThrowExceptionForHR(Platform.WindowsCreateString((ushort*)sourceString, value.Length, &result)); } return result; } public unsafe static MarshalerArray CreateMarshalerArray(string[] array) { MarshalerArray result = default(MarshalerArray); if (array == null) { return result; } bool flag = false; try { int num = array.Length; result._array = Marshal.AllocCoTaskMem(num * sizeof(IntPtr)); result._marshalers = new MarshalString[num]; IntPtr* ptr = (IntPtr*)result._array.ToPointer(); for (int i = 0; i < num; i++) { result._marshalers[i] = CreateMarshaler(array[i]); ptr[i] = GetAbi(result._marshalers[i]); } flag = true; return result; } finally { if (!flag) { result.Dispose(); } } } public static (int length, IntPtr data) GetAbiArray(object box) { MarshalerArray marshalerArray = (MarshalerArray)box; MarshalString[] marshalers = marshalerArray._marshalers; return (length: (marshalers != null) ? marshalers.Length : 0, data: marshalerArray._array); } public unsafe static string[] FromAbiArray(object box) { if (box == null) { return null; } (int, IntPtr) tuple = ((int, IntPtr))box; if (tuple.Item2 == IntPtr.Zero) { return null; } string[] array = new string[tuple.Item1]; IntPtr* ptr = (IntPtr*)tuple.Item2.ToPointer(); for (int i = 0; i < tuple.Item1; i++) { array[i] = FromAbi(ptr[i]); } return array; } public unsafe static void CopyAbiArray(string[] array, object box) { (int, IntPtr) tuple = ((int, IntPtr))box; IntPtr* ptr = (IntPtr*)tuple.Item2.ToPointer(); for (int i = 0; i < tuple.Item1; i++) { array[i] = FromAbi(ptr[i]); } } public unsafe static (int length, IntPtr data) FromManagedArray(string[] array) { if (array == null) { return (length: 0, data: IntPtr.Zero); } IntPtr intPtr = IntPtr.Zero; int i = 0; bool flag = false; try { int num = array.Length; intPtr = Marshal.AllocCoTaskMem(num * sizeof(IntPtr)); IntPtr* ptr = (IntPtr*)(void*)intPtr; for (i = 0; i < num; i++) { ptr[i] = FromManaged(array[i]); } flag = true; return (length: i, data: intPtr); } finally { if (!flag) { DisposeAbiArray((i, intPtr)); } } } public unsafe static void CopyManagedArray(string[] array, IntPtr data) { if (array == null) { return; } DisposeAbiArrayElements((length: array.Length, data: data)); int i = 0; bool flag = false; try { int num = array.Length; IntPtr* ptr = (IntPtr*)(void*)data; for (i = 0; i < num; i++) { ptr[i] = FromManaged(array[i]); } flag = true; } finally { if (!flag) { DisposeAbiArrayElements((length: i, data: data)); } } } public static void DisposeMarshalerArray(object box) { if (box != null) { ((MarshalerArray)box).Dispose(); } } public unsafe static void DisposeAbiArrayElements((int length, IntPtr data) abi) { IntPtr* ptr = (IntPtr*)(void*)abi.data; for (int i = 0; i < abi.length; i++) { DisposeAbi(ptr[i]); } } public static void DisposeAbiArray(object box) { if (box != null) { (int, IntPtr) abi = ((int, IntPtr))box; DisposeAbiArrayElements(abi); Marshal.FreeCoTaskMem(abi.Item2); } } } [StructLayout(LayoutKind.Sequential, Size = 1)] public struct MarshalBlittable { public struct MarshalerArray { public GCHandle _gchandle; public MarshalerArray(Array array) { _gchandle = ((array == null) ? default(GCHandle) : GCHandle.Alloc(array, GCHandleType.Pinned)); } public void Dispose() { _gchandle.Dispose(); } } public static MarshalerArray CreateMarshalerArray(Array array) { return new MarshalerArray(array); } public static (int length, IntPtr data) GetAbiArray(object box) { MarshalerArray marshalerArray = (MarshalerArray)box; if (!marshalerArray._gchandle.IsAllocated) { return (length: 0, data: IntPtr.Zero); } return (length: ((Array)marshalerArray._gchandle.Target).Length, data: marshalerArray._gchandle.AddrOfPinnedObject()); } public unsafe static T[] FromAbiArray(object box) { if (box == null) { return null; } (int, IntPtr) tuple = ((int, IntPtr))box; if (tuple.Item2 == IntPtr.Zero) { return null; } if (tuple.Item1 == 0) { return new T[0]; } return new ReadOnlySpan(tuple.Item2.ToPointer(), tuple.Item1).ToArray(); } public static (int length, IntPtr data) FromManagedArray(Array array) { if (array == null) { return (length: 0, data: IntPtr.Zero); } int length = array.Length; int cb = length * Unsafe.SizeOf(); IntPtr intPtr = Marshal.AllocCoTaskMem(cb); CopyManagedArray(array, intPtr); return (length: length, data: intPtr); } public unsafe static void CopyManagedArray(Array array, IntPtr data) { if (array != null) { int length = array.Length; int num = length * Unsafe.SizeOf(); fixed (byte* arrayDataReference = &MemoryMarshal.GetArrayDataReference(array)) { Buffer.MemoryCopy(arrayDataReference, data.ToPointer(), num, num); } } } public static void DisposeMarshalerArray(object box) { if (box != null) { ((MarshalerArray)box).Dispose(); } } public static void DisposeAbiArray(object box) { if (box != null) { Marshal.FreeCoTaskMem((((int, IntPtr))box).Item2); } } } public class MarshalGeneric { [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] protected static readonly System.Type HelperType; protected static readonly System.Type AbiType; protected static readonly System.Type MarshalerType; internal static readonly bool MarshalByObjectReferenceValueSupported; public static readonly Func CreateMarshaler; public static readonly Func GetAbi; public static readonly Action CopyAbi; public static readonly Func FromAbi; public static readonly Func FromManaged; public static readonly Action CopyManaged; public static readonly Action DisposeMarshaler; internal static readonly Func CreateMarshaler2; internal static readonly Action DisposeAbi; internal static readonly Func CreateMarshalerArray; internal static readonly Func GetAbiArray; internal static readonly Func FromAbiArray; internal static readonly Func FromManagedArray; internal static readonly Action DisposeMarshalerArray; internal static readonly Action DisposeAbiArray; static MarshalGeneric() { if (typeof(T) == typeof(System.Numerics.Vector2)) { HelperType = typeof(ABI.System.Numerics.Vector2); } else if (typeof(T) == typeof(System.Numerics.Vector3)) { HelperType = typeof(ABI.System.Numerics.Vector3); } else if (typeof(T) == typeof(System.Numerics.Vector4)) { HelperType = typeof(ABI.System.Numerics.Vector4); } else if (typeof(T) == typeof(System.Numerics.Plane)) { HelperType = typeof(ABI.System.Numerics.Plane); } else if (typeof(T) == typeof(System.Numerics.Matrix3x2)) { HelperType = typeof(ABI.System.Numerics.Matrix3x2); } else if (typeof(T) == typeof(System.Numerics.Matrix4x4)) { HelperType = typeof(ABI.System.Numerics.Matrix4x4); } else if (typeof(T) == typeof(System.Numerics.Quaternion)) { HelperType = typeof(ABI.System.Numerics.Quaternion); } else if (typeof(T) == typeof(Windows.Foundation.Size)) { HelperType = typeof(ABI.Windows.Foundation.Size); } else if (typeof(T) == typeof(Windows.Foundation.Point)) { HelperType = typeof(ABI.Windows.Foundation.Point); } else if (typeof(T) == typeof(Windows.Foundation.Rect)) { HelperType = typeof(ABI.Windows.Foundation.Rect); } else if (!(typeof(T) == typeof(int)) && !(typeof(T) == typeof(byte)) && !(typeof(T) == typeof(sbyte)) && !(typeof(T) == typeof(short)) && !(typeof(T) == typeof(ushort)) && !(typeof(T) == typeof(uint)) && !(typeof(T) == typeof(long)) && !(typeof(T) == typeof(ulong)) && !(typeof(T) == typeof(float)) && !(typeof(T) == typeof(double)) && !(typeof(T) == typeof(Guid)) && !typeof(System.Exception).IsAssignableFrom(typeof(T))) { if (typeof(T) == typeof(bool)) { HelperType = typeof(ABI.System.Boolean); AbiType = typeof(byte); MarshalerType = typeof(bool); CreateMarshaler = (Func)(object)new Func(NonBlittableMarshallingStubs.Boolean_CreateMarshaler); CreateMarshaler2 = CreateMarshaler; GetAbi = NonBlittableMarshallingStubs.Boolean_GetAbi; FromAbi = (Func)(object)new Func(NonBlittableMarshallingStubs.Boolean_FromAbi); CopyAbi = NonBlittableMarshallingStubs.Boolean_CopyAbi; FromManaged = (Func)(object)new Func(NonBlittableMarshallingStubs.Boolean_FromManaged); CopyManaged = (Action)(object)new Action(ABI.System.Boolean.CopyManaged); DisposeMarshaler = NonBlittableMarshallingStubs.NoOpFunc; DisposeAbi = NonBlittableMarshallingStubs.NoOpFunc; } else if (typeof(T) == typeof(char)) { HelperType = typeof(ABI.System.Char); AbiType = typeof(ushort); MarshalerType = typeof(char); CreateMarshaler = (Func)(object)new Func(NonBlittableMarshallingStubs.Char_CreateMarshaler); CreateMarshaler2 = CreateMarshaler; GetAbi = NonBlittableMarshallingStubs.Char_GetAbi; FromAbi = (Func)(object)new Func(NonBlittableMarshallingStubs.Char_FromAbi); CopyAbi = NonBlittableMarshallingStubs.Char_CopyAbi; FromManaged = (Func)(object)new Func(NonBlittableMarshallingStubs.Char_FromManaged); CopyManaged = (Action)(object)new Action(ABI.System.Char.CopyManaged); DisposeMarshaler = NonBlittableMarshallingStubs.NoOpFunc; DisposeAbi = NonBlittableMarshallingStubs.NoOpFunc; } else if (typeof(T) == typeof(System.TimeSpan)) { HelperType = typeof(ABI.System.TimeSpan); AbiType = typeof(ABI.System.TimeSpan); MarshalerType = typeof(ABI.System.TimeSpan.Marshaler); CreateMarshaler = (Func)(object)new Func(NonBlittableMarshallingStubs.TimeSpan_CreateMarshaler); CreateMarshaler2 = CreateMarshaler; GetAbi = NonBlittableMarshallingStubs.TimeSpan_GetAbi; FromAbi = (Func)(object)new Func(NonBlittableMarshallingStubs.TimeSpan_FromAbi); CopyAbi = NonBlittableMarshallingStubs.TimeSpan_CopyAbi; FromManaged = (Func)(object)new Func(NonBlittableMarshallingStubs.TimeSpan_FromManaged); CopyManaged = (Action)(object)new Action(ABI.System.TimeSpan.CopyManaged); DisposeMarshaler = NonBlittableMarshallingStubs.NoOpFunc; DisposeAbi = NonBlittableMarshallingStubs.NoOpFunc; } else if (typeof(T) == typeof(System.DateTimeOffset)) { HelperType = typeof(ABI.System.DateTimeOffset); AbiType = typeof(ABI.System.DateTimeOffset); MarshalerType = typeof(ABI.System.DateTimeOffset.Marshaler); CreateMarshaler = (Func)(object)new Func(NonBlittableMarshallingStubs.DateTimeOffset_CreateMarshaler); CreateMarshaler2 = CreateMarshaler; GetAbi = NonBlittableMarshallingStubs.DateTimeOffset_GetAbi; FromAbi = (Func)(object)new Func(NonBlittableMarshallingStubs.DateTimeOffset_FromAbi); CopyAbi = NonBlittableMarshallingStubs.DateTimeOffset_CopyAbi; FromManaged = (Func)(object)new Func(NonBlittableMarshallingStubs.DateTimeOffset_FromManaged); CopyManaged = (Action)(object)new Action(ABI.System.DateTimeOffset.CopyManaged); DisposeMarshaler = NonBlittableMarshallingStubs.NoOpFunc; DisposeAbi = NonBlittableMarshallingStubs.NoOpFunc; } else if (typeof(T).IsValueType) { HelperType = typeof(T).GetHelperType(); AbiType = typeof(T).GetAbiType(); MarshalerType = typeof(T).GetMarshalerType(); MarshalByObjectReferenceValueSupported = typeof(T).GetMarshaler2Type() == typeof(ObjectReferenceValue); MarshalGenericFallback marshalGenericFallback = new MarshalGenericFallback(HelperType); CreateMarshaler = marshalGenericFallback.CreateMarshaler; CreateMarshaler2 = (MarshalByObjectReferenceValueSupported ? new Func(marshalGenericFallback.CreateMarshaler2) : CreateMarshaler); GetAbi = marshalGenericFallback.GetAbi; CopyAbi = marshalGenericFallback.CopyAbi; FromAbi = marshalGenericFallback.FromAbi; FromManaged = marshalGenericFallback.FromManaged; CopyManaged = marshalGenericFallback.CopyManaged; DisposeMarshaler = marshalGenericFallback.DisposeMarshaler; DisposeAbi = marshalGenericFallback.DisposeAbi; CreateMarshalerArray = marshalGenericFallback.CreateMarshalerArray; GetAbiArray = marshalGenericFallback.GetAbiArray; FromAbiArray = marshalGenericFallback.FromAbiArray; FromManagedArray = marshalGenericFallback.FromManagedArray; DisposeMarshalerArray = marshalGenericFallback.DisposeMarshalerArray; DisposeAbiArray = marshalGenericFallback.DisposeAbiArray; } else { HelperType = typeof(T).GetHelperType(); AbiType = typeof(T).GetAbiType(); MarshalerType = typeof(T).GetMarshalerType(); MarshalByObjectReferenceValueSupported = typeof(T).GetMarshaler2Type() == typeof(ObjectReferenceValue); CreateMarshaler = HelperType.GetMethod("CreateMarshaler", BindingFlags.Static | BindingFlags.Public)?.CreateDelegate>(); CreateMarshaler2 = ((!MarshalByObjectReferenceValueSupported) ? CreateMarshaler : HelperType.GetMethod("CreateMarshaler2", BindingFlags.Static | BindingFlags.Public)?.CreateDelegate>().WithObjectTResult()); GetAbi = HelperType.GetMethod("GetAbi", BindingFlags.Static | BindingFlags.Public)?.CreateDelegate>().WithMarshaler2Support(); FromAbi = HelperType.GetMethod("FromAbi", BindingFlags.Static | BindingFlags.Public)?.CreateDelegate>().WithObjectT(); FromManaged = HelperType.GetMethod("FromManaged", BindingFlags.Static | BindingFlags.Public)?.CreateDelegate>().WithObjectTResult(); DisposeMarshaler = HelperType.GetMethod("DisposeMarshaler", BindingFlags.Static | BindingFlags.Public)?.CreateDelegate>().WithMarshaler2Support(); DisposeAbi = HelperType.GetMethod("DisposeAbi", BindingFlags.Static | BindingFlags.Public)?.CreateDelegate>().WithObjectParams(); CreateMarshalerArray = HelperType.GetMethod("CreateMarshalerArray", BindingFlags.Static | BindingFlags.Public)?.CreateDelegate.MarshalerArray>>().WithObjectTResult(); GetAbiArray = HelperType.GetMethod("GetAbiArray", BindingFlags.Static | BindingFlags.Public)?.CreateDelegate>(); FromAbiArray = HelperType.GetMethod("FromAbiArray", BindingFlags.Static | BindingFlags.Public)?.CreateDelegate>(); FromManagedArray = HelperType.GetMethod("FromManagedArray", BindingFlags.Static | BindingFlags.Public)?.CreateDelegate>(); DisposeMarshalerArray = HelperType.GetMethod("DisposeMarshalerArray", BindingFlags.Static | BindingFlags.Public)?.CreateDelegate.MarshalerArray>>().WithObjectParams(); DisposeAbiArray = HelperType.GetMethod("DisposeAbiArray", BindingFlags.Static | BindingFlags.Public)?.CreateDelegate>(); } } } } internal sealed class MarshalGenericFallback { private readonly MethodInfo _createMarshaler; private readonly MethodInfo _getAbi; private readonly MethodInfo _copyAbi; private readonly MethodInfo _fromAbi; private readonly MethodInfo _fromManaged; private readonly MethodInfo _copyManaged; private readonly MethodInfo _disposeMarshaler; private readonly MethodInfo _createMarshaler2; private readonly MethodInfo _disposeAbi; private readonly MethodInfo _createMarshalerArray; private readonly MethodInfo _getAbiArray; private readonly MethodInfo _fromAbiArray; private readonly MethodInfo _fromManagedArray; private readonly MethodInfo _disposeMarshalerArray; private readonly MethodInfo _disposeAbiArray; public MarshalGenericFallback([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] System.Type helperType) { _createMarshaler = helperType.GetMethod("CreateMarshaler", BindingFlags.Static | BindingFlags.Public); _getAbi = helperType.GetMethod("GetAbi", BindingFlags.Static | BindingFlags.Public); _copyAbi = helperType.GetMethod("CopyAbi", BindingFlags.Static | BindingFlags.Public); _fromAbi = helperType.GetMethod("FromAbi", BindingFlags.Static | BindingFlags.Public); _fromManaged = helperType.GetMethod("FromManaged", BindingFlags.Static | BindingFlags.Public); _copyManaged = helperType.GetMethod("CopyManaged", BindingFlags.Static | BindingFlags.Public); _disposeMarshaler = helperType.GetMethod("DisposeMarshaler", BindingFlags.Static | BindingFlags.Public); _createMarshaler2 = helperType.GetMethod("CreateMarshaler2", BindingFlags.Static | BindingFlags.Public); _disposeAbi = helperType.GetMethod("DisposeAbi", BindingFlags.Static | BindingFlags.Public); _createMarshalerArray = helperType.GetMethod("CreateMarshalerArray", BindingFlags.Static | BindingFlags.Public); _getAbiArray = helperType.GetMethod("GetAbiArray", BindingFlags.Static | BindingFlags.Public); _fromAbiArray = helperType.GetMethod("FromAbiArray", BindingFlags.Static | BindingFlags.Public); _fromManagedArray = helperType.GetMethod("FromManagedArray", BindingFlags.Static | BindingFlags.Public); _disposeMarshalerArray = helperType.GetMethod("DisposeMarshalerArray", BindingFlags.Static | BindingFlags.Public); _disposeAbiArray = helperType.GetMethod("DisposeAbiArray", BindingFlags.Static | BindingFlags.Public); } public object CreateMarshaler(T arg) { return _createMarshaler.Invoke(null, new object[1] { arg }); } public object CreateMarshaler2(T arg) { return _createMarshaler2.Invoke(null, new object[1] { arg }); } public object GetAbi(object arg) { if (arg is ObjectReferenceValue objectReferenceValue) { return objectReferenceValue.GetAbi(); } return _getAbi.Invoke(null, new object[1] { arg }); } public void CopyAbi(object arg, IntPtr dest) { _copyAbi.Invoke(null, new object[2] { arg, dest }); } public T FromAbi(object arg) { return (T)_fromAbi.Invoke(null, new object[1] { arg }); } public object FromManaged(T arg) { return _fromManaged.Invoke(null, new object[1] { arg }); } public void CopyManaged(T arg, IntPtr dest) { _copyManaged.Invoke(null, new object[2] { arg, dest }); } public void DisposeMarshaler(object arg) { if (arg is ObjectReferenceValue objectReferenceValue) { objectReferenceValue.Dispose(); return; } _disposeMarshaler.Invoke(null, new object[1] { arg }); } public void DisposeAbi(object arg) { _disposeAbi.Invoke(null, new object[1] { arg }); } public object CreateMarshalerArray(T[] arg) { MethodInfo createMarshalerArray = _createMarshalerArray; object[] parameters = new T[1][] { arg }; return createMarshalerArray.Invoke(null, parameters); } public (int, IntPtr) GetAbiArray(object arg) { return ((int, IntPtr))_getAbiArray.Invoke(null, new object[1] { arg }); } public T[] FromAbiArray(object arg) { return (T[])_fromAbiArray.Invoke(null, new object[1] { arg }); } public (int, IntPtr) FromManagedArray(T[] arg) { return ((int, IntPtr))_fromManagedArray.Invoke(null, new object[1] { arg }); } public void DisposeMarshalerArray(object arg) { _disposeMarshalerArray.Invoke(null, new object[1] { arg }); } public void DisposeAbiArray(object arg) { _disposeAbiArray.Invoke(null, new object[1] { arg }); } } internal static class MarshalGenericHelper { private unsafe static void CopyManagedFallback(T value, IntPtr dest) { if (MarshalGeneric.MarshalByObjectReferenceValueSupported) { *(IntPtr*)dest.ToPointer() = ((value == null) ? IntPtr.Zero : ((ObjectReferenceValue)MarshalGeneric.CreateMarshaler2(value)).Detach()); } else { *(IntPtr*)dest.ToPointer() = ((value == null) ? IntPtr.Zero : ((IObjectReference)MarshalGeneric.CreateMarshaler(value)).GetRef()); } } internal static void CopyManagedArray(T[] array, IntPtr data) { MarshalInterfaceHelper.CopyManagedArray(array, data, MarshalGeneric.CopyManaged ?? new Action(CopyManagedFallback)); } } public class MarshalNonBlittable : MarshalGeneric { public struct MarshalerArray { public IntPtr _array; public object[] _marshalers; public void Dispose() { if (_marshalers != null) { object[] marshalers = _marshalers; foreach (object obj in marshalers) { Marshaler.DisposeMarshaler(obj); } } if (_array != IntPtr.Zero) { Marshal.FreeCoTaskMem(_array); } } } private new static readonly System.Type AbiType = GetAbiType(); private static System.Type GetAbiType() { if (typeof(T).IsEnum) { return Enum.GetUnderlyingType(typeof(T)); } if (typeof(T) == typeof(bool)) { return typeof(byte); } if (typeof(T) == typeof(char)) { return typeof(ushort); } if (typeof(T) == typeof(System.TimeSpan)) { return typeof(ABI.System.TimeSpan); } if (typeof(T) == typeof(System.DateTimeOffset)) { return typeof(ABI.System.DateTimeOffset); } if (typeof(T) == typeof(System.Exception)) { return typeof(ABI.System.Exception); } if (typeof(T) == typeof(int) || typeof(T) == typeof(byte) || typeof(T) == typeof(sbyte) || typeof(T) == typeof(short) || typeof(T) == typeof(ushort) || typeof(T) == typeof(uint) || typeof(T) == typeof(long) || typeof(T) == typeof(ulong) || typeof(T) == typeof(float) || typeof(T) == typeof(double) || typeof(T) == typeof(Guid) || typeof(T) == typeof(Windows.Foundation.Point) || typeof(T) == typeof(Windows.Foundation.Rect) || typeof(T) == typeof(Windows.Foundation.Size) || typeof(T) == typeof(System.Numerics.Matrix3x2) || typeof(T) == typeof(System.Numerics.Matrix4x4) || typeof(T) == typeof(System.Numerics.Plane) || typeof(T) == typeof(System.Numerics.Quaternion) || typeof(T) == typeof(System.Numerics.Vector2) || typeof(T) == typeof(System.Numerics.Vector3) || typeof(T) == typeof(System.Numerics.Vector4)) { return null; } if (typeof(T) == typeof(System.Type)) { throw new NotSupportedException("Using 'System.Type' with MarshalNonBlittable isn't supported, use Marshaler instead."); } return typeof(T).GetAbiType(); } public new unsafe static MarshalerArray CreateMarshalerArray(T[] array) { if (!RuntimeFeature.IsDynamicCodeCompiled) { throw new NotSupportedException($"Cannot handle array marshalling for non blittable type '{typeof(T)}'."); } MarshalerArray result = default(MarshalerArray); if (array == null) { return result; } bool flag = false; try { int num = array.Length; int num2 = Marshal.SizeOf(AbiType); int cb = num * num2; result._array = Marshal.AllocCoTaskMem(cb); result._marshalers = new object[num]; byte* ptr = (byte*)result._array.ToPointer(); for (int i = 0; i < num; i++) { result._marshalers[i] = Marshaler.CreateMarshaler(array[i]); Marshaler.CopyAbi(result._marshalers[i], (IntPtr)ptr); ptr += num2; } flag = true; return result; } finally { if (!flag) { result.Dispose(); } } } public new static (int length, IntPtr data) GetAbiArray(object box) { MarshalerArray marshalerArray = (MarshalerArray)box; object[] marshalers = marshalerArray._marshalers; return (length: (marshalers != null) ? marshalers.Length : 0, data: marshalerArray._array); } public new unsafe static T[] FromAbiArray(object box) { if (!RuntimeFeature.IsDynamicCodeCompiled) { throw new NotSupportedException($"Cannot handle array marshalling for non blittable type '{typeof(T)}'."); } if (box == null) { return null; } (int, IntPtr) tuple = ((int, IntPtr))box; if (tuple.Item2 == IntPtr.Zero) { return null; } T[] array = new T[tuple.Item1]; byte* ptr = (byte*)tuple.Item2.ToPointer(); int num = Marshal.SizeOf(AbiType); for (int i = 0; i < tuple.Item1; i++) { object arg = Marshal.PtrToStructure((IntPtr)ptr, AbiType); array[i] = Marshaler.FromAbi(arg); ptr += num; } return array; } public unsafe static void CopyAbiArray(T[] array, object box) { if (!RuntimeFeature.IsDynamicCodeCompiled) { throw new NotSupportedException($"Cannot handle array marshalling for non blittable type '{typeof(T)}'."); } (int, IntPtr) tuple = ((int, IntPtr))box; if (!(tuple.Item2 == IntPtr.Zero)) { byte* ptr = (byte*)tuple.Item2.ToPointer(); int num = Marshal.SizeOf(AbiType); for (int i = 0; i < tuple.Item1; i++) { object arg = Marshal.PtrToStructure((IntPtr)ptr, AbiType); array[i] = Marshaler.FromAbi(arg); ptr += num; } } } public new unsafe static (int length, IntPtr data) FromManagedArray(T[] array) { if (!RuntimeFeature.IsDynamicCodeCompiled) { throw new NotSupportedException($"Cannot handle array marshalling for non blittable type '{typeof(T)}'."); } if (array == null) { return (length: 0, data: IntPtr.Zero); } IntPtr item = IntPtr.Zero; int i = 0; bool flag = false; try { int num = array.Length; int num2 = Marshal.SizeOf(AbiType); int cb = num * num2; item = Marshal.AllocCoTaskMem(cb); byte* ptr = (byte*)item.ToPointer(); for (i = 0; i < num; i++) { Marshaler.CopyManaged(array[i], (IntPtr)ptr); ptr += num2; } flag = true; return (length: i, data: item); } finally { if (!flag) { DisposeAbiArray((i, item)); } } } public unsafe static void CopyManagedArray(T[] array, IntPtr data) { if (!RuntimeFeature.IsDynamicCodeCompiled) { throw new NotSupportedException($"Cannot handle array marshalling for non blittable type '{typeof(T)}'."); } if (array == null) { return; } DisposeAbiArrayElements((length: array.Length, data: data)); int i = 0; bool flag = false; try { int num = array.Length; int num2 = Marshal.SizeOf(AbiType); int num3 = num * num2; byte* ptr = (byte*)data.ToPointer(); for (i = 0; i < num; i++) { Marshaler.CopyManaged(array[i], (IntPtr)ptr); ptr += num2; } flag = true; } finally { if (!flag) { DisposeAbiArrayElements((length: i, data: data)); } } } public new static void DisposeMarshalerArray(object box) { ((MarshalerArray)box).Dispose(); } public unsafe static void DisposeAbiArrayElements((int length, IntPtr data) abi) { if (!RuntimeFeature.IsDynamicCodeCompiled) { throw new NotSupportedException($"Cannot handle array marshalling for non blittable type '{typeof(T)}'."); } byte* ptr = (byte*)abi.data.ToPointer(); int num = Marshal.SizeOf(AbiType); for (int i = 0; i < abi.length; i++) { object obj = Marshal.PtrToStructure((IntPtr)ptr, AbiType); Marshaler.DisposeAbi(obj); ptr += num; } } public new static void DisposeAbiArray(object box) { if (box != null) { (int, IntPtr) abi = ((int, IntPtr))box; if (!(abi.Item2 == IntPtr.Zero)) { DisposeAbiArrayElements(abi); Marshal.FreeCoTaskMem(abi.Item2); } } } } public class MarshalInterfaceHelper { public struct MarshalerArray { public IntPtr _array; public IObjectReference[] _marshalers; internal ObjectReferenceValue[] _objectReferenceValues; public void Dispose() { if (_marshalers != null) { IObjectReference[] marshalers = _marshalers; foreach (IObjectReference objRef in marshalers) { MarshalInterfaceHelper.DisposeMarshaler(objRef); } } if (_objectReferenceValues != null) { ObjectReferenceValue[] objectReferenceValues = _objectReferenceValues; foreach (ObjectReferenceValue objectReferenceValue in objectReferenceValues) { objectReferenceValue.Dispose(); } } if (_array != IntPtr.Zero) { Marshal.FreeCoTaskMem(_array); } } } private unsafe static MarshalerArray CreateMarshalerArray(T[] array, Func createMarshaler, Func createMarshaler2) { MarshalerArray result = default(MarshalerArray); if (array == null) { return result; } bool flag = false; try { int num = array.Length; int cb = num * IntPtr.Size; result._array = Marshal.AllocCoTaskMem(cb); IntPtr* ptr = (IntPtr*)result._array.ToPointer(); if (createMarshaler2 != null) { result._objectReferenceValues = new ObjectReferenceValue[num]; for (int i = 0; i < num; i++) { result._objectReferenceValues[i] = createMarshaler2(array[i]); ptr[i] = GetAbi(result._objectReferenceValues[i]); } } else { result._marshalers = new IObjectReference[num]; for (int j = 0; j < num; j++) { result._marshalers[j] = createMarshaler(array[j]); ptr[j] = GetAbi(result._marshalers[j]); } } flag = true; return result; } finally { if (!flag) { result.Dispose(); } } } public static MarshalerArray CreateMarshalerArray(T[] array, Func createMarshaler) { return CreateMarshalerArray(array, createMarshaler, null); } public static MarshalerArray CreateMarshalerArray2(T[] array, Func createMarshaler) { return CreateMarshalerArray(array, null, createMarshaler); } public static (int length, IntPtr data) GetAbiArray(object box) { MarshalerArray marshalerArray = (MarshalerArray)box; ObjectReferenceValue[] objectReferenceValues = marshalerArray._objectReferenceValues; int item; if (objectReferenceValues == null) { IObjectReference[] marshalers = marshalerArray._marshalers; item = ((marshalers != null) ? marshalers.Length : 0); } else { item = objectReferenceValues.Length; } return (length: item, data: marshalerArray._array); } public unsafe static T[] FromAbiArray(object box, Func fromAbi) { if (box == null) { return null; } (int, IntPtr) tuple = ((int, IntPtr))box; if (tuple.Item2 == IntPtr.Zero) { return null; } T[] array = new T[tuple.Item1]; IntPtr* ptr = (IntPtr*)tuple.Item2.ToPointer(); for (int i = 0; i < tuple.Item1; i++) { array[i] = fromAbi(ptr[i]); } return array; } public unsafe static void CopyAbiArray(T[] array, object box, Func fromAbi) { if (box != null) { (int, IntPtr) tuple = ((int, IntPtr))box; IntPtr* ptr = (IntPtr*)tuple.Item2.ToPointer(); for (int i = 0; i < tuple.Item1; i++) { array[i] = fromAbi(ptr[i]); } } } public unsafe static (int length, IntPtr data) FromManagedArray(T[] array, Func fromManaged) { if (array == null) { return (length: 0, data: IntPtr.Zero); } IntPtr item = IntPtr.Zero; int i = 0; bool flag = false; try { int num = array.Length; int cb = num * IntPtr.Size; item = Marshal.AllocCoTaskMem(cb); IntPtr* ptr = (IntPtr*)item.ToPointer(); for (i = 0; i < num; i++) { ptr[i] = fromManaged(array[i]); } flag = true; return (length: i, data: item); } finally { if (!flag) { DisposeAbiArray((i, item)); } } } public unsafe static void CopyManagedArray(T[] array, IntPtr data, Action copyManaged) { if (array == null) { return; } DisposeAbiArrayElements((length: array.Length, data: data)); int i = 0; bool flag = false; try { int num = array.Length; int num2 = num * IntPtr.Size; byte* ptr = (byte*)data.ToPointer(); for (i = 0; i < num; i++) { copyManaged(array[i], (IntPtr)ptr); ptr += IntPtr.Size; } flag = true; } finally { if (!flag) { DisposeAbiArrayElements((length: i, data: data)); } } } public static void DisposeMarshalerArray(object box) { ((MarshalerArray)box).Dispose(); } public unsafe static void DisposeAbiArrayElements((int length, IntPtr data) abi) { IntPtr* ptr = (IntPtr*)abi.data.ToPointer(); for (int i = 0; i < abi.length; i++) { DisposeAbi(ptr[i]); } } public static void DisposeAbiArray(object box) { if (box != null) { (int, IntPtr) abi = ((int, IntPtr))box; if (!(abi.Item2 == IntPtr.Zero)) { DisposeAbiArrayElements(abi); Marshal.FreeCoTaskMem(abi.Item2); } } } public static IntPtr GetAbi(IObjectReference objRef) { return objRef?.ThisPtr ?? IntPtr.Zero; } public static IntPtr GetAbi(ObjectReferenceValue value) { return value.GetAbi(); } public static void DisposeMarshaler(IObjectReference objRef) { objRef?.Dispose(); } public static void DisposeMarshaler(ObjectReferenceValue value) { value.Dispose(); } public unsafe static void DisposeAbi(IntPtr ptr) { if (!(ptr == IntPtr.Zero)) { ((IUnknownVftbl*)(*(nint*)(void*)ptr))->Release(ptr); } } } [StructLayout(LayoutKind.Sequential, Size = 1)] public struct MarshalInterface { [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicFields)] private static System.Type _HelperType; private static object _CreateMarshaler; private static object _Iid; [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicFields)] private static System.Type HelperType => _HelperType ?? (_HelperType = typeof(T).GetHelperType()); private static Guid IID => (Guid)(_Iid ?? (_Iid = GetIID())); private static Guid GetIID() { if (typeof(T).IsValueType && typeof(T).IsGenericType && typeof(T).GetGenericTypeDefinition() == typeof(System.Nullable<>)) { return GuidGenerator.CreateIIDUnsafe(typeof(T)); } return GuidGenerator.GetIID(HelperType); } public static T FromAbi(IntPtr ptr) { if (ptr == IntPtr.Zero) { return (T)(object)null; } return MarshalInspectable.FromAbi(ptr); } public static IObjectReference CreateMarshaler(T value) { if (value == null) { return null; } return CreateMarshalerCore(value); } public static ObjectReferenceValue CreateMarshaler2(T value, Guid iid = default(Guid)) { if (value == null) { return default(ObjectReferenceValue); } return MarshalInspectable.CreateMarshaler2(value, (iid == default(Guid)) ? IID : iid); } public static IntPtr GetAbi(IObjectReference value) { if (value != null) { return MarshalInterfaceHelper.GetAbi(value); } return IntPtr.Zero; } public static IntPtr GetAbi(ObjectReferenceValue value) { return MarshalInterfaceHelper.GetAbi(value); } public static void DisposeAbi(IntPtr thisPtr) { MarshalInterfaceHelper.DisposeAbi(thisPtr); } public static void DisposeMarshaler(IObjectReference value) { MarshalInterfaceHelper.DisposeMarshaler(value); } public static void DisposeMarshaler(ObjectReferenceValue value) { MarshalInterfaceHelper.DisposeMarshaler(value); } internal static void DisposeMarshaler(object value) { if (value is ObjectReferenceValue value2) { DisposeMarshaler(value2); } else { DisposeMarshaler((IObjectReference)value); } } public static IntPtr FromManaged(T value) { return CreateMarshaler2(value).Detach(); } public unsafe static void CopyManaged(T value, IntPtr dest) { *(IntPtr*)dest.ToPointer() = CreateMarshaler2(value).Detach(); } public static MarshalInterfaceHelper.MarshalerArray CreateMarshalerArray(T[] array) { return MarshalInterfaceHelper.CreateMarshalerArray2(array, (T o) => CreateMarshaler2(o)); } public static (int length, IntPtr data) GetAbiArray(object box) { return MarshalInterfaceHelper.GetAbiArray(box); } public static T[] FromAbiArray(object box) { return MarshalInterfaceHelper.FromAbiArray(box, FromAbi); } public static void CopyAbiArray(T[] array, object box) { MarshalInterfaceHelper.CopyAbiArray(array, box, FromAbi); } public static (int length, IntPtr data) FromManagedArray(T[] array) { return MarshalInterfaceHelper.FromManagedArray(array, FromManaged); } public static void CopyManagedArray(T[] array, IntPtr data) { MarshalInterfaceHelper.CopyManagedArray(array, data, CopyManaged); } public static void DisposeMarshalerArray(object box) { MarshalInterfaceHelper.DisposeMarshalerArray(box); } public static void DisposeAbiArray(object box) { MarshalInterfaceHelper.DisposeAbiArray(box); } private static IObjectReference CreateMarshalerCore(T value) { if (!RuntimeFeature.IsDynamicCodeCompiled) { return MarshalInspectable.CreateMarshaler(value, IID); } if (_CreateMarshaler == null) { _CreateMarshaler = BindCreateMarshaler(); } return ((Func)_CreateMarshaler)(value); } private static Func BindCreateMarshaler() { System.Type type = HelperType.FindVftblType(); if ((object)type != null) { MethodInfo methodInfo = typeof(MarshalInspectable).GetMethod("CreateMarshaler", new System.Type[3] { typeof(T), typeof(Guid), typeof(bool) }).MakeGenericMethod(type); Func createMarshaler = (Func)methodInfo.CreateDelegate(typeof(Func)); return (T obj) => createMarshaler(obj, IID, arg3: true); } return (T obj) => MarshalInspectable.CreateMarshaler(obj, IID); } } public static class MarshalInspectable { public static IObjectReference CreateMarshaler(T o, Guid iid, bool unwrapObject = true) { if (o == null) { return null; } if (unwrapObject && ComWrappersSupport.TryUnwrapObject(o, out var objRef)) { return objRef.As(iid); } System.Type type = o.GetType(); System.Type type2 = Projections.FindCustomHelperTypeMapping(type, filterToRuntimeClass: true); if (type2 != null) { MethodInfo method = type2.GetMethod("CreateMarshaler", BindingFlags.Static | BindingFlags.Public); return (IObjectReference)method.Invoke(null, new object[1] { o }); } return ComWrappersSupport.CreateCCWForObject(o, iid); } public static IObjectReference CreateMarshaler(T o, bool unwrapObject = true) { return CreateMarshaler(o, IID.IID_IInspectable, unwrapObject); } public static ObjectReferenceValue CreateMarshaler2(T o, Guid iid, bool unwrapObject = true) { if (o == null) { return default(ObjectReferenceValue); } if (unwrapObject && ComWrappersSupport.TryUnwrapObject(o, out var objRef)) { return objRef.AsValue(iid); } System.Type type = o.GetType(); System.Type type2 = Projections.FindCustomHelperTypeMapping(type, filterToRuntimeClass: true); if (type2 != null) { MethodInfo method = type2.GetMethod("CreateMarshaler2", BindingFlags.Static | BindingFlags.Public); return (ObjectReferenceValue)method.Invoke(null, new object[1] { o }); } return ComWrappersSupport.CreateCCWForObjectForMarshaling(o, iid); } public static ObjectReferenceValue CreateMarshaler2(T o, bool unwrapObject = true) { return CreateMarshaler2(o, IID.IID_IInspectable, unwrapObject); } public static IntPtr GetAbi(IObjectReference objRef) { if (objRef != null) { return MarshalInterfaceHelper.GetAbi(objRef); } return IntPtr.Zero; } public static IntPtr GetAbi(ObjectReferenceValue value) { return value.GetAbi(); } public static T FromAbi(IntPtr ptr) { if (ptr == IntPtr.Zero) { return default(T); } IntPtr ppv = IntPtr.Zero; try { Marshal.QueryInterface(ptr, in Unsafe.AsRef(in IID.IID_IUnknown), out ppv); if (IUnknownVftbl.IsReferenceToManagedObject(ppv)) { if (ComWrappersSupport.FindObject(ppv) is T result) { return result; } return ComWrappersSupport.CreateRcwForComObject(ptr); } return ComWrappersSupport.CreateRcwForComObject(ptr); } finally { DisposeAbi(ppv); } } public static void DisposeMarshaler(IObjectReference objRef) { MarshalInterfaceHelper.DisposeMarshaler(objRef); } public static void DisposeMarshaler(ObjectReferenceValue value) { value.Dispose(); } internal static void DisposeMarshaler(object value) { if (value is ObjectReferenceValue value2) { DisposeMarshaler(value2); } else { DisposeMarshaler((IObjectReference)value); } } public static void DisposeAbi(IntPtr ptr) { MarshalInterfaceHelper.DisposeAbi(ptr); } public static IntPtr FromManaged(T o, bool unwrapObject = true) { return CreateMarshaler2(o, unwrapObject).Detach(); } public unsafe static void CopyManaged(T o, IntPtr dest, bool unwrapObject = true) { *(IntPtr*)dest.ToPointer() = CreateMarshaler2(o, unwrapObject).Detach(); } public static MarshalInterfaceHelper.MarshalerArray CreateMarshalerArray(T[] array) { return MarshalInterfaceHelper.CreateMarshalerArray2(array, (T o) => CreateMarshaler2(o)); } public static (int length, IntPtr data) GetAbiArray(T box) { return MarshalInterfaceHelper.GetAbiArray(box); } internal static (int length, IntPtr data) GetAbiArray(object box) { return MarshalInterfaceHelper.GetAbiArray(box); } public static T[] FromAbiArray(T box) { return MarshalInterfaceHelper.FromAbiArray(box, FromAbi); } internal static T[] FromAbiArray(object box) { return MarshalInterfaceHelper.FromAbiArray(box, FromAbi); } public static void CopyAbiArray(T[] array, object box) { MarshalInterfaceHelper.CopyAbiArray(array, box, FromAbi); } public static (int length, IntPtr data) FromManagedArray(T[] array) { return MarshalInterfaceHelper.FromManagedArray(array, (T o) => FromManaged(o)); } public static void CopyManagedArray(T[] array, IntPtr data) { MarshalInterfaceHelper.CopyManagedArray(array, data, delegate(T o, IntPtr dest) { CopyManaged(o, dest); }); } public static void DisposeMarshalerArray(T box) { MarshalInterfaceHelper.DisposeMarshalerArray(box); } public static void DisposeAbiArray(T box) { MarshalInterfaceHelper.DisposeAbiArray(box); } internal static void DisposeMarshalerArray(object box) { MarshalInterfaceHelper.DisposeMarshalerArray(box); } internal static void DisposeAbiArray(object box) { MarshalInterfaceHelper.DisposeAbiArray(box); } } public static class MarshalDelegate { public static IObjectReference CreateMarshaler(object o, Guid delegateIID, bool unwrapObject = true) { if (o == null) { return null; } if (unwrapObject && ComWrappersSupport.TryUnwrapObject(o, out var objRef)) { return objRef.As(delegateIID); } return ComWrappersSupport.CreateCCWForObject(o, delegateIID); } public static ObjectReferenceValue CreateMarshaler2(object o, Guid delegateIID, bool unwrapObject = true) { if (o == null) { return default(ObjectReferenceValue); } if (unwrapObject && ComWrappersSupport.TryUnwrapObject(o, out var objRef)) { return objRef.AsValue(delegateIID); } return ComWrappersSupport.CreateCCWForObjectForMarshaling(o, delegateIID); } public static T FromAbi(IntPtr nativeDelegate) where T : Delegate { if (nativeDelegate == IntPtr.Zero) { return null; } if (IUnknownVftbl.IsReferenceToManagedObject(nativeDelegate)) { if (ComWrappersSupport.FindObject(nativeDelegate) is T result) { return result; } return ComWrappersSupport.CreateRcwForComObject(nativeDelegate); } return ComWrappersSupport.CreateRcwForComObject(nativeDelegate); } } internal static class Marshaler { internal static readonly Func ReturnParameterFunc = ReturnParameter; internal static readonly Action CopyIntEnumFunc = CopyIntEnum; internal static readonly Action CopyIntEnumDirectFunc = CopyIntEnumDirect; internal static readonly Action CopyUIntEnumFunc = CopyUIntEnum; internal static readonly Action CopyUIntEnumDirectFunc = CopyUIntEnumDirect; private static object ReturnParameter(object arg) { return arg; } private unsafe static void CopyIntEnum(object value, IntPtr dest) { *(int*)dest.ToPointer() = Convert.ToInt32(value); } private unsafe static void CopyIntEnumDirect(object value, IntPtr dest) { *(int*)dest.ToPointer() = (int)value; } private unsafe static void CopyUIntEnum(object value, IntPtr dest) { *(uint*)dest.ToPointer() = Convert.ToUInt32(value); } private unsafe static void CopyUIntEnumDirect(object value, IntPtr dest) { *(uint*)dest.ToPointer() = (uint)value; } } public class Marshaler { public static readonly System.Type AbiType; [Obsolete("This method is deprecated and will be removed in a future release.")] public static readonly System.Type RefAbiType; public static readonly Func CreateMarshaler; internal static readonly Func CreateMarshaler2; public static readonly Func GetAbi; public static readonly Action CopyAbi; public static readonly Func FromAbi; public static readonly Func FromManaged; public static readonly Action CopyManaged; public static readonly Action DisposeMarshaler; public static readonly Action DisposeAbi; public static readonly Func CreateMarshalerArray; public static readonly Func GetAbiArray; public static readonly Func FromAbiArray; public static readonly Func FromManagedArray; public static readonly Action CopyManagedArray; public static readonly Action DisposeMarshalerArray; public static readonly Action DisposeAbiArray; static Marshaler() { if (typeof(T).IsArray) { throw new InvalidOperationException("Arrays may not be marshaled generically."); } if (typeof(T) == typeof(string)) { AbiType = typeof(IntPtr); CreateMarshaler = (Func)(object)new Func(MarshalString.CreateMarshaler); CreateMarshaler2 = CreateMarshaler; GetAbi = (object box) => MarshalString.GetAbi(box); FromAbi = (object value) => (T)(object)MarshalString.FromAbi((IntPtr)value); FromManaged = (T value) => MarshalString.FromManaged((string)(object)value); DisposeMarshaler = MarshalString.DisposeMarshaler; DisposeAbi = MarshalString.DisposeAbi; CreateMarshalerArray = (T[] array) => MarshalString.CreateMarshalerArray((string[])(object)array); GetAbiArray = MarshalString.GetAbiArray; FromAbiArray = (Func)(object)new Func(MarshalString.FromAbiArray); FromManagedArray = (Func)new Func(MarshalString.FromManagedArray); CopyManagedArray = (Action)new Action(MarshalString.CopyManagedArray); DisposeMarshalerArray = MarshalString.DisposeMarshalerArray; DisposeAbiArray = MarshalString.DisposeAbiArray; } else if (typeof(T) == typeof(System.Type)) { AbiType = typeof(ABI.System.Type); CreateMarshaler = (T value) => ABI.System.Type.CreateMarshaler((System.Type)(object)value); CreateMarshaler2 = CreateMarshaler; GetAbi = (object box) => ABI.System.Type.GetAbi((ABI.System.Type.Marshaler)box); FromAbi = (object value) => (T)(object)ABI.System.Type.FromAbi((ABI.System.Type)value); CopyAbi = delegate(object box, IntPtr dest) { ABI.System.Type.CopyAbi((ABI.System.Type.Marshaler)box, dest); }; CopyManaged = (Action)(object)new Action(ABI.System.Type.CopyManaged); FromManaged = (T value) => ABI.System.Type.FromManaged((System.Type)(object)value); DisposeMarshaler = delegate(object box) { ABI.System.Type.DisposeMarshaler((ABI.System.Type.Marshaler)box); }; DisposeAbi = delegate(object box) { ABI.System.Type.DisposeAbi((ABI.System.Type)box); }; CreateMarshalerArray = (Func)new Func(NonBlittableMarshallingStubs.Type_CreateMarshalerArray); GetAbiArray = ABI.System.Type.GetAbiArray; FromAbiArray = (Func)(object)new Func(ABI.System.Type.FromAbiArray); FromManagedArray = (Func)new Func(ABI.System.Type.FromManagedArray); CopyManagedArray = (Action)new Action(ABI.System.Type.CopyManagedArray); DisposeMarshalerArray = ABI.System.Type.DisposeMarshalerArray; DisposeAbiArray = ABI.System.Type.DisposeAbiArray; } else if (typeof(System.Exception).IsAssignableFrom(typeof(T))) { AbiType = typeof(ABI.System.Exception); CreateMarshaler = (T value) => ABI.System.Exception.CreateMarshaler((System.Exception)(object)value); CreateMarshaler2 = CreateMarshaler; GetAbi = (object box) => ABI.System.Exception.GetAbi((ABI.System.Exception.Marshaler)box); FromAbi = (object value) => (T)(object)ABI.System.Exception.FromAbi((ABI.System.Exception)value); CopyAbi = delegate(object box, IntPtr dest) { ABI.System.Exception.CopyAbi((ABI.System.Exception.Marshaler)box, dest); }; CopyManaged = (Action)(object)new Action(ABI.System.Exception.CopyManaged); FromManaged = (T value) => ABI.System.Exception.FromManaged((System.Exception)(object)value); DisposeMarshaler = delegate(object box) { ABI.System.Exception.DisposeMarshaler((ABI.System.Exception.Marshaler)box); }; DisposeAbi = delegate(object box) { ABI.System.Exception.DisposeAbi((ABI.System.Exception)box); }; CreateMarshalerArray = (Func)new Func(NonBlittableMarshallingStubs.Exception_CreateMarshalerArray); GetAbiArray = MarshalNonBlittable.GetAbiArray; FromAbiArray = (Func)(object)new Func(MarshalNonBlittable.FromAbiArray); FromManagedArray = (Func)new Func(MarshalNonBlittable.FromManagedArray); CopyManagedArray = (Action)new Action(MarshalNonBlittable.CopyManagedArray); DisposeMarshalerArray = MarshalNonBlittable.DisposeMarshalerArray; DisposeAbiArray = MarshalNonBlittable.DisposeAbiArray; } else if (typeof(T).IsValueType) { if (typeof(T) == typeof(bool)) { AbiType = typeof(byte); } else if (typeof(T) == typeof(char)) { AbiType = typeof(ushort); } else if (typeof(T) == typeof(int) || typeof(T) == typeof(byte) || typeof(T) == typeof(sbyte) || typeof(T) == typeof(short) || typeof(T) == typeof(ushort) || typeof(T) == typeof(uint) || typeof(T) == typeof(long) || typeof(T) == typeof(ulong) || typeof(T) == typeof(float) || typeof(T) == typeof(double) || typeof(T) == typeof(Guid) || typeof(T) == typeof(Windows.Foundation.Point) || typeof(T) == typeof(Windows.Foundation.Rect) || typeof(T) == typeof(Windows.Foundation.Size) || typeof(T) == typeof(System.Numerics.Matrix3x2) || typeof(T) == typeof(System.Numerics.Matrix4x4) || typeof(T) == typeof(System.Numerics.Plane) || typeof(T) == typeof(System.Numerics.Quaternion) || typeof(T) == typeof(System.Numerics.Vector2) || typeof(T) == typeof(System.Numerics.Vector3) || typeof(T) == typeof(System.Numerics.Vector4)) { AbiType = null; } else if (typeof(T) == typeof(System.TimeSpan)) { AbiType = typeof(ABI.System.TimeSpan); } else if (typeof(T) == typeof(System.DateTimeOffset)) { AbiType = typeof(ABI.System.DateTimeOffset); } else { if (typeof(T).IsGenericType && typeof(T).GetGenericTypeDefinition() == typeof(System.Collections.Generic.KeyValuePair<, >)) { AbiType = typeof(IntPtr); CreateMarshaler = MarshalGeneric.CreateMarshaler2; CreateMarshaler2 = MarshalGeneric.CreateMarshaler2; GetAbi = MarshalGeneric.GetAbi; CopyAbi = MarshalGeneric.CopyAbi; FromAbi = MarshalGeneric.FromAbi; FromManaged = MarshalGeneric.FromManaged; CopyManaged = MarshalGeneric.CopyManaged; DisposeMarshaler = MarshalGeneric.DisposeMarshaler; DisposeAbi = MarshalGeneric.DisposeAbi; CreateMarshalerArray = MarshalGeneric.CreateMarshalerArray; GetAbiArray = MarshalGeneric.GetAbiArray; FromAbiArray = MarshalGeneric.FromAbiArray; FromManagedArray = MarshalGeneric.FromManagedArray; CopyManagedArray = MarshalGenericHelper.CopyManagedArray; DisposeMarshalerArray = MarshalInterface.DisposeMarshalerArray; DisposeAbiArray = MarshalInterface.DisposeAbiArray; return; } if (typeof(T).IsNullableT()) { AbiType = typeof(IntPtr); CreateMarshaler = (T value) => MarshalInterface.CreateMarshaler2(value); CreateMarshaler2 = CreateMarshaler; GetAbi = (object objRef) => (objRef is ObjectReferenceValue value) ? MarshalInspectable.GetAbi(value) : MarshalInterface.GetAbi((IObjectReference)objRef); FromAbi = (object value) => MarshalInterface.FromAbi((IntPtr)value); FromManaged = (T value) => MarshalInterface.CreateMarshaler2(value).Detach(); DisposeMarshaler = MarshalInterface.DisposeMarshaler; DisposeAbi = delegate(object box) { MarshalInterface.DisposeAbi((IntPtr)box); }; CreateMarshalerArray = (T[] array) => MarshalInterface.CreateMarshalerArray(array); GetAbiArray = MarshalInterface.GetAbiArray; FromAbiArray = MarshalInterface.FromAbiArray; FromManagedArray = MarshalInterface.FromManagedArray; CopyManagedArray = MarshalInterface.CopyManagedArray; DisposeMarshalerArray = MarshalInterface.DisposeMarshalerArray; DisposeAbiArray = MarshalInterface.DisposeAbiArray; return; } System.Type type = typeof(T).FindHelperType(); if ((object)type?.GetMethod("FromAbi", BindingFlags.Static | BindingFlags.Public) == null) { AbiType = null; } else { AbiType = type; } } if (typeof(T) == typeof(int) || typeof(T) == typeof(byte) || typeof(T) == typeof(sbyte) || typeof(T) == typeof(short) || typeof(T) == typeof(ushort) || typeof(T) == typeof(uint) || typeof(T) == typeof(long) || typeof(T) == typeof(ulong) || typeof(T) == typeof(float) || typeof(T) == typeof(double) || typeof(T) == typeof(Guid) || typeof(T) == typeof(Windows.Foundation.Point) || typeof(T) == typeof(Windows.Foundation.Rect) || typeof(T) == typeof(Windows.Foundation.Size) || typeof(T) == typeof(System.Numerics.Matrix3x2) || typeof(T) == typeof(System.Numerics.Matrix4x4) || typeof(T) == typeof(System.Numerics.Plane) || typeof(T) == typeof(System.Numerics.Quaternion) || typeof(T) == typeof(System.Numerics.Vector2) || typeof(T) == typeof(System.Numerics.Vector3) || typeof(T) == typeof(System.Numerics.Vector4) || AbiType == null) { Func func = (T value) => value; AbiType = typeof(T); CreateMarshaler = func; CreateMarshaler2 = CreateMarshaler; GetAbi = Marshaler.ReturnParameterFunc; FromAbi = (object value) => (T)value; FromManaged = func; DisposeMarshaler = NonBlittableMarshallingStubs.NoOpFunc; DisposeAbi = NonBlittableMarshallingStubs.NoOpFunc; if (typeof(T).IsEnum) { if (typeof(T).GetEnumUnderlyingType() == typeof(int)) { CopyAbi = Marshaler.CopyIntEnumFunc; CopyManaged = Marshaler.CopyIntEnumDirectFunc.WithTypedT1(); } else { CopyAbi = Marshaler.CopyUIntEnumFunc; CopyManaged = Marshaler.CopyUIntEnumDirectFunc.WithTypedT1(); } } CreateMarshalerArray = (T[] array) => MarshalBlittable.CreateMarshalerArray(array); GetAbiArray = MarshalBlittable.GetAbiArray; FromAbiArray = MarshalBlittable.FromAbiArray; FromManagedArray = MarshalBlittable.FromManagedArray; CopyManagedArray = MarshalBlittable.CopyManagedArray; DisposeMarshalerArray = MarshalBlittable.DisposeMarshalerArray; DisposeAbiArray = MarshalBlittable.DisposeAbiArray; } else { CreateMarshaler = MarshalGeneric.CreateMarshaler; CreateMarshaler2 = CreateMarshaler; GetAbi = MarshalGeneric.GetAbi; CopyAbi = MarshalGeneric.CopyAbi; FromAbi = MarshalGeneric.FromAbi; FromManaged = MarshalGeneric.FromManaged; CopyManaged = MarshalGeneric.CopyManaged; DisposeMarshaler = MarshalGeneric.DisposeMarshaler; DisposeAbi = MarshalGeneric.DisposeAbi; CreateMarshalerArray = (T[] array) => MarshalNonBlittable.CreateMarshalerArray(array); GetAbiArray = MarshalNonBlittable.GetAbiArray; FromAbiArray = MarshalNonBlittable.FromAbiArray; FromManagedArray = MarshalNonBlittable.FromManagedArray; CopyManagedArray = MarshalNonBlittable.CopyManagedArray; DisposeMarshalerArray = MarshalNonBlittable.DisposeMarshalerArray; DisposeAbiArray = MarshalNonBlittable.DisposeAbiArray; } } else if (typeof(T).IsInterface) { AbiType = typeof(IntPtr); CreateMarshaler = (T value) => MarshalInterface.CreateMarshaler2(value); CreateMarshaler2 = CreateMarshaler; GetAbi = (object objRef) => (objRef is ObjectReferenceValue value) ? MarshalInspectable.GetAbi(value) : MarshalInterface.GetAbi((IObjectReference)objRef); FromAbi = (object value) => MarshalInterface.FromAbi((IntPtr)value); FromManaged = (T value) => MarshalInterface.CreateMarshaler2(value).Detach(); DisposeMarshaler = MarshalInterface.DisposeMarshaler; DisposeAbi = delegate(object box) { MarshalInterface.DisposeAbi((IntPtr)box); }; CreateMarshalerArray = (T[] array) => MarshalInterface.CreateMarshalerArray(array); GetAbiArray = MarshalInterface.GetAbiArray; FromAbiArray = MarshalInterface.FromAbiArray; FromManagedArray = MarshalInterface.FromManagedArray; CopyManagedArray = MarshalInterface.CopyManagedArray; DisposeMarshalerArray = MarshalInterface.DisposeMarshalerArray; DisposeAbiArray = MarshalInterface.DisposeAbiArray; } else if (typeof(T) == typeof(object)) { AbiType = typeof(IntPtr); CreateMarshaler = (T value) => MarshalInspectable.CreateMarshaler2(value); CreateMarshaler2 = CreateMarshaler; GetAbi = (object objRef) => (objRef is ObjectReferenceValue value) ? MarshalInspectable.GetAbi(value) : MarshalInspectable.GetAbi((IObjectReference)objRef); FromAbi = (object box) => MarshalInspectable.FromAbi((IntPtr)box); FromManaged = (T value) => MarshalInspectable.FromManaged(value); CopyManaged = delegate(T value, IntPtr dest) { MarshalInspectable.CopyManaged(value, dest); }; DisposeMarshaler = MarshalInspectable.DisposeMarshaler; DisposeAbi = delegate(object box) { MarshalInspectable.DisposeAbi((IntPtr)box); }; CreateMarshalerArray = (T[] array) => MarshalInspectable.CreateMarshalerArray(array); GetAbiArray = MarshalInspectable.GetAbiArray; FromAbiArray = MarshalInspectable.FromAbiArray; FromManagedArray = MarshalInspectable.FromManagedArray; CopyManagedArray = MarshalInspectable.CopyManagedArray; DisposeMarshalerArray = MarshalInspectable.DisposeMarshalerArray; DisposeAbiArray = MarshalInspectable.DisposeAbiArray; } else { AbiType = typeof(IntPtr); CreateMarshaler = (typeof(T).IsDelegate() ? MarshalGeneric.CreateMarshaler : MarshalGeneric.CreateMarshaler2); CreateMarshaler2 = MarshalGeneric.CreateMarshaler2; GetAbi = MarshalGeneric.GetAbi; FromAbi = MarshalGeneric.FromAbi; FromManaged = MarshalGeneric.FromManaged; CopyManaged = MarshalGeneric.CopyManaged; DisposeMarshaler = MarshalGeneric.DisposeMarshaler; DisposeAbi = MarshalGeneric.DisposeAbi; CreateMarshalerArray = MarshalGeneric.CreateMarshalerArray; GetAbiArray = MarshalGeneric.GetAbiArray; FromAbiArray = MarshalGeneric.FromAbiArray; FromManagedArray = MarshalGeneric.FromManagedArray; CopyManagedArray = MarshalGenericHelper.CopyManagedArray; DisposeMarshalerArray = MarshalGeneric.DisposeMarshalerArray; DisposeAbiArray = MarshalGeneric.DisposeAbiArray; } } } internal static class Mono { private struct MonoObject { private IntPtr vtable; private IntPtr synchronisation; } private struct MonoThread { private MonoObject obj; public unsafe MonoInternalThread_x64* internal_thread; private IntPtr start_obj; private IntPtr pending_exception; } [Flags] private enum MonoThreadFlag { MONO_THREAD_FLAG_DONT_MANAGE = 1, MONO_THREAD_FLAG_NAME_SET = 2, MONO_THREAD_FLAG_APPDOMAIN_ABORT = 4 } [StructLayout(LayoutKind.Explicit)] private struct MonoInternalThread_x64 { [FieldOffset(208)] public MonoThreadFlag flags; } public sealed class ThreadContext : System.IDisposable { private static readonly Lazy> _foreignThreads = new Lazy>(); private readonly IntPtr _threadPtr = IntPtr.Zero; public unsafe ThreadContext() { if (!_usingMono.Value) { return; } IntPtr intPtr = mono_thread_current(); if (mono_thread_is_foreign(intPtr)) { if (_foreignThreads.Value.Add(intPtr)) { mono_thread_pop_appdomain_ref(); ((MonoThread*)(void*)intPtr)->internal_thread->flags |= MonoThreadFlag.MONO_THREAD_FLAG_DONT_MANAGE; } mono_unity_thread_fast_attach(mono_domain_get()); _threadPtr = intPtr; } } public void Dispose() { if (_threadPtr != IntPtr.Zero) { mono_unity_thread_fast_detach(); } } } private static readonly Lazy _usingMono = new Lazy(delegate { IntPtr intPtr = Platform.LoadLibraryExW("mono-2.0-bdwgc.dll", IntPtr.Zero, 0u); if (intPtr == IntPtr.Zero) { return false; } if (!Platform.FreeLibrary(intPtr)) { Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); } return true; }); [DllImport("mono-2.0-bdwgc.dll")] private static extern IntPtr mono_thread_current(); [DllImport("mono-2.0-bdwgc.dll")] [return: MarshalAs(UnmanagedType.Bool)] private static extern bool mono_thread_is_foreign(IntPtr threadPtr); [DllImport("mono-2.0-bdwgc.dll")] private static extern void mono_unity_thread_fast_attach(IntPtr domainPtr); [DllImport("mono-2.0-bdwgc.dll")] private static extern void mono_unity_thread_fast_detach(); [DllImport("mono-2.0-bdwgc.dll")] private static extern void mono_thread_pop_appdomain_ref(); [DllImport("mono-2.0-bdwgc.dll")] private static extern IntPtr mono_domain_get(); } public abstract class IObjectReference : System.IDisposable { private const int NOT_DISPOSED = 0; private const int DISPOSE_PENDING = 1; private const int DISPOSE_COMPLETED = 2; private readonly IntPtr _thisPtr; private IntPtr _referenceTrackerPtr; private int _disposedFlags; public IntPtr ThisPtr { get { ThrowIfDisposed(); return GetThisPtrForCurrentContext(); } } public bool IsFreeThreaded => GetContextToken() == IntPtr.Zero; public bool IsInCurrentContext { get { IntPtr contextToken = GetContextToken(); if (!(contextToken == IntPtr.Zero)) { return contextToken == Context.GetContextToken(); } return true; } } private protected IntPtr ThisPtrFromOriginalContext { get { ThrowIfDisposed(); return _thisPtr; } } internal bool IsAggregated { get; set; } internal bool PreventReleaseOnDispose { get; set; } internal bool PreventReleaseFromTrackerSourceOnDispose { get; set; } internal IntPtr ReferenceTrackerPtr { get { return _referenceTrackerPtr; } set { _referenceTrackerPtr = value; if (_referenceTrackerPtr != IntPtr.Zero) { Marshal.AddRef(_referenceTrackerPtr); AddRefFromTrackerSource(); } } } internal unsafe IReferenceTrackerVftbl ReferenceTracker { get { ThrowIfDisposed(); return *(*(IReferenceTrackerVftbl**)(void*)ReferenceTrackerPtr); } } protected unsafe IUnknownVftbl VftblIUnknown { get { ThrowIfDisposed(); return *(*(IUnknownVftbl**)(void*)ThisPtr); } } private protected unsafe IUnknownVftbl VftblIUnknownFromOriginalContext { get { ThrowIfDisposed(); return *(*(IUnknownVftbl**)(void*)ThisPtrFromOriginalContext); } } internal bool IsReferenceToManagedObject => VftblIUnknown.Equals(IUnknownVftbl.AbiToProjectionVftbl); protected IObjectReference(IntPtr thisPtr) { if (thisPtr == IntPtr.Zero) { throw new ArgumentNullException("thisPtr"); } _thisPtr = thisPtr; if (RuntimeFeature.IsDynamicCodeCompiled) { GC.AddMemoryPressure(1000L); } } ~IObjectReference() { Dispose(); } [RequiresUnreferencedCode("This method is not trim-safe, and is only supported for use when not using trimming (or AOT).")] [Obsolete("This method is deprecated and will be removed in a future release.")] [EditorBrowsable(EditorBrowsableState.Never)] public ObjectReference As() { return As(GuidGenerator.GetIID(typeof(T))); } public ObjectReference As(Guid iid) { Marshal.ThrowExceptionForHR(TryAs(iid, out ObjectReference objRef)); return objRef; } public TInterface AsInterface() { if (typeof(TInterface).IsDefined(typeof(ComImportAttribute))) { Guid iid = typeof(TInterface).GUID; Marshal.ThrowExceptionForHR(Marshal.QueryInterface(ThisPtr, in iid, out var ppv)); try { return (TInterface)Marshal.GetObjectForIUnknown(ppv); } finally { Marshal.Release(ppv); } } if (!FeatureSwitches.EnableIDynamicInterfaceCastableSupport) { throw new NotSupportedException("Using 'AsInterface' to cast an RCW to an interface type not present in metadata relies on 'IDynamicInterfaceCastable' support, which is not currently available. Make sure the 'EnableIDynamicInterfaceCastableSupport' property is not set to 'false'."); } return (TInterface)(object)new IInspectable(this); } [RequiresUnreferencedCode("This method is not trim-safe, and is only supported for use when not using trimming (or AOT).")] [Obsolete("This method is deprecated and will be removed in a future release.")] [EditorBrowsable(EditorBrowsableState.Never)] public int TryAs(out ObjectReference objRef) { return TryAs(GuidGenerator.GetIID(typeof(T)), out objRef); } public int TryAs(Guid iid, out ObjectReference objRef) { if (this is IObjectReferenceWithContext) { return ObjectReferenceWithContext.TryAs(this, iid, out objRef); } return ObjectReference.TryAs(this, iid, out objRef); } public virtual ObjectReference AsKnownPtr(IntPtr ptr) { AddRef(refFromTrackerSource: true); ObjectReference objectReference = ObjectReference.Attach(ref ptr, IID.IID_IUnknown); objectReference.IsAggregated = IsAggregated; objectReference.PreventReleaseOnDispose = IsAggregated; objectReference.ReferenceTrackerPtr = ReferenceTrackerPtr; return objectReference; } public virtual int TryAs(Guid iid, out IntPtr ppv) { ppv = IntPtr.Zero; ThrowIfDisposed(); IntPtr ppv2 = IntPtr.Zero; int num = Marshal.QueryInterface(ThisPtr, in iid, out ppv2); if (num >= 0) { ppv = ppv2; } return num; } public IObjectReference As(Guid iid) { return As(iid); } [Obsolete("This method is deprecated and will be removed in a future release.")] [EditorBrowsable(EditorBrowsableState.Never)] public T AsType() { ThrowIfDisposed(); WinRTImplementationTypeRcwFactoryAttribute customAttribute = typeof(T).GetCustomAttribute(inherit: false); if (customAttribute != null) { return (T)customAttribute.CreateInstance(new IInspectable(this)); } if (!RuntimeFeature.IsDynamicCodeCompiled) { throw new NotSupportedException($"Cannot create an RCW instance for type '{typeof(T)}', because it doesn't have a " + "[WinRTImplementationTypeRcwFactory] derived attribute on it. The fallback path for older projections is not trim-safe, and isn't supported in AOT environments. Make sure to reference updated projections."); } if (TryCreateRcwFallback(this, out var rcwInstance)) { return (T)rcwInstance; } throw new InvalidOperationException($"Target type '{typeof(T)}' is not a projected type."); [UnconditionalSuppressMessage("Trimming", "IL2090", Justification = "This fallback path is not trim-safe by design (to avoid annotations).")] static bool TryCreateRcwFallback(IObjectReference objectReference, out object reference) { ConstructorInfo constructor = typeof(T).GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.CreateInstance, null, new System.Type[1] { typeof(IObjectReference) }, null); if ((object)constructor != null) { object[] parameters = new IObjectReference[1] { objectReference }; reference = constructor.Invoke(parameters); return true; } reference = null; return false; } } public IntPtr GetRef() { ThrowIfDisposed(); AddRef(refFromTrackerSource: false); return ThisPtr; } [MethodImpl(MethodImplOptions.AggressiveInlining)] protected void ThrowIfDisposed() { if (Volatile.Read(in _disposedFlags) == 2) { ThrowObjectDisposedException(); } static void ThrowObjectDisposedException() { throw new ObjectDisposedException("ObjectReference"); } } public void Dispose() { GC.SuppressFinalize(this); if (Interlocked.CompareExchange(ref _disposedFlags, 1, 0) == 0) { if (!PreventReleaseOnDispose) { Release(); } DisposeTrackerSource(); if (RuntimeFeature.IsDynamicCodeCompiled) { GC.RemoveMemoryPressure(1000L); } Volatile.Write(ref _disposedFlags, 2); } } protected virtual void AddRef(bool refFromTrackerSource) { Marshal.AddRef(ThisPtr); if (refFromTrackerSource) { AddRefFromTrackerSource(); } } protected virtual void AddRef() { AddRef(refFromTrackerSource: true); } protected virtual void Release() { ReleaseFromTrackerSource(); Marshal.Release(ThisPtr); } private protected void ReleaseWithoutContext() { ReleaseFromTrackerSource(); Marshal.Release(ThisPtrFromOriginalContext); } internal unsafe void AddRefFromTrackerSource() { if (ReferenceTrackerPtr != IntPtr.Zero) { ReferenceTracker.AddRefFromTrackerSource(ReferenceTrackerPtr); } } internal unsafe void ReleaseFromTrackerSource() { if (ReferenceTrackerPtr != IntPtr.Zero) { ReferenceTracker.ReleaseFromTrackerSource(ReferenceTrackerPtr); } } private unsafe void DisposeTrackerSource() { if (ReferenceTrackerPtr != IntPtr.Zero) { if (!PreventReleaseFromTrackerSourceOnDispose) { ReferenceTracker.ReleaseFromTrackerSource(ReferenceTrackerPtr); } Marshal.Release(ReferenceTrackerPtr); } } private protected virtual IntPtr GetThisPtrForCurrentContext() { return ThisPtrFromOriginalContext; } private protected virtual IntPtr GetContextToken() { return IntPtr.Zero; } public ObjectReferenceValue AsValue() { return new ObjectReferenceValue(ThisPtr, IntPtr.Zero, preventReleaseOnDispose: true, this); } public ObjectReferenceValue AsValue(Guid iid) { IntPtr ppv = IntPtr.Zero; Marshal.ThrowExceptionForHR(Marshal.QueryInterface(ThisPtr, in iid, out ppv)); if (IsAggregated) { Marshal.Release(ppv); } AddRefFromTrackerSource(); return new ObjectReferenceValue(ppv, ReferenceTrackerPtr, IsAggregated, this); } } public class ObjectReference : IObjectReference { private readonly T _vftbl; public T Vftbl { get { ThrowIfDisposed(); return GetVftblForCurrentContext(); } } private protected ObjectReference(IntPtr thisPtr, T vftblT) : base(thisPtr) { _vftbl = vftblT; } private protected ObjectReference(IntPtr thisPtr) : this(thisPtr, GetVtable(thisPtr)) { } [RequiresUnreferencedCode("This method is not trim-safe, and is only supported for use when not using trimming (or AOT).")] [Obsolete("This method is deprecated and will be removed in a future release.")] [EditorBrowsable(EditorBrowsableState.Never)] public static ObjectReference Attach(ref IntPtr thisPtr) { if (thisPtr == IntPtr.Zero) { return null; } if (ComWrappersSupport.IsFreeThreaded(thisPtr)) { ObjectReference result = new ObjectReference(thisPtr); thisPtr = IntPtr.Zero; return result; } ObjectReferenceWithContext result2 = new ObjectReferenceWithContext(thisPtr, Context.GetContextCallback(), Context.GetContextToken()); thisPtr = IntPtr.Zero; return result2; } public static ObjectReference Attach(ref IntPtr thisPtr, Guid iid) { if (thisPtr == IntPtr.Zero) { return null; } if (ComWrappersSupport.IsFreeThreaded(thisPtr)) { ObjectReference result = new ObjectReference(thisPtr); thisPtr = IntPtr.Zero; return result; } ObjectReferenceWithContext result2 = new ObjectReferenceWithContext(thisPtr, Context.GetContextCallback(), Context.GetContextToken(), iid); thisPtr = IntPtr.Zero; return result2; } [RequiresUnreferencedCode("This method is not trim-safe, and is only supported for use when not using trimming (or AOT).")] [Obsolete("This method is deprecated and will be removed in a future release.")] [EditorBrowsable(EditorBrowsableState.Never)] public static ObjectReference FromAbi(IntPtr thisPtr, T vftblT) { if (thisPtr == IntPtr.Zero) { return null; } Marshal.AddRef(thisPtr); if (ComWrappersSupport.IsFreeThreaded(thisPtr)) { return new ObjectReference(thisPtr, vftblT); } return new ObjectReferenceWithContext(thisPtr, vftblT, Context.GetContextCallback(), Context.GetContextToken()); } public static ObjectReference FromAbi(IntPtr thisPtr, T vftblT, Guid iid) { if (thisPtr == IntPtr.Zero) { return null; } Marshal.AddRef(thisPtr); if (ComWrappersSupport.IsFreeThreaded(thisPtr)) { return new ObjectReference(thisPtr, vftblT); } return new ObjectReferenceWithContext(thisPtr, vftblT, Context.GetContextCallback(), Context.GetContextToken(), iid); } [RequiresUnreferencedCode("This method is not trim-safe, and is only supported for use when not using trimming (or AOT).")] [Obsolete("This method is deprecated and will be removed in a future release.")] [EditorBrowsable(EditorBrowsableState.Never)] public static ObjectReference FromAbi(IntPtr thisPtr) { if (thisPtr == IntPtr.Zero) { return null; } T vtable = GetVtable(thisPtr); return FromAbi(thisPtr, vtable); } public static ObjectReference FromAbi(IntPtr thisPtr, Guid iid) { if (thisPtr == IntPtr.Zero) { return null; } T vtable = GetVtable(thisPtr); return FromAbi(thisPtr, vtable, iid); } private unsafe static T GetVtable(IntPtr thisPtr) { if (RuntimeHelpers.IsReferenceOrContainsReferences()) { if (!RuntimeFeature.IsDynamicCodeCompiled) { throw new NotSupportedException("Managed vtable types (ie. containing any reference types) are not supported."); } return GetVtableForJitEnvironment(thisPtr); } return Unsafe.Read(*(void**)(void*)thisPtr); [MethodImpl(MethodImplOptions.NoInlining)] [UnconditionalSuppressMessage("Trimming", "IL2090", Justification = "Fallback method for JIT environments that is not trim-safe by design.")] static T GetVtableForJitEnvironment(IntPtr intPtr) { return (T)typeof(T).GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.CreateInstance, null, new System.Type[1] { typeof(IntPtr) }, null).Invoke(new object[1] { intPtr }); } } private protected virtual T GetVftblForCurrentContext() { return _vftbl; } internal static int TryAs(IObjectReference sourceRef, Guid iid, out ObjectReference objRef) { objRef = null; IntPtr ppv; int num = Marshal.QueryInterface(sourceRef.ThisPtr, in iid, out ppv); if (num >= 0) { if (sourceRef.IsAggregated) { Marshal.Release(ppv); } sourceRef.AddRefFromTrackerSource(); objRef = Attach(ref ppv, iid); objRef.IsAggregated = sourceRef.IsAggregated; objRef.PreventReleaseOnDispose = sourceRef.IsAggregated; objRef.ReferenceTrackerPtr = sourceRef.ReferenceTrackerPtr; } return num; } } internal sealed class ObjectReferenceWithContext : ObjectReference, IObjectReferenceWithContext { private static class ContextCallbackHolder { public static readonly Func Value = CreateForCurrentContext; [UnconditionalSuppressMessage("Trimming", "IL2087", Justification = "The '_iid' field is only empty when using annotated APIs not trim-safe.")] private static IObjectReference CreateForCurrentContext(IntPtr _, IObjectReference state) { ObjectReferenceWithContext objectReferenceWithContext = Unsafe.As>(state); AgileReference agileReference = objectReferenceWithContext.AgileReference; if (agileReference == null) { return null; } try { if (!RuntimeFeature.IsDynamicCodeCompiled) { return agileReference.Get(objectReferenceWithContext._iid); } if (objectReferenceWithContext._iid == Guid.Empty) { return agileReference.Get(GuidGenerator.GetIID(typeof(T))); } return agileReference.Get(objectReferenceWithContext._iid); } catch (System.Exception) { return null; } } } private readonly IntPtr _contextCallbackPtr; private readonly IntPtr _contextToken; private volatile ConcurrentDictionary __cachedContext; private volatile bool _isAgileReferenceSet; private volatile AgileReference __agileReference; private readonly Guid _iid; private ConcurrentDictionary CachedContext => __cachedContext ?? Make_CachedContext(); private AgileReference AgileReference { get { if (!_isAgileReferenceSet) { return Make_AgileReference(); } return __agileReference; } } private ConcurrentDictionary Make_CachedContext() { Interlocked.CompareExchange(ref __cachedContext, new ConcurrentDictionary(), null); return __cachedContext; } private unsafe AgileReference Make_AgileReference() { Context.CallInContext(_contextCallbackPtr, _contextToken, (delegate*)(&InitAgileReference), (delegate*)null, (object)this); _isAgileReferenceSet = true; return __agileReference; static void InitAgileReference(object state) { ObjectReferenceWithContext objectReferenceWithContext = Unsafe.As>(state); Interlocked.CompareExchange(ref objectReferenceWithContext.__agileReference, new AgileReference(objectReferenceWithContext), null); } } [RequiresUnreferencedCode("This method is not trim-safe, and is only supported for use when not using trimming (or AOT).")] [Obsolete("This method is deprecated and will be removed in a future release.")] [EditorBrowsable(EditorBrowsableState.Never)] internal ObjectReferenceWithContext(IntPtr thisPtr, IntPtr contextCallbackPtr, IntPtr contextToken) : base(thisPtr) { _contextCallbackPtr = contextCallbackPtr; _contextToken = contextToken; } [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "This constructor is setting the '_iid' field directly.")] internal ObjectReferenceWithContext(IntPtr thisPtr, IntPtr contextCallbackPtr, IntPtr contextToken, Guid iid) : this(thisPtr, contextCallbackPtr, contextToken) { if (iid == default(Guid)) { ObjectReferenceWithContextHelper.ThrowArgumentExceptionForEmptyIid(); } _iid = iid; } [RequiresUnreferencedCode("This method is not trim-safe, and is only supported for use when not using trimming (or AOT).")] [Obsolete("This method is deprecated and will be removed in a future release.")] [EditorBrowsable(EditorBrowsableState.Never)] internal ObjectReferenceWithContext(IntPtr thisPtr, T vftblT, IntPtr contextCallbackPtr, IntPtr contextToken) : base(thisPtr, vftblT) { _contextCallbackPtr = contextCallbackPtr; _contextToken = contextToken; } [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "This constructor is setting the '_iid' field directly.")] internal ObjectReferenceWithContext(IntPtr thisPtr, T vftblT, IntPtr contextCallbackPtr, IntPtr contextToken, Guid iid) : this(thisPtr, vftblT, contextCallbackPtr, contextToken) { if (iid == default(Guid)) { ObjectReferenceWithContextHelper.ThrowArgumentExceptionForEmptyIid(); } _iid = iid; } private protected override IntPtr GetThisPtrForCurrentContext() { return GetCurrentContext()?.ThisPtr ?? base.GetThisPtrForCurrentContext(); } private protected override IntPtr GetContextToken() { return _contextToken; } private protected override T GetVftblForCurrentContext() { ObjectReference currentContext = GetCurrentContext(); if (currentContext == null) { return base.GetVftblForCurrentContext(); } return currentContext.Vftbl; } private ObjectReference GetCurrentContext() { IntPtr contextToken = Context.GetContextToken(); if (_contextCallbackPtr == IntPtr.Zero || contextToken == _contextToken) { return null; } IObjectReference orAdd = CachedContext.GetOrAdd(contextToken, ContextCallbackHolder.Value, this); return Unsafe.As>(orAdd); } protected unsafe override void Release() { if (__cachedContext != null) { CachedContext.Clear(); } Context.CallInContext(_contextCallbackPtr, _contextToken, (delegate*)(&Release), (delegate*)(&ReleaseWithoutContext), (object)this); Context.DisposeContextCallback(_contextCallbackPtr); static void Release(object state) { ObjectReferenceWithContext objectReferenceWithContext = Unsafe.As>(state); objectReferenceWithContext.ReleaseFromBase(); } static void ReleaseWithoutContext(object state) { ObjectReferenceWithContext objectReferenceWithContext = Unsafe.As>(state); objectReferenceWithContext.ReleaseWithoutContext(); } } private void ReleaseFromBase() { base.Release(); } public override ObjectReference AsKnownPtr(IntPtr ptr) { AddRef(refFromTrackerSource: true); return new ObjectReferenceWithContext(ptr, Context.GetContextCallback(), Context.GetContextToken(), IID.IID_IUnknown) { IsAggregated = base.IsAggregated, PreventReleaseOnDispose = base.IsAggregated, ReferenceTrackerPtr = base.ReferenceTrackerPtr }; } internal new static int TryAs(IObjectReference sourceRef, Guid iid, out ObjectReference objRef) { objRef = null; IntPtr ppv; int num = Marshal.QueryInterface(sourceRef.ThisPtr, in iid, out ppv); if (num >= 0) { if (sourceRef.IsAggregated) { Marshal.Release(ppv); } sourceRef.AddRefFromTrackerSource(); objRef = new ObjectReferenceWithContext(ppv, Context.GetContextCallback(), Context.GetContextToken(), iid) { IsAggregated = sourceRef.IsAggregated, PreventReleaseOnDispose = sourceRef.IsAggregated, ReferenceTrackerPtr = sourceRef.ReferenceTrackerPtr }; } return num; } } internal static class ObjectReferenceWithContextHelper { public static void ThrowArgumentExceptionForEmptyIid() { throw new ArgumentException("The input argument 'iid' cannot be empty and must be set to a valid IID."); } } internal interface IObjectReferenceWithContext { } public readonly struct ObjectReferenceValue { internal readonly IntPtr ptr; internal readonly IntPtr referenceTracker; internal readonly bool preventReleaseOnDispose; internal readonly IObjectReference objRef; internal ObjectReferenceValue(IntPtr ptr) { this = default(ObjectReferenceValue); this.ptr = ptr; } internal ObjectReferenceValue(IntPtr ptr, IntPtr referenceTracker, bool preventReleaseOnDispose, IObjectReference objRef) { this.ptr = ptr; this.referenceTracker = referenceTracker; this.preventReleaseOnDispose = preventReleaseOnDispose; this.objRef = objRef; } public static ObjectReferenceValue Attach(ref IntPtr thisPtr) { ObjectReferenceValue result = new ObjectReferenceValue(thisPtr); thisPtr = IntPtr.Zero; return result; } public IntPtr GetAbi() { return ptr; } public unsafe IntPtr Detach() { if (preventReleaseOnDispose && ptr != IntPtr.Zero) { Marshal.AddRef(ptr); } if (referenceTracker != IntPtr.Zero) { ((IReferenceTrackerVftbl*)(*(nint*)(void*)referenceTracker))->ReleaseFromTrackerSource(referenceTracker); } return ptr; } public unsafe void Dispose() { if (referenceTracker != IntPtr.Zero) { ((IReferenceTrackerVftbl*)(*(nint*)(void*)referenceTracker))->ReleaseFromTrackerSource(referenceTracker); } if (!preventReleaseOnDispose && ptr != IntPtr.Zero) { Marshal.Release(ptr); } } } internal sealed class HelperTypeMetadataNotAvailableOnAot { } public static class Projections { private static readonly ReaderWriterLockSlim rwlock; private static readonly Dictionary CustomTypeToHelperTypeMappings; private static readonly Dictionary CustomAbiTypeToTypeMappings; private static readonly Dictionary CustomAbiTypeNameToTypeMappings; private static readonly Dictionary CustomTypeToAbiTypeNameMappings; private static readonly HashSet ProjectedRuntimeClassNames; private static readonly HashSet ProjectedCustomTypeRuntimeClasses; private static readonly ConcurrentDictionary IsTypeWindowsRuntimeTypeCache; private static readonly ConcurrentDictionary DefaultInterfaceTypeCache; private static int _EventHandler; private static int _NotifyCollectionChangedEventHandler; private static int _PropertyChangedEventHandler; private static ComWrappers.ComInterfaceEntry[]? _AbiEventHandlerExposedInterfaces; private static ComWrappers.ComInterfaceEntry[]? _AbiNotifyCollectionChangedEventHandlerExposedInterfaces; private static ComWrappers.ComInterfaceEntry[]? _AbiPropertyChangedEventHandlerExposedInterfaces; private static int _EventRegistrationToken; private static int _Nullable__; private static int _int_; private static int _byte_; private static int _sbyte_; private static int _short_; private static int _ushort_; private static int _uint_; private static int _long_; private static int _ulong_; private static int _float_; private static int _double_; private static int _char_; private static int _bool_; private static int _Guid_; private static int _DateTimeOffset_; private static int _TimeSpan_; private static int _DateTimeOffset; private static int _Exception; private static int _TimeSpan; private static int _Uri; private static int _DataErrorsChangedEventArgs; private static int _PropertyChangedEventArgs; private static int _INotifyDataErrorInfo; private static int _INotifyPropertyChanged; private static int _ICommand; private static int _IServiceProvider; private static int _EventHandler__; private static int _KeyValuePair___; private static int _IEnumerable__; private static int _IEnumerator__; private static int _IList__; private static int _IReadOnlyList__; private static int _IDictionary___; private static int _IReadOnlyDictionary___; private static int _IDisposable; private static int _IEnumerable; private static int _IList; private static int _INotifyCollectionChanged; private static int _NotifyCollectionChangedAction; private static int _NotifyCollectionChangedEventArgs; private static int _Matrix3x2; private static int _Matrix4x4; private static int _Plane; private static int _Quaternion; private static int _Vector2; private static int _Vector3; private static int _Vector4; private static int _IMap___; private static int _IVector__; private static int _IMapView___; private static int _IVectorView__; private static int _IBindableVector; private static int _ICollection__; private static int _IReadOnlyCollection__; private static int _ICollection; static Projections() { rwlock = new ReaderWriterLockSlim(); CustomTypeToHelperTypeMappings = new Dictionary(); CustomAbiTypeToTypeMappings = new Dictionary(); CustomAbiTypeNameToTypeMappings = new Dictionary(StringComparer.Ordinal); CustomTypeToAbiTypeNameMappings = new Dictionary(); ProjectedRuntimeClassNames = new HashSet(StringComparer.Ordinal); ProjectedCustomTypeRuntimeClasses = new HashSet(); IsTypeWindowsRuntimeTypeCache = new ConcurrentDictionary(); DefaultInterfaceTypeCache = new ConcurrentDictionary(); RegisterCustomAbiTypeMappingNoLock(typeof(bool), typeof(ABI.System.Boolean), "Boolean"); RegisterCustomAbiTypeMappingNoLock(typeof(char), typeof(ABI.System.Char), "Char"); CustomTypeToAbiTypeNameMappings.Add(typeof(System.Type), "Windows.UI.Xaml.Interop.TypeName"); CustomAbiTypeNameToTypeMappings.Add("Windows.UI.Xaml.Interop.TypeName", typeof(System.Type)); if (FeatureSwitches.EnableDefaultCustomTypeMappings) { RegisterCustomAbiTypeMappingNoLock(typeof(EventRegistrationToken), typeof(ABI.WinRT.EventRegistrationToken), "Windows.Foundation.EventRegistrationToken"); RegisterCustomAbiTypeMappingNoLock(typeof(System.Nullable<>), typeof(ABI.System.Nullable<>), "Windows.Foundation.IReference`1"); RegisterCustomAbiTypeMappingNoLock(typeof(System.DateTimeOffset), typeof(ABI.System.DateTimeOffset), "Windows.Foundation.DateTime"); RegisterCustomAbiTypeMappingNoLock(typeof(System.Exception), typeof(ABI.System.Exception), "Windows.Foundation.HResult"); RegisterCustomAbiTypeMappingNoLock(typeof(System.TimeSpan), typeof(ABI.System.TimeSpan), "Windows.Foundation.TimeSpan"); RegisterCustomAbiTypeMappingNoLock(typeof(System.Uri), typeof(ABI.System.Uri), "Windows.Foundation.Uri", isRuntimeClass: true); if (!FeatureSwitches.UseWindowsUIXamlProjections) { RegisterCustomAbiTypeMappingNoLock(typeof(System.ComponentModel.DataErrorsChangedEventArgs), typeof(ABI.System.ComponentModel.DataErrorsChangedEventArgs), "Microsoft.UI.Xaml.Data.DataErrorsChangedEventArgs", isRuntimeClass: true); RegisterCustomAbiTypeMappingNoLock(typeof(System.ComponentModel.PropertyChangedEventArgs), typeof(ABI.System.ComponentModel.PropertyChangedEventArgs), "Microsoft.UI.Xaml.Data.PropertyChangedEventArgs", isRuntimeClass: true); RegisterCustomAbiTypeMappingNoLock(typeof(System.ComponentModel.PropertyChangedEventHandler), typeof(ABI.System.ComponentModel.PropertyChangedEventHandler), "Microsoft.UI.Xaml.Data.PropertyChangedEventHandler"); RegisterCustomAbiTypeMappingNoLock(typeof(System.ComponentModel.INotifyDataErrorInfo), typeof(ABI.System.ComponentModel.INotifyDataErrorInfo), "Microsoft.UI.Xaml.Data.INotifyDataErrorInfo"); RegisterCustomAbiTypeMappingNoLock(typeof(System.ComponentModel.INotifyPropertyChanged), typeof(ABI.System.ComponentModel.INotifyPropertyChanged), "Microsoft.UI.Xaml.Data.INotifyPropertyChanged"); RegisterCustomAbiTypeMappingNoLock(typeof(System.Windows.Input.ICommand), typeof(ABI.System.Windows.Input.ICommand), "Microsoft.UI.Xaml.Input.ICommand"); RegisterCustomAbiTypeMappingNoLock(typeof(System.IServiceProvider), typeof(ABI.System.IServiceProvider), "Microsoft.UI.Xaml.IXamlServiceProvider"); RegisterCustomAbiTypeMappingNoLock(typeof(System.Collections.IEnumerable), typeof(ABI.System.Collections.IEnumerable), "Microsoft.UI.Xaml.Interop.IBindableIterable"); RegisterCustomAbiTypeMappingNoLock(typeof(System.Collections.IList), typeof(ABI.System.Collections.IList), "Microsoft.UI.Xaml.Interop.IBindableVector"); RegisterCustomAbiTypeMappingNoLock(typeof(System.Collections.Specialized.INotifyCollectionChanged), typeof(ABI.System.Collections.Specialized.INotifyCollectionChanged), "Microsoft.UI.Xaml.Interop.INotifyCollectionChanged"); RegisterCustomAbiTypeMappingNoLock(typeof(System.Collections.Specialized.NotifyCollectionChangedAction), typeof(ABI.System.Collections.Specialized.NotifyCollectionChangedAction), "Microsoft.UI.Xaml.Interop.NotifyCollectionChangedAction"); RegisterCustomAbiTypeMappingNoLock(typeof(System.Collections.Specialized.NotifyCollectionChangedEventArgs), typeof(ABI.System.Collections.Specialized.NotifyCollectionChangedEventArgs), "Microsoft.UI.Xaml.Interop.NotifyCollectionChangedEventArgs", isRuntimeClass: true); RegisterCustomAbiTypeMappingNoLock(typeof(System.Collections.Specialized.NotifyCollectionChangedEventHandler), typeof(ABI.System.Collections.Specialized.NotifyCollectionChangedEventHandler), "Microsoft.UI.Xaml.Interop.NotifyCollectionChangedEventHandler"); } else { RegisterCustomAbiTypeMappingNoLock(typeof(System.ComponentModel.PropertyChangedEventArgs), typeof(ABI.System.ComponentModel.PropertyChangedEventArgs), "Windows.UI.Xaml.Data.PropertyChangedEventArgs", isRuntimeClass: true); RegisterCustomAbiTypeMappingNoLock(typeof(System.ComponentModel.PropertyChangedEventHandler), typeof(ABI.System.ComponentModel.PropertyChangedEventHandler), "Windows.UI.Xaml.Data.PropertyChangedEventHandler"); RegisterCustomAbiTypeMappingNoLock(typeof(System.ComponentModel.INotifyPropertyChanged), typeof(ABI.System.ComponentModel.INotifyPropertyChanged), "Windows.UI.Xaml.Data.INotifyPropertyChanged"); RegisterCustomAbiTypeMappingNoLock(typeof(System.Windows.Input.ICommand), typeof(ABI.System.Windows.Input.ICommand), "Windows.UI.Xaml.Interop.ICommand"); RegisterCustomAbiTypeMappingNoLock(typeof(System.Collections.IEnumerable), typeof(ABI.System.Collections.IEnumerable), "Windows.UI.Xaml.Interop.IBindableIterable"); RegisterCustomAbiTypeMappingNoLock(typeof(System.Collections.IList), typeof(ABI.System.Collections.IList), "Windows.UI.Xaml.Interop.IBindableVector"); RegisterCustomAbiTypeMappingNoLock(typeof(System.Collections.Specialized.INotifyCollectionChanged), typeof(ABI.System.Collections.Specialized.INotifyCollectionChanged), "Windows.UI.Xaml.Interop.INotifyCollectionChanged"); RegisterCustomAbiTypeMappingNoLock(typeof(System.Collections.Specialized.NotifyCollectionChangedAction), typeof(ABI.System.Collections.Specialized.NotifyCollectionChangedAction), "Windows.UI.Xaml.Interop.NotifyCollectionChangedAction"); RegisterCustomAbiTypeMappingNoLock(typeof(System.Collections.Specialized.NotifyCollectionChangedEventArgs), typeof(ABI.System.Collections.Specialized.NotifyCollectionChangedEventArgs), "Windows.UI.Xaml.Interop.NotifyCollectionChangedEventArgs", isRuntimeClass: true); RegisterCustomAbiTypeMappingNoLock(typeof(System.Collections.Specialized.NotifyCollectionChangedEventHandler), typeof(ABI.System.Collections.Specialized.NotifyCollectionChangedEventHandler), "Windows.UI.Xaml.Interop.NotifyCollectionChangedEventHandler"); } RegisterCustomAbiTypeMappingNoLock(typeof(System.EventHandler<>), typeof(ABI.System.EventHandler<>), "Windows.Foundation.EventHandler`1"); RegisterCustomAbiTypeMappingNoLock(typeof(System.Collections.Generic.KeyValuePair<, >), typeof(ABI.System.Collections.Generic.KeyValuePair<, >), "Windows.Foundation.Collections.IKeyValuePair`2"); RegisterCustomAbiTypeMappingNoLock(typeof(System.Collections.Generic.IEnumerable<>), typeof(ABI.System.Collections.Generic.IEnumerable<>), "Windows.Foundation.Collections.IIterable`1"); RegisterCustomAbiTypeMappingNoLock(typeof(System.Collections.Generic.IEnumerator<>), typeof(ABI.System.Collections.Generic.IEnumerator<>), "Windows.Foundation.Collections.IIterator`1"); RegisterCustomAbiTypeMappingNoLock(typeof(System.Collections.Generic.IList<>), typeof(ABI.System.Collections.Generic.IList<>), "Windows.Foundation.Collections.IVector`1"); RegisterCustomAbiTypeMappingNoLock(typeof(System.Collections.Generic.IReadOnlyList<>), typeof(ABI.System.Collections.Generic.IReadOnlyList<>), "Windows.Foundation.Collections.IVectorView`1"); RegisterCustomAbiTypeMappingNoLock(typeof(System.Collections.Generic.IDictionary<, >), typeof(ABI.System.Collections.Generic.IDictionary<, >), "Windows.Foundation.Collections.IMap`2"); RegisterCustomAbiTypeMappingNoLock(typeof(System.Collections.Generic.IReadOnlyDictionary<, >), typeof(ABI.System.Collections.Generic.IReadOnlyDictionary<, >), "Windows.Foundation.Collections.IMapView`2"); RegisterCustomAbiTypeMappingNoLock(typeof(System.IDisposable), typeof(ABI.System.IDisposable), "Windows.Foundation.IClosable"); RegisterCustomAbiTypeMappingNoLock(typeof(System.Numerics.Matrix3x2), typeof(ABI.System.Numerics.Matrix3x2), "Windows.Foundation.Numerics.Matrix3x2"); RegisterCustomAbiTypeMappingNoLock(typeof(System.Numerics.Matrix4x4), typeof(ABI.System.Numerics.Matrix4x4), "Windows.Foundation.Numerics.Matrix4x4"); RegisterCustomAbiTypeMappingNoLock(typeof(System.Numerics.Plane), typeof(ABI.System.Numerics.Plane), "Windows.Foundation.Numerics.Plane"); RegisterCustomAbiTypeMappingNoLock(typeof(System.Numerics.Quaternion), typeof(ABI.System.Numerics.Quaternion), "Windows.Foundation.Numerics.Quaternion"); RegisterCustomAbiTypeMappingNoLock(typeof(System.Numerics.Vector2), typeof(ABI.System.Numerics.Vector2), "Windows.Foundation.Numerics.Vector2"); RegisterCustomAbiTypeMappingNoLock(typeof(System.Numerics.Vector3), typeof(ABI.System.Numerics.Vector3), "Windows.Foundation.Numerics.Vector3"); RegisterCustomAbiTypeMappingNoLock(typeof(System.Numerics.Vector4), typeof(ABI.System.Numerics.Vector4), "Windows.Foundation.Numerics.Vector4"); RegisterCustomAbiTypeMappingNoLock(typeof(System.EventHandler), typeof(ABI.System.EventHandler)); RegisterCustomTypeToHelperTypeMappingNoLock(typeof(IMap<, >), typeof(ABI.System.Collections.Generic.IDictionary<, >)); RegisterCustomTypeToHelperTypeMappingNoLock(typeof(IVector<>), typeof(ABI.System.Collections.Generic.IList<>)); RegisterCustomTypeToHelperTypeMappingNoLock(typeof(IMapView<, >), typeof(ABI.System.Collections.Generic.IReadOnlyDictionary<, >)); RegisterCustomTypeToHelperTypeMappingNoLock(typeof(IVectorView<>), typeof(ABI.System.Collections.Generic.IReadOnlyList<>)); RegisterCustomTypeToHelperTypeMappingNoLock(typeof(IBindableVector), typeof(ABI.System.Collections.IList)); RegisterCustomTypeToHelperTypeMappingNoLock(typeof(System.Collections.Generic.ICollection<>), typeof(ABI.System.Collections.Generic.ICollection<>)); RegisterCustomTypeToHelperTypeMappingNoLock(typeof(System.Collections.Generic.IReadOnlyCollection<>), typeof(ABI.System.Collections.Generic.IReadOnlyCollection<>)); RegisterCustomTypeToHelperTypeMappingNoLock(typeof(System.Collections.ICollection), typeof(ABI.System.Collections.ICollection)); } } private static void RegisterCustomAbiTypeMapping(System.Type publicType, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicFields)] System.Type abiType, string winrtTypeName, bool isRuntimeClass = false) { rwlock.EnterWriteLock(); try { RegisterCustomAbiTypeMappingNoLock(publicType, abiType, winrtTypeName, isRuntimeClass); } finally { rwlock.ExitWriteLock(); } } private static void RegisterCustomTypeToHelperTypeMapping(System.Type publicType, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicFields)] System.Type helperType) { rwlock.EnterWriteLock(); try { CustomTypeToHelperTypeMappings.Add(publicType, helperType); } finally { rwlock.ExitWriteLock(); } } private static void RegisterCustomTypeToHelperTypeMappingNoLock(System.Type publicType, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicFields)] System.Type helperType) { CustomTypeToHelperTypeMappings.Add(publicType, helperType); } private static void RegisterCustomAbiTypeMappingNoLock(System.Type publicType, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicFields)] System.Type abiType, string winrtTypeName, bool isRuntimeClass = false) { CustomTypeToHelperTypeMappings.Add(publicType, abiType); CustomAbiTypeToTypeMappings.Add(abiType, publicType); CustomTypeToAbiTypeNameMappings.Add(publicType, winrtTypeName); CustomAbiTypeNameToTypeMappings.Add(winrtTypeName, publicType); if (isRuntimeClass) { ProjectedRuntimeClassNames.Add(winrtTypeName); ProjectedCustomTypeRuntimeClasses.Add(publicType); } } private static void RegisterCustomAbiTypeMapping(System.Type publicType, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicFields)] System.Type abiType) { rwlock.EnterWriteLock(); try { RegisterCustomAbiTypeMappingNoLock(publicType, abiType); } finally { rwlock.ExitWriteLock(); } } private static void RegisterCustomAbiTypeMappingNoLock(System.Type publicType, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicFields)] System.Type abiType) { CustomTypeToHelperTypeMappings.Add(publicType, abiType); CustomAbiTypeToTypeMappings.Add(abiType, publicType); } [UnconditionalSuppressMessage("Trimming", "IL2055", Justification = "The type arguments are guaranteed to be valid for the generic ABI types.")] [UnconditionalSuppressMessage("Trimming", "IL2068", Justification = "All types added to 'CustomTypeToHelperTypeMappings' have metadata explicitly preserved.")] [return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicFields)] public static System.Type FindCustomHelperTypeMapping(System.Type publicType, bool filterToRuntimeClass = false) { return FindCustomHelperTypeMapping(publicType, filterToRuntimeClass, returnMarkerTypeIfNotAotCompatible: false); } [UnconditionalSuppressMessage("Trimming", "IL2055", Justification = "The type arguments are guaranteed to be valid for the generic ABI types.")] [UnconditionalSuppressMessage("Trimming", "IL2068", Justification = "All types added to 'CustomTypeToHelperTypeMappings' have metadata explicitly preserved.")] [return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicFields)] internal static System.Type FindCustomHelperTypeMapping(System.Type publicType, bool filterToRuntimeClass, bool returnMarkerTypeIfNotAotCompatible) { rwlock.EnterReadLock(); try { if (filterToRuntimeClass && !ProjectedCustomTypeRuntimeClasses.Contains(publicType)) { return null; } if (publicType.IsGenericType && !publicType.IsGenericTypeDefinition) { if (CustomTypeToHelperTypeMappings.TryGetValue(publicType, out var value)) { return value; } if (CustomTypeToHelperTypeMappings.TryGetValue(publicType.GetGenericTypeDefinition(), out var value2)) { if (!RuntimeFeature.IsDynamicCodeCompiled) { if (!returnMarkerTypeIfNotAotCompatible) { throw new NotSupportedException($"Cannot retrieve a helper type for public type '{publicType}'."); } return typeof(HelperTypeMetadataNotAvailableOnAot); } return value2.MakeGenericType(publicType.GetGenericArguments()); } return null; } System.Type value3; return CustomTypeToHelperTypeMappings.TryGetValue(publicType, out value3) ? value3 : null; } finally { rwlock.ExitReadLock(); } } [UnconditionalSuppressMessage("Trimming", "IL2055", Justification = "The type arguments are guaranteed to be valid for the generic ABI types.")] public static System.Type FindCustomPublicTypeForAbiType(System.Type abiType) { rwlock.EnterReadLock(); try { if (abiType.IsGenericType) { if (CustomAbiTypeToTypeMappings.TryGetValue(abiType, out var value)) { return value; } if (CustomAbiTypeToTypeMappings.TryGetValue(abiType.GetGenericTypeDefinition(), out var value2)) { if (!RuntimeFeature.IsDynamicCodeCompiled) { throw new NotSupportedException($"Cannot retrieve a public type for ABI type '{abiType}'."); } return value2.MakeGenericType(abiType.GetGenericArguments()); } return null; } System.Type value3; return CustomAbiTypeToTypeMappings.TryGetValue(abiType, out value3) ? value3 : null; } finally { rwlock.ExitReadLock(); } } public static System.Type FindCustomTypeForAbiTypeName(string abiTypeName) { rwlock.EnterReadLock(); try { System.Type value; return CustomAbiTypeNameToTypeMappings.TryGetValue(abiTypeName, out value) ? value : null; } finally { rwlock.ExitReadLock(); } } public static string FindCustomAbiTypeNameForType(System.Type type) { rwlock.EnterReadLock(); try { string value; return CustomTypeToAbiTypeNameMappings.TryGetValue(type, out value) ? value : null; } finally { rwlock.ExitReadLock(); } } public static bool IsTypeWindowsRuntimeType(System.Type type) { return IsTypeWindowsRuntimeTypeCache.GetOrAdd(type, delegate(System.Type type3) { System.Type type2 = type3; if (type2.IsArray) { type2 = type2.GetElementType(); } return IsTypeWindowsRuntimeTypeNoArray(type2); }); } private static bool IsTypeWindowsRuntimeTypeNoArray(System.Type type) { if (type.IsConstructedGenericType) { if (IsTypeWindowsRuntimeTypeNoArray(type.GetGenericTypeDefinition())) { System.Type[] genericArguments = type.GetGenericArguments(); foreach (System.Type type2 in genericArguments) { if (!IsTypeWindowsRuntimeTypeNoArray(type2)) { return false; } } return true; } return false; } if (!CustomTypeToAbiTypeNameMappings.ContainsKey(type) && !type.IsPrimitive && !(type == typeof(string)) && !(type == typeof(Guid)) && !(type == typeof(object)) && !type.IsDefined(typeof(WindowsRuntimeTypeAttribute))) { return type.GetAuthoringMetadataType() != null; } return true; } [UnconditionalSuppressMessage("Trimming", "IL2055", Justification = "Calls to 'MakeGenericType' are always done with compatible types.")] public static bool TryGetCompatibleWindowsRuntimeTypeForVariantType(System.Type type, out System.Type compatibleType) { compatibleType = null; if (!type.IsConstructedGenericType) { throw new ArgumentException("type"); } System.Type genericTypeDefinition = type.GetGenericTypeDefinition(); if (!IsTypeWindowsRuntimeTypeNoArray(genericTypeDefinition)) { return false; } if (!RuntimeFeature.IsDynamicCodeCompiled) { throw new NotSupportedException($"Cannot retrieve a compatible WinRT type for variant type '{type}'."); } System.Type[] genericArguments = genericTypeDefinition.GetGenericArguments(); System.Type[] genericArguments2 = type.GetGenericArguments(); System.Type[] array = new System.Type[genericArguments2.Length]; for (int i = 0; i < genericArguments2.Length; i++) { if (!IsTypeWindowsRuntimeTypeNoArray(genericArguments2[i])) { if ((genericArguments[i].GenericParameterAttributes & GenericParameterAttributes.VarianceMask) != GenericParameterAttributes.Covariant || genericArguments2[i].IsValueType) { return false; } array[i] = typeof(object); } else { array[i] = genericArguments2[i]; } } compatibleType = genericTypeDefinition.MakeGenericType(array); return true; } [RequiresUnreferencedCode("This method is not trim-safe, and is only supported for use when not using trimming (or AOT).")] private static HashSet GetCompatibleTypes(System.Type type, Stack typeStack) { HashSet hashSet = new HashSet(); System.Type[] interfaces = type.GetInterfaces(); foreach (System.Type type2 in interfaces) { if (IsTypeWindowsRuntimeTypeNoArray(type2)) { hashSet.Add(type2); } if (type2.IsConstructedGenericType && TryGetCompatibleWindowsRuntimeTypesForVariantType(type2, typeStack, out var compatibleTypes)) { hashSet.UnionWith(compatibleTypes); } } System.Type baseType = type.BaseType; while (baseType != null) { if (IsTypeWindowsRuntimeTypeNoArray(baseType)) { hashSet.Add(baseType); } baseType = baseType.BaseType; } return hashSet; } internal static System.Collections.Generic.IEnumerable GetAllPossibleTypeCombinations(System.Collections.Generic.IEnumerable> compatibleTypesPerGeneric, System.Type definition) { List list = new List(); System.Collections.Generic.IEnumerable[] array = compatibleTypesPerGeneric.ToArray(); if (array.Length != 0) { GetAllPossibleTypeCombinationsCore(list, new Stack(), array, array.Length - 1); } return list; [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "No members of the generic type are dynamically accessed other than for the attributes on it.")] [UnconditionalSuppressMessage("Trimming", "IL2055", Justification = "Calls to 'MakeGenericType' are always done with compatible types.")] void GetAllPossibleTypeCombinationsCore(List accum, Stack stack, System.Collections.Generic.IEnumerable[] compatibleTypes, int index) { foreach (System.Type item in compatibleTypes[index]) { stack.Push(item); if (index == 0) { accum.Add(definition.MakeGenericType(stack.ToArray())); } else { GetAllPossibleTypeCombinationsCore(accum, stack, compatibleTypes, index - 1); } stack.Pop(); } } } [RequiresUnreferencedCode("This method is not trim-safe, and is only supported for use when not using trimming (or AOT).")] internal static bool TryGetCompatibleWindowsRuntimeTypesForVariantType(System.Type type, Stack typeStack, out System.Collections.Generic.IEnumerable compatibleTypes) { compatibleTypes = null; if (!type.IsConstructedGenericType) { throw new ArgumentException("type"); } System.Type genericTypeDefinition = type.GetGenericTypeDefinition(); if (!IsTypeWindowsRuntimeTypeNoArray(genericTypeDefinition)) { return false; } if (typeStack == null) { typeStack = new Stack(); } else if (typeStack.Contains(type)) { return false; } typeStack.Push(type); System.Type[] genericArguments = genericTypeDefinition.GetGenericArguments(); System.Type[] genericArguments2 = type.GetGenericArguments(); List> list = new List>(); for (int i = 0; i < genericArguments2.Length; i++) { List list2 = new List(); bool flag = (genericArguments[i].GenericParameterAttributes & GenericParameterAttributes.VarianceMask) == GenericParameterAttributes.Covariant && !genericArguments2[i].IsValueType; if (IsTypeWindowsRuntimeTypeNoArray(genericArguments2[i])) { list2.Add(genericArguments2[i]); } else if (!flag) { typeStack.Pop(); return false; } if (flag) { list2.AddRange(GetCompatibleTypes(genericArguments2[i], typeStack)); } list.Add(list2); } typeStack.Pop(); compatibleTypes = GetAllPossibleTypeCombinations(list, genericTypeDefinition); return true; } [UnconditionalSuppressMessage("Trimming", "IL2070", Justification = "The path using reflection to retrieve the default interface property is only used with legacy projections. Applications which make use of trimming will make use of updated projections and won't hit that code path.")] internal static bool TryGetDefaultInterfaceTypeForRuntimeClassType(System.Type runtimeClass, out System.Type defaultInterface) { defaultInterface = DefaultInterfaceTypeCache.GetOrAdd(runtimeClass, delegate(System.Type type) { type = type.GetRuntimeClassCCWType() ?? type; ProjectedRuntimeClassAttribute customAttribute = type.GetCustomAttribute(); if (customAttribute == null) { return (System.Type)null; } if (!RuntimeFeature.IsDynamicCodeCompiled) { return customAttribute.DefaultInterface; } if (customAttribute.DefaultInterface != null) { return customAttribute.DefaultInterface; } return (customAttribute.DefaultInterfaceProperty != null) ? type.GetProperty(customAttribute.DefaultInterfaceProperty, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).PropertyType : null; }); return defaultInterface != null; } internal static System.Type GetDefaultInterfaceTypeForRuntimeClassType(System.Type runtimeClass) { if (!TryGetDefaultInterfaceTypeForRuntimeClassType(runtimeClass, out var defaultInterface)) { throw new ArgumentException("The provided type '" + runtimeClass.FullName + "' is not a WinRT projected runtime class.", "runtimeClass"); } return defaultInterface; } internal static System.Type GetAbiDelegateType(params System.Type[] typeArgs) { return Expression.GetDelegateType(typeArgs); } public static void RegisterEventHandlerMapping() { if (!FeatureSwitches.EnableDefaultCustomTypeMappings && Interlocked.CompareExchange(ref _EventHandler, 1, 0) != 1) { RegisterCustomAbiTypeMapping(typeof(System.EventHandler), typeof(ABI.System.EventHandler)); _AbiEventHandlerExposedInterfaces = ABI.System.EventHandler.GetExposedInterfaces(); } } internal static ComWrappers.ComInterfaceEntry[] GetAbiEventHandlerExposedInterfaces() { if (FeatureSwitches.EnableDefaultCustomTypeMappings) { return ABI.System.EventHandler.GetExposedInterfaces(); } ComWrappers.ComInterfaceEntry[] abiEventHandlerExposedInterfaces = _AbiEventHandlerExposedInterfaces; if (abiEventHandlerExposedInterfaces == null) { throw new NotSupportedException("Support for type mapping for the 'EventHandler' type is currently disabled. To enable it, either make sure to not set the 'CsWinRTEnableCustomTypeMappings' property to 'false', or manually enable support for this specific type by calling 'Projections.RegisterEventHandlerMapping()'."); } return abiEventHandlerExposedInterfaces; } public static void RegisterNotifyCollectionChangedEventHandlerMapping() { if (!FeatureSwitches.EnableDefaultCustomTypeMappings && Interlocked.CompareExchange(ref _NotifyCollectionChangedEventHandler, 1, 0) != 1) { if (FeatureSwitches.UseWindowsUIXamlProjections) { RegisterCustomAbiTypeMapping(typeof(System.Collections.Specialized.NotifyCollectionChangedEventHandler), typeof(ABI.System.Collections.Specialized.NotifyCollectionChangedEventHandler), "Windows.UI.Xaml.Interop.NotifyCollectionChangedEventHandler"); } else { RegisterCustomAbiTypeMapping(typeof(System.Collections.Specialized.NotifyCollectionChangedEventHandler), typeof(ABI.System.Collections.Specialized.NotifyCollectionChangedEventHandler), "Microsoft.UI.Xaml.Interop.NotifyCollectionChangedEventHandler"); } _AbiNotifyCollectionChangedEventHandlerExposedInterfaces = ABI.System.Collections.Specialized.NotifyCollectionChangedEventHandler.GetExposedInterfaces(); } } internal static ComWrappers.ComInterfaceEntry[] GetAbiNotifyCollectionChangedEventHandlerExposedInterfaces() { if (FeatureSwitches.EnableDefaultCustomTypeMappings) { return ABI.System.Collections.Specialized.NotifyCollectionChangedEventHandler.GetExposedInterfaces(); } ComWrappers.ComInterfaceEntry[] abiNotifyCollectionChangedEventHandlerExposedInterfaces = _AbiNotifyCollectionChangedEventHandlerExposedInterfaces; if (abiNotifyCollectionChangedEventHandlerExposedInterfaces == null) { throw new NotSupportedException("Support for type mapping for the 'NotifyCollectionChangedEventHandler' type is currently disabled. To enable it, either make sure to not set the 'CsWinRTEnableCustomTypeMappings' property to 'false', or manually enable support for this specific type by calling 'Projections.RegisterNotifyCollectionChangedEventHandlerMapping()'."); } return abiNotifyCollectionChangedEventHandlerExposedInterfaces; } public static void RegisterPropertyChangedEventHandlerMapping() { if (!FeatureSwitches.EnableDefaultCustomTypeMappings && Interlocked.CompareExchange(ref _PropertyChangedEventHandler, 1, 0) != 1) { if (FeatureSwitches.UseWindowsUIXamlProjections) { RegisterCustomAbiTypeMapping(typeof(System.ComponentModel.PropertyChangedEventHandler), typeof(ABI.System.ComponentModel.PropertyChangedEventHandler), "Windows.UI.Xaml.Data.PropertyChangedEventHandler"); } else { RegisterCustomAbiTypeMapping(typeof(System.ComponentModel.PropertyChangedEventHandler), typeof(ABI.System.ComponentModel.PropertyChangedEventHandler), "Microsoft.UI.Xaml.Data.PropertyChangedEventHandler"); } _AbiPropertyChangedEventHandlerExposedInterfaces = ABI.System.ComponentModel.PropertyChangedEventHandler.GetExposedInterfaces(); } } internal static ComWrappers.ComInterfaceEntry[] GetAbiPropertyChangedEventHandlerExposedInterfaces() { if (FeatureSwitches.EnableDefaultCustomTypeMappings) { return ABI.System.ComponentModel.PropertyChangedEventHandler.GetExposedInterfaces(); } ComWrappers.ComInterfaceEntry[] abiPropertyChangedEventHandlerExposedInterfaces = _AbiPropertyChangedEventHandlerExposedInterfaces; if (abiPropertyChangedEventHandlerExposedInterfaces == null) { throw new NotSupportedException("Support for type mapping for the 'PropertyChangedEventHandler' type is currently disabled. To enable it, either make sure to not set the 'CsWinRTEnableCustomTypeMappings' property to 'false', or manually enable support for this specific type by calling 'Projections.RegisterPropertyChangedEventHandlerMapping()'."); } return abiPropertyChangedEventHandlerExposedInterfaces; } public static void RegisterEventRegistrationTokenMapping() { if (!FeatureSwitches.EnableDefaultCustomTypeMappings && Interlocked.CompareExchange(ref _EventRegistrationToken, 1, 0) != 1) { RegisterCustomAbiTypeMapping(typeof(EventRegistrationToken), typeof(ABI.WinRT.EventRegistrationToken), "Windows.Foundation.EventRegistrationToken"); } } public static void RegisterNullableOpenGenericMapping() { if (!FeatureSwitches.EnableDefaultCustomTypeMappings && Interlocked.CompareExchange(ref _Nullable__, 1, 0) != 1) { RegisterCustomAbiTypeMapping(typeof(System.Nullable<>), typeof(ABI.System.Nullable<>), "Windows.Foundation.IReference`1"); } } public static void RegisterNullableIntMapping() { if (!FeatureSwitches.EnableDefaultCustomTypeMappings && Interlocked.CompareExchange(ref _int_, 1, 0) != 1) { RegisterCustomAbiTypeMapping(typeof(int?), typeof(Nullable_int), "Windows.Foundation.IReference`1"); } } public static void RegisterNullableByteMapping() { if (!FeatureSwitches.EnableDefaultCustomTypeMappings && Interlocked.CompareExchange(ref _byte_, 1, 0) != 1) { RegisterCustomAbiTypeMapping(typeof(byte?), typeof(Nullable_byte), "Windows.Foundation.IReference`1"); } } public static void RegisterNullableSByteMapping() { if (!FeatureSwitches.EnableDefaultCustomTypeMappings && Interlocked.CompareExchange(ref _sbyte_, 1, 0) != 1) { RegisterCustomAbiTypeMapping(typeof(sbyte?), typeof(Nullable_sbyte), "Windows.Foundation.IReference`1"); } } public static void RegisterNullableShortMapping() { if (!FeatureSwitches.EnableDefaultCustomTypeMappings && Interlocked.CompareExchange(ref _short_, 1, 0) != 1) { RegisterCustomAbiTypeMapping(typeof(short?), typeof(Nullable_short), "Windows.Foundation.IReference`1"); } } public static void RegisterNullableUShortMapping() { if (!FeatureSwitches.EnableDefaultCustomTypeMappings && Interlocked.CompareExchange(ref _ushort_, 1, 0) != 1) { RegisterCustomAbiTypeMapping(typeof(ushort?), typeof(Nullable_ushort), "Windows.Foundation.IReference`1"); } } public static void RegisterNullableUIntMapping() { if (!FeatureSwitches.EnableDefaultCustomTypeMappings && Interlocked.CompareExchange(ref _uint_, 1, 0) != 1) { RegisterCustomAbiTypeMapping(typeof(uint?), typeof(Nullable_uint), "Windows.Foundation.IReference`1"); } } public static void RegisterNullableLongMapping() { if (!FeatureSwitches.EnableDefaultCustomTypeMappings && Interlocked.CompareExchange(ref _long_, 1, 0) != 1) { RegisterCustomAbiTypeMapping(typeof(long?), typeof(Nullable_long), "Windows.Foundation.IReference`1"); } } public static void RegisterNullableULongMapping() { if (!FeatureSwitches.EnableDefaultCustomTypeMappings && Interlocked.CompareExchange(ref _ulong_, 1, 0) != 1) { RegisterCustomAbiTypeMapping(typeof(ulong?), typeof(Nullable_ulong), "Windows.Foundation.IReference`1"); } } public static void RegisterNullableFloatMapping() { if (!FeatureSwitches.EnableDefaultCustomTypeMappings && Interlocked.CompareExchange(ref _float_, 1, 0) != 1) { RegisterCustomAbiTypeMapping(typeof(float?), typeof(Nullable_float), "Windows.Foundation.IReference`1"); } } public static void RegisterNullableDoubleMapping() { if (!FeatureSwitches.EnableDefaultCustomTypeMappings && Interlocked.CompareExchange(ref _double_, 1, 0) != 1) { RegisterCustomAbiTypeMapping(typeof(double?), typeof(Nullable_double), "Windows.Foundation.IReference`1"); } } public static void RegisterNullableCharMapping() { if (!FeatureSwitches.EnableDefaultCustomTypeMappings && Interlocked.CompareExchange(ref _char_, 1, 0) != 1) { RegisterCustomAbiTypeMapping(typeof(char?), typeof(Nullable_char), "Windows.Foundation.IReference`1"); } } public static void RegisterNullableBoolMapping() { if (!FeatureSwitches.EnableDefaultCustomTypeMappings && Interlocked.CompareExchange(ref _bool_, 1, 0) != 1) { RegisterCustomAbiTypeMapping(typeof(bool?), typeof(Nullable_bool), "Windows.Foundation.IReference`1"); } } public static void RegisterNullableGuidMapping() { if (!FeatureSwitches.EnableDefaultCustomTypeMappings && Interlocked.CompareExchange(ref _Guid_, 1, 0) != 1) { RegisterCustomAbiTypeMapping(typeof(Guid?), typeof(Nullable_guid), "Windows.Foundation.IReference`1"); } } public static void RegisterNullableDateTimeOffsetMapping() { if (!FeatureSwitches.EnableDefaultCustomTypeMappings && Interlocked.CompareExchange(ref _DateTimeOffset_, 1, 0) != 1) { RegisterCustomAbiTypeMapping(typeof(System.DateTimeOffset?), typeof(Nullable_DateTimeOffset), "Windows.Foundation.IReference`1"); } } public static void RegisterNullableTimeSpanMapping() { if (!FeatureSwitches.EnableDefaultCustomTypeMappings && Interlocked.CompareExchange(ref _TimeSpan_, 1, 0) != 1) { RegisterCustomAbiTypeMapping(typeof(System.TimeSpan?), typeof(Nullable_TimeSpan), "Windows.Foundation.IReference`1"); } } public static void RegisterDateTimeOffsetMapping() { if (!FeatureSwitches.EnableDefaultCustomTypeMappings && Interlocked.CompareExchange(ref _DateTimeOffset, 1, 0) != 1) { RegisterCustomAbiTypeMapping(typeof(System.DateTimeOffset), typeof(ABI.System.DateTimeOffset), "Windows.Foundation.DateTime"); } } public static void RegisterExceptionMapping() { if (!FeatureSwitches.EnableDefaultCustomTypeMappings && Interlocked.CompareExchange(ref _Exception, 1, 0) != 1) { RegisterCustomAbiTypeMapping(typeof(System.Exception), typeof(ABI.System.Exception), "Windows.Foundation.HResult"); } } public static void RegisterTimeSpanMapping() { if (!FeatureSwitches.EnableDefaultCustomTypeMappings && Interlocked.CompareExchange(ref _TimeSpan, 1, 0) != 1) { RegisterCustomAbiTypeMapping(typeof(System.TimeSpan), typeof(ABI.System.TimeSpan), "Windows.Foundation.TimeSpan"); } } public static void RegisterUriMapping() { if (!FeatureSwitches.EnableDefaultCustomTypeMappings && Interlocked.CompareExchange(ref _Uri, 1, 0) != 1) { RegisterCustomAbiTypeMapping(typeof(System.Uri), typeof(ABI.System.Uri), "Windows.Foundation.Uri", isRuntimeClass: true); } } public static void RegisterDataErrorsChangedEventArgsMapping() { if (!FeatureSwitches.EnableDefaultCustomTypeMappings) { if (FeatureSwitches.UseWindowsUIXamlProjections) { throw new NotSupportedException("The 'DataErrorsChangedEventArgs' type is only supported for WinUI, and not when using System XAML projections (make sure the 'CsWinRTUseWindowsUIXamlProjections' property is not set to 'true')."); } if (Interlocked.CompareExchange(ref _DataErrorsChangedEventArgs, 1, 0) != 1) { RegisterCustomAbiTypeMapping(typeof(System.ComponentModel.DataErrorsChangedEventArgs), typeof(ABI.System.ComponentModel.DataErrorsChangedEventArgs), "Microsoft.UI.Xaml.Data.DataErrorsChangedEventArgs", isRuntimeClass: true); } } } public static void RegisterPropertyChangedEventArgsMapping() { if (!FeatureSwitches.EnableDefaultCustomTypeMappings && Interlocked.CompareExchange(ref _PropertyChangedEventArgs, 1, 0) != 1) { if (FeatureSwitches.UseWindowsUIXamlProjections) { RegisterCustomAbiTypeMapping(typeof(System.ComponentModel.PropertyChangedEventArgs), typeof(ABI.System.ComponentModel.PropertyChangedEventArgs), "Windows.UI.Xaml.Data.PropertyChangedEventArgs", isRuntimeClass: true); } else { RegisterCustomAbiTypeMapping(typeof(System.ComponentModel.PropertyChangedEventArgs), typeof(ABI.System.ComponentModel.PropertyChangedEventArgs), "Microsoft.UI.Xaml.Data.PropertyChangedEventArgs", isRuntimeClass: true); } } } public static void RegisterINotifyDataErrorInfoMapping() { if (!FeatureSwitches.EnableDefaultCustomTypeMappings) { if (FeatureSwitches.UseWindowsUIXamlProjections) { throw new NotSupportedException("The 'INotifyDataErrorInfo' type is only supported for WinUI, and not when using System XAML projections (make sure the 'CsWinRTUseWindowsUIXamlProjections' property is not set to 'true')."); } if (Interlocked.CompareExchange(ref _INotifyDataErrorInfo, 1, 0) != 1) { RegisterCustomAbiTypeMapping(typeof(System.ComponentModel.INotifyDataErrorInfo), typeof(ABI.System.ComponentModel.INotifyDataErrorInfo), "Microsoft.UI.Xaml.Data.INotifyDataErrorInfo"); } } } public static void RegisterINotifyPropertyChangedMapping() { if (!FeatureSwitches.EnableDefaultCustomTypeMappings && Interlocked.CompareExchange(ref _INotifyPropertyChanged, 1, 0) != 1) { if (FeatureSwitches.UseWindowsUIXamlProjections) { RegisterCustomAbiTypeMapping(typeof(System.ComponentModel.INotifyPropertyChanged), typeof(ABI.System.ComponentModel.INotifyPropertyChanged), "Windows.UI.Xaml.Data.INotifyPropertyChanged"); } else { RegisterCustomAbiTypeMapping(typeof(System.ComponentModel.INotifyPropertyChanged), typeof(ABI.System.ComponentModel.INotifyPropertyChanged), "Microsoft.UI.Xaml.Data.INotifyPropertyChanged"); } } } public static void RegisterICommandMapping() { if (!FeatureSwitches.EnableDefaultCustomTypeMappings && Interlocked.CompareExchange(ref _ICommand, 1, 0) != 1) { if (FeatureSwitches.UseWindowsUIXamlProjections) { RegisterCustomAbiTypeMapping(typeof(System.Windows.Input.ICommand), typeof(ABI.System.Windows.Input.ICommand), "Windows.UI.Xaml.Interop.ICommand"); } else { RegisterCustomAbiTypeMapping(typeof(System.Windows.Input.ICommand), typeof(ABI.System.Windows.Input.ICommand), "Microsoft.UI.Xaml.Interop.ICommand"); } } } public static void RegisterIServiceProviderMapping() { if (!FeatureSwitches.EnableDefaultCustomTypeMappings) { if (FeatureSwitches.UseWindowsUIXamlProjections) { throw new NotSupportedException("The 'IServiceProvider' type is only supported for WinUI, and not when using System XAML projections (make sure the 'CsWinRTUseWindowsUIXamlProjections' property is not set to 'true')."); } if (Interlocked.CompareExchange(ref _IServiceProvider, 1, 0) != 1) { RegisterCustomAbiTypeMapping(typeof(System.IServiceProvider), typeof(ABI.System.IServiceProvider), "Microsoft.UI.Xaml.IXamlServiceProvider"); } } } public static void RegisterEventHandlerOpenGenericMapping() { if (!FeatureSwitches.EnableDefaultCustomTypeMappings && Interlocked.CompareExchange(ref _EventHandler__, 1, 0) != 1) { RegisterCustomAbiTypeMapping(typeof(System.EventHandler<>), typeof(ABI.System.EventHandler<>), "Windows.Foundation.EventHandler`1"); } } public static void RegisterKeyValuePairOpenGenericMapping() { if (!FeatureSwitches.EnableDefaultCustomTypeMappings && Interlocked.CompareExchange(ref _KeyValuePair___, 1, 0) != 1) { RegisterCustomAbiTypeMapping(typeof(System.Collections.Generic.KeyValuePair<, >), typeof(ABI.System.Collections.Generic.KeyValuePair<, >), "Windows.Foundation.Collections.IKeyValuePair`2"); } } public static void RegisterIEnumerableOpenGenericMapping() { if (!FeatureSwitches.EnableDefaultCustomTypeMappings && Interlocked.CompareExchange(ref _IEnumerable__, 1, 0) != 1) { RegisterCustomAbiTypeMapping(typeof(System.Collections.Generic.IEnumerable<>), typeof(ABI.System.Collections.Generic.IEnumerable<>), "Windows.Foundation.Collections.IIterable`1"); } } public static void RegisterIEnumeratorOpenGenericMapping() { if (!FeatureSwitches.EnableDefaultCustomTypeMappings && Interlocked.CompareExchange(ref _IEnumerator__, 1, 0) != 1) { RegisterCustomAbiTypeMapping(typeof(System.Collections.Generic.IEnumerator<>), typeof(ABI.System.Collections.Generic.IEnumerator<>), "Windows.Foundation.Collections.IIterator`1"); } } public static void RegisterIListOpenGenericMapping() { if (!FeatureSwitches.EnableDefaultCustomTypeMappings && Interlocked.CompareExchange(ref _IList__, 1, 0) != 1) { RegisterCustomAbiTypeMapping(typeof(System.Collections.Generic.IList<>), typeof(ABI.System.Collections.Generic.IList<>), "Windows.Foundation.Collections.IVector`1"); } } public static void RegisterIReadOnlyListOpenGenericMapping() { if (!FeatureSwitches.EnableDefaultCustomTypeMappings && Interlocked.CompareExchange(ref _IReadOnlyList__, 1, 0) != 1) { RegisterCustomAbiTypeMapping(typeof(System.Collections.Generic.IReadOnlyList<>), typeof(ABI.System.Collections.Generic.IReadOnlyList<>), "Windows.Foundation.Collections.IVectorView`1"); } } public static void RegisterIDictionaryOpenGenericMapping() { if (!FeatureSwitches.EnableDefaultCustomTypeMappings && Interlocked.CompareExchange(ref _IDictionary___, 1, 0) != 1) { RegisterCustomAbiTypeMapping(typeof(System.Collections.Generic.IDictionary<, >), typeof(ABI.System.Collections.Generic.IDictionary<, >), "Windows.Foundation.Collections.IMap`2"); } } public static void RegisterIReadOnlyDictionaryOpenGenericMapping() { if (!FeatureSwitches.EnableDefaultCustomTypeMappings && Interlocked.CompareExchange(ref _IReadOnlyDictionary___, 1, 0) != 1) { RegisterCustomAbiTypeMapping(typeof(System.Collections.Generic.IReadOnlyDictionary<, >), typeof(ABI.System.Collections.Generic.IReadOnlyDictionary<, >), "Windows.Foundation.Collections.IMapView`2"); } } public static void RegisterIDisposableMapping() { if (!FeatureSwitches.EnableDefaultCustomTypeMappings && Interlocked.CompareExchange(ref _IDisposable, 1, 0) != 1) { RegisterCustomAbiTypeMapping(typeof(System.IDisposable), typeof(ABI.System.IDisposable), "Windows.Foundation.IClosable"); } } public static void RegisterIEnumerableMapping() { if (!FeatureSwitches.EnableDefaultCustomTypeMappings && Interlocked.CompareExchange(ref _IEnumerable, 1, 0) != 1) { if (FeatureSwitches.UseWindowsUIXamlProjections) { RegisterCustomAbiTypeMapping(typeof(System.Collections.IEnumerable), typeof(ABI.System.Collections.IEnumerable), "Windows.UI.Xaml.Interop.IBindableIterable"); } else { RegisterCustomAbiTypeMapping(typeof(System.Collections.IEnumerable), typeof(ABI.System.Collections.IEnumerable), "Microsoft.UI.Xaml.Interop.IBindableIterable"); } } } public static void RegisterIListMapping() { if (!FeatureSwitches.EnableDefaultCustomTypeMappings && Interlocked.CompareExchange(ref _IList, 1, 0) != 1) { if (FeatureSwitches.UseWindowsUIXamlProjections) { RegisterCustomAbiTypeMapping(typeof(System.Collections.IList), typeof(ABI.System.Collections.IList), "Windows.UI.Xaml.Interop.IBindableVector"); } else { RegisterCustomAbiTypeMapping(typeof(System.Collections.IList), typeof(ABI.System.Collections.IList), "Microsoft.UI.Xaml.Interop.IBindableVector"); } } } public static void RegisterINotifyCollectionChangedMapping() { if (!FeatureSwitches.EnableDefaultCustomTypeMappings && Interlocked.CompareExchange(ref _INotifyCollectionChanged, 1, 0) != 1) { if (FeatureSwitches.UseWindowsUIXamlProjections) { RegisterCustomAbiTypeMapping(typeof(System.Collections.Specialized.INotifyCollectionChanged), typeof(ABI.System.Collections.Specialized.INotifyCollectionChanged), "Windows.UI.Xaml.Interop.INotifyCollectionChanged"); } else { RegisterCustomAbiTypeMapping(typeof(System.Collections.Specialized.INotifyCollectionChanged), typeof(ABI.System.Collections.Specialized.INotifyCollectionChanged), "Microsoft.UI.Xaml.Interop.INotifyCollectionChanged"); } } } public static void RegisterNotifyCollectionChangedActionMapping() { if (!FeatureSwitches.EnableDefaultCustomTypeMappings && Interlocked.CompareExchange(ref _NotifyCollectionChangedAction, 1, 0) != 1) { if (FeatureSwitches.UseWindowsUIXamlProjections) { RegisterCustomAbiTypeMapping(typeof(System.Collections.Specialized.NotifyCollectionChangedAction), typeof(ABI.System.Collections.Specialized.NotifyCollectionChangedAction), "Windows.UI.Xaml.Interop.NotifyCollectionChangedAction"); } else { RegisterCustomAbiTypeMapping(typeof(System.Collections.Specialized.NotifyCollectionChangedAction), typeof(ABI.System.Collections.Specialized.NotifyCollectionChangedAction), "Microsoft.UI.Xaml.Interop.NotifyCollectionChangedAction"); } } } public static void RegisterNotifyCollectionChangedEventArgsMapping() { if (!FeatureSwitches.EnableDefaultCustomTypeMappings && Interlocked.CompareExchange(ref _NotifyCollectionChangedEventArgs, 1, 0) != 1) { if (FeatureSwitches.UseWindowsUIXamlProjections) { RegisterCustomAbiTypeMapping(typeof(System.Collections.Specialized.NotifyCollectionChangedEventArgs), typeof(ABI.System.Collections.Specialized.NotifyCollectionChangedEventArgs), "Windows.UI.Xaml.Interop.NotifyCollectionChangedEventArgs", isRuntimeClass: true); } else { RegisterCustomAbiTypeMapping(typeof(System.Collections.Specialized.NotifyCollectionChangedEventArgs), typeof(ABI.System.Collections.Specialized.NotifyCollectionChangedEventArgs), "Microsoft.UI.Xaml.Interop.NotifyCollectionChangedEventArgs", isRuntimeClass: true); } } } public static void RegisterMatrix3x2Mapping() { if (!FeatureSwitches.EnableDefaultCustomTypeMappings && Interlocked.CompareExchange(ref _Matrix3x2, 1, 0) != 1) { RegisterCustomAbiTypeMapping(typeof(System.Numerics.Matrix3x2), typeof(ABI.System.Numerics.Matrix3x2), "Windows.Foundation.Numerics.Matrix3x2"); } } public static void RegisterMatrix4x4Mapping() { if (!FeatureSwitches.EnableDefaultCustomTypeMappings && Interlocked.CompareExchange(ref _Matrix4x4, 1, 0) != 1) { RegisterCustomAbiTypeMapping(typeof(System.Numerics.Matrix4x4), typeof(ABI.System.Numerics.Matrix4x4), "Windows.Foundation.Numerics.Matrix4x4"); } } public static void RegisterPlaneMapping() { if (!FeatureSwitches.EnableDefaultCustomTypeMappings && Interlocked.CompareExchange(ref _Plane, 1, 0) != 1) { RegisterCustomAbiTypeMapping(typeof(System.Numerics.Plane), typeof(ABI.System.Numerics.Plane), "Windows.Foundation.Numerics.Plane"); } } public static void RegisterQuaternionMapping() { if (!FeatureSwitches.EnableDefaultCustomTypeMappings && Interlocked.CompareExchange(ref _Quaternion, 1, 0) != 1) { RegisterCustomAbiTypeMapping(typeof(System.Numerics.Quaternion), typeof(ABI.System.Numerics.Quaternion), "Windows.Foundation.Numerics.Quaternion"); } } public static void RegisterVector2Mapping() { if (!FeatureSwitches.EnableDefaultCustomTypeMappings && Interlocked.CompareExchange(ref _Vector2, 1, 0) != 1) { RegisterCustomAbiTypeMapping(typeof(System.Numerics.Vector2), typeof(ABI.System.Numerics.Vector2), "Windows.Foundation.Numerics.Vector2"); } } public static void RegisterVector3Mapping() { if (!FeatureSwitches.EnableDefaultCustomTypeMappings && Interlocked.CompareExchange(ref _Vector3, 1, 0) != 1) { RegisterCustomAbiTypeMapping(typeof(System.Numerics.Vector3), typeof(ABI.System.Numerics.Vector3), "Windows.Foundation.Numerics.Vector3"); } } public static void RegisterVector4Mapping() { if (!FeatureSwitches.EnableDefaultCustomTypeMappings && Interlocked.CompareExchange(ref _Vector4, 1, 0) != 1) { RegisterCustomAbiTypeMapping(typeof(System.Numerics.Vector4), typeof(ABI.System.Numerics.Vector4), "Windows.Foundation.Numerics.Vector4"); } } public static void RegisterIMapOpenGenericMapping() { if (!FeatureSwitches.EnableDefaultCustomTypeMappings && Interlocked.CompareExchange(ref _IMap___, 1, 0) != 1) { RegisterCustomTypeToHelperTypeMapping(typeof(IMap<, >), typeof(ABI.System.Collections.Generic.IDictionary<, >)); } } public static void RegisterIVectorOpenGenericMapping() { if (!FeatureSwitches.EnableDefaultCustomTypeMappings && Interlocked.CompareExchange(ref _IVector__, 1, 0) != 1) { RegisterCustomTypeToHelperTypeMapping(typeof(IVector<>), typeof(ABI.System.Collections.Generic.IList<>)); } } public static void RegisterIMapViewOpenGenericMapping() { if (!FeatureSwitches.EnableDefaultCustomTypeMappings && Interlocked.CompareExchange(ref _IMapView___, 1, 0) != 1) { RegisterCustomTypeToHelperTypeMapping(typeof(IMapView<, >), typeof(ABI.System.Collections.Generic.IReadOnlyDictionary<, >)); } } public static void RegisterIVectorViewOpenGenericMapping() { if (!FeatureSwitches.EnableDefaultCustomTypeMappings && Interlocked.CompareExchange(ref _IVectorView__, 1, 0) != 1) { RegisterCustomTypeToHelperTypeMapping(typeof(IVectorView<>), typeof(ABI.System.Collections.Generic.IReadOnlyList<>)); } } public static void RegisterIBindableVectorMapping() { if (!FeatureSwitches.EnableDefaultCustomTypeMappings && Interlocked.CompareExchange(ref _IBindableVector, 1, 0) != 1) { RegisterCustomTypeToHelperTypeMapping(typeof(IBindableVector), typeof(ABI.System.Collections.IList)); } } public static void RegisterICollectionOpenGenericMapping() { if (!FeatureSwitches.EnableDefaultCustomTypeMappings && Interlocked.CompareExchange(ref _ICollection__, 1, 0) != 1) { RegisterCustomTypeToHelperTypeMapping(typeof(System.Collections.Generic.ICollection<>), typeof(ABI.System.Collections.Generic.ICollection<>)); } } public static void RegisterIReadOnlyCollectionOpenGenericMapping() { if (!FeatureSwitches.EnableDefaultCustomTypeMappings && Interlocked.CompareExchange(ref _IReadOnlyCollection__, 1, 0) != 1) { RegisterCustomTypeToHelperTypeMapping(typeof(System.Collections.Generic.IReadOnlyCollection<>), typeof(ABI.System.Collections.Generic.IReadOnlyCollection<>)); } } public static void RegisterICollectionMapping() { if (!FeatureSwitches.EnableDefaultCustomTypeMappings && Interlocked.CompareExchange(ref _ICollection, 1, 0) != 1) { RegisterCustomTypeToHelperTypeMapping(typeof(System.Collections.ICollection), typeof(ABI.System.Collections.ICollection)); } } } internal static class GenericDelegateHelper { internal static ConditionalWeakTable DelegateTable = new ConditionalWeakTable(); internal unsafe static Delegate CreateDelegate(IntPtr ptr, ref Delegate delegateRef, System.Type delegateType, int offset) { Delegate delegateForFunctionPointer = Marshal.GetDelegateForFunctionPointer(*(IntPtr*)((nint)(*(IntPtr*)(void*)ptr) + (nint)offset * (nint)sizeof(IntPtr)), delegateType); Interlocked.CompareExchange(ref delegateRef, delegateForFunctionPointer, null); return delegateRef; } } internal interface IWinRTNullableTypeDetails { object GetNullableValue(IInspectable inspectable); System.Type GetNullableType(); } public sealed class StructTypeDetails : IWinRTExposedTypeDetails, IWinRTNullableTypeDetails where T : struct where TAbi : unmanaged { private static readonly Guid PIID = ABI.System.Nullable.PIID; [SkipLocalsInit] public ComWrappers.ComInterfaceEntry[] GetExposedInterfaces() { Span span = stackalloc ComWrappers.ComInterfaceEntry[2]; int length = 0; if (FeatureSwitches.EnableIReferenceSupport) { span[length++] = new ComWrappers.ComInterfaceEntry { IID = IID.IID_IPropertyValue, Vtable = ManagedIPropertyValueImpl.AbiToProjectionVftablePtr }; span[length++] = new ComWrappers.ComInterfaceEntry { IID = PIID, Vtable = BoxedValueIReferenceImpl.AbiToProjectionVftablePtr }; } return span.Slice(0, length).ToArray(); } unsafe object IWinRTNullableTypeDetails.GetNullableValue(IInspectable inspectable) { IntPtr ppv = IntPtr.Zero; TAbi val = default(TAbi); try { ExceptionHelpers.ThrowExceptionForHR(Marshal.QueryInterface(inspectable.ThisPtr, in Unsafe.AsRef(in PIID), out ppv)); ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)ppv) + (nint)6 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(ppv, &val)); if (typeof(T) == typeof(TAbi)) { return val; } return Marshaler.FromAbi(val); } finally { Marshaler.DisposeAbi(val); MarshalExtensions.ReleaseIfNotNull(ppv); } } System.Type IWinRTNullableTypeDetails.GetNullableType() { return typeof(T?); } } public abstract class DelegateTypeDetails : IWinRTExposedTypeDetails, IWinRTNullableTypeDetails where T : Delegate { private static readonly Guid PIID = ABI.System.Nullable.PIID; public ComWrappers.ComInterfaceEntry[] GetExposedInterfaces() { return GetExposedInterfaces(GetDelegateInterface()); } public static ComWrappers.ComInterfaceEntry[] GetExposedInterfaces(ComWrappers.ComInterfaceEntry delegateInterface) { Span span = stackalloc ComWrappers.ComInterfaceEntry[3]; int length = 0; span[length++] = delegateInterface; if (FeatureSwitches.EnableIReferenceSupport) { span[length++] = new ComWrappers.ComInterfaceEntry { IID = IID.IID_IPropertyValue, Vtable = ManagedIPropertyValueImpl.AbiToProjectionVftablePtr }; span[length++] = new ComWrappers.ComInterfaceEntry { IID = PIID, Vtable = Nullable_Delegate.AbiToProjectionVftablePtr }; } return span.Slice(0, length).ToArray(); } public abstract ComWrappers.ComInterfaceEntry GetDelegateInterface(); unsafe object IWinRTNullableTypeDetails.GetNullableValue(IInspectable inspectable) { IntPtr ppv = IntPtr.Zero; IntPtr intPtr = default(IntPtr); try { ExceptionHelpers.ThrowExceptionForHR(Marshal.QueryInterface(inspectable.ThisPtr, in Unsafe.AsRef(in PIID), out ppv)); ExceptionHelpers.ThrowExceptionForHR(((delegate* unmanaged[Stdcall])(*(IntPtr*)((nint)(*(IntPtr*)(void*)ppv) + (nint)6 * (nint)sizeof(delegate* unmanaged[Stdcall]))))(ppv, &intPtr)); return new ABI.System.Nullable(Marshaler.FromAbi(intPtr)); } finally { Marshaler.DisposeAbi(intPtr); MarshalExtensions.ReleaseIfNotNull(ppv); } } System.Type IWinRTNullableTypeDetails.GetNullableType() { throw new NotImplementedException(); } } public sealed class EnumTypeDetails : IWinRTExposedTypeDetails, IWinRTNullableTypeDetails where T : unmanaged, Enum { [SkipLocalsInit] public ComWrappers.ComInterfaceEntry[] GetExposedInterfaces() { Span span = stackalloc ComWrappers.ComInterfaceEntry[2]; int length = 0; if (FeatureSwitches.EnableIReferenceSupport) { span[length++] = new ComWrappers.ComInterfaceEntry { IID = IID.IID_IPropertyValue, Vtable = ManagedIPropertyValueImpl.AbiToProjectionVftablePtr }; if (typeof(T).IsDefined(typeof(FlagsAttribute))) { span[length++] = new ComWrappers.ComInterfaceEntry { IID = Nullable_FlagsEnum.GetIID(typeof(T)), Vtable = Nullable_FlagsEnum.AbiToProjectionVftablePtr }; } else { span[length++] = new ComWrappers.ComInterfaceEntry { IID = Nullable_IntEnum.GetIID(typeof(T)), Vtable = Nullable_IntEnum.AbiToProjectionVftablePtr }; } } return span.Slice(0, length).ToArray(); } System.Type IWinRTNullableTypeDetails.GetNullableType() { return typeof(T?); } object IWinRTNullableTypeDetails.GetNullableValue(IInspectable inspectable) { throw new NotImplementedException(); } } public sealed class SingleInterfaceOptimizedObject : IWinRTObject, IDynamicInterfaceCastable { private readonly System.Type _type; private readonly IObjectReference _obj; private volatile ConcurrentDictionary _queryInterfaceCache; private volatile ConcurrentDictionary _additionalTypeData; IObjectReference IWinRTObject.NativeObject => _obj; bool IWinRTObject.HasUnwrappableNativeObject => false; ConcurrentDictionary IWinRTObject.QueryInterfaceCache => _queryInterfaceCache ?? MakeQueryInterfaceCache(); ConcurrentDictionary IWinRTObject.AdditionalTypeData => _additionalTypeData ?? MakeAdditionalTypeData(); public SingleInterfaceOptimizedObject(System.Type type, IObjectReference objRef) : this(type, objRef, requireQI: true) { } internal SingleInterfaceOptimizedObject(System.Type type, IObjectReference objRef, bool requireQI) { _type = type; if (requireQI) { System.Type type2 = type.FindHelperType(); if (RuntimeFeature.IsDynamicCodeCompiled) { IObjectReference objectReference = TryGetObjectReferenceViaVftbl(objRef, type2); if (objectReference != null) { _obj = objectReference; return; } } _obj = objRef.As(GuidGenerator.GetIID(type2)); } else { _obj = objRef; } [MethodImpl(MethodImplOptions.NoInlining)] [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "If the 'Vftbl' type is kept, we can assume all its metadata will also have been rooted.")] static IObjectReference TryGetObjectReferenceViaVftbl(IObjectReference obj, System.Type helperType) { System.Type type3 = helperType.FindVftblType(); if ((object)type3 != null) { return (IObjectReference)typeof(IObjectReference).GetMethod("As", System.Type.EmptyTypes).MakeGenericMethod(type3).Invoke(obj, null); } return null; } } private ConcurrentDictionary MakeQueryInterfaceCache() { Interlocked.CompareExchange(ref _queryInterfaceCache, new ConcurrentDictionary(), null); return _queryInterfaceCache; } private ConcurrentDictionary MakeAdditionalTypeData() { Interlocked.CompareExchange(ref _additionalTypeData, new ConcurrentDictionary(), null); return _additionalTypeData; } bool IDynamicInterfaceCastable.IsInterfaceImplemented(RuntimeTypeHandle interfaceType, bool throwIfNotImplemented) { if (_type.Equals(System.Type.GetTypeFromHandle(interfaceType))) { return true; } if (!FeatureSwitches.EnableIDynamicInterfaceCastableSupport) { return false; } return ((IWinRTObject)this).IsInterfaceImplementedFallback(interfaceType, throwIfNotImplemented); } IObjectReference IWinRTObject.GetObjectReferenceForType(RuntimeTypeHandle interfaceType) { if (_type.Equals(System.Type.GetTypeFromHandle(interfaceType))) { return _obj; } return ((IWinRTObject)this).GetObjectReferenceForTypeFallback(interfaceType); } } public static class TypeExtensions { internal static readonly ConcurrentDictionary HelperTypeCache = new ConcurrentDictionary(); private static readonly ConcurrentDictionary AuthoringMetadataTypeCache = new ConcurrentDictionary(); private static readonly List> AuthoringMetadaTypeLookup = new List>(); [UnconditionalSuppressMessage("Trimming", "IL2073", Justification = "Matching trimming annotations are used at all callsites registering helper types present in the cache.")] [return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicFields)] public static System.Type FindHelperType(this System.Type type) { return type.FindHelperType(throwIfNotAotSupported: true); } [UnconditionalSuppressMessage("Trimming", "IL2073", Justification = "Matching trimming annotations are used at all callsites registering helper types present in the cache.")] [return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicFields)] internal static System.Type FindHelperType(this System.Type type, bool throwIfNotAotSupported) { System.Type orAdd = HelperTypeCache.GetOrAdd(type, FindHelperTypeNoCache); if (!RuntimeFeature.IsDynamicCodeCompiled && orAdd == typeof(HelperTypeMetadataNotAvailableOnAot)) { if (!throwIfNotAotSupported) { return null; } throw new NotSupportedException($"Cannot retrieve a helper type for generic public type '{type}'."); } return orAdd; [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "This is a fallback for compat purposes with existing projections. Applications which make use of trimming will make use of updated projections that won't hit this code path.")] [UnconditionalSuppressMessage("Trimming", "IL2057", Justification = "This is a fallback for compat purposes with existing projections. Applications which make use of trimming will make use of updated projections that won't hit this code path.")] static System.Type FindHelperTypeFallback(System.Type type2) { string text = type2.FullName; string text2 = "ABI.Impl."; if (text.StartsWith(text2, StringComparison.Ordinal)) { text = text.Substring(text2.Length); } string text3 = "ABI." + text; return type2.Assembly.GetType(text3) ?? System.Type.GetType(text3); } [return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicFields)] static System.Type FindHelperTypeNoCache(System.Type typeFromHandle) { if (typeof(System.Exception).IsAssignableFrom(typeFromHandle)) { typeFromHandle = typeof(System.Exception); } System.Type type2 = Projections.FindCustomHelperTypeMapping(typeFromHandle, filterToRuntimeClass: false, returnMarkerTypeIfNotAotCompatible: true); if ((object)type2 != null) { return type2; } WindowsRuntimeHelperTypeAttribute customAttribute = typeFromHandle.GetCustomAttribute(); if (customAttribute != null) { return GetHelperTypeFromAttribute(customAttribute, typeFromHandle); } System.Type authoringMetadataType = typeFromHandle.GetAuthoringMetadataType(); if ((object)authoringMetadataType != null) { customAttribute = authoringMetadataType.GetCustomAttribute(); if (customAttribute != null) { return GetHelperTypeFromAttribute(customAttribute, typeFromHandle); } } if (!RuntimeFeature.IsDynamicCodeCompiled) { return null; } return FindHelperTypeFallback(typeFromHandle); } [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "No members of the generic type are dynamically accessed other than for the attributes on it.")] [UnconditionalSuppressMessage("Trimming", "IL2055", Justification = "The type arguments are guaranteed to be valid for the generic ABI types.")] [return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicFields)] static System.Type GetHelperTypeFromAttribute(WindowsRuntimeHelperTypeAttribute helperTypeAtribute, System.Type type2) { if (type2.IsGenericType && !type2.IsGenericTypeDefinition) { if (!RuntimeFeature.IsDynamicCodeCompiled) { return typeof(HelperTypeMetadataNotAvailableOnAot); } return helperTypeAtribute.HelperType.MakeGenericType(type2.GetGenericArguments()); } return helperTypeAtribute.HelperType; } } [return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicFields)] public static System.Type GetHelperType(this System.Type type) { System.Type type2 = type.FindHelperType(); if ((object)type2 != null) { return type2; } throw new InvalidOperationException("Target type is not a projected type: " + type.FullName + "."); } [return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] public static System.Type GetGuidType([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] this System.Type type) { if (!type.IsDelegate()) { return type; } return type.GetHelperType(); } [UnconditionalSuppressMessage("AOT", "IL3050", Justification = "The fallback path is not AOT-safe by design (to avoid annotations).")] [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "The fallback path is not trim-safe by design (to avoid annotations).")] public static System.Type FindVftblType(this System.Type helperType) { if (!RuntimeFeature.IsDynamicCodeCompiled) { return null; } return FindVftblTypeFallback(helperType); [DynamicDependency(DynamicallyAccessedMemberTypes.All, "ABI.Windows.Foundation.IAsyncActionWithProgress`1+Vftbl", "Microsoft.Windows.SDK.NET")] [DynamicDependency(DynamicallyAccessedMemberTypes.All, "ABI.Windows.Foundation.IAsyncOperationWithProgress`2+Vftbl", "Microsoft.Windows.SDK.NET")] [DynamicDependency(DynamicallyAccessedMemberTypes.All, "ABI.Windows.Foundation.IAsyncOperation`1+Vftbl", "Microsoft.Windows.SDK.NET")] [DynamicDependency(DynamicallyAccessedMemberTypes.All, "ABI.Windows.Foundation.Collections.IMapChangedEventArgs`1+Vftbl", "Microsoft.Windows.SDK.NET")] [DynamicDependency(DynamicallyAccessedMemberTypes.All, "ABI.Windows.Foundation.Collections.IObservableMap`2+Vftbl", "Microsoft.Windows.SDK.NET")] [DynamicDependency(DynamicallyAccessedMemberTypes.All, "ABI.Windows.Foundation.Collections.IObservableVector`1+Vftbl", "Microsoft.Windows.SDK.NET")] [DynamicDependency(DynamicallyAccessedMemberTypes.All, "ABI.System.EventHandler`1+Vftbl", "WinRT.Runtime")] [DynamicDependency(DynamicallyAccessedMemberTypes.All, "ABI.System.Collections.Generic.KeyValuePair`2+Vftbl", "WinRT.Runtime")] [DynamicDependency(DynamicallyAccessedMemberTypes.All, "ABI.System.Collections.Generic.IEnumerable`1+Vftbl", "WinRT.Runtime")] [DynamicDependency(DynamicallyAccessedMemberTypes.All, "ABI.System.Collections.Generic.IEnumerator`1+Vftbl", "WinRT.Runtime")] [DynamicDependency(DynamicallyAccessedMemberTypes.All, "ABI.System.Collections.Generic.IList`1+Vftbl", "WinRT.Runtime")] [DynamicDependency(DynamicallyAccessedMemberTypes.All, "ABI.System.Collections.Generic.IReadOnlyList`1+Vftbl", "WinRT.Runtime")] [DynamicDependency(DynamicallyAccessedMemberTypes.All, "ABI.System.Collections.Generic.IDictionary`2+Vftbl", "WinRT.Runtime")] [DynamicDependency(DynamicallyAccessedMemberTypes.All, "ABI.System.Collections.Generic.IReadOnlyDictionary`2+Vftbl", "WinRT.Runtime")] [RequiresUnreferencedCode("This method is not trim-safe, and is only supported for use when not using trimming (or AOT).")] static System.Type FindVftblTypeFallback(System.Type type2) { System.Type type = type2.GetNestedType("Vftbl"); if ((object)type == null) { return null; } if (type2.IsGenericType) { type = type.MakeGenericType(type2.GetGenericArguments()); } return type; } } [UnconditionalSuppressMessage("Trimming", "IL2075", Justification = "The path using vtable types is a fallback and is not trim-safe by design.")] internal static IntPtr GetAbiToProjectionVftblPtr([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] this System.Type helperType) { return (IntPtr)(helperType.FindVftblType() ?? helperType).GetField("AbiToProjectionVftablePtr", BindingFlags.Static | BindingFlags.Public).GetValue(null); } public static System.Type GetAbiType(this System.Type type) { return type.GetHelperType().GetMethod("GetAbi", BindingFlags.Static | BindingFlags.Public).ReturnType; } public static System.Type GetMarshalerType(this System.Type type) { return type.GetHelperType().GetMethod("CreateMarshaler", BindingFlags.Static | BindingFlags.Public).ReturnType; } internal static System.Type GetMarshaler2Type(this System.Type type) { System.Type helperType = type.GetHelperType(); MethodInfo methodInfo = helperType.GetMethod("CreateMarshaler2", BindingFlags.Static | BindingFlags.Public) ?? helperType.GetMethod("CreateMarshaler", BindingFlags.Static | BindingFlags.Public); return methodInfo.ReturnType; } internal static System.Type GetMarshalerArrayType(this System.Type type) { return type.GetHelperType().GetMethod("CreateMarshalerArray", BindingFlags.Static | BindingFlags.Public)?.ReturnType; } public static bool IsDelegate(this System.Type type) { return typeof(Delegate).IsAssignableFrom(type); } internal static bool IsNullableT(this System.Type type) { if (type.IsGenericType) { return type.GetGenericTypeDefinition() == typeof(System.Nullable<>); } return false; } internal static bool IsAbiNullableDelegate(this System.Type type) { if (type.IsGenericType) { return type.GetGenericTypeDefinition() == typeof(Nullable_Delegate<>); } return false; } internal static bool IsIReferenceArray(this System.Type type) { if (!FeatureSwitches.EnableIReferenceSupport) { return false; } if (type.IsGenericType) { return type.GetGenericTypeDefinition() == typeof(Windows.Foundation.IReferenceArray<>); } return false; } internal static bool ShouldProvideIReference(this System.Type type) { if (!FeatureSwitches.EnableIReferenceSupport) { return false; } if (!type.IsPrimitive && !(type == typeof(string)) && !(type == typeof(Guid)) && !(type == typeof(System.DateTimeOffset)) && !(type == typeof(System.TimeSpan)) && !type.IsTypeOfType() && !type.IsTypeOfException()) { if (type.IsValueType || type.IsDelegate()) { return Projections.IsTypeWindowsRuntimeType(type); } return false; } return true; } internal static bool IsTypeOfType(this System.Type type) { return typeof(System.Type).IsAssignableFrom(type); } internal static bool IsTypeOfException(this System.Type type) { return typeof(System.Exception).IsAssignableFrom(type); } public static System.Type GetRuntimeClassCCWType(this System.Type type) { if (!type.IsClass || type.IsArray) { return null; } return type.GetAuthoringMetadataType(); } internal static System.Type GetCCWType(this System.Type type) { if (type.IsArray) { return null; } return type.GetAuthoringMetadataType(); } internal static void RegisterAuthoringMetadataTypeLookup(Func authoringMetadataTypeLookup) { AuthoringMetadaTypeLookup.Add(authoringMetadataTypeLookup); } internal static System.Type GetAuthoringMetadataType(this System.Type type) { return AuthoringMetadataTypeCache.GetOrAdd(type, delegate(System.Type type3) { int count = AuthoringMetadaTypeLookup.Count; for (int i = 0; i < count; i++) { System.Type type2 = AuthoringMetadaTypeLookup[i](type3); if ((object)type2 != null) { return type2; } } return (!RuntimeFeature.IsDynamicCodeCompiled) ? null : GetAuthoringMetadataTypeFallback(type3); }); } [UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", Justification = "This is a fallback for compat purposes with existing projections. Applications making use of updated projections won't hit this code path.")] private static System.Type GetAuthoringMetadataTypeFallback(System.Type type) { string name = "ABI.Impl." + type.FullName; return type.Assembly.GetType(name, throwOnError: false); } } [Flags] internal enum TypeNameGenerationFlags { None = 0, GenerateBoxedName = 1, ForGetRuntimeClassName = 2 } internal static class TypeNameSupport { private struct VisitedType { public System.Type Type { get; set; } public bool Covariant { get; set; } } private static readonly List projectionAssemblies = new List(); private static readonly List> projectionTypeNameToBaseTypeNameMappings = new List>(); private static readonly ConcurrentDictionary typeNameCache = new ConcurrentDictionary(StringComparer.Ordinal) { ["TrackerCollection"] = null }; private static readonly ConcurrentDictionary baseRcwTypeCache = new ConcurrentDictionary(StringComparer.Ordinal) { ["TrackerCollection"] = null }; [ThreadStatic] private static Stack? visitedTypesInstance; [ThreadStatic] private static StringBuilder? nameForTypeBuilderInstance; public static void RegisterProjectionAssembly(Assembly assembly) { projectionAssemblies.Add(assembly); } public static void RegisterProjectionTypeBaseTypeMapping(System.Collections.Generic.IDictionary typeNameToBaseTypeNameMapping) { projectionTypeNameToBaseTypeNameMappings.Add(typeNameToBaseTypeNameMapping); } public static System.Type FindRcwTypeByNameCached(string runtimeClassName) { System.Type type = FindTypeByNameCached(runtimeClassName); if ((object)type == null) { type = baseRcwTypeCache.GetOrAdd(runtimeClassName, delegate(string key) { int count = projectionTypeNameToBaseTypeNameMappings.Count; for (int i = 0; i < count; i++) { if (projectionTypeNameToBaseTypeNameMappings[i].ContainsKey(key)) { return FindRcwTypeByNameCached(projectionTypeNameToBaseTypeNameMappings[i][key]); } } return (System.Type)null; }); } return type; } public static System.Type FindTypeByNameCached(string runtimeClassName) { return typeNameCache.GetOrAdd(runtimeClassName, delegate(string text) { System.Type result = null; try { result = FindTypeByName(text.AsSpan()).type; } catch (System.Exception) { } return result; }); } [MethodImpl(MethodImplOptions.NoInlining)] private static System.Exception GetExceptionForUnsupportedIReferenceType(ReadOnlySpan runtimeClassName) { return new NotSupportedException("The requested runtime class name is '" + runtimeClassName.ToString() + "', which maps to an 'IReference' projected type. This can only be used when support for 'IReference' types is enabled in the CsWinRT configuration. To enable it, make sure that the 'CsWinRTEnableIReferenceSupport' MSBuild property is not being set to 'false' anywhere."); } public static (System.Type type, int remaining) FindTypeByName(ReadOnlySpan runtimeClassName) { if (runtimeClassName.StartsWith("<>f__AnonymousType".AsSpan(), StringComparison.Ordinal)) { if (FeatureSwitches.EnableDynamicObjectsSupport) { return (type: typeof(ExpandoObject), remaining: 0); } throw new NotSupportedException("The requested runtime class name is '" + runtimeClassName.ToString() + "', which maps to a dynamic projected type. This can only be used when support for dynamic objects is enabled in the CsWinRT configuration. To enable it, make sure that the 'CsWinRTEnableDynamicObjectsSupport' MSBuild property is not being set to 'false' anywhere."); } if (runtimeClassName.CompareTo("Windows.Foundation.IReference`1".AsSpan(), StringComparison.Ordinal) == 0) { if (FeatureSwitches.EnableIReferenceSupport) { return (type: typeof(Nullable_string), remaining: 0); } throw GetExceptionForUnsupportedIReferenceType(runtimeClassName); } if (runtimeClassName.CompareTo("Windows.Foundation.IReference`1".AsSpan(), StringComparison.Ordinal) == 0) { if (FeatureSwitches.EnableIReferenceSupport) { return (type: typeof(Nullable_Type), remaining: 0); } throw GetExceptionForUnsupportedIReferenceType(runtimeClassName); } if (runtimeClassName.CompareTo("Windows.Foundation.IReference`1".AsSpan(), StringComparison.Ordinal) == 0) { if (FeatureSwitches.EnableIReferenceSupport) { return (type: typeof(Nullable_Exception), remaining: 0); } throw GetExceptionForUnsupportedIReferenceType(runtimeClassName); } var (text, genericTypes, item) = ParseGenericTypeName(runtimeClassName); if (text == null) { return (type: null, remaining: -1); } return (type: FindTypeByNameCore(text, genericTypes), remaining: item); } [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Any types which are trimmed are not used by user code and there is fallback logic to handle that.")] private static System.Type FindTypeByNameCore(string runtimeClassName, System.Type[] genericTypes) { System.Type type = Projections.FindCustomTypeForAbiTypeName(runtimeClassName); if ((object)type == null) { if (genericTypes == null) { System.Type type2 = ResolvePrimitiveType(runtimeClassName); if ((object)type2 != null) { return type2; } } int count = projectionAssemblies.Count; for (int i = 0; i < count; i++) { System.Type type3 = projectionAssemblies[i].GetType(runtimeClassName); if ((object)type3 != null) { type = type3; break; } } } if ((object)type == null) { Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (Assembly assembly in assemblies) { System.Type type4 = assembly.GetType(runtimeClassName); if ((object)type4 != null) { type = type4; break; } } } if ((object)type != null) { if (genericTypes != null) { return ResolveGenericType(type, genericTypes, runtimeClassName); } return type; } return null; [UnconditionalSuppressMessage("Trimming", "IL2055", Justification = "The 'MakeGenericType' call is guarded by explicit checks in our code.")] [UnconditionalSuppressMessage("AOT", "IL3050", Justification = "Calls to MakeGenericType are done with reference types.")] static System.Type ResolveGenericType(System.Type resolvedType, System.Type[] array, string text) { if (resolvedType == typeof(System.Nullable<>)) { if (array[0].IsDelegate()) { if (FeatureSwitches.EnableIReferenceSupport) { return typeof(Nullable_Delegate<>).MakeGenericType(array); } throw GetExceptionForUnsupportedIReferenceType(text.AsSpan()); } System.Type typeAsNullableType = NullableType.GetTypeAsNullableType(array[0]); if ((object)typeAsNullableType != null) { return typeAsNullableType; } } if (!RuntimeFeature.IsDynamicCodeCompiled) { foreach (System.Type type5 in array) { if (type5.IsValueType) { return null; } } } return resolvedType.MakeGenericType(array); } } public static System.Type ResolvePrimitiveType(string primitiveTypeName) { return primitiveTypeName switch { "UInt8" => typeof(byte), "Int8" => typeof(sbyte), "UInt16" => typeof(ushort), "Int16" => typeof(short), "UInt32" => typeof(uint), "Int32" => typeof(int), "UInt64" => typeof(ulong), "Int64" => typeof(long), "Boolean" => typeof(bool), "String" => typeof(string), "Char" => typeof(char), "Char16" => typeof(char), "Single" => typeof(float), "Double" => typeof(double), "Guid" => typeof(Guid), "Object" => typeof(object), "TimeSpan" => typeof(System.TimeSpan), _ => null, }; } private static (string genericTypeName, System.Type[] genericTypes, int remaining) ParseGenericTypeName(ReadOnlySpan partialTypeName) { int num = partialTypeName.IndexOfAny(',', '>'); int num2 = partialTypeName.Length; if (num != -1) { num2 = num; } ReadOnlySpan span = partialTypeName.Slice(0, num2); if (!span.Contains("`".AsSpan(), StringComparison.Ordinal)) { return (genericTypeName: span.ToString(), genericTypes: null, remaining: num2); } int num3 = partialTypeName.IndexOf('<'); ReadOnlySpan readOnlySpan = partialTypeName.Slice(0, num3); ReadOnlySpan runtimeClassName = partialTypeName.Slice(num3 + 1); int num4 = num3 + 1; List list = new List(); while (true) { var (type, num5) = FindTypeByName(runtimeClassName); if (type == null) { return (genericTypeName: null, genericTypes: null, remaining: -1); } num4 += num5; list.Add(type); runtimeClassName = runtimeClassName.Slice(num5); if (runtimeClassName[0] != ',') { break; } num4 += 2; runtimeClassName = runtimeClassName.Slice(2); } if (runtimeClassName[0] == '>') { int num6 = ((runtimeClassName.Length <= 1 || runtimeClassName[1] != ' ') ? 1 : 2); num4 += num6; runtimeClassName = runtimeClassName.Slice(num6); return (genericTypeName: readOnlySpan.ToString(), genericTypes: list.ToArray(), remaining: partialTypeName.Length - runtimeClassName.Length); } throw new InvalidOperationException("The provided type name is invalid."); } public static string GetNameForType(System.Type? type, TypeNameGenerationFlags flags) { if ((object)type == null) { return string.Empty; } StringBuilder stringBuilder = nameForTypeBuilderInstance ?? (nameForTypeBuilderInstance = new StringBuilder()); stringBuilder.Clear(); if (TryAppendTypeName(type, stringBuilder, flags)) { return stringBuilder.ToString(); } return string.Empty; } private static bool TryAppendSimpleTypeName(System.Type type, StringBuilder builder, TypeNameGenerationFlags flags) { if (type.IsPrimitive || type == typeof(string) || type == typeof(Guid) || type == typeof(System.TimeSpan)) { if (type == typeof(byte)) { builder.Append("UInt8"); } else if (type == typeof(sbyte)) { builder.Append("Int8"); } else { builder.Append(type.Name); } } else if (type == typeof(object)) { builder.Append("Object"); } else if ((flags & TypeNameGenerationFlags.ForGetRuntimeClassName) != TypeNameGenerationFlags.None && type.IsTypeOfType()) { builder.Append("Windows.UI.Xaml.Interop.TypeName"); } else { string text = Projections.FindCustomAbiTypeNameForType(type); if (text != null) { builder.Append(text); } else if (Projections.IsTypeWindowsRuntimeType(type)) { builder.Append(type.FullName); } else { if ((flags & TypeNameGenerationFlags.ForGetRuntimeClassName) != TypeNameGenerationFlags.None) { return TryAppendWinRTInterfaceNameForType(type, builder, flags); } builder.Append(type.FullName); } } return true; } private static bool TryAppendWinRTInterfaceNameForType(System.Type type, StringBuilder builder, TypeNameGenerationFlags flags) { WinRTRuntimeClassNameAttribute customAttribute = type.GetCustomAttribute(); if (customAttribute != null) { builder.Append(customAttribute.RuntimeClassName); return true; } string runtimeClassNameForNonWinRTTypeFromLookupTable = ComWrappersSupport.GetRuntimeClassNameForNonWinRTTypeFromLookupTable(type); if (!string.IsNullOrEmpty(runtimeClassNameForNonWinRTTypeFromLookupTable)) { builder.Append(runtimeClassNameForNonWinRTTypeFromLookupTable); return true; } if (!RuntimeFeature.IsDynamicCodeCompiled) { return false; } Stack stack = visitedTypesInstance ?? (visitedTypesInstance = new Stack()); if (HasAnyVisitedTypes(stack, type)) { if (stack.Peek().Covariant && !type.IsValueType) { builder.Append("Object"); return true; } return false; } return TryAppendWinRTInterfaceNameForTypeJit(type, builder, flags); static bool HasAnyVisitedTypes(Stack visitedTypes, System.Type type2) { foreach (VisitedType visitedType in visitedTypes) { if (visitedType.Type == type2) { return true; } } return false; } [UnconditionalSuppressMessage("Trimming", "IL2070", Justification = "Updated binaries will have WinRTRuntimeClassNameAttribute which will be used instead.")] static bool TryAppendWinRTInterfaceNameForTypeJit(System.Type type2, StringBuilder builder2, TypeNameGenerationFlags flags2) { Stack stack2 = visitedTypesInstance; stack2.Push(new VisitedType { Type = type2 }); System.Type type3 = null; System.Type[] interfaces = type2.GetInterfaces(); foreach (System.Type type4 in interfaces) { if (Projections.IsTypeWindowsRuntimeType(type4) && ((object)type3 == null || type3.IsAssignableFrom(type4))) { type3 = type4; } } bool result = false; if ((object)type3 != null) { result = TryAppendTypeName(type3, builder2, flags2); } stack2.Pop(); return result; } } private static bool TryAppendTypeName(System.Type type, StringBuilder builder, TypeNameGenerationFlags flags) { if (type.IsSZArray) { System.Type elementType = type.GetElementType(); if (elementType.ShouldProvideIReference()) { builder.Append("Windows.Foundation.IReferenceArray`1<"); if (TryAppendTypeName(elementType, builder, flags & ~TypeNameGenerationFlags.GenerateBoxedName)) { builder.Append('>'); return true; } return false; } return false; } if ((flags & TypeNameGenerationFlags.GenerateBoxedName) != TypeNameGenerationFlags.None && type.ShouldProvideIReference()) { builder.Append("Windows.Foundation.IReference`1<"); if (!TryAppendSimpleTypeName(type, builder, flags & ~TypeNameGenerationFlags.GenerateBoxedName)) { return false; } builder.Append('>'); return true; } if (!type.IsGenericType || type.IsGenericTypeDefinition) { return TryAppendSimpleTypeName(type, builder, flags); } if ((flags & TypeNameGenerationFlags.ForGetRuntimeClassName) != TypeNameGenerationFlags.None && !Projections.IsTypeWindowsRuntimeType(type)) { return TryAppendWinRTInterfaceNameForType(type, builder, flags); } System.Type genericTypeDefinition = type.GetGenericTypeDefinition(); if (!TryAppendSimpleTypeName(genericTypeDefinition, builder, flags)) { return false; } builder.Append('<'); bool flag = true; System.Type[] genericArguments = type.GetGenericArguments(); System.Type[] genericArguments2 = genericTypeDefinition.GetGenericArguments(); Stack stack = visitedTypesInstance ?? (visitedTypesInstance = new Stack()); for (int i = 0; i < genericArguments.Length; i++) { System.Type type2 = genericArguments[i]; if (type2.ContainsGenericParameters) { throw new ArgumentException("type"); } if (!flag) { builder.Append(", "); } flag = false; if ((flags & TypeNameGenerationFlags.ForGetRuntimeClassName) != TypeNameGenerationFlags.None) { stack.Push(new VisitedType { Type = type, Covariant = ((genericArguments2[i].GenericParameterAttributes & GenericParameterAttributes.VarianceMask) == GenericParameterAttributes.Covariant) }); } bool flag2 = TryAppendTypeName(type2, builder, flags & ~TypeNameGenerationFlags.GenerateBoxedName); if ((flags & TypeNameGenerationFlags.ForGetRuntimeClassName) != TypeNameGenerationFlags.None) { stack.Pop(); } if (!flag2) { return false; } } builder.Append('>'); return true; } } internal static class WinRTRuntimeErrorStrings { private static ResourceManager? s_resourceManager; private static ResourceManager ResourceManager => s_resourceManager ?? (s_resourceManager = new ResourceManager("WinRT.WinRTRuntimeErrorStrings", typeof(WinRTRuntimeErrorStrings).Assembly)); internal static string Arg_IndexOutOfRangeException => GetResourceString("Arg_IndexOutOfRangeException"); internal static string Arg_KeyNotFound => GetResourceString("Arg_KeyNotFound"); internal static string Arg_KeyNotFoundWithKey => GetResourceString("Arg_KeyNotFoundWithKey"); internal static string Arg_RankMultiDimNotSupported => GetResourceString("Arg_RankMultiDimNotSupported"); internal static string Argument_AddingDuplicate => GetResourceString("Argument_AddingDuplicate"); internal static string Argument_AddingDuplicateWithKey => GetResourceString("Argument_AddingDuplicateWithKey"); internal static string Argument_IndexOutOfArrayBounds => GetResourceString("Argument_IndexOutOfArrayBounds"); internal static string Argument_InsufficientSpaceToCopyCollection => GetResourceString("Argument_InsufficientSpaceToCopyCollection"); internal static string ArgumentOutOfRange_Index => GetResourceString("ArgumentOutOfRange_Index"); internal static string ArgumentOutOfRange_IndexLargerThanMaxValue => GetResourceString("ArgumentOutOfRange_IndexLargerThanMaxValue"); internal static string InvalidOperation_CannotRemoveLastFromEmptyCollection => GetResourceString("InvalidOperation_CannotRemoveLastFromEmptyCollection"); internal static string InvalidOperation_CollectionBackingDictionaryTooLarge => GetResourceString("InvalidOperation_CollectionBackingDictionaryTooLarge"); internal static string InvalidOperation_CollectionBackingListTooLarge => GetResourceString("InvalidOperation_CollectionBackingListTooLarge"); internal static string InvalidOperation_EnumEnded => GetResourceString("InvalidOperation_EnumEnded"); internal static string InvalidOperation_EnumFailedVersion => GetResourceString("InvalidOperation_EnumFailedVersion"); internal static string InvalidOperation_EnumNotStarted => GetResourceString("InvalidOperation_EnumNotStarted"); internal static string NotSupported_KeyCollectionSet => GetResourceString("NotSupported_KeyCollectionSet"); internal static string NotSupported_ValueCollectionSet => GetResourceString("NotSupported_ValueCollectionSet"); private static string GetResourceString([CallerMemberName] string? resourceKey = null) { if (FeatureSwitches.UseExceptionResourceKeys) { return resourceKey; } return ResourceManager.GetString(resourceKey); } } internal static class ProjectionInitializer { [ModuleInitializer] public static void InitalizeProjection() { ComWrappersSupport.RegisterProjectionAssembly(typeof(ProjectionInitializer).Assembly); } } } namespace WinRT.Interop { [WinRTExposedType(typeof(ManagedExceptionErrorInfoTypeDetails))] internal sealed class ManagedExceptionErrorInfo { private readonly System.Exception _exception; public ManagedExceptionErrorInfo(System.Exception ex) { _exception = ex; } public bool InterfaceSupportsErrorInfo(Guid riid) { return true; } public Guid GetGuid() { return default(Guid); } public string GetSource() { return _exception.Source; } public string GetDescription() { string text = _exception.Message; if (string.IsNullOrEmpty(text)) { text = _exception.GetType().FullName; } return text; } public string GetHelpFile() { return _exception.HelpLink; } public string GetHelpFileContent() { return string.Empty; } } internal sealed class ManagedExceptionErrorInfoTypeDetails : IWinRTExposedTypeDetails { public ComWrappers.ComInterfaceEntry[] GetExposedInterfaces() { return new ComWrappers.ComInterfaceEntry[2] { new ComWrappers.ComInterfaceEntry { IID = IID.IID_IErrorInfo, Vtable = IErrorInfoVftbl.AbiToProjectionVftablePtr }, new ComWrappers.ComInterfaceEntry { IID = IID.IID_ISupportErrorInfo, Vtable = ISupportErrorInfoVftbl.AbiToProjectionVftablePtr } }; } } [WindowsRuntimeType(null)] [Guid("00000035-0000-0000-C000-000000000046")] [WindowsRuntimeHelperType(typeof(ABI.WinRT.Interop.IActivationFactory))] public interface IActivationFactory { IntPtr ActivateInstance(); } [WindowsRuntimeType(null)] [Guid("C03F6A43-65A4-9818-987E-E0B810D2A6F2")] [WindowsRuntimeHelperType(typeof(ABI.WinRT.Interop.IAgileReference))] internal interface IAgileReference { IObjectReference Resolve(Guid riid); } [WindowsRuntimeType(null)] [Guid("94ea2b94-e9cc-49e0-c0ff-ee64ca8f5b90")] [WindowsRuntimeHelperType(typeof(ABI.WinRT.Interop.IAgileObject))] public interface IAgileObject { static readonly Guid IID = WinRT.Interop.IID.IID_IAgileObject; } internal struct IDelegateVftbl { public IUnknownVftbl IUnknownVftbl; public IntPtr Invoke; } public static class IID { public static ref readonly Guid IID_IUnknown { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 0, 0, 0, 0, 0, 0, 0, 0, 192, 0, 0, 0, 0, 0, 0, 70 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } public static ref readonly Guid IID_IInspectable { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 224, 226, 134, 175, 45, 177, 106, 76, 156, 90, 215, 170, 101, 16, 30, 144 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_IWeakReference { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 55, 0, 0, 0, 0, 0, 0, 0, 192, 0, 0, 0, 0, 0, 0, 70 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_IWeakReferenceSource { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 56, 0, 0, 0, 0, 0, 0, 0, 192, 0, 0, 0, 0, 0, 0, 70 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_IReferenceTracker { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 58, 177, 211, 17, 14, 24, 137, 71, 168, 190, 119, 18, 136, 40, 147, 230 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_IReferenceTrackerTarget { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 248, 67, 189, 100, 238, 191, 196, 78, 183, 235, 41, 53, 21, 141, 174, 33 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } public static ref readonly Guid IID_IActivationFactory { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 53, 0, 0, 0, 0, 0, 0, 0, 192, 0, 0, 0, 0, 0, 0, 70 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } public static ref readonly Guid IID_IAgileObject { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 148, 43, 234, 148, 204, 233, 224, 73, 192, 255, 238, 100, 202, 143, 91, 144 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } public static ref readonly Guid IID_IMarshal { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 3, 0, 0, 0, 0, 0, 0, 0, 192, 0, 0, 0, 0, 0, 0, 70 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } public static ref readonly Guid IID_IBuffer { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 224, 15, 90, 144, 83, 188, 223, 17, 140, 73, 0, 30, 79, 198, 134, 218 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } public static ref readonly Guid IID_IBufferByteAccess { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 239, 15, 90, 144, 83, 188, 223, 17, 140, 73, 0, 30, 79, 198, 134, 218 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } public static ref readonly Guid IID_IMemoryBufferByteAccess { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 53, 50, 13, 91, 186, 77, 68, 77, 134, 94, 143, 29, 14, 79, 208, 77 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_IContextCallback { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 218, 1, 0, 0, 0, 0, 0, 0, 192, 0, 0, 0, 0, 0, 0, 70 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_ICallbackWithNoReentrancyToApplicationSTA { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 116, 151, 41, 10, 78, 62, 66, 252, 29, 157, 114, 206, 225, 5, 202, 87 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_IErrorInfo { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 32, 177, 242, 28, 125, 84, 27, 16, 142, 101, 8, 0, 43, 43, 209, 25 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_ISupportErrorInfo { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 96, 61, 11, 223, 143, 84, 27, 16, 142, 101, 8, 0, 43, 43, 209, 25 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_ILanguageExceptionErrorInfo { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 243, 219, 162, 4, 131, 223, 108, 17, 9, 70, 8, 18, 171, 246, 224, 125 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_ILanguageExceptionErrorInfo2 { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 196, 229, 70, 87, 151, 91, 76, 66, 182, 32, 40, 34, 145, 87, 52, 221 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_IRestrictedErrorInfo { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 146, 112, 186, 130, 136, 76, 125, 66, 167, 188, 22, 221, 147, 254, 182, 126 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_MUX_INotifyPropertyChanged { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 1, 118, 177, 144, 101, 176, 110, 88, 131, 217, 154, 220, 58, 105, 82, 132 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_WUX_INotifyPropertyChanged { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 156, 214, 117, 207, 244, 242, 107, 72, 179, 2, 187, 76, 9, 186, 235, 250 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_MUX_INotifyCollectionChanged { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 225, 85, 1, 83, 165, 40, 147, 86, 135, 206, 48, 114, 77, 149, 160, 109 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_WUX_INotifyCollectionChanged { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 213, 103, 177, 40, 49, 26, 91, 70, 155, 37, 213, 195, 174, 104, 108, 64 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_MUX_INotifyCollectionChangedEventArgsFactory { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 164, 235, 8, 81, 146, 72, 32, 90, 131, 116, 169, 104, 21, 224, 253, 39 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_WUX_INotifyCollectionChangedEventArgsFactory { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 58, 62, 12, 179, 141, 223, 165, 68, 154, 56, 122, 192, 208, 140, 230, 61 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_MUX_INotifyCollectionChangedEventArgs { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 242, 159, 4, 218, 224, 210, 232, 95, 140, 123, 248, 127, 38, 6, 11, 111 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_WUX_INotifyCollectionChangedEventArgs { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 51, 141, 246, 76, 242, 227, 100, 73, 184, 94, 148, 91, 79, 126, 47, 33 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_MUX_NotifyCollectionChangedEventHandler { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 220, 9, 9, 139, 5, 32, 147, 93, 191, 138, 114, 95, 1, 123, 170, 141 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_WUX_NotifyCollectionChangedEventHandler { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 124, 179, 16, 202, 130, 243, 145, 69, 133, 87, 94, 36, 150, 82, 121, 176 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_MUX_PropertyChangedEventArgsRuntimeClassFactory { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 168, 39, 12, 124, 65, 11, 112, 80, 177, 96, 252, 154, 233, 96, 163, 108 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_WUX_PropertyChangedEventArgsRuntimeClassFactory { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 3, 156, 204, 109, 199, 224, 238, 78, 142, 169, 55, 227, 64, 110, 235, 28 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_MUX_PropertyChangedEventHandler { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 246, 82, 222, 227, 50, 30, 166, 93, 187, 45, 181, 182, 9, 108, 150, 45 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_WUX_PropertyChangedEventHandler { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 22, 156, 241, 80, 34, 10, 142, 77, 160, 137, 30, 169, 149, 22, 87, 210 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_DataErrorsChangedEventArgsRuntimeClassFactory { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 30, 189, 208, 98, 95, 184, 204, 95, 132, 42, 124, 176, 221, 163, 127, 229 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_UriRuntimeClassFactory { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 111, 121, 169, 68, 62, 114, 223, 79, 162, 24, 3, 62, 117, 176, 192, 132 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_INotifyDataErrorInfo { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 204, 194, 230, 14, 62, 39, 125, 86, 188, 10, 29, 216, 126, 229, 30, 186 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_ICommand { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 66, 53, 175, 229, 103, 202, 129, 64, 153, 91, 112, 157, 209, 55, 146, 223 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_IGlobalInterfaceTable { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 70, 1, 0, 0, 0, 0, 0, 0, 192, 0, 0, 0, 0, 0, 0, 70 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_EventHandler { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 246, 152, 8, 197, 54, 197, 71, 95, 133, 131, 139, 44, 36, 56, 161, 59 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_IBindableVectorView { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 231, 214, 109, 52, 110, 151, 195, 75, 129, 93, 236, 226, 67, 188, 15, 51 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_IEnumerable { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 8, 44, 109, 3, 41, 223, 175, 65, 138, 162, 215, 116, 190, 98, 186, 111 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_IList { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 222, 231, 61, 57, 208, 111, 13, 76, 187, 113, 71, 36, 74, 17, 62, 147 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_ICustomProperty { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 192, 146, 218, 48, 232, 35, 160, 66, 174, 124, 115, 74, 14, 93, 39, 130 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_ICustomPropertyProvider { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 85, 87, 146, 124, 72, 62, 180, 66, 134, 119, 118, 55, 34, 103, 3, 63 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_IPropertyValue { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 221, 130, 214, 75, 84, 117, 233, 64, 154, 155, 130, 101, 78, 222, 126, 98 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_IDisposable { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 41, 168, 213, 48, 164, 127, 38, 64, 131, 187, 215, 91, 174, 78, 169, 158 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_IStringable { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 84, 159, 54, 150, 182, 142, 240, 72, 171, 206, 193, 178, 17, 230, 39, 195 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_IServiceProvider { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 223, 162, 179, 104, 115, 129, 159, 83, 181, 36, 200, 162, 52, 143, 90, 251 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_IReferenceOfPoint { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 34, 76, 241, 132, 10, 160, 114, 82, 141, 61, 130, 17, 46, 102, 223, 0 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_IReferenceOfSize { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 134, 48, 114, 97, 83, 142, 118, 82, 159, 54, 42, 75, 185, 62, 43, 117 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_IReferenceOfRect { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 17, 63, 66, 128, 79, 5, 172, 94, 175, 211, 99, 182, 206, 21, 231, 123 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_IReferenceMatrix3x2 { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 253, 140, 53, 118, 189, 44, 91, 82, 164, 158, 144, 238, 24, 36, 123, 113 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_IReferenceMatrix4x4 { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 220, 255, 203, 218, 239, 104, 208, 95, 182, 87, 120, 45, 10, 201, 128, 126 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_IReferencePlane { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 161, 66, 213, 70, 247, 82, 231, 88, 172, 252, 154, 109, 54, 77, 160, 34 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_IReferenceQuaternion { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 187, 4, 112, 178, 20, 192, 206, 93, 154, 33, 121, 156, 90, 60, 20, 97 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_IReferenceVector2 { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 158, 166, 246, 72, 101, 132, 174, 87, 148, 0, 151, 100, 8, 127, 101, 173 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_IReferenceVector3 { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 255, 112, 231, 30, 84, 201, 202, 89, 167, 84, 97, 153, 169, 190, 40, 44 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_IReferenceVector4 { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 201, 67, 232, 165, 32, 237, 57, 83, 143, 141, 159, 228, 4, 207, 54, 84 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_IReferenceArrayOfInt32 { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 165, 128, 208, 166, 135, 176, 194, 91, 154, 159, 92, 214, 135, 180, 209, 247 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_IReferenceArrayOfString { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 142, 104, 133, 3, 199, 227, 94, 92, 163, 137, 85, 36, 237, 227, 73, 241 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_IReferenceArrayOfByte { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 131, 38, 242, 42, 52, 55, 208, 86, 166, 14, 104, 140, 200, 93, 22, 25 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_IReferenceArrayOfInt16 { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 215, 143, 47, 145, 192, 173, 96, 93, 168, 150, 126, 215, 96, 137, 204, 91 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_IReferenceArrayOfUInt16 { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 221, 162, 36, 102, 247, 131, 156, 81, 157, 85, 187, 31, 101, 96, 69, 107 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_IReferenceArrayOfUInt32 { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 104, 75, 55, 151, 135, 235, 204, 86, 177, 142, 39, 239, 15, 156, 252, 12 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_IReferenceArrayOfInt64 { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 113, 50, 51, 110, 42, 46, 85, 89, 135, 144, 131, 108, 118, 238, 83, 182 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_IReferenceArrayOfUInt64 { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 52, 4, 182, 56, 124, 214, 62, 82, 157, 14, 36, 214, 67, 65, 16, 115 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_IReferenceArrayOfSingle { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 131, 234, 177, 106, 65, 203, 153, 95, 146, 204, 35, 189, 67, 54, 161, 251 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_IReferenceArrayOfDouble { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 83, 242, 1, 211, 163, 224, 43, 93, 154, 65, 164, 214, 43, 236, 70, 35 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_IReferenceArrayOfChar { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 171, 90, 9, 164, 125, 235, 130, 87, 143, 173, 22, 9, 222, 162, 73, 173 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_IReferenceArrayOfBoolean { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 102, 38, 231, 232, 204, 72, 63, 89, 186, 133, 38, 99, 73, 105, 86, 227 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_IReferenceArrayOfGuid { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 56, 152, 207, 238, 194, 193, 74, 91, 151, 111, 206, 194, 97, 174, 29, 85 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_IReferenceArrayOfDateTimeOffset { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 148, 149, 142, 27, 142, 88, 7, 90, 158, 101, 7, 49, 164, 201, 162, 219 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_IReferenceArrayOfTimeSpan { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 125, 25, 115, 173, 250, 44, 166, 87, 137, 147, 159, 172, 64, 254, 183, 145 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_IReferenceArrayOfObject { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 79, 168, 215, 156, 128, 12, 197, 89, 180, 78, 151, 120, 65, 187, 67, 217 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_IReferenceArrayOfType { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 167, 87, 132, 218, 235, 194, 161, 93, 128, 190, 113, 50, 162, 225, 191, 164 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_IReferenceArrayOfMatrix3x2 { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 255, 217, 37, 165, 155, 192, 26, 80, 167, 133, 77, 30, 217, 225, 2, 184 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_IReferenceArrayOfMatrix4x4 { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 21, 90, 13, 252, 157, 143, 143, 94, 136, 40, 174, 242, 194, 226, 91, 173 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_IReferenceArrayOfPlane { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 125, 127, 207, 249, 89, 84, 152, 95, 145, 185, 242, 99, 42, 158, 194, 152 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_IReferenceArrayOfQuaternion { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 190, 118, 186, 233, 49, 44, 29, 94, 152, 164, 235, 219, 98, 90, 238, 147 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_IReferenceArrayOfVector2 { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 120, 33, 223, 41, 219, 255, 62, 86, 136, 219, 56, 105, 160, 7, 48, 94 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_IReferenceArrayOfVector3 { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 250, 53, 26, 170, 78, 11, 72, 82, 189, 121, 255, 212, 124, 254, 64, 39 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_IReferenceArrayOfVector4 { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 80, 114, 117, 104, 73, 88, 114, 87, 144, 227, 170, 219, 76, 151, 11, 255 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_IReferenceArrayOfException { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 204, 228, 26, 64, 185, 74, 143, 90, 185, 147, 227, 39, 144, 12, 54, 77 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_NullableByte { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 200, 140, 25, 229, 115, 40, 245, 85, 176, 161, 132, 255, 158, 74, 173, 98 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_NullableSByte { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 41, 1, 80, 149, 246, 251, 252, 90, 137, 223, 112, 100, 45, 116, 25, 144 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_NullableShort { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 27, 228, 201, 110, 9, 103, 71, 86, 153, 24, 161, 39, 1, 16, 252, 78 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_NullableUShort { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 195, 210, 183, 90, 98, 107, 113, 94, 164, 182, 45, 73, 196, 242, 56, 253 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_NullableInt { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 189, 239, 140, 84, 138, 188, 160, 95, 141, 242, 149, 116, 64, 252, 139, 244 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_NullableUInt { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 175, 243, 62, 81, 132, 231, 37, 83, 169, 30, 151, 194, 184, 17, 28, 243 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_NullableLong { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 36, 158, 218, 77, 159, 230, 106, 92, 160, 166, 147, 66, 115, 101, 175, 42 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_NullableULong { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 118, 227, 85, 103, 187, 83, 139, 86, 161, 29, 23, 35, 152, 104, 48, 158 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_NullableFloat { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 186, 194, 156, 113, 118, 62, 239, 93, 159, 26, 56, 216, 90, 20, 94, 168 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_NullableDouble { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 41, 108, 45, 47, 115, 84, 62, 95, 146, 231, 150, 87, 43, 185, 144, 226 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_NullableChar { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 243, 62, 57, 251, 172, 187, 213, 91, 145, 68, 132, 242, 53, 118, 244, 21 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_NullableBool { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 96, 253, 0, 60, 80, 41, 57, 89, 162, 26, 45, 18, 197, 160, 27, 138 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_NullableGuid { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 73, 246, 80, 125, 44, 99, 249, 81, 132, 154, 238, 73, 66, 137, 51, 234 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_NullableDateTimeOffset { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 167, 216, 65, 85, 124, 73, 164, 90, 134, 252, 119, 19, 173, 191, 42, 44 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_NullableTimeSpan { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 76, 12, 77, 96, 222, 145, 42, 92, 147, 95, 54, 47, 19, 234, 248, 0 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_NullableObject { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 144, 204, 220, 6, 88, 160, 136, 92, 135, 183, 111, 51, 96, 162, 252, 22 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_NullableType { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 153, 173, 48, 56, 218, 216, 243, 83, 152, 155, 252, 146, 173, 34, 39, 120 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_NullableException { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 30, 122, 242, 111, 106, 75, 183, 89, 178, 195, 209, 242, 238, 71, 69, 147 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_NullableEventHandler { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 5, 15, 35, 37, 156, 180, 238, 87, 137, 97, 83, 115, 217, 142, 26, 177 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_NullableString { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 251, 109, 65, 253, 7, 42, 235, 82, 170, 227, 223, 206, 20, 17, 108, 5 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_MUX_NullablePropertyChangedEventHandler { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 203, 224, 234, 30, 87, 143, 55, 92, 160, 135, 165, 93, 70, 226, 254, 63 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_WUX_NullablePropertyChangedEventHandler { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 169, 32, 169, 177, 242, 194, 83, 84, 165, 62, 102, 177, 41, 74, 139, 254 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_MUX_NullableNotifyCollectionChangedEventHandler { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 33, 90, 157, 119, 125, 14, 118, 84, 187, 144, 39, 250, 59, 75, 141, 229 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } internal static ref readonly Guid IID_WUX_NullableNotifyCollectionChangedEventHandler { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan span = new byte[16] { 110, 92, 253, 164, 73, 101, 169, 89, 134, 239, 90, 73, 10, 24, 117, 217 }; return ref Unsafe.As(ref MemoryMarshal.GetReference(span)); } } } internal enum MSHCTX { Local, NoSharedMem, DifferentMachine, InProc, CrossCtx } internal enum MSHLFLAGS { Normal = 0, TableStrong = 1, TableWeak = 2, NoPing = 4 } [Guid("11D3B13A-180E-4789-A8BE-7712882893E6")] internal struct IReferenceTrackerVftbl { public IUnknownVftbl IUnknownVftbl; private unsafe void* _ConnectFromTrackerSource_0; private unsafe void* _DisconnectFromTrackerSource_1; private unsafe void* _FindTrackerTargets_2; private unsafe void* _GetReferenceTrackerManager_3; private unsafe void* _AddRefFromTrackerSource_4; private unsafe void* _ReleaseFromTrackerSource_5; private unsafe void* _PegFromTrackerSource_6; public unsafe delegate* unmanaged[Stdcall] AddRefFromTrackerSource { get { return (delegate* unmanaged[Stdcall])_AddRefFromTrackerSource_4; } set { _AddRefFromTrackerSource_4 = value; } } public unsafe delegate* unmanaged[Stdcall] ReleaseFromTrackerSource { get { return (delegate* unmanaged[Stdcall])_ReleaseFromTrackerSource_5; } set { _ReleaseFromTrackerSource_5 = value; } } } [Guid("00000000-0000-0000-C000-000000000046")] public struct IUnknownVftbl { private unsafe void* _QueryInterface; private unsafe void* _AddRef; private unsafe void* _Release; public unsafe delegate* unmanaged[Stdcall] QueryInterface { get { return (delegate* unmanaged[Stdcall])_QueryInterface; } set { _QueryInterface = value; } } public unsafe delegate* unmanaged[Stdcall] AddRef { get { return (delegate* unmanaged[Stdcall])_AddRef; } set { _AddRef = value; } } public unsafe delegate* unmanaged[Stdcall] Release { get { return (delegate* unmanaged[Stdcall])_Release; } set { _Release = value; } } public static IUnknownVftbl AbiToProjectionVftbl => ComWrappersSupport.IUnknownVftbl; public static IntPtr AbiToProjectionVftblPtr => ComWrappersSupport.IUnknownVftblPtr; internal unsafe bool Equals(IUnknownVftbl other) { if (_QueryInterface == other._QueryInterface && _AddRef == other._AddRef) { return _Release == other._Release; } return false; } internal unsafe static bool IsReferenceToManagedObject(IntPtr ptr) { return ((IUnknownVftbl*)(*(nint*)(void*)ptr))->Equals(AbiToProjectionVftbl); } } [WindowsRuntimeType(null)] [Guid("00000038-0000-0000-C000-000000000046")] [WindowsRuntimeHelperType(typeof(ABI.WinRT.Interop.IWeakReferenceSource))] public interface IWeakReferenceSource { IWeakReference GetWeakReference(); } [WindowsRuntimeType(null)] [Guid("00000037-0000-0000-C000-000000000046")] [WindowsRuntimeHelperType(typeof(ABI.WinRT.Interop.IWeakReference))] public interface IWeakReference { IObjectReference Resolve(Guid riid); } [WinRTExposedType(typeof(ManagedWeakReferenceTypeDetails))] internal sealed class ManagedWeakReference : IWeakReference { private readonly WeakReference _ref; public ManagedWeakReference(object obj) { _ref = new WeakReference(obj); } public IObjectReference Resolve(Guid riid) { if (!_ref.TryGetTarget(out var target)) { return null; } return ComWrappersSupport.CreateCCWForObject(target, riid); } public IntPtr ResolveForABI(Guid riid) { if (!_ref.TryGetTarget(out var target)) { return IntPtr.Zero; } return ComWrappersSupport.CreateCCWForObjectForABI(target, riid); } } internal sealed class ManagedWeakReferenceTypeDetails : IWinRTExposedTypeDetails { public ComWrappers.ComInterfaceEntry[] GetExposedInterfaces() { return new ComWrappers.ComInterfaceEntry[1] { new ComWrappers.ComInterfaceEntry { IID = IID.IID_IWeakReference, Vtable = ABI.WinRT.Interop.IWeakReference.AbiToProjectionVftablePtr } }; } } [EditorBrowsable(EditorBrowsableState.Never)] public delegate int _get_PropertyAsBoolean(IntPtr thisPtr, out byte value); [EditorBrowsable(EditorBrowsableState.Never)] internal unsafe delegate int _get_PropertyAsBoolean_Abi(IntPtr thisPtr, byte* value); [EditorBrowsable(EditorBrowsableState.Never)] public delegate int _put_PropertyAsBoolean(IntPtr thisPtr, byte value); [EditorBrowsable(EditorBrowsableState.Never)] public delegate int _get_PropertyAsChar(IntPtr thisPtr, out ushort value); [EditorBrowsable(EditorBrowsableState.Never)] public delegate int _put_PropertyAsChar(IntPtr thisPtr, ushort value); [EditorBrowsable(EditorBrowsableState.Never)] public delegate int _get_PropertyAsSByte(IntPtr thisPtr, out sbyte value); [EditorBrowsable(EditorBrowsableState.Never)] public delegate int _put_PropertyAsSByte(IntPtr thisPtr, sbyte value); [EditorBrowsable(EditorBrowsableState.Never)] public delegate int _get_PropertyAsByte(IntPtr thisPtr, out byte value); [EditorBrowsable(EditorBrowsableState.Never)] public delegate int _put_PropertyAsByte(IntPtr thisPtr, byte value); [EditorBrowsable(EditorBrowsableState.Never)] public delegate int _get_PropertyAsInt16(IntPtr thisPtr, out short value); [EditorBrowsable(EditorBrowsableState.Never)] public delegate int _put_PropertyAsInt16(IntPtr thisPtr, short value); [EditorBrowsable(EditorBrowsableState.Never)] public delegate int _get_PropertyAsUInt16(IntPtr thisPtr, out ushort value); [EditorBrowsable(EditorBrowsableState.Never)] public delegate int _put_PropertyAsUInt16(IntPtr thisPtr, ushort value); [EditorBrowsable(EditorBrowsableState.Never)] public delegate int _get_PropertyAsInt32(IntPtr thisPtr, out int value); [EditorBrowsable(EditorBrowsableState.Never)] public delegate int _put_PropertyAsInt32(IntPtr thisPtr, int value); [EditorBrowsable(EditorBrowsableState.Never)] public delegate int _get_PropertyAsUInt32(IntPtr thisPtr, out uint value); [EditorBrowsable(EditorBrowsableState.Never)] internal unsafe delegate int _get_PropertyAsUInt32_Abi(IntPtr thisPtr, uint* value); [EditorBrowsable(EditorBrowsableState.Never)] public delegate int _put_PropertyAsUInt32(IntPtr thisPtr, uint value); [EditorBrowsable(EditorBrowsableState.Never)] public delegate int _get_PropertyAsInt64(IntPtr thisPtr, out long value); [EditorBrowsable(EditorBrowsableState.Never)] public delegate int _put_PropertyAsInt64(IntPtr thisPtr, long value); [EditorBrowsable(EditorBrowsableState.Never)] public delegate int _get_PropertyAsUInt64(IntPtr thisPtr, out ulong value); [EditorBrowsable(EditorBrowsableState.Never)] public delegate int _put_PropertyAsUInt64(IntPtr thisPtr, ulong value); [EditorBrowsable(EditorBrowsableState.Never)] public delegate int _get_PropertyAsFloat(IntPtr thisPtr, out float value); [EditorBrowsable(EditorBrowsableState.Never)] public delegate int _put_PropertyAsFloat(IntPtr thisPtr, float value); [EditorBrowsable(EditorBrowsableState.Never)] public delegate int _get_PropertyAsDouble(IntPtr thisPtr, out double value); [EditorBrowsable(EditorBrowsableState.Never)] public delegate int _put_PropertyAsDouble(IntPtr thisPtr, double value); [EditorBrowsable(EditorBrowsableState.Never)] public delegate int _get_PropertyAsObject(IntPtr thisPtr, out IntPtr value); [EditorBrowsable(EditorBrowsableState.Never)] public delegate int _put_PropertyAsObject(IntPtr thisPtr, IntPtr value); [EditorBrowsable(EditorBrowsableState.Never)] public delegate int _get_PropertyAsGuid(IntPtr thisPtr, out Guid value); [EditorBrowsable(EditorBrowsableState.Never)] public delegate int _put_PropertyAsGuid(IntPtr thisPtr, Guid value); [EditorBrowsable(EditorBrowsableState.Never)] public delegate int _get_PropertyAsString(IntPtr thisPtr, out IntPtr value); [EditorBrowsable(EditorBrowsableState.Never)] public delegate int _put_PropertyAsString(IntPtr thisPtr, IntPtr value); [EditorBrowsable(EditorBrowsableState.Never)] public delegate int _add_EventHandler(IntPtr thisPtr, IntPtr handler, out EventRegistrationToken token); [EditorBrowsable(EditorBrowsableState.Never)] public delegate int _remove_EventHandler(IntPtr thisPtr, EventRegistrationToken token); [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] internal sealed class WuxMuxProjectedTypeAttribute : Attribute { } internal static class Platform { [DllImport("api-ms-win-core-com-l1-1-0.dll")] public unsafe static extern int CoCreateInstance(Guid* clsid, IntPtr outer, uint clsContext, Guid* iid, IntPtr* instance); [DllImport("api-ms-win-core-com-l1-1-0.dll")] public static extern int CoDecrementMTAUsage(IntPtr cookie); [DllImport("api-ms-win-core-com-l1-1-0.dll")] public unsafe static extern int CoIncrementMTAUsage(IntPtr* cookie); [DllImport("api-ms-win-core-winrt-l1-1-0.dll")] public unsafe static extern int RoGetActivationFactory(IntPtr runtimeClassId, Guid* iid, IntPtr* factory); [DllImport("api-ms-win-core-winrt-string-l1-1-0.dll", CallingConvention = CallingConvention.StdCall)] public unsafe static extern int WindowsCreateString(ushort* sourceString, int length, IntPtr* hstring); [DllImport("api-ms-win-core-winrt-string-l1-1-0.dll", CallingConvention = CallingConvention.StdCall)] public unsafe static extern int WindowsCreateStringReference(ushort* sourceString, int length, IntPtr* hstring_header, IntPtr* hstring); [DllImport("api-ms-win-core-winrt-string-l1-1-0.dll", CallingConvention = CallingConvention.StdCall)] public static extern int WindowsDeleteString(IntPtr hstring); [DllImport("api-ms-win-core-winrt-string-l1-1-0.dll", CallingConvention = CallingConvention.StdCall)] public unsafe static extern char* WindowsGetStringRawBuffer(IntPtr hstring, uint* length); [DllImport("api-ms-win-core-com-l1-1-1.dll", CallingConvention = CallingConvention.StdCall)] public unsafe static extern int RoGetAgileReference(uint options, Guid* iid, IntPtr unknown, IntPtr* agileReference); [DllImport("api-ms-win-core-com-l1-1-0.dll")] public unsafe static extern int CoGetContextToken(IntPtr* contextToken); [DllImport("api-ms-win-core-com-l1-1-0.dll")] public unsafe static extern int CoGetObjectContext(Guid* riid, IntPtr* ppv); [DllImport("oleaut32.dll")] public static extern int SetErrorInfo(uint dwReserved, IntPtr perrinfo); [DllImport("api-ms-win-core-com-l1-1-0.dll")] public unsafe static extern int CoCreateFreeThreadedMarshaler(IntPtr outer, IntPtr* marshalerPtr); public static bool FreeLibrary(IntPtr moduleHandle) { return LibraryImportStubs.FreeLibrary(moduleHandle); } public unsafe static IntPtr TryGetProcAddress(IntPtr moduleHandle, ReadOnlySpan functionName) { fixed (byte* functionName2 = functionName) { return LibraryImportStubs.GetProcAddress(moduleHandle, (sbyte*)functionName2); } } public static IntPtr GetProcAddress(IntPtr moduleHandle, ReadOnlySpan functionName) { IntPtr intPtr = TryGetProcAddress(moduleHandle, functionName); if (intPtr == IntPtr.Zero) { Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error(), new IntPtr(-1)); } return intPtr; } public unsafe static IntPtr LoadLibraryExW(string fileName, IntPtr fileHandle, uint flags) { fixed (char* fileName2 = fileName) { return LibraryImportStubs.LoadLibraryExW((ushort*)fileName2, fileHandle, flags); } } } internal static class LibraryImportStubs { public static bool FreeLibrary(IntPtr moduleHandle) { Marshal.SetLastSystemError(0); int num = PInvoke(moduleHandle); int lastSystemError = Marshal.GetLastSystemError(); bool result = num != 0; Marshal.SetLastPInvokeError(lastSystemError); return result; [DllImport("kernel32.dll", EntryPoint = "FreeLibrary", ExactSpelling = true)] static extern int PInvoke(IntPtr nativeModuleHandle); } public unsafe static IntPtr GetProcAddress(IntPtr moduleHandle, sbyte* functionName) { Marshal.SetLastSystemError(0); IntPtr result = PInvoke(moduleHandle, functionName); int lastSystemError = Marshal.GetLastSystemError(); Marshal.SetLastPInvokeError(lastSystemError); return result; [DllImport("kernel32.dll", EntryPoint = "GetProcAddress", ExactSpelling = true)] static extern unsafe IntPtr PInvoke(IntPtr nativeModuleHandle, sbyte* nativeFunctionName); } public unsafe static IntPtr LoadLibraryExW(ushort* fileName, IntPtr fileHandle, uint flags) { Marshal.SetLastSystemError(0); IntPtr result = PInvoke(fileName, fileHandle, flags); int lastSystemError = Marshal.GetLastSystemError(); Marshal.SetLastPInvokeError(lastSystemError); return result; [DllImport("kernel32.dll", EntryPoint = "LoadLibraryExW", ExactSpelling = true)] static extern unsafe IntPtr PInvoke(ushort* nativeFileName, IntPtr nativeFileHandle, uint nativeFlags); } } }