diff --git a/src/Authoring/WinRT.SourceGenerator/AotOptimizer.cs b/src/Authoring/WinRT.SourceGenerator/AotOptimizer.cs index 027618f9d..159320cb7 100644 --- a/src/Authoring/WinRT.SourceGenerator/AotOptimizer.cs +++ b/src/Authoring/WinRT.SourceGenerator/AotOptimizer.cs @@ -20,17 +20,28 @@ public void Initialize(IncrementalGeneratorInitializationContext context) { var properties = context.AnalyzerConfigOptionsProvider.Select(static (provider, _) => (provider.IsCsWinRTAotOptimizerEnabled(), provider.IsCsWinRTComponent())); - var vtableAttributesToAdd = context.SyntaxProvider.CreateSyntaxProvider( + var typeMapper = context.AnalyzerConfigOptionsProvider.Select((options, ct) => options.GlobalOptions.GetUiXamlMode()).Select((mode, ct) => new TypeMapper(mode)); + + var possibleVtableAttributesToAdd = context.SyntaxProvider.CreateSyntaxProvider( static (n, _) => NeedVtableAttribute(n), - static (n, _) => GetVtableAttributeToAdd(n) - ).Where(vtableAttribute => vtableAttribute != null); + static (n, _) => n + ); + + var vtableAttributesToAdd = possibleVtableAttributesToAdd + .Combine(typeMapper) + .Select((data, ct) => GetVtableAttributeToAdd(data.Left, data.Right)) + .Where(n => n is not null); context.RegisterImplementationSourceOutput(vtableAttributesToAdd.Collect().Combine(properties), GenerateVtableAttributes); - var vtablesToAddOnLookupTable = context.SyntaxProvider.CreateSyntaxProvider( + var possibleVtablesToAddOnLookupTable = context.SyntaxProvider.CreateSyntaxProvider( static (n, _) => NeedVtableOnLookupTable(n), - static (n, _) => GetVtableAttributesToAddOnLookupTable(n) - ).Where(vtableAttribute => vtableAttribute != null); + static (n, _) => n); + + var vtablesToAddOnLookupTable = possibleVtablesToAddOnLookupTable + .Combine(typeMapper) + .Select((data, ct) => GetVtableAttributesToAddOnLookupTable(data.Left, data.Right)) + .Where(vtableAttribute => vtableAttribute != null); var genericInterfacesFromVtableAttribute = vtableAttributesToAdd.SelectMany(static (vtableAttribute, _) => vtableAttribute.GenericInterfaces).Collect(); var genericInterfacesFromVtableLookupTable = vtablesToAddOnLookupTable.SelectMany(static (vtable, _) => vtable.SelectMany(v => v.GenericInterfaces)).Collect(); @@ -52,10 +63,10 @@ private static bool NeedVtableAttribute(SyntaxNode node) !GeneratorHelper.IsWinRTType(declaration); // Making sure it isn't an RCW we are projecting. } - private static VtableAttribute GetVtableAttributeToAdd(GeneratorSyntaxContext context) + private static VtableAttribute GetVtableAttributeToAdd(GeneratorSyntaxContext context, TypeMapper typeMapper) { var symbol = context.SemanticModel.GetDeclaredSymbol(context.Node as ClassDeclarationSyntax); - return GetVtableAttributeToAdd(symbol, GeneratorHelper.IsWinRTType, context.SemanticModel.Compilation.Assembly, false); + return GetVtableAttributeToAdd(symbol, GeneratorHelper.IsWinRTType, typeMapper, context.SemanticModel.Compilation.Assembly, false); } private static string ToFullyQualifiedString(ISymbol symbol) @@ -88,7 +99,7 @@ private static string ToVtableLookupString(ISymbol symbol) } } - internal static VtableAttribute GetVtableAttributeToAdd(ITypeSymbol symbol, Func isWinRTType, IAssemblySymbol assemblySymbol, bool isAuthoring, string authoringDefaultInterface = "") + internal static VtableAttribute GetVtableAttributeToAdd(ITypeSymbol symbol, Func isWinRTType, TypeMapper mapper, IAssemblySymbol assemblySymbol, bool isAuthoring, string authoringDefaultInterface = "") { if (GeneratorHelper.HasNonInstantiatedGeneric(symbol) || GeneratorHelper.HasPrivateclass(symbol)) { @@ -105,13 +116,13 @@ internal static VtableAttribute GetVtableAttributeToAdd(ITypeSymbol symbol, Func foreach (var iface in symbol.AllInterfaces) { - if (isWinRTType(iface)) + if (isWinRTType(iface, mapper)) { interfacesToAddToVtable.Add(ToFullyQualifiedString(iface)); AddGenericInterfaceInstantiation(iface); } - if (iface.IsGenericType && TryGetCompatibleWindowsRuntimeTypesForVariantType(iface, null, isWinRTType, out var compatibleIfaces)) + if (iface.IsGenericType && TryGetCompatibleWindowsRuntimeTypesForVariantType(iface, mapper, null, isWinRTType, out var compatibleIfaces)) { foreach (var compatibleIface in compatibleIfaces) { @@ -181,7 +192,7 @@ void AddGenericInterfaceInstantiation(INamedTypeSymbol iface) genericParameters.Add(new GenericParameter( ToFullyQualifiedString(genericParameter), - GeneratorHelper.GetAbiType(genericParameter), + GeneratorHelper.GetAbiType(genericParameter, mapper), genericParameter.TypeKind)); } @@ -199,7 +210,7 @@ bool IsExternalInternalInterface(INamedTypeSymbol iface) } } - private static bool TryGetCompatibleWindowsRuntimeTypesForVariantType(INamedTypeSymbol type, Stack typeStack, Func isWinRTType, out IList compatibleTypes) + private static bool TryGetCompatibleWindowsRuntimeTypesForVariantType(INamedTypeSymbol type, TypeMapper mapper, Stack typeStack, Func isWinRTType, out IList compatibleTypes) { compatibleTypes = null; @@ -212,7 +223,7 @@ private static bool TryGetCompatibleWindowsRuntimeTypesForVariantType(INamedType } var definition = type.OriginalDefinition; - if (!isWinRTType(definition)) + if (!isWinRTType(definition, mapper)) { return false; } @@ -232,20 +243,20 @@ private static bool TryGetCompatibleWindowsRuntimeTypesForVariantType(INamedType HashSet compatibleTypesForGeneric = new(SymbolEqualityComparer.Default); - if (isWinRTType(type.TypeArguments[0])) + if (isWinRTType(type.TypeArguments[0], mapper)) { compatibleTypesForGeneric.Add(type.TypeArguments[0]); } foreach (var iface in type.TypeArguments[0].AllInterfaces) { - if (isWinRTType(iface)) + if (isWinRTType(iface, mapper)) { compatibleTypesForGeneric.Add(iface); } if (iface.IsGenericType - && TryGetCompatibleWindowsRuntimeTypesForVariantType(iface, typeStack, isWinRTType, out var compatibleIfaces)) + && TryGetCompatibleWindowsRuntimeTypesForVariantType(iface, mapper, typeStack, isWinRTType, out var compatibleIfaces)) { compatibleTypesForGeneric.UnionWith(compatibleIfaces); } @@ -254,7 +265,7 @@ private static bool TryGetCompatibleWindowsRuntimeTypesForVariantType(INamedType var baseType = type.TypeArguments[0].BaseType; while (baseType != null) { - if (isWinRTType(baseType)) + if (isWinRTType(baseType, mapper)) { compatibleTypesForGeneric.Add(baseType); } @@ -488,7 +499,7 @@ private static bool NeedVtableOnLookupTable(SyntaxNode node) node is AssignmentExpressionSyntax; } - private static List GetVtableAttributesToAddOnLookupTable(GeneratorSyntaxContext context) + private static List GetVtableAttributesToAddOnLookupTable(GeneratorSyntaxContext context, TypeMapper mapper) { HashSet vtableAttributes = new(); @@ -496,7 +507,7 @@ private static List GetVtableAttributesToAddOnLookupTable(Gener { var invocationSymbol = context.SemanticModel.GetSymbolInfo(invocation.Expression).Symbol; // Check if function is within a CsWinRT projected class or interface. - if (invocationSymbol is IMethodSymbol methodSymbol && GeneratorHelper.IsWinRTType(methodSymbol.ContainingSymbol)) + if (invocationSymbol is IMethodSymbol methodSymbol && GeneratorHelper.IsWinRTType(methodSymbol.ContainingSymbol, mapper)) { // Get the concrete types directly from the argument rather than // using what the method accepts, which might just be an interface, so @@ -515,14 +526,14 @@ private static List GetVtableAttributesToAddOnLookupTable(Gener { if (methodSymbol.Parameters[paramsIdx].Type is not IArrayTypeSymbol) { - var vtableAtribute = GetVtableAttributeToAdd(arrayType, GeneratorHelper.IsWinRTType, context.SemanticModel.Compilation.Assembly, false); + var vtableAtribute = GetVtableAttributeToAdd(arrayType, GeneratorHelper.IsWinRTType, mapper, context.SemanticModel.Compilation.Assembly, false); if (vtableAtribute != default) { vtableAttributes.Add(vtableAtribute); } // Also add the enumerator type to the lookup table as the native caller may call it. - AddEnumeratorAdapterForType(arrayType.ElementType, context.SemanticModel, vtableAttributes); + AddEnumeratorAdapterForType(arrayType.ElementType, mapper, context.SemanticModel, vtableAttributes); } } else if (argumentType.Type is not null) @@ -532,10 +543,10 @@ private static List GetVtableAttributesToAddOnLookupTable(Gener // This handles the case where a generic delegate is passed. if (argumentClassTypeSymbol.TypeKind == TypeKind.Delegate && argumentClassTypeSymbol.MetadataName.Contains("`") && - GeneratorHelper.IsWinRTType(argumentClassTypeSymbol)) + GeneratorHelper.IsWinRTType(argumentClassTypeSymbol, mapper)) { var argumentClassNamedTypeSymbol = argumentClassTypeSymbol as INamedTypeSymbol; - vtableAttributes.Add(GetVtableAttributeToAdd(argumentClassTypeSymbol, GeneratorHelper.IsWinRTType, context.SemanticModel.Compilation.Assembly, false)); + vtableAttributes.Add(GetVtableAttributeToAdd(argumentClassTypeSymbol, GeneratorHelper.IsWinRTType, mapper, context.SemanticModel.Compilation.Assembly, false)); } // This handles the case where the source generator wasn't able to run @@ -548,19 +559,19 @@ private static List GetVtableAttributesToAddOnLookupTable(Gener // we handle it here. if (argumentClassTypeSymbol.TypeKind == TypeKind.Class && (argumentClassTypeSymbol.MetadataName.Contains("`") || - (!GeneratorHelper.IsWinRTType(argumentClassTypeSymbol) && + (!GeneratorHelper.IsWinRTType(argumentClassTypeSymbol, mapper) && !GeneratorHelper.HasWinRTExposedTypeAttribute(argumentClassTypeSymbol) && // If the type is defined in the same assembly as what the source generator is running on, // we let the WinRTExposedType attribute generator handle it. !SymbolEqualityComparer.Default.Equals(argumentClassTypeSymbol.ContainingAssembly, context.SemanticModel.Compilation.Assembly)))) { - var vtableAtribute = GetVtableAttributeToAdd(argumentClassTypeSymbol, GeneratorHelper.IsWinRTType, context.SemanticModel.Compilation.Assembly, false); + var vtableAtribute = GetVtableAttributeToAdd(argumentClassTypeSymbol, GeneratorHelper.IsWinRTType, mapper, context.SemanticModel.Compilation.Assembly, false); if (vtableAtribute != default) { vtableAttributes.Add(vtableAtribute); } - AddEnumeratorAdapterForEnumerableInterface(argumentClassTypeSymbol, context.SemanticModel, vtableAttributes); + AddEnumeratorAdapterForEnumerableInterface(argumentClassTypeSymbol, mapper, context.SemanticModel, vtableAttributes); } } } @@ -577,12 +588,12 @@ private static List GetVtableAttributesToAddOnLookupTable(Gener // This handles the async calls scenario where // the awaiter will register a completed handler which can be // a generic. - if (GeneratorHelper.IsWinRTType(methodSymbol.ReturnType)) + if (GeneratorHelper.IsWinRTType(methodSymbol.ReturnType, mapper)) { var completedProperty = methodSymbol.ReturnType.GetMembers("Completed").FirstOrDefault() as IPropertySymbol; if (completedProperty != null && completedProperty.Type.MetadataName.Contains("Async") && completedProperty.Type.MetadataName.Contains("`")) { - vtableAttributes.Add(GetVtableAttributeToAdd(completedProperty.Type, GeneratorHelper.IsWinRTType, context.SemanticModel.Compilation.Assembly, false)); + vtableAttributes.Add(GetVtableAttributeToAdd(completedProperty.Type, GeneratorHelper.IsWinRTType, mapper, context.SemanticModel.Compilation.Assembly, false)); } } } @@ -593,7 +604,7 @@ private static List GetVtableAttributesToAddOnLookupTable(Gener // Check if property being assigned to is within a CsWinRT projected class or interface. if (leftSymbol is IPropertySymbol propertySymbol && - GeneratorHelper.IsWinRTType(propertySymbol.ContainingSymbol)) + GeneratorHelper.IsWinRTType(propertySymbol.ContainingSymbol, mapper)) { var argumentType = context.SemanticModel.GetTypeInfo(assignment.Right); @@ -604,14 +615,14 @@ private static List GetVtableAttributesToAddOnLookupTable(Gener { if (propertySymbol.Type is not IArrayTypeSymbol) { - var vtableAtribute = GetVtableAttributeToAdd(arrayType, GeneratorHelper.IsWinRTType, context.SemanticModel.Compilation.Assembly, false); + var vtableAtribute = GetVtableAttributeToAdd(arrayType, GeneratorHelper.IsWinRTType, mapper, context.SemanticModel.Compilation.Assembly, false); if (vtableAtribute != default) { vtableAttributes.Add(vtableAtribute); } // Also add the enumerator type to the lookup table as the native caller can call it. - AddEnumeratorAdapterForType(arrayType.ElementType, context.SemanticModel, vtableAttributes); + AddEnumeratorAdapterForType(arrayType.ElementType, mapper, context.SemanticModel, vtableAttributes); } } else if (argumentType.Type is not null || argumentType.ConvertedType is not null) @@ -623,38 +634,38 @@ private static List GetVtableAttributesToAddOnLookupTable(Gener // WinRT type meaning we will need to probably create a CCW for. if (argumentClassTypeSymbol.TypeKind == TypeKind.Delegate && argumentClassTypeSymbol.MetadataName.Contains("`") && - GeneratorHelper.IsWinRTType(argumentClassTypeSymbol)) + GeneratorHelper.IsWinRTType(argumentClassTypeSymbol, mapper)) { var argumentClassNamedTypeSymbol = argumentClassTypeSymbol as INamedTypeSymbol; - vtableAttributes.Add(GetVtableAttributeToAdd(argumentClassTypeSymbol, GeneratorHelper.IsWinRTType, context.SemanticModel.Compilation.Assembly, false)); + vtableAttributes.Add(GetVtableAttributeToAdd(argumentClassTypeSymbol, GeneratorHelper.IsWinRTType, mapper, context.SemanticModel.Compilation.Assembly, false)); } if (argumentClassTypeSymbol.TypeKind == TypeKind.Class && (argumentClassTypeSymbol.MetadataName.Contains("`") || - (!GeneratorHelper.IsWinRTType(argumentClassTypeSymbol) && + (!GeneratorHelper.IsWinRTType(argumentClassTypeSymbol, mapper) && !GeneratorHelper.HasWinRTExposedTypeAttribute(argumentClassTypeSymbol) && // If the type is defined in the same assembly as what the source generator is running on, // we let the WinRTExposedType attribute generator handle it. !SymbolEqualityComparer.Default.Equals(argumentClassTypeSymbol.ContainingAssembly, context.SemanticModel.Compilation.Assembly)))) { - var vtableAtribute = GetVtableAttributeToAdd(argumentClassTypeSymbol, GeneratorHelper.IsWinRTType, context.SemanticModel.Compilation.Assembly, false); + var vtableAtribute = GetVtableAttributeToAdd(argumentClassTypeSymbol, GeneratorHelper.IsWinRTType, mapper, context.SemanticModel.Compilation.Assembly, false); if (vtableAtribute != default) { vtableAttributes.Add(vtableAtribute); } - AddEnumeratorAdapterForEnumerableInterface(argumentClassTypeSymbol, context.SemanticModel, vtableAttributes); + AddEnumeratorAdapterForEnumerableInterface(argumentClassTypeSymbol, mapper, context.SemanticModel, vtableAttributes); } } } // This handles the class.event += event scenario where the event // can be generic and not have the have the WinRTExposedType attribute. else if (leftSymbol is IEventSymbol eventSymbol && - GeneratorHelper.IsWinRTType(eventSymbol.ContainingSymbol) && + GeneratorHelper.IsWinRTType(eventSymbol.ContainingSymbol, mapper) && eventSymbol.Type.MetadataName.Contains("`") && - GeneratorHelper.IsWinRTType(eventSymbol.Type)) + GeneratorHelper.IsWinRTType(eventSymbol.Type, mapper)) { - var vtableAtribute = GetVtableAttributeToAdd(eventSymbol.Type, GeneratorHelper.IsWinRTType, context.SemanticModel.Compilation.Assembly, false); + var vtableAtribute = GetVtableAttributeToAdd(eventSymbol.Type, GeneratorHelper.IsWinRTType, mapper, context.SemanticModel.Compilation.Assembly, false); if (vtableAtribute != default) { vtableAttributes.Add(vtableAtribute); @@ -668,11 +679,11 @@ private static List GetVtableAttributesToAddOnLookupTable(Gener // Any of the IEnumerable interfaces on the vtable can be used to get the enumerator. Given IEnumerable is // a covariant interface, it means that we can end up getting an instance of the enumerable adapter for any one // of those covariant interfaces and thereby need vtable lookup entries for all of them. - private static void AddEnumeratorAdapterForType(ITypeSymbol type, SemanticModel semanticModel, HashSet vtableAttributes) + private static void AddEnumeratorAdapterForType(ITypeSymbol type, TypeMapper mapper, SemanticModel semanticModel, HashSet vtableAttributes) { var enumerableType = semanticModel.Compilation.GetTypeByMetadataName("System.Collections.Generic.IEnumerable`1"). Construct(type); - if (TryGetCompatibleWindowsRuntimeTypesForVariantType(enumerableType, null, GeneratorHelper.IsWinRTType, out var compatibleIfaces)) + if (TryGetCompatibleWindowsRuntimeTypesForVariantType(enumerableType, mapper, null, GeneratorHelper.IsWinRTType, out var compatibleIfaces)) { foreach (var compatibleIface in compatibleIfaces) { @@ -681,20 +692,20 @@ private static void AddEnumeratorAdapterForType(ITypeSymbol type, SemanticModel { var enumeratorAdapterType = semanticModel.Compilation.GetTypeByMetadataName("ABI.System.Collections.Generic.ToAbiEnumeratorAdapter`1"). Construct(compatibleIface.TypeArguments[0]); - vtableAttributes.Add(GetVtableAttributeToAdd(enumeratorAdapterType, GeneratorHelper.IsWinRTType, semanticModel.Compilation.Assembly, false)); + vtableAttributes.Add(GetVtableAttributeToAdd(enumeratorAdapterType, GeneratorHelper.IsWinRTType, mapper, semanticModel.Compilation.Assembly, false)); } } } } - private static void AddEnumeratorAdapterForEnumerableInterface(ITypeSymbol classType, SemanticModel semanticModel, HashSet vtableAttributes) + private static void AddEnumeratorAdapterForEnumerableInterface(ITypeSymbol classType, TypeMapper mapper, SemanticModel semanticModel, HashSet vtableAttributes) { // Type may implement multiple unique IEnumerable interfaces. foreach (var iface in classType.AllInterfaces) { if (iface.MetadataName == "IEnumerable`1") { - AddEnumeratorAdapterForType(iface.TypeArguments[0], semanticModel, vtableAttributes); + AddEnumeratorAdapterForType(iface.TypeArguments[0], mapper, semanticModel, vtableAttributes); } } } diff --git a/src/Authoring/WinRT.SourceGenerator/DiagnosticUtils.cs b/src/Authoring/WinRT.SourceGenerator/DiagnosticUtils.cs index 9c2215de1..528bd1598 100644 --- a/src/Authoring/WinRT.SourceGenerator/DiagnosticUtils.cs +++ b/src/Authoring/WinRT.SourceGenerator/DiagnosticUtils.cs @@ -16,11 +16,13 @@ public WinRTComponentScanner(GeneratorExecutionContext context, string assemblyN _assemblyName = assemblyName; _context = context; _flag = false; + _typeMapper = new TypeMapper(context.AnalyzerConfigOptions.GlobalOptions.GetUiXamlMode()); } private readonly string _assemblyName; private readonly GeneratorExecutionContext _context; private bool _flag; + private readonly TypeMapper _typeMapper; public bool Found() { return _flag; } @@ -105,7 +107,7 @@ private void CheckDeclarations() var props = @class.DescendantNodes().OfType().Where(IsPublic); // filter out methods and properties that will be replaced with our custom type mappings - IgnoreCustomTypeMappings(classSymbol, ref publicMethods, ref props); + IgnoreCustomTypeMappings(classSymbol, _typeMapper, ref publicMethods, ref props); if (!classSymbol.IsSealed && !classSymbol.IsStatic) { @@ -137,7 +139,7 @@ private void CheckDeclarations() var props = @interface.DescendantNodes().OfType().Where(IsPublic); // filter out methods and properties that will be replaced with our custom type mappings - IgnoreCustomTypeMappings(interfaceSym, ref methods, ref props); + IgnoreCustomTypeMappings(interfaceSym, _typeMapper, ref methods, ref props); if (interfaceSym.IsGenericType) { @@ -206,6 +208,7 @@ private bool IsMethodImpl(IMethodSymbol m, IMethodSymbol interfaceMethod) } private void IgnoreCustomTypeMappings(INamedTypeSymbol typeSymbol, + TypeMapper typeMapper, ref IEnumerable methods, ref IEnumerable properties) { @@ -217,7 +220,7 @@ string QualifiedName(INamedTypeSymbol sym) HashSet classMethods = new(); foreach (var @interface in typeSymbol.AllInterfaces. - Where(symbol => GeneratorHelper.MappedCSharpTypes.ContainsKey(QualifiedName(symbol)) || + Where(symbol => typeMapper.HasMappingForType(QualifiedName(symbol)) || WinRTTypeWriter.ImplementedInterfacesWithoutMapping.Contains(QualifiedName(symbol)))) { foreach (var interfaceMember in @interface.GetMembers()) diff --git a/src/Authoring/WinRT.SourceGenerator/Generator.cs b/src/Authoring/WinRT.SourceGenerator/Generator.cs index 3bc10f2d2..90bb01286 100644 --- a/src/Authoring/WinRT.SourceGenerator/Generator.cs +++ b/src/Authoring/WinRT.SourceGenerator/Generator.cs @@ -20,11 +20,14 @@ public class ComponentGenerator private Logger Logger { get; } private readonly GeneratorExecutionContext context; private string tempFolder; + private readonly TypeMapper mapper; public ComponentGenerator(GeneratorExecutionContext context) { this.context = context; Logger = new Logger(context); + mapper = new(context.AnalyzerConfigOptions.GlobalOptions.GetUiXamlMode()); + // TODO-WuxMux: output a module initializer that validates the MUX/WUX projection mode to ensure that things don't get out of sync. } private string GetTempFolder(bool clearSourceFilesFromFolder = false) @@ -152,7 +155,8 @@ public void Generate() assembly, version, metadataBuilder, - Logger); + Logger, + mapper); WinRTSyntaxReceiver syntaxReceiver = (WinRTSyntaxReceiver)context.SyntaxReceiver; Logger.Log("Found " + syntaxReceiver.Declarations.Count + " types"); diff --git a/src/Authoring/WinRT.SourceGenerator/Helper.cs b/src/Authoring/WinRT.SourceGenerator/Helper.cs index 9ce98add8..a75bfe4c1 100644 --- a/src/Authoring/WinRT.SourceGenerator/Helper.cs +++ b/src/Authoring/WinRT.SourceGenerator/Helper.cs @@ -177,7 +177,7 @@ private static bool IsFundamentalType(ISymbol type) return type.ToDisplayString() == "System.Guid"; } - public static bool IsWinRTType(ISymbol type) + public static bool IsWinRTType(ISymbol type, TypeMapper mapper) { bool isProjectedType = type.GetAttributes(). Any(attribute => string.CompareOrdinal(attribute.AttributeClass.Name, "WindowsRuntimeTypeAttribute") == 0) || @@ -185,13 +185,13 @@ public static bool IsWinRTType(ISymbol type) if (!isProjectedType & type.ContainingNamespace != null) { - isProjectedType = MappedCSharpTypes.ContainsKey(string.Join(".", type.ContainingNamespace.ToDisplayString(), type.MetadataName)); + isProjectedType = mapper.HasMappingForType(string.Join(".", type.ContainingNamespace.ToDisplayString(), type.MetadataName)); } // Ensure all generic parameters are WinRT types. if (isProjectedType && type is INamedTypeSymbol namedType && namedType.IsGenericType && !namedType.IsDefinition) { - isProjectedType = namedType.TypeArguments.All(IsWinRTType); + isProjectedType = namedType.TypeArguments.All(type => IsWinRTType(type, mapper)); } return isProjectedType; } @@ -262,7 +262,7 @@ private static string GetAbiTypeForFundamentalType(ISymbol type) return type.ToDisplayString(); } - public static bool IsBlittableValueType(ITypeSymbol type) + public static bool IsBlittableValueType(ITypeSymbol type, TypeMapper typeMapper) { if (!type.IsValueType) { @@ -292,9 +292,9 @@ public static bool IsBlittableValueType(ITypeSymbol type) } string customTypeMapKey = string.Join(".", type.ContainingNamespace.ToDisplayString(), type.MetadataName); - if (MappedCSharpTypes.ContainsKey(customTypeMapKey)) + if (typeMapper.HasMappingForType(customTypeMapKey)) { - return MappedCSharpTypes[customTypeMapKey].IsBlittable(); + return typeMapper.GetMappedType(customTypeMapKey).IsBlittable(); } if (type.TypeKind == TypeKind.Enum) @@ -306,7 +306,7 @@ public static bool IsBlittableValueType(ITypeSymbol type) { foreach (var typeMember in type.GetMembers()) { - if (typeMember is IFieldSymbol field && !IsBlittableValueType(field.Type)) + if (typeMember is IFieldSymbol field && !IsBlittableValueType(field.Type, typeMapper)) { return false; } @@ -315,7 +315,7 @@ public static bool IsBlittableValueType(ITypeSymbol type) return true; } - public static string GetAbiType(ITypeSymbol type) + public static string GetAbiType(ITypeSymbol type, TypeMapper mapper) { if (IsFundamentalType(type)) { @@ -335,9 +335,9 @@ public static string GetAbiType(ITypeSymbol type) if (type.IsValueType) { string customTypeMapKey = string.Join(".", type.ContainingNamespace.ToDisplayString(), type.MetadataName); - if (MappedCSharpTypes.ContainsKey(customTypeMapKey)) + if (mapper.HasMappingForType(customTypeMapKey)) { - string prefix = MappedCSharpTypes[customTypeMapKey].IsBlittable() ? "" : "ABI."; + string prefix = mapper.GetMappedType(customTypeMapKey).IsBlittable() ? "" : "ABI."; return prefix + typeStr; } @@ -352,7 +352,7 @@ public static string GetAbiType(ITypeSymbol type) // Handling authoring scenario where Impl type has the attributes and // if the current component is the one being authored, it may not be // generated yet to check given it is the same compilation. - else if (!IsBlittableValueType(type)) + else if (!IsBlittableValueType(type, mapper)) { return "ABI." + typeStr; } @@ -698,65 +698,5 @@ public bool IsBlittable() return isValueType && isBlittable; } } - - // Based on whether System.Type is used in an attribute declaration or elsewhere, we need to choose the correct custom mapping - // as attributes don't use the TypeName mapping. - internal static (string, string, string, bool, bool) GetSystemTypeCustomMapping(ISymbol containingSymbol) - { - bool isDefinedInAttribute = - containingSymbol != null && - string.CompareOrdinal((containingSymbol as INamedTypeSymbol).BaseType?.ToString(), "System.Attribute") == 0; - return isDefinedInAttribute ? - ("System", "Type", "mscorlib", true, false) : - ("Windows.UI.Xaml.Interop", "TypeName", "Windows.Foundation.UniversalApiContract", false, true); - } - - // This should be in sync with the reverse mapping from WinRT.Runtime/Projections.cs and cswinrt/helpers.h. - // TODO-WuxMux: Update this table to respect a property the defines WUX vs MUX projections. - // Additionally, output a module initializer that validates the MUX/WUX projection mode to ensure that things don't get out of sync. - public static readonly Dictionary MappedCSharpTypes = new(StringComparer.Ordinal) - { - { "System.DateTimeOffset", new MappedType("Windows.Foundation", "DateTime", "Windows.Foundation.FoundationContract", true, false) }, - { "System.Exception", new MappedType("Windows.Foundation", "HResult", "Windows.Foundation.FoundationContract", true, false) }, - { "System.EventHandler`1", new MappedType("Windows.Foundation", "EventHandler`1", "Windows.Foundation.FoundationContract") }, - { "System.FlagsAttribute", new MappedType("System", "FlagsAttribute", "mscorlib" ) }, - { "System.IDisposable", new MappedType("Windows.Foundation", "IClosable", "Windows.Foundation.FoundationContract") }, - { "System.IServiceProvider", new MappedType("Microsoft.UI.Xaml", "IXamlServiceProvider", "Microsoft.UI") }, - { "System.Nullable`1", new MappedType("Windows.Foundation", "IReference`1", "Windows.Foundation.FoundationContract" ) }, - { "System.Object", new MappedType("System", "Object", "mscorlib" ) }, - { "System.TimeSpan", new MappedType("Windows.Foundation", "TimeSpan", "Windows.Foundation.FoundationContract", true, false) }, - { "System.Uri", new MappedType("Windows.Foundation", "Uri", "Windows.Foundation.FoundationContract") }, - { "System.ComponentModel.DataErrorsChangedEventArgs", new MappedType("Microsoft.UI.Xaml.Data", "DataErrorsChangedEventArgs", "Microsoft.UI") }, - { "System.ComponentModel.INotifyDataErrorInfo", new MappedType("Microsoft.UI.Xaml.Data", "INotifyDataErrorInfo", "Microsoft.UI") }, - { "System.ComponentModel.INotifyPropertyChanged", new MappedType("Microsoft.UI.Xaml.Data", "INotifyPropertyChanged", "Microsoft.UI") }, - { "System.ComponentModel.PropertyChangedEventArgs", new MappedType("Microsoft.UI.Xaml.Data", "PropertyChangedEventArgs", "Microsoft.UI") }, - { "System.ComponentModel.PropertyChangedEventHandler", new MappedType("Microsoft.UI.Xaml.Data", "PropertyChangedEventHandler", "Microsoft.UI") }, - { "System.Windows.Input.ICommand", new MappedType("Microsoft.UI.Xaml.Input", "ICommand", "Microsoft.UI") }, - { "System.Collections.IEnumerable", new MappedType("Microsoft.UI.Xaml.Interop", "IBindableIterable", "Microsoft.UI") }, - { "System.Collections.IList", new MappedType("Microsoft.UI.Xaml.Interop", "IBindableVector", "Microsoft.UI") }, - { "System.Collections.Specialized.INotifyCollectionChanged", new MappedType("Microsoft.UI.Xaml.Interop", "INotifyCollectionChanged", "Microsoft.UI") }, - { "System.Collections.Specialized.NotifyCollectionChangedAction", new MappedType("Microsoft.UI.Xaml.Interop", "NotifyCollectionChangedAction", "Microsoft.UI") }, - { "System.Collections.Specialized.NotifyCollectionChangedEventArgs", new MappedType("Microsoft.UI.Xaml.Interop", "NotifyCollectionChangedEventArgs", "Microsoft.UI") }, - { "System.Collections.Specialized.NotifyCollectionChangedEventHandler", new MappedType("Microsoft.UI.Xaml.Interop", "NotifyCollectionChangedEventHandler", "Microsoft.UI") }, - { "WinRT.EventRegistrationToken", new MappedType("Windows.Foundation", "EventRegistrationToken", "Windows.Foundation.FoundationContract", true, true) }, - { "System.AttributeTargets", new MappedType("Windows.Foundation.Metadata", "AttributeTargets", "Windows.Foundation.FoundationContract", true, true) }, - { "System.AttributeUsageAttribute", new MappedType("Windows.Foundation.Metadata", "AttributeUsageAttribute", "Windows.Foundation.FoundationContract") }, - { "System.Numerics.Matrix3x2", new MappedType("Windows.Foundation.Numerics", "Matrix3x2", "Windows.Foundation.FoundationContract", true, true) }, - { "System.Numerics.Matrix4x4", new MappedType("Windows.Foundation.Numerics", "Matrix4x4", "Windows.Foundation.FoundationContract", true, true) }, - { "System.Numerics.Plane", new MappedType("Windows.Foundation.Numerics", "Plane", "Windows.Foundation.FoundationContract", true, true) }, - { "System.Numerics.Quaternion", new MappedType("Windows.Foundation.Numerics", "Quaternion", "Windows.Foundation.FoundationContract", true, true) }, - { "System.Numerics.Vector2", new MappedType("Windows.Foundation.Numerics", "Vector2", "Windows.Foundation.FoundationContract", true, true) }, - { "System.Numerics.Vector3", new MappedType("Windows.Foundation.Numerics", "Vector3", "Windows.Foundation.FoundationContract", true, true) }, - { "System.Numerics.Vector4", new MappedType("Windows.Foundation.Numerics", "Vector4", "Windows.Foundation.FoundationContract", true, true) }, - { "System.Type", new MappedType(GetSystemTypeCustomMapping) }, - { "System.Collections.Generic.IEnumerable`1", new MappedType("Windows.Foundation.Collections", "IIterable`1", "Windows.Foundation.FoundationContract") }, - { "System.Collections.Generic.IEnumerator`1", new MappedType("Windows.Foundation.Collections", "IIterator`1", "Windows.Foundation.FoundationContract") }, - { "System.Collections.Generic.KeyValuePair`2", new MappedType("Windows.Foundation.Collections", "IKeyValuePair`2", "Windows.Foundation.FoundationContract") }, - { "System.Collections.Generic.IReadOnlyDictionary`2", new MappedType("Windows.Foundation.Collections", "IMapView`2", "Windows.Foundation.FoundationContract") }, - { "System.Collections.Generic.IDictionary`2", new MappedType("Windows.Foundation.Collections", "IMap`2", "Windows.Foundation.FoundationContract") }, - { "System.Collections.Generic.IReadOnlyList`1", new MappedType("Windows.Foundation.Collections", "IVectorView`1", "Windows.Foundation.FoundationContract") }, - { "System.Collections.Generic.IList`1", new MappedType("Windows.Foundation.Collections", "IVector`1", "Windows.Foundation.FoundationContract") }, - { "Windows.UI.Color", new MappedType("Windows.UI", "Color", "Windows.Foundation.UniversalApiContract", true, true) }, - }; } } diff --git a/src/Authoring/WinRT.SourceGenerator/TypeMapper.cs b/src/Authoring/WinRT.SourceGenerator/TypeMapper.cs new file mode 100644 index 000000000..e35ccc63e --- /dev/null +++ b/src/Authoring/WinRT.SourceGenerator/TypeMapper.cs @@ -0,0 +1,125 @@ +using Microsoft.CodeAnalysis; +using System; +using System.Collections.Generic; +using System.Text; +using static Generator.GeneratorHelper; + +namespace Generator +{ + internal sealed class TypeMapper + { + private readonly Dictionary typeMapping; + + // Based on whether System.Type is used in an attribute declaration or elsewhere, we need to choose the correct custom mapping + // as attributes don't use the TypeName mapping. + private static (string, string, string, bool, bool) GetSystemTypeCustomMapping(ISymbol containingSymbol) + { + bool isDefinedInAttribute = + containingSymbol != null && + string.CompareOrdinal((containingSymbol as INamedTypeSymbol).BaseType?.ToString(), "System.Attribute") == 0; + return isDefinedInAttribute ? + ("System", "Type", "mscorlib", true, false) : + ("Windows.UI.Xaml.Interop", "TypeName", "Windows.Foundation.UniversalApiContract", false, true); + } + + public TypeMapper(UiXamlMode xamlMode) + { + // This should be in sync with the reverse mapping from WinRT.Runtime/Projections.cs and cswinrt/helpers.h. + if (xamlMode == UiXamlMode.WindowsUiXaml) + { + typeMapping = new(StringComparer.Ordinal) + { + { "System.DateTimeOffset", new MappedType("Windows.Foundation", "DateTime", "Windows.Foundation.FoundationContract", true, false) }, + { "System.Exception", new MappedType("Windows.Foundation", "HResult", "Windows.Foundation.FoundationContract", true, false) }, + { "System.EventHandler`1", new MappedType("Windows.Foundation", "EventHandler`1", "Windows.Foundation.FoundationContract") }, + { "System.FlagsAttribute", new MappedType("System", "FlagsAttribute", "mscorlib" ) }, + { "System.IDisposable", new MappedType("Windows.Foundation", "IClosable", "Windows.Foundation.FoundationContract") }, + { "System.Nullable`1", new MappedType("Windows.Foundation", "IReference`1", "Windows.Foundation.FoundationContract" ) }, + { "System.Object", new MappedType("System", "Object", "mscorlib" ) }, + { "System.TimeSpan", new MappedType("Windows.Foundation", "TimeSpan", "Windows.Foundation.FoundationContract", true, false) }, + { "System.Uri", new MappedType("Windows.Foundation", "Uri", "Windows.Foundation.FoundationContract") }, + { "System.ComponentModel.INotifyPropertyChanged", new MappedType("Windows.UI.Xaml.Data", "INotifyPropertyChanged", "Windows.UI.Xaml") }, + { "System.ComponentModel.PropertyChangedEventArgs", new MappedType("Windows.UI.Xaml.Data", "PropertyChangedEventArgs", "Windows.UI.Xaml") }, + { "System.ComponentModel.PropertyChangedEventHandler", new MappedType("Windows.UI.Xaml.Data", "PropertyChangedEventHandler", "Windows.UI.Xaml") }, + { "System.Windows.Input.ICommand", new MappedType("Windows.UI.Xaml.Input", "ICommand", "Windows.UI.Xaml") }, + { "System.Collections.IEnumerable", new MappedType("Windows.UI.Xaml.Interop", "IBindableIterable", "Windows.UI.Xaml") }, + { "System.Collections.IList", new MappedType("Windows.UI.Xaml.Interop", "IBindableVector", "Windows.UI.Xaml") }, + { "System.Collections.Specialized.INotifyCollectionChanged", new MappedType("Windows.UI.Xaml.Interop", "INotifyCollectionChanged", "Windows.UI.Xaml") }, + { "System.Collections.Specialized.NotifyCollectionChangedAction", new MappedType("Windows.UI.Xaml.Interop", "NotifyCollectionChangedAction", "Windows.UI.Xaml") }, + { "System.Collections.Specialized.NotifyCollectionChangedEventArgs", new MappedType("Windows.UI.Xaml.Interop", "NotifyCollectionChangedEventArgs", "Windows.UI.Xaml") }, + { "System.Collections.Specialized.NotifyCollectionChangedEventHandler", new MappedType("Windows.UI.Xaml.Interop", "NotifyCollectionChangedEventHandler", "Windows.UI.Xaml") }, + { "WinRT.EventRegistrationToken", new MappedType("Windows.Foundation", "EventRegistrationToken", "Windows.Foundation.FoundationContract", true, true) }, + { "System.AttributeTargets", new MappedType("Windows.Foundation.Metadata", "AttributeTargets", "Windows.Foundation.FoundationContract", true, true) }, + { "System.AttributeUsageAttribute", new MappedType("Windows.Foundation.Metadata", "AttributeUsageAttribute", "Windows.Foundation.FoundationContract") }, + { "System.Numerics.Matrix3x2", new MappedType("Windows.Foundation.Numerics", "Matrix3x2", "Windows.Foundation.FoundationContract", true, true) }, + { "System.Numerics.Matrix4x4", new MappedType("Windows.Foundation.Numerics", "Matrix4x4", "Windows.Foundation.FoundationContract", true, true) }, + { "System.Numerics.Plane", new MappedType("Windows.Foundation.Numerics", "Plane", "Windows.Foundation.FoundationContract", true, true) }, + { "System.Numerics.Quaternion", new MappedType("Windows.Foundation.Numerics", "Quaternion", "Windows.Foundation.FoundationContract", true, true) }, + { "System.Numerics.Vector2", new MappedType("Windows.Foundation.Numerics", "Vector2", "Windows.Foundation.FoundationContract", true, true) }, + { "System.Numerics.Vector3", new MappedType("Windows.Foundation.Numerics", "Vector3", "Windows.Foundation.FoundationContract", true, true) }, + { "System.Numerics.Vector4", new MappedType("Windows.Foundation.Numerics", "Vector4", "Windows.Foundation.FoundationContract", true, true) }, + { "System.Type", new MappedType(GetSystemTypeCustomMapping) }, + { "System.Collections.Generic.IEnumerable`1", new MappedType("Windows.Foundation.Collections", "IIterable`1", "Windows.Foundation.FoundationContract") }, + { "System.Collections.Generic.IEnumerator`1", new MappedType("Windows.Foundation.Collections", "IIterator`1", "Windows.Foundation.FoundationContract") }, + { "System.Collections.Generic.KeyValuePair`2", new MappedType("Windows.Foundation.Collections", "IKeyValuePair`2", "Windows.Foundation.FoundationContract") }, + { "System.Collections.Generic.IReadOnlyDictionary`2", new MappedType("Windows.Foundation.Collections", "IMapView`2", "Windows.Foundation.FoundationContract") }, + { "System.Collections.Generic.IDictionary`2", new MappedType("Windows.Foundation.Collections", "IMap`2", "Windows.Foundation.FoundationContract") }, + { "System.Collections.Generic.IReadOnlyList`1", new MappedType("Windows.Foundation.Collections", "IVectorView`1", "Windows.Foundation.FoundationContract") }, + { "System.Collections.Generic.IList`1", new MappedType("Windows.Foundation.Collections", "IVector`1", "Windows.Foundation.FoundationContract") }, + { "Windows.UI.Color", new MappedType("Windows.UI", "Color", "Windows.Foundation.UniversalApiContract", true, true) }, + }; + } + else + { + typeMapping = new(StringComparer.Ordinal) + { + { "System.DateTimeOffset", new MappedType("Windows.Foundation", "DateTime", "Windows.Foundation.FoundationContract", true, false) }, + { "System.Exception", new MappedType("Windows.Foundation", "HResult", "Windows.Foundation.FoundationContract", true, false) }, + { "System.EventHandler`1", new MappedType("Windows.Foundation", "EventHandler`1", "Windows.Foundation.FoundationContract") }, + { "System.FlagsAttribute", new MappedType("System", "FlagsAttribute", "mscorlib" ) }, + { "System.IDisposable", new MappedType("Windows.Foundation", "IClosable", "Windows.Foundation.FoundationContract") }, + { "System.IServiceProvider", new MappedType("Microsoft.UI.Xaml", "IXamlServiceProvider", "Microsoft.UI") }, + { "System.Nullable`1", new MappedType("Windows.Foundation", "IReference`1", "Windows.Foundation.FoundationContract" ) }, + { "System.Object", new MappedType("System", "Object", "mscorlib" ) }, + { "System.TimeSpan", new MappedType("Windows.Foundation", "TimeSpan", "Windows.Foundation.FoundationContract", true, false) }, + { "System.Uri", new MappedType("Windows.Foundation", "Uri", "Windows.Foundation.FoundationContract") }, + { "System.ComponentModel.DataErrorsChangedEventArgs", new MappedType("Microsoft.UI.Xaml.Data", "DataErrorsChangedEventArgs", "Microsoft.UI") }, + { "System.ComponentModel.INotifyDataErrorInfo", new MappedType("Microsoft.UI.Xaml.Data", "INotifyDataErrorInfo", "Microsoft.UI") }, + { "System.ComponentModel.INotifyPropertyChanged", new MappedType("Microsoft.UI.Xaml.Data", "INotifyPropertyChanged", "Microsoft.UI") }, + { "System.ComponentModel.PropertyChangedEventArgs", new MappedType("Microsoft.UI.Xaml.Data", "PropertyChangedEventArgs", "Microsoft.UI") }, + { "System.ComponentModel.PropertyChangedEventHandler", new MappedType("Microsoft.UI.Xaml.Data", "PropertyChangedEventHandler", "Microsoft.UI") }, + { "System.Windows.Input.ICommand", new MappedType("Microsoft.UI.Xaml.Input", "ICommand", "Microsoft.UI") }, + { "System.Collections.IEnumerable", new MappedType("Microsoft.UI.Xaml.Interop", "IBindableIterable", "Microsoft.UI") }, + { "System.Collections.IList", new MappedType("Microsoft.UI.Xaml.Interop", "IBindableVector", "Microsoft.UI") }, + { "System.Collections.Specialized.INotifyCollectionChanged", new MappedType("Microsoft.UI.Xaml.Interop", "INotifyCollectionChanged", "Microsoft.UI") }, + { "System.Collections.Specialized.NotifyCollectionChangedAction", new MappedType("Microsoft.UI.Xaml.Interop", "NotifyCollectionChangedAction", "Microsoft.UI") }, + { "System.Collections.Specialized.NotifyCollectionChangedEventArgs", new MappedType("Microsoft.UI.Xaml.Interop", "NotifyCollectionChangedEventArgs", "Microsoft.UI") }, + { "System.Collections.Specialized.NotifyCollectionChangedEventHandler", new MappedType("Microsoft.UI.Xaml.Interop", "NotifyCollectionChangedEventHandler", "Microsoft.UI") }, + { "WinRT.EventRegistrationToken", new MappedType("Windows.Foundation", "EventRegistrationToken", "Windows.Foundation.FoundationContract", true, true) }, + { "System.AttributeTargets", new MappedType("Windows.Foundation.Metadata", "AttributeTargets", "Windows.Foundation.FoundationContract", true, true) }, + { "System.AttributeUsageAttribute", new MappedType("Windows.Foundation.Metadata", "AttributeUsageAttribute", "Windows.Foundation.FoundationContract") }, + { "System.Numerics.Matrix3x2", new MappedType("Windows.Foundation.Numerics", "Matrix3x2", "Windows.Foundation.FoundationContract", true, true) }, + { "System.Numerics.Matrix4x4", new MappedType("Windows.Foundation.Numerics", "Matrix4x4", "Windows.Foundation.FoundationContract", true, true) }, + { "System.Numerics.Plane", new MappedType("Windows.Foundation.Numerics", "Plane", "Windows.Foundation.FoundationContract", true, true) }, + { "System.Numerics.Quaternion", new MappedType("Windows.Foundation.Numerics", "Quaternion", "Windows.Foundation.FoundationContract", true, true) }, + { "System.Numerics.Vector2", new MappedType("Windows.Foundation.Numerics", "Vector2", "Windows.Foundation.FoundationContract", true, true) }, + { "System.Numerics.Vector3", new MappedType("Windows.Foundation.Numerics", "Vector3", "Windows.Foundation.FoundationContract", true, true) }, + { "System.Numerics.Vector4", new MappedType("Windows.Foundation.Numerics", "Vector4", "Windows.Foundation.FoundationContract", true, true) }, + { "System.Type", new MappedType(GetSystemTypeCustomMapping) }, + { "System.Collections.Generic.IEnumerable`1", new MappedType("Windows.Foundation.Collections", "IIterable`1", "Windows.Foundation.FoundationContract") }, + { "System.Collections.Generic.IEnumerator`1", new MappedType("Windows.Foundation.Collections", "IIterator`1", "Windows.Foundation.FoundationContract") }, + { "System.Collections.Generic.KeyValuePair`2", new MappedType("Windows.Foundation.Collections", "IKeyValuePair`2", "Windows.Foundation.FoundationContract") }, + { "System.Collections.Generic.IReadOnlyDictionary`2", new MappedType("Windows.Foundation.Collections", "IMapView`2", "Windows.Foundation.FoundationContract") }, + { "System.Collections.Generic.IDictionary`2", new MappedType("Windows.Foundation.Collections", "IMap`2", "Windows.Foundation.FoundationContract") }, + { "System.Collections.Generic.IReadOnlyList`1", new MappedType("Windows.Foundation.Collections", "IVectorView`1", "Windows.Foundation.FoundationContract") }, + { "System.Collections.Generic.IList`1", new MappedType("Windows.Foundation.Collections", "IVector`1", "Windows.Foundation.FoundationContract") }, + { "Windows.UI.Color", new MappedType("Windows.UI", "Color", "Windows.Foundation.UniversalApiContract", true, true) }, + }; + } + } + + public bool HasMappingForType(string typeName) => typeMapping.ContainsKey(typeName); + + public MappedType GetMappedType(string typeName) => typeMapping[typeName]; + } +} diff --git a/src/Authoring/WinRT.SourceGenerator/UiXamlMode.cs b/src/Authoring/WinRT.SourceGenerator/UiXamlMode.cs new file mode 100644 index 000000000..7432a1075 --- /dev/null +++ b/src/Authoring/WinRT.SourceGenerator/UiXamlMode.cs @@ -0,0 +1,26 @@ +using Microsoft.CodeAnalysis.Diagnostics; +using System; +using System.Collections.Generic; +using System.Text; + +namespace Generator +{ + internal enum UiXamlMode + { + MicrosoftUiXaml, + WindowsUiXaml, + } + + internal static class OptionsHelper + { + public static UiXamlMode GetUiXamlMode(this AnalyzerConfigOptions options) + { + if (options.TryGetValue("build_property.CsWinRTUiXamlMode", out var value) && Enum.TryParse(value, out UiXamlMode mode)) + { + return mode; + } + + return UiXamlMode.MicrosoftUiXaml; + } + } +} diff --git a/src/Authoring/WinRT.SourceGenerator/WinRTTypeWriter.cs b/src/Authoring/WinRT.SourceGenerator/WinRTTypeWriter.cs index 3a64b1e8b..686320671 100644 --- a/src/Authoring/WinRT.SourceGenerator/WinRTTypeWriter.cs +++ b/src/Authoring/WinRT.SourceGenerator/WinRTTypeWriter.cs @@ -265,7 +265,7 @@ class WinRTTypeWriter : CSharpSyntaxWalker private readonly Dictionary typeReferenceMapping; private readonly Dictionary assemblyReferenceMapping; private readonly MetadataBuilder metadataBuilder; - + private readonly TypeMapper mapper; private readonly Dictionary typeDefinitionMapping; private TypeDeclaration currentTypeDeclaration; @@ -275,12 +275,14 @@ public WinRTTypeWriter( string assembly, string version, MetadataBuilder metadataBuilder, - Logger logger) + Logger logger, + TypeMapper mapper) { this.assembly = assembly; this.version = version; this.metadataBuilder = metadataBuilder; Logger = logger; + this.mapper = mapper; typeReferenceMapping = new Dictionary(StringComparer.Ordinal); assemblyReferenceMapping = new Dictionary(StringComparer.Ordinal); typeDefinitionMapping = new Dictionary(StringComparer.Ordinal); @@ -435,9 +437,9 @@ private EntityHandle GetTypeReference(ISymbol symbol) var assembly = GetAssemblyForWinRTType(symbol); if (assembly == null) { - if (GeneratorHelper.MappedCSharpTypes.ContainsKey(fullType)) + if (mapper.HasMappingForType(fullType)) { - (@namespace, name, assembly, _, _) = GeneratorHelper.MappedCSharpTypes[fullType].GetMapping(currentTypeDeclaration.Node); + (@namespace, name, assembly, _, _) = mapper.GetMappedType(fullType).GetMapping(currentTypeDeclaration.Node); Logger.Log("custom mapping " + fullType + " to " + QualifiedName(@namespace, name) + " from " + assembly); } else @@ -520,9 +522,9 @@ private void EncodeSymbol(Symbol symbol, SignatureTypeEncoder typeEncoder) else { bool isValueType = symbol.Type.TypeKind == TypeKind.Enum || symbol.Type.TypeKind == TypeKind.Struct; - if (GeneratorHelper.MappedCSharpTypes.ContainsKey(QualifiedName(symbol.Type))) + if (mapper.HasMappingForType(QualifiedName(symbol.Type))) { - (_, _, _, _, isValueType) = GeneratorHelper.MappedCSharpTypes[QualifiedName(symbol.Type)].GetMapping(currentTypeDeclaration.Node); + (_, _, _, _, isValueType) = mapper.GetMappedType(QualifiedName(symbol.Type)).GetMapping(currentTypeDeclaration.Node); } typeEncoder.Type(GetTypeReference(symbol.Type), isValueType); } @@ -804,7 +806,7 @@ private void ProcessCustomMappedInterfaces(INamedTypeSymbol classSymbol) // Mark custom mapped interface members for removal later. // Note we want to also mark members from interfaces without mappings. foreach (var implementedInterface in GetInterfaces(classSymbol, true). - Where(symbol => GeneratorHelper.MappedCSharpTypes.ContainsKey(QualifiedName(symbol)) || + Where(symbol => mapper.HasMappingForType(QualifiedName(symbol)) || ImplementedInterfacesWithoutMapping.Contains(QualifiedName(symbol)))) { bool isPubliclyImplemented = false; @@ -825,7 +827,7 @@ private void ProcessCustomMappedInterfaces(INamedTypeSymbol classSymbol) } foreach (var implementedInterface in GetInterfaces(classSymbol) - .Where(symbol => GeneratorHelper.MappedCSharpTypes.ContainsKey(QualifiedName(symbol)))) + .Where(symbol => mapper.HasMappingForType(QualifiedName(symbol)))) { WriteCustomMappedTypeMembers(implementedInterface, true, isPublicImplementation[implementedInterface]); } @@ -853,9 +855,9 @@ INamedTypeSymbol GetTypeByMetadataName(string metadataName) private string GetMappedQualifiedTypeName(ITypeSymbol symbol) { string qualifiedName = QualifiedName(symbol); - if (GeneratorHelper.MappedCSharpTypes.ContainsKey(qualifiedName)) + if (mapper.HasMappingForType(qualifiedName)) { - var (@namespace, mappedTypeName, _, _, _) = GeneratorHelper.MappedCSharpTypes[qualifiedName].GetMapping(currentTypeDeclaration.Node); + var (@namespace, mappedTypeName, _, _, _) = mapper.GetMappedType(qualifiedName).GetMapping(currentTypeDeclaration.Node); qualifiedName = QualifiedName(@namespace, mappedTypeName); if (symbol is INamedTypeSymbol namedType && namedType.TypeArguments.Length > 0) { @@ -874,7 +876,7 @@ private string GetMappedQualifiedTypeName(ITypeSymbol symbol) private void WriteCustomMappedTypeMembers(INamedTypeSymbol symbol, bool isDefinition, bool isPublic = true) { - var (_, mappedTypeName, _, _, _) = GeneratorHelper.MappedCSharpTypes[QualifiedName(symbol)].GetMapping(currentTypeDeclaration.Node); + var (_, mappedTypeName, _, _, _) = mapper.GetMappedType(QualifiedName(symbol)).GetMapping(currentTypeDeclaration.Node); string qualifiedName = GetMappedQualifiedTypeName(symbol); Logger.Log("writing custom mapped type members for " + mappedTypeName + " public: " + isPublic + " qualified name: " + qualifiedName); @@ -1233,7 +1235,7 @@ void GatherPubliclyAccessibleInterfaces(ITypeSymbol symbol) GatherPubliclyAccessibleInterfaces(symbol); var baseType = symbol.BaseType; - while (baseType != null && !GeneratorHelper.IsWinRTType(baseType)) + while (baseType != null && !GeneratorHelper.IsWinRTType(baseType, mapper)) { GatherPubliclyAccessibleInterfaces(baseType); @@ -2438,9 +2440,9 @@ void AddType(INamedTypeSymbol type, bool treatAsProjectedType = false) { AddProjectedType(type); } - else if (GeneratorHelper.MappedCSharpTypes.ContainsKey(qualifiedName)) + else if (mapper.HasMappingForType(qualifiedName)) { - var (@namespace, name, assembly, isSystemType, _) = GeneratorHelper.MappedCSharpTypes[qualifiedName].GetMapping(); + var (@namespace, name, assembly, isSystemType, _) = mapper.GetMappedType(qualifiedName).GetMapping(); if (isSystemType) { var projectedType = Model.Compilation.GetTypeByMetadataName(QualifiedName(@namespace, name)); @@ -2532,7 +2534,7 @@ public void FinalizeGeneration() Logger.Log("finalizing interface " + implementedInterfaceQualifiedNameWithGenerics); var interfaceTypeDeclaration = typeDefinitionMapping[implementedInterfaceQualifiedNameWithGenerics]; - if (GeneratorHelper.MappedCSharpTypes.ContainsKey(QualifiedName(implementedInterface))) + if (mapper.HasMappingForType(QualifiedName(implementedInterface))) { Logger.Log("adding MethodImpls for custom mapped interface"); foreach (var interfaceMember in interfaceTypeDeclaration.MethodReferences) @@ -2663,7 +2665,7 @@ public void FinalizeGeneration() public void GenerateWinRTExposedClassAttributes(GeneratorExecutionContext context) { - static bool IsWinRTType(ISymbol symbol) + static bool IsWinRTType(ISymbol symbol, TypeMapper mapper) { if (symbol is INamedTypeSymbol namedType) { @@ -2694,7 +2696,7 @@ typeDeclaration.Node is INamedTypeSymbol symbol && symbol.TypeKind == TypeKind.Class && !symbol.IsStatic) { - vtableAttributesToAdd.Add(WinRTAotSourceGenerator.GetVtableAttributeToAdd(symbol, IsWinRTType, context.Compilation.Assembly, true, typeDeclaration.DefaultInterface)); + vtableAttributesToAdd.Add(WinRTAotSourceGenerator.GetVtableAttributeToAdd(symbol, IsWinRTType, mapper, context.Compilation.Assembly, true, typeDeclaration.DefaultInterface)); } } diff --git a/src/Perf/IIDOptimizer/GuidPatcher.cs b/src/Perf/IIDOptimizer/GuidPatcher.cs index bd200dfd6..e12723150 100644 --- a/src/Perf/IIDOptimizer/GuidPatcher.cs +++ b/src/Perf/IIDOptimizer/GuidPatcher.cs @@ -72,12 +72,14 @@ public GuidPatcher(AssemblyDefinition winRTRuntime, AssemblyDefinition targetAss guidGeneratorType = null; TypeDefinition? typeExtensionsType = null; + TypeDefinition? wuxMuxProjectedInterfaceAttributeType = null; // Use the type definition if we are patching WinRT.Runtime, otherwise lookup the types as references if (string.CompareOrdinal(assembly.Name.Name, "WinRT.Runtime") == 0) { - guidGeneratorType = winRTRuntimeAssembly.MainModule.Types.Where(typeDef => string.CompareOrdinal(typeDef.Name, "GuidGenerator") == 0).First(); - typeExtensionsType = winRTRuntimeAssembly.MainModule.Types.Where(typeDef => string.CompareOrdinal(typeDef.Name, "TypeExtensions") == 0).First(); + guidGeneratorType = winRTRuntimeAssembly.MainModule.Types.Where(typeDef => string.Equals(typeDef.Name, "GuidGenerator", StringComparison.Ordinal)).First(); + typeExtensionsType = winRTRuntimeAssembly.MainModule.Types.Where(typeDef => string.Equals(typeDef.Name, "TypeExtensions", StringComparison.Ordinal)).First(); + wuxMuxProjectedInterfaceAttributeType = winRTRuntimeAssembly.MainModule.Types.Where(typedef => string.Equals(typedef.Name, "WuxMuxProjectedInterfaceAttribute", StringComparison.Ordinal)).First(); } foreach (var asm in assembly.MainModule.AssemblyReferences) @@ -87,6 +89,7 @@ public GuidPatcher(AssemblyDefinition winRTRuntime, AssemblyDefinition targetAss guidGeneratorType = new TypeReference("WinRT", "GuidGenerator", assembly.MainModule, asm).Resolve(); typeExtensionsType = new TypeReference("WinRT", "TypeExtensions", assembly.MainModule, asm).Resolve(); + wuxMuxProjectedInterfaceAttributeType = new TypeReference("WinRT", "WuxMuxProjectedInterfaceAttribute", assembly.MainModule, asm).Resolve(); } else if (string.CompareOrdinal(asm.Name, "System.Runtime.InteropServices") == 0) { @@ -101,7 +104,7 @@ public GuidPatcher(AssemblyDefinition winRTRuntime, AssemblyDefinition targetAss getHelperTypeMethod = typeExtensionsType.Methods.First(m => String.CompareOrdinal(m.Name, "GetHelperType") == 0); } - signatureGenerator = new SignatureGenerator(assembly, guidAttributeType!, winRTRuntimeAssembly); + signatureGenerator = new SignatureGenerator(assembly, guidAttributeType!, wuxMuxProjectedInterfaceAttributeType!, winRTRuntimeAssembly); methodCache = new Dictionary(); } diff --git a/src/Perf/IIDOptimizer/SignatureGenerator.cs b/src/Perf/IIDOptimizer/SignatureGenerator.cs index 819bcabaa..2f9d3cfbf 100644 --- a/src/Perf/IIDOptimizer/SignatureGenerator.cs +++ b/src/Perf/IIDOptimizer/SignatureGenerator.cs @@ -55,12 +55,14 @@ sealed class SignatureGenerator { private readonly AssemblyDefinition assembly; private readonly TypeDefinition guidAttributeType; + private readonly TypeDefinition wuxMuxProjectedInterfaceAttributeType; private readonly AssemblyDefinition winRTRuntimeAssembly; - public SignatureGenerator(AssemblyDefinition assembly, TypeDefinition guidAttributeType, AssemblyDefinition runtimeAssembly) + public SignatureGenerator(AssemblyDefinition assembly, TypeDefinition guidAttributeType, TypeDefinition wuxMuxProjectedInterfaceAttributeType, AssemblyDefinition runtimeAssembly) { this.assembly = assembly; this.guidAttributeType = guidAttributeType; + this.wuxMuxProjectedInterfaceAttributeType = wuxMuxProjectedInterfaceAttributeType; this.winRTRuntimeAssembly = runtimeAssembly; } @@ -73,9 +75,9 @@ public SignaturePart GetSignatureParts(TypeReference type) var typeDef = type.Resolve(); - var helperType = new TypeReference($"ABI.{typeDef.Namespace}", typeDef.Name, typeDef.Module, assembly.MainModule); + TypeReference helperType = type.GetCswinrtAbiTypeDefinition(winRTRuntimeAssembly); - if (helperType.Resolve() is not null) + if (helperType is not null) { if (type.IsGenericInstance) { @@ -167,9 +169,25 @@ public SignaturePart GetSignatureParts(TypeReference type) return new RuntimeClassSignature(type, GetSignatureParts(iface)); } - // TODO-WuxMux: We need to intercept the WUX/MUX types here and do one of the following options: - // - Take an option in the IID optimizer to hard-code for one or the other (for OutputType Exe or for libraries that are one flavor only, this is reasonable) - // - Fall back to runtime-based IID lookup for the type (works for everything, less efficient) + // For types projected from WUX or MUX into .NET, we'll need to do a runtime lookup for the IID. + // TODO-WuxMux: We can instead take an option in the IID optimizer to hard-code the lookup for WUX or MUX when specified, which would be more efficient for scenarios where this is possible. + if (helperType?.Resolve().CustomAttributes.Any(attr => attr.AttributeType.Resolve() == wuxMuxProjectedInterfaceAttributeType) == true) + { + var getGuidSignatureMethod = new MethodReference("GetGuidSignature", assembly.MainModule.TypeSystem.String, helperType) + { + HasThis = false + }; + + if (getGuidSignatureMethod.Resolve() is not null) + { + return new CustomSignatureMethod(assembly.MainModule.ImportReference(getGuidSignatureMethod)); + } + else + { + throw new InvalidOperationException($"Unable to resolve GetGuidSignature method for type projected into .NET from WUX/MUX: {type.FullName}."); + } + } + Guid? guidAttributeValue = type.ReadGuidFromAttribute(guidAttributeType, winRTRuntimeAssembly); if (guidAttributeValue == null) { diff --git a/src/WinRT.Runtime/GuidGenerator.cs b/src/WinRT.Runtime/GuidGenerator.cs index 066536625..246238ad8 100644 --- a/src/WinRT.Runtime/GuidGenerator.cs +++ b/src/WinRT.Runtime/GuidGenerator.cs @@ -7,6 +7,7 @@ using System.Reflection; using System.Security.Cryptography; using System.Text; +using WinRT.Interop; namespace WinRT { @@ -28,11 +29,11 @@ public static Guid GetIID( #endif Type type) { - if (Projections.FindCustomIIDForAbiType(type) is Guid customIID) + type = type.GetGuidType(); + if (type.IsDefined(typeof(WuxMuxProjectedTypeAttribute))) { - return customIID; + return Guid.Parse(GetSignature(type)); } - type = type.GetGuidType(); if (!type.IsGenericType) { return type.GUID; diff --git a/src/WinRT.Runtime/Interop/WuxMuxProjectedInterfaceAttribute.cs b/src/WinRT.Runtime/Interop/WuxMuxProjectedInterfaceAttribute.cs new file mode 100644 index 000000000..10b746ebd --- /dev/null +++ b/src/WinRT.Runtime/Interop/WuxMuxProjectedInterfaceAttribute.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace WinRT.Interop +{ + /// + /// This type signals that the type it is applied to is projected into .NET from either a Windows.UI.Xaml type or a Microsoft.UI.Xaml type. + /// For this type, the GuidAttribute is not used and instead the GetGuidSignature method must be called to get the IID or generic IID signature part of the type. + /// + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] + internal sealed class WuxMuxProjectedTypeAttribute : Attribute + { + } +} diff --git a/src/WinRT.Runtime/Projections.cs b/src/WinRT.Runtime/Projections.cs index 0ee03e99d..fab580b15 100644 --- a/src/WinRT.Runtime/Projections.cs +++ b/src/WinRT.Runtime/Projections.cs @@ -25,14 +25,28 @@ namespace WinRT #endif static class Projections { - private enum UiXamlMode + internal enum UiXamlMode { - Unsupported, MicrosoftUiXaml, WindowsUiXaml } - private static UiXamlMode UiXamlMode { get; } = AppContext.GetData("CsWinRT.UiXamlMode") is string str && Enum.TryParse(str, out var mode) ? mode : UiXamlMode.Unsupported; + private static UiXamlMode GetUIXamlModeSetting() + { + if (AppContext.GetData("CsWinRT.UiXamlMode") is string str && Enum.TryParse(str, out var mode)) + { +#if !NET5_0_OR_GREATER + if (mode == UiXamlMode.WindowsUiXaml) + { + throw new NotSupportedException("Windows.UI.Xaml is not supported before .NET 5. Please use built-in WinRT interop for Windows.UI.Xaml experiences"); + } +#endif + return mode; + } + return UiXamlMode.MicrosoftUiXaml; // We default to MUX for back-compat with existing projects. + } + + internal static UiXamlMode UiXamlModeSetting { get; } = GetUIXamlModeSetting(); private static readonly ReaderWriterLockSlim rwlock = new ReaderWriterLockSlim(); @@ -46,7 +60,7 @@ private enum UiXamlMode static Projections() { - // This should be in sync with cswinrt/helpers.h and the reverse mapping from WinRT.SourceGenerator/WinRTTypeWriter.cs. + // This should be in sync with cswinrt/helpers.h and the reverse mapping from WinRT.SourceGenerator/TypeMapper.cs. RegisterCustomAbiTypeMappingNoLock(typeof(bool), typeof(ABI.System.Boolean), "Boolean"); RegisterCustomAbiTypeMappingNoLock(typeof(char), typeof(ABI.System.Char), "Char"); RegisterCustomAbiTypeMappingNoLock(typeof(EventRegistrationToken), typeof(ABI.WinRT.EventRegistrationToken), "Windows.Foundation.EventRegistrationToken"); @@ -73,7 +87,7 @@ static Projections() RegisterCustomAbiTypeMappingNoLock(typeof(TimeSpan), typeof(ABI.System.TimeSpan), "Windows.Foundation.TimeSpan"); RegisterCustomAbiTypeMappingNoLock(typeof(Uri), typeof(ABI.System.Uri), "Windows.Foundation.Uri", isRuntimeClass: true); - if (UiXamlMode == UiXamlMode.MicrosoftUiXaml) + if (UiXamlModeSetting == UiXamlMode.MicrosoftUiXaml) { RegisterCustomAbiTypeMappingNoLock(typeof(DataErrorsChangedEventArgs), typeof(ABI.System.ComponentModel.DataErrorsChangedEventArgs), "Microsoft.UI.Xaml.Data.DataErrorsChangedEventArgs", isRuntimeClass: true); RegisterCustomAbiTypeMappingNoLock(typeof(PropertyChangedEventArgs), typeof(ABI.System.ComponentModel.PropertyChangedEventArgs), "Microsoft.UI.Xaml.Data.PropertyChangedEventArgs", isRuntimeClass: true); @@ -89,18 +103,14 @@ static Projections() RegisterCustomAbiTypeMappingNoLock(typeof(NotifyCollectionChangedEventArgs), typeof(ABI.System.Collections.Specialized.NotifyCollectionChangedEventArgs), "Microsoft.UI.Xaml.Interop.NotifyCollectionChangedEventArgs", isRuntimeClass: true); RegisterCustomAbiTypeMappingNoLock(typeof(NotifyCollectionChangedEventHandler), typeof(ABI.System.Collections.Specialized.NotifyCollectionChangedEventHandler), "Microsoft.UI.Xaml.Interop.NotifyCollectionChangedEventHandler"); CustomTypeToHelperTypeMappings.Add(typeof(Microsoft.UI.Xaml.Interop.IBindableVector), typeof(ABI.System.Collections.IList)); - - // TODO-WuxMux: Add custom IIDs to the IID lookup } - else if (UiXamlMode == UiXamlMode.WindowsUiXaml) +#if NET5_0_OR_GREATER + else if (UiXamlModeSetting == UiXamlMode.WindowsUiXaml) { - RegisterCustomAbiTypeMappingNoLock(typeof(DataErrorsChangedEventArgs), typeof(ABI.System.ComponentModel.DataErrorsChangedEventArgs), "Windows.UI.Xaml.Data.DataErrorsChangedEventArgs", isRuntimeClass: true); RegisterCustomAbiTypeMappingNoLock(typeof(PropertyChangedEventArgs), typeof(ABI.System.ComponentModel.PropertyChangedEventArgs), "Windows.UI.Xaml.Data.PropertyChangedEventArgs", isRuntimeClass: true); RegisterCustomAbiTypeMappingNoLock(typeof(PropertyChangedEventHandler), typeof(ABI.System.ComponentModel.PropertyChangedEventHandler), "Windows.UI.Xaml.Data.PropertyChangedEventHandler"); - RegisterCustomAbiTypeMappingNoLock(typeof(INotifyDataErrorInfo), typeof(ABI.System.ComponentModel.INotifyDataErrorInfo), "Windows.UI.Xaml.Data.INotifyDataErrorInfo"); RegisterCustomAbiTypeMappingNoLock(typeof(INotifyPropertyChanged), typeof(ABI.System.ComponentModel.INotifyPropertyChanged), "Windows.UI.Xaml.Data.INotifyPropertyChanged"); RegisterCustomAbiTypeMappingNoLock(typeof(ICommand), typeof(ABI.System.Windows.Input.ICommand), "Windows.UI.Xaml.Interop.ICommand"); - RegisterCustomAbiTypeMappingNoLock(typeof(IServiceProvider), typeof(ABI.System.IServiceProvider), "Windows.UI.Xaml.IXamlServiceProvider"); RegisterCustomAbiTypeMappingNoLock(typeof(IEnumerable), typeof(ABI.System.Collections.IEnumerable), "Windows.UI.Xaml.Interop.IBindableIterable"); RegisterCustomAbiTypeMappingNoLock(typeof(IList), typeof(ABI.System.Collections.IList), "Windows.UI.Xaml.Interop.IBindableVector"); RegisterCustomAbiTypeMappingNoLock(typeof(INotifyCollectionChanged), typeof(ABI.System.Collections.Specialized.INotifyCollectionChanged), "Windows.UI.Xaml.Interop.INotifyCollectionChanged"); @@ -108,9 +118,8 @@ static Projections() RegisterCustomAbiTypeMappingNoLock(typeof(NotifyCollectionChangedEventArgs), typeof(ABI.System.Collections.Specialized.NotifyCollectionChangedEventArgs), "Windows.UI.Xaml.Interop.NotifyCollectionChangedEventArgs", isRuntimeClass: true); RegisterCustomAbiTypeMappingNoLock(typeof(NotifyCollectionChangedEventHandler), typeof(ABI.System.Collections.Specialized.NotifyCollectionChangedEventHandler), "Windows.UI.Xaml.Interop.NotifyCollectionChangedEventHandler"); CustomTypeToHelperTypeMappings.Add(typeof(Windows.UI.Xaml.Interop.IBindableVector), typeof(ABI.System.Collections.IList)); - - // TODO-WuxMux: Add custom IIDs to the IID lookup } +#endif RegisterCustomAbiTypeMappingNoLock(typeof(EventHandler<>), typeof(ABI.System.EventHandler<>), "Windows.Foundation.EventHandler`1"); diff --git a/src/WinRT.Runtime/Projections/Bindable.net5.cs b/src/WinRT.Runtime/Projections/Bindable.net5.cs index 2b31c540d..809c4eadd 100644 --- a/src/WinRT.Runtime/Projections/Bindable.net5.cs +++ b/src/WinRT.Runtime/Projections/Bindable.net5.cs @@ -1,101 +1,162 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -using System; -using System.Collections; -using System.Collections.Generic; +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using System; +using System.Collections; +using System.Collections.Generic; using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using WinRT; +using System.Runtime.InteropServices; +using WinRT; using WinRT.Interop; -#pragma warning disable 0169 // warning CS0169: The field '...' is never used -#pragma warning disable 0649 // warning CS0169: Field '...' is never assigned to - -namespace Microsoft.UI.Xaml.Interop -{ - [global::WinRT.WindowsRuntimeType] - [Guid("036D2C08-DF29-41AF-8AA2-D774BE62BA6F")] - [global::WinRT.WindowsRuntimeHelperType(typeof(global::ABI.Microsoft.UI.Xaml.Interop.IBindableIterable))] - internal interface IBindableIterable - { - IBindableIterator First(); - } - [global::WinRT.WindowsRuntimeType] - [Guid("6A1D6C07-076D-49F2-8314-F52C9C9A8331")] - [global::WinRT.WindowsRuntimeHelperType(typeof(global::ABI.Microsoft.UI.Xaml.Interop.IBindableIterator))] - internal interface IBindableIterator - { - bool MoveNext(); - // GetMany is not implemented by IBindableIterator, but it is here - // for compat purposes with WinUI where there are scenarios they do - // reinterpret_cast from IBindableIterator to IIterable. It is - // the last function in the vftable and shouldn't be called by anyone. - // If called, it will return NotImplementedException. - uint GetMany(ref object[] items); - object Current { get; } - bool HasCurrent { get; } - } - [global::WinRT.WindowsRuntimeType] - [Guid("393DE7DE-6FD0-4C0D-BB71-47244A113E93")] - internal interface IBindableVector : IEnumerable - { - 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(); - uint Size { get; } - } - [global::WinRT.WindowsRuntimeType] - [Guid("346DD6E7-976E-4BC3-815D-ECE243BC0F33")] - [global::WinRT.WindowsRuntimeHelperType(typeof(global::ABI.Microsoft.UI.Xaml.Interop.IBindableVectorView))] - internal interface IBindableVectorView : IEnumerable - { - object GetAt(uint index); - bool IndexOf(object value, out uint index); - uint Size { get; } - } -} - -namespace ABI.Microsoft.UI.Xaml.Interop -{ - [DynamicInterfaceCastableImplementation] - [Guid("036D2C08-DF29-41AF-8AA2-D774BE62BA6F")] - internal unsafe interface IBindableIterable : global::Microsoft.UI.Xaml.Interop.IBindableIterable, ABI.System.Collections.IEnumerable - { - - } - - [DynamicInterfaceCastableImplementation] - [Guid("6A1D6C07-076D-49F2-8314-F52C9C9A8331")] - internal unsafe interface IBindableIterator : global::Microsoft.UI.Xaml.Interop.IBindableIterator +#pragma warning disable 0169 // warning CS0169: The field '...' is never used +#pragma warning disable 0649 // warning CS0169: Field '...' is never assigned to + +namespace ABI.System.Collections +{ + using WUX = global::Windows.UI.Xaml.Interop; + using MUX = global::Microsoft.UI.Xaml.Interop; + using global::System; + using global::System.Runtime.CompilerServices; + using global::System.Diagnostics.CodeAnalysis; + +#if EMBED + internal +#else + public +#endif + static class IEnumerableMethods + { + public static global::System.Guid IID { get; } = new Guid(new global::System.ReadOnlySpan(new byte[] { 0x08, 0x2C, 0x6D, 0x03, 0x29, 0xDF, 0xAF, 0x41, 0x8A, 0xA2, 0xD7, 0x74, 0xBE, 0x62, 0xBA, 0x6F })); + + public static IntPtr AbiToProjectionVftablePtr => IEnumerable.AbiToProjectionVftablePtr; + } + + [DynamicInterfaceCastableImplementation] + [Guid("036D2C08-DF29-41AF-8AA2-D774BE62BA6F")] + internal unsafe interface IEnumerable : global::System.Collections.IEnumerable, WUX.IBindableIterable, MUX.IBindableIterable { - public static readonly IntPtr AbiToProjectionVftablePtr; - static IBindableIterator() + public static string GetGuidSignature() => GuidGenerator.GetSignature(typeof(IEnumerable)); + + public sealed class AdaptiveFromAbiHelper : global::System.Collections.IEnumerable { - AbiToProjectionVftablePtr = ComWrappersSupport.AllocateVtableMemory(typeof(IBindableIterator), sizeof(IInspectable.Vftbl) + sizeof(IntPtr) * 4); - *(IInspectable.Vftbl*)AbiToProjectionVftablePtr = IInspectable.Vftbl.AbiToProjectionVftable; - ((delegate* unmanaged[Stdcall]*)AbiToProjectionVftablePtr)[6] = &Do_Abi_get_Current_0; - ((delegate* unmanaged[Stdcall]*)AbiToProjectionVftablePtr)[7] = &Do_Abi_get_HasCurrent_1; - ((delegate* unmanaged[Stdcall]*)AbiToProjectionVftablePtr)[8] = &Do_Abi_MoveNext_2; - ((delegate* unmanaged[Stdcall]*)AbiToProjectionVftablePtr)[9] = &Do_Abi_GetMany_3; + private readonly Func _enumerator; + private readonly IWinRTObject _winRTObject; + + [DynamicDependency(DynamicallyAccessedMemberTypes.PublicMethods, typeof(IEnumerable<>))] + [SuppressMessage("Trimming", "IL2070:'this' argument does not satisfy 'DynamicallyAccessedMembersAttribute' in call to target method. The parameter of method does not have matching annotations.", Justification = "We explicitly preserve the type we're looking for with the DynamicDependency attribute.")] + [SuppressMessage("Trimming", "IL2075:'this' argument does not satisfy 'DynamicallyAccessedMembersAttribute' in call to target method. The return value of the source method does not have matching annotations.", Justification = "We can't annotate this case (GetMethod on a type returned from GetInterface), so we use DynamicDependency to keep alive the one type we care about's public methods.")] + public AdaptiveFromAbiHelper( + Type runtimeType, IWinRTObject winRTObject) + : this(winRTObject) + { + Type enumGenericType = (runtimeType.IsGenericType && runtimeType.GetGenericTypeDefinition() == typeof(IEnumerable<>)) ? + runtimeType : runtimeType.GetInterface("System.Collections.Generic.IEnumerable`1"); + if(enumGenericType != null) + { + var getEnumerator = enumGenericType.GetMethod("GetEnumerator"); + _enumerator = (IWinRTObject obj) => (IEnumerator)getEnumerator.Invoke(obj, null); + } + } + + public AdaptiveFromAbiHelper(IWinRTObject winRTObject) + { + _winRTObject = winRTObject; + if (winRTObject is WUX.IBindableIterable) + { + _enumerator = (IWinRTObject obj) => new Generic.FromAbiEnumerator(new NonGenericToGenericWuxIterator(((WUX.IBindableIterable)obj).First())); + } + else if (winRTObject is MUX.IBindableIterable) + { + _enumerator = (IWinRTObject obj) => new Generic.FromAbiEnumerator(new NonGenericToGenericMuxIterator(((MUX.IBindableIterable)obj).First())); + } + } + + public IEnumerator GetEnumerator() => _enumerator(_winRTObject); + + private sealed class NonGenericToGenericWuxIterator : global::Windows.Foundation.Collections.IIterator + { + private readonly WUX.IBindableIterator iterator; + + public NonGenericToGenericWuxIterator(WUX.IBindableIterator iterator) => this.iterator = iterator; + + public object _Current => iterator.Current; + public bool HasCurrent => iterator.HasCurrent; + public bool _MoveNext() { return iterator.MoveNext(); } + public uint GetMany(ref object[] items) => throw new NotSupportedException(); + } + + private sealed class NonGenericToGenericMuxIterator : global::Windows.Foundation.Collections.IIterator + { + private readonly MUX.IBindableIterator iterator; + + public NonGenericToGenericMuxIterator(MUX.IBindableIterator iterator) => this.iterator = iterator; + + public object _Current => iterator.Current; + public bool HasCurrent => iterator.HasCurrent; + public bool _MoveNext() { return iterator.MoveNext(); } + public uint GetMany(ref object[] items) => throw new NotSupportedException(); + } + } + + private sealed class ToWuxAbiHelper : WUX.IBindableIterable + { + private readonly IEnumerable m_enumerable; + + internal ToWuxAbiHelper(IEnumerable enumerable) => m_enumerable = enumerable; + + WUX.IBindableIterator WUX.IBindableIterable.First() => MakeBindableIterator(m_enumerable.GetEnumerator()); + + internal static WUX.IBindableIterator MakeBindableIterator(IEnumerator enumerator) => + new Generic.IEnumerator.ToAbiHelper(new NonGenericToGenericEnumerator(enumerator)); + + private sealed class NonGenericToGenericEnumerator : IEnumerator + { + private readonly IEnumerator enumerator; + + public NonGenericToGenericEnumerator(IEnumerator enumerator) => this.enumerator = enumerator; + + public object Current => enumerator.Current; + public bool MoveNext() { return enumerator.MoveNext(); } + public void Reset() { enumerator.Reset(); } + public void Dispose() { } + } } - [UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })] - private static unsafe int Do_Abi_MoveNext_2(IntPtr thisPtr, byte* result) + private sealed class ToMuxAbiHelper(IEnumerable enumerable) : MUX.IBindableIterable + { + MUX.IBindableIterator MUX.IBindableIterable.First() => MakeBindableIterator(enumerable.GetEnumerator()); + + internal static MUX.IBindableIterator MakeBindableIterator(IEnumerator enumerator) => + new Generic.IEnumerator.ToAbiHelper(new NonGenericToGenericEnumerator(enumerator)); + + private sealed class NonGenericToGenericEnumerator(IEnumerator enumerator) : IEnumerator + { + public object Current => enumerator.Current; + public bool MoveNext() { return enumerator.MoveNext(); } + public void Reset() { enumerator.Reset(); } + public void Dispose() { } + } + } + + public static readonly IntPtr AbiToProjectionVftablePtr; + static IEnumerable() + { + AbiToProjectionVftablePtr = ComWrappersSupport.AllocateVtableMemory(typeof(IEnumerable), sizeof(IInspectable.Vftbl) + sizeof(IntPtr) * 1); + *(IInspectable.Vftbl*)AbiToProjectionVftablePtr = IInspectable.Vftbl.AbiToProjectionVftable; + ((delegate* unmanaged[Stdcall]*)AbiToProjectionVftablePtr)[6] = Projections.UiXamlModeSetting is Projections.UiXamlMode.WindowsUiXaml ? &Do_Wux_Abi_First_0 : &Do_Mux_Abi_First_0; + } + + [UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })] + private static unsafe int Do_Wux_Abi_First_0(IntPtr thisPtr, IntPtr* result) { - bool __result = default; *result = default; try { - __result = global::WinRT.ComWrappersSupport.FindObject(thisPtr).MoveNext(); - *result = (byte)(__result ? 1 : 0); + var __this = global::WinRT.ComWrappersSupport.FindObject(thisPtr); + var iterator = ToWuxAbiHelper.MakeBindableIterator(__this.GetEnumerator()); + *result = MarshalInterface.FromManaged(iterator); } catch (Exception __exception__) { @@ -105,907 +166,620 @@ private static unsafe int Do_Abi_MoveNext_2(IntPtr thisPtr, byte* result) return 0; } - [UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })] - private static unsafe int Do_Abi_GetMany_3(IntPtr thisPtr, int __itemsSize, IntPtr items, uint* result) + [UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })] + private static unsafe int Do_Mux_Abi_First_0(IntPtr thisPtr, IntPtr* result) { *result = default; - try { - // Should never be called. - throw new NotImplementedException(); + var __this = global::WinRT.ComWrappersSupport.FindObject(thisPtr); + var iterator = ToMuxAbiHelper.MakeBindableIterator(__this.GetEnumerator()); + *result = MarshalInterface.FromManaged(iterator); } catch (Exception __exception__) { global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); } + return 0; } - [UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })] - private static unsafe int Do_Abi_get_Current_0(IntPtr thisPtr, IntPtr* value) + internal static ObjectReference ObjRefFromAbi(IntPtr thisPtr) { - object __value = default; - *value = default; + if (thisPtr == IntPtr.Zero) + { + return null; + } + return ObjectReference.FromAbi(thisPtr); + } + + private static AdaptiveFromAbiHelper _AbiHelper(IWinRTObject _this) + { + return (AdaptiveFromAbiHelper)_this.GetOrCreateTypeHelperData(typeof(global::System.Collections.IEnumerable).TypeHandle, + () => new AdaptiveFromAbiHelper(_this)); + } + + unsafe WUX.IBindableIterator WUX.IBindableIterable.First() + { + var _obj = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.IEnumerable).TypeHandle); + var ThisPtr = _obj.ThisPtr; + IntPtr __retval = default; try { - __value = global::WinRT.ComWrappersSupport.FindObject(thisPtr).Current; - *value = MarshalInspectable.FromManaged(__value); + global::WinRT.ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]**)ThisPtr)[6](ThisPtr, &__retval)); + return MarshalInterface.FromAbi(__retval); } - catch (Exception __exception__) + finally { - global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); - return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); + MarshalInterface.DisposeAbi(__retval); } - return 0; } - [UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })] - private static unsafe int Do_Abi_get_HasCurrent_1(IntPtr thisPtr, byte* value) + unsafe MUX.IBindableIterator MUX.IBindableIterable.First() { - bool __value = default; - *value = default; + var _obj = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.IEnumerable).TypeHandle); + var ThisPtr = _obj.ThisPtr; + IntPtr __retval = default; try { - __value = global::WinRT.ComWrappersSupport.FindObject(thisPtr).HasCurrent; - *value = (byte)(__value ? 1 : 0); + global::WinRT.ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]**)ThisPtr)[6](ThisPtr, &__retval)); + return MarshalInterface.FromAbi(__retval); } - catch (Exception __exception__) + finally { - global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); - return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); + MarshalInterface.DisposeAbi(__retval); } - return 0; - } - - internal static ObjectReference FromAbi(IntPtr thisPtr) => ObjectReference.FromAbi(thisPtr); - - unsafe bool global::Microsoft.UI.Xaml.Interop.IBindableIterator.MoveNext() - { - var _obj = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Microsoft.UI.Xaml.Interop.IBindableIterator).TypeHandle); - var ThisPtr = _obj.ThisPtr; - byte __retval = default; - global::WinRT.ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]**)ThisPtr)[8](ThisPtr, &__retval)); - return __retval != 0; - } - - unsafe uint global::Microsoft.UI.Xaml.Interop.IBindableIterator.GetMany(ref object[] items) - { - // Should never be called. - throw new NotImplementedException(); - } - - unsafe object global::Microsoft.UI.Xaml.Interop.IBindableIterator.Current - { - get - { - var _obj = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Microsoft.UI.Xaml.Interop.IBindableIterator).TypeHandle); - var ThisPtr = _obj.ThisPtr; - IntPtr __retval = default; - try - { - global::WinRT.ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]**)ThisPtr)[6](ThisPtr, &__retval)); - return MarshalInspectable.FromAbi(__retval); - } - finally - { - MarshalInspectable.DisposeAbi(__retval); - } - } - } - - unsafe bool global::Microsoft.UI.Xaml.Interop.IBindableIterator.HasCurrent - { - get - { - var _obj = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Microsoft.UI.Xaml.Interop.IBindableIterator).TypeHandle); - var ThisPtr = _obj.ThisPtr; - byte __retval = default; - global::WinRT.ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]**)ThisPtr)[7](ThisPtr, &__retval)); - return __retval != 0; - } - } - - } - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.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 unsafe interface IBindableVectorView : global::Microsoft.UI.Xaml.Interop.IBindableVectorView + } + + IEnumerator global::System.Collections.IEnumerable.GetEnumerator() + { + return _AbiHelper((IWinRTObject)this).GetEnumerator(); + } + } + + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] +#if EMBED + internal +#else + public +#endif + static class IEnumerable_Delegates + { + public unsafe delegate int First_0(IntPtr thisPtr, IntPtr* result); + } + +#if EMBED + internal +#else + public +#endif + static class IListMethods { - public static readonly IntPtr AbiToProjectionVftablePtr; - static IBindableVectorView() + public static Guid IID { get; } = new Guid(new global::System.ReadOnlySpan(new byte[] { 0xDE, 0xE7, 0x3D, 0x39, 0xD0, 0x6F, 0x0D, 0x4C, 0xBB, 0x71, 0x47, 0x24, 0x4A, 0x11, 0x3E, 0x93 })); + + public static IntPtr AbiToProjectionVftablePtr => IList.AbiToProjectionVftablePtr; + } + + [DynamicInterfaceCastableImplementation] + [Guid("393DE7DE-6FD0-4C0D-BB71-47244A113E93")] + internal unsafe interface IList : global::System.Collections.IList, global::Windows.UI.Xaml.Interop.IBindableVector + { + public static string GetGuidSignature() => GuidGenerator.GetSignature(typeof(IList)); + + public interface IBindableVectorAdapter { - AbiToProjectionVftablePtr = ComWrappersSupport.AllocateVtableMemory(typeof(IBindableVectorView), sizeof(IInspectable.Vftbl) + sizeof(IntPtr) * 3); - *(IInspectable.Vftbl*)AbiToProjectionVftablePtr = IInspectable.Vftbl.AbiToProjectionVftable; - ((delegate* unmanaged[Stdcall]*)AbiToProjectionVftablePtr)[6] = &Do_Abi_GetAt_0; - ((delegate* unmanaged[Stdcall]*)AbiToProjectionVftablePtr)[7] = &Do_Abi_get_Size_1; - ((delegate* unmanaged[Stdcall]*)AbiToProjectionVftablePtr)[8] = &Do_Abi_IndexOf_2; + object GetAt(uint index); + IBindableVectorViewAdapter 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(); + uint Size { get; } } - [UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })] - private static unsafe int Do_Abi_GetAt_0(IntPtr thisPtr, uint index, IntPtr* result) + public interface IBindableVectorViewAdapter { - object __result = default; + object GetAt(uint index); + bool IndexOf(object value, out uint index); + uint Size { get; } + } - try - { - __result = global::WinRT.ComWrappersSupport.FindObject(thisPtr).GetAt(index); - *result = MarshalInspectable.FromManaged(__result); + private sealed class WuxBindableVectorAdapter(WUX.IBindableVector vector) : IBindableVectorAdapter + { + public object GetAt(uint index) => vector.GetAt(index); + public IBindableVectorViewAdapter GetView() => new WuxBindableVectorViewAdapter(vector.GetView()); + public bool IndexOf(object value, out uint index) => vector.IndexOf(value, out index); + public void SetAt(uint index, object value) => vector.SetAt(index, value); + public void InsertAt(uint index, object value) => vector.InsertAt(index, value); + public void RemoveAt(uint index) => vector.RemoveAt(index); + public void Append(object value) => vector.Append(value); + public void RemoveAtEnd() => vector.RemoveAtEnd(); + public void Clear() => vector.Clear(); + public uint Size => vector.Size; + private sealed class WuxBindableVectorViewAdapter(WUX.IBindableVectorView vectorView) : IBindableVectorViewAdapter + { + public object GetAt(uint index) => vectorView.GetAt(index); + public bool IndexOf(object value, out uint index) => vectorView.IndexOf(value, out index); + public uint Size => vectorView.Size; } - catch (Exception __exception__) + } + + private sealed class MuxBindableVectorAdapter(MUX.IBindableVector vector) : IBindableVectorAdapter + { + public object GetAt(uint index) => vector.GetAt(index); + public IBindableVectorViewAdapter GetView() => new WuxBindableVectorViewAdapter(vector.GetView()); + public bool IndexOf(object value, out uint index) => vector.IndexOf(value, out index); + public void SetAt(uint index, object value) => vector.SetAt(index, value); + public void InsertAt(uint index, object value) => vector.InsertAt(index, value); + public void RemoveAt(uint index) => vector.RemoveAt(index); + public void Append(object value) => vector.Append(value); + public void RemoveAtEnd() => vector.RemoveAtEnd(); + public void Clear() => vector.Clear(); + public uint Size => vector.Size; + + private sealed class WuxBindableVectorViewAdapter(MUX.IBindableVectorView vectorView) : IBindableVectorViewAdapter { - global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); - return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); + public object GetAt(uint index) => vectorView.GetAt(index); + public bool IndexOf(object value, out uint index) => vectorView.IndexOf(value, out index); + public uint Size => vectorView.Size; } - return 0; } - [UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })] - private static unsafe int Do_Abi_IndexOf_2(IntPtr thisPtr, IntPtr value, uint* index, byte* returnValue) + public sealed class FromAbiHelper : global::System.Collections.IList { - bool __returnValue = default; + private readonly IBindableVectorAdapter _vector; - *index = default; - *returnValue = default; - uint __index = default; + public FromAbiHelper(IBindableVectorAdapter vector) + { + _vector = vector; + } - try + public bool IsSynchronized => false; + + public object SyncRoot { get => this; } + + public int Count { - __returnValue = global::WinRT.ComWrappersSupport.FindObject(thisPtr).IndexOf(MarshalInspectable.FromAbi(value), out __index); - *index = __index; - *returnValue = (byte)(__returnValue ? 1 : 0); + get + { + uint size = _vector.Size; + if (((uint)int.MaxValue) < size) + { + throw new InvalidOperationException(WinRTRuntimeErrorStrings.InvalidOperation_CollectionBackingListTooLarge); + } + return (int)size; + } } - catch (Exception __exception__) + + public void CopyTo(Array array, int arrayIndex) { - global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); - return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); + if (array == null) + throw new ArgumentNullException(nameof(array)); + + // ICollection expects the destination array to be single-dimensional. + if (array.Rank != 1) + throw new ArgumentException(WinRTRuntimeErrorStrings.Arg_RankMultiDimNotSupported); + + int destLB = array.GetLowerBound(0); + int srcLen = Count; + int destLen = array.GetLength(0); + + if (arrayIndex < destLB) + throw new ArgumentOutOfRangeException(nameof(arrayIndex)); + + // Does the dimension in question have sufficient space to copy the expected number of entries? + // We perform this check before valid index check to ensure the exception message is in sync with + // the following snippet that uses regular framework code: + // + // ArrayList list = new ArrayList(); + // list.Add(1); + // Array items = Array.CreateInstance(typeof(object), new int[] { 1 }, new int[] { -1 }); + // list.CopyTo(items, 0); + + if (srcLen > (destLen - (arrayIndex - destLB))) + throw new ArgumentException(WinRTRuntimeErrorStrings.Argument_InsufficientSpaceToCopyCollection); + + if (arrayIndex - destLB > destLen) + throw new ArgumentException(WinRTRuntimeErrorStrings.Argument_IndexOutOfArrayBounds); + + // We need to verify the index as we; + for (uint i = 0; i < srcLen; i++) + { + array.SetValue(_vector.GetAt(i), i + arrayIndex); + } } - return 0; - } - [UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })] - private static unsafe int Do_Abi_get_Size_1(IntPtr thisPtr, uint* value) - { - uint __value = default; + public object this[int index] + { + get => Indexer_Get(index); + set => Indexer_Set(index, value); + } - *value = default; + internal object Indexer_Get(int index) + { + if (index < 0) + throw new ArgumentOutOfRangeException(nameof(index)); - try + return GetAt(_vector, (uint)index); + } + + internal void Indexer_Set(int index, object value) { - __value = global::WinRT.ComWrappersSupport.FindObject(thisPtr).Size; - *value = __value; + if (index < 0) + throw new ArgumentOutOfRangeException(nameof(index)); + SetAt(_vector, (uint)index, value); } - catch (Exception __exception__) + + public int Add(object value) { - global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); - return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); + _vector.Append(value); + + uint size = _vector.Size; + if (((uint)int.MaxValue) < size) + { + throw new InvalidOperationException(WinRTRuntimeErrorStrings.InvalidOperation_CollectionBackingListTooLarge); + } + + return (int)(size - 1); } - return 0; - } - - internal static ObjectReference FromAbi(IntPtr thisPtr) => ObjectReference.FromAbi(thisPtr); - - private static readonly global::System.Runtime.CompilerServices.ConditionalWeakTable _helperTable = new(); - - unsafe object global::Microsoft.UI.Xaml.Interop.IBindableVectorView.GetAt(uint index) - { - var _obj = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Microsoft.UI.Xaml.Interop.IBindableIterator).TypeHandle); - var ThisPtr = _obj.ThisPtr; - IntPtr __retval = default; - try - { - global::WinRT.ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]**)ThisPtr)[6](ThisPtr, index, &__retval)); - return MarshalInspectable.FromAbi(__retval); - } - finally - { - MarshalInspectable.DisposeAbi(__retval); - } - } - - unsafe bool global::Microsoft.UI.Xaml.Interop.IBindableVectorView.IndexOf(object value, out uint index) - { - var _obj = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Microsoft.UI.Xaml.Interop.IBindableIterator).TypeHandle); - var ThisPtr = _obj.ThisPtr; - ObjectReferenceValue __value = default; - uint __index = default; - byte __retval = default; - try - { - __value = MarshalInspectable.CreateMarshaler2(value); - global::WinRT.ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]**)ThisPtr)[8]( - ThisPtr, - MarshalInspectable.GetAbi(__value), - &__index, - &__retval)); - index = __index; - return __retval != 0; - } - finally - { - MarshalInspectable.DisposeMarshaler(__value); - } - } - - unsafe uint global::Microsoft.UI.Xaml.Interop.IBindableVectorView.Size - { - get - { - var _obj = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Microsoft.UI.Xaml.Interop.IBindableIterator).TypeHandle); - var ThisPtr = _obj.ThisPtr; - uint __retval = default; - global::WinRT.ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]**)ThisPtr)[7](ThisPtr, &__retval)); - return __retval; - } - } - - IEnumerator IEnumerable.GetEnumerator() - { - return _helperTable.GetValue((IWinRTObject)this, - (enumerable) => new ABI.System.Collections.IEnumerable.FromAbiHelper((global::System.Collections.IEnumerable)(IWinRTObject)enumerable) - ).GetEnumerator(); - } - } - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.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); - } -} - -namespace ABI.System.Collections -{ - using global::Microsoft.UI.Xaml.Interop; - using global::System; - using global::System.Runtime.CompilerServices; -#if EMBED - internal -#else - public -#endif - static class IEnumerableMethods - { - public static global::System.Guid IID { get; } = new Guid(new global::System.ReadOnlySpan(new byte[] { 0x08, 0x2C, 0x6D, 0x03, 0x29, 0xDF, 0xAF, 0x41, 0x8A, 0xA2, 0xD7, 0x74, 0xBE, 0x62, 0xBA, 0x6F })); + public bool Contains(object item) + { + return _vector.IndexOf(item, out _); + } - public static IntPtr AbiToProjectionVftablePtr => IEnumerable.AbiToProjectionVftablePtr; - } - - [DynamicInterfaceCastableImplementation] - [Guid("036D2C08-DF29-41AF-8AA2-D774BE62BA6F")] - internal unsafe interface IEnumerable : global::System.Collections.IEnumerable, global::Microsoft.UI.Xaml.Interop.IBindableIterable - { - public static string GetGuidSignature() => GuidGenerator.GetSignature(typeof(IEnumerable)); - - public sealed class AdaptiveFromAbiHelper : FromAbiHelper, global::System.Collections.IEnumerable - { - private readonly Func _enumerator; - - public AdaptiveFromAbiHelper(Type runtimeType, IWinRTObject winRTObject) - :base(winRTObject) - { - Type enumGenericType = (runtimeType.IsGenericType && runtimeType.GetGenericTypeDefinition() == typeof(global::System.Collections.Generic.IEnumerable<>)) ? - runtimeType : runtimeType.GetInterface("System.Collections.Generic.IEnumerable`1"); - if(enumGenericType != null) - { - var getEnumerator = enumGenericType.GetMethod("GetEnumerator"); - _enumerator = (IWinRTObject obj) => (global::System.Collections.IEnumerator)getEnumerator.Invoke(obj, null); - } - } - - public override global::System.Collections.IEnumerator GetEnumerator() => _enumerator != null ? _enumerator(_winrtObject) : base.GetEnumerator(); - } - - public class FromAbiHelper : global::System.Collections.IEnumerable - { - 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 global::System.Collections.IEnumerator GetEnumerator() => - new Generic.FromAbiEnumerator(new NonGenericToGenericIterator(((global::Microsoft.UI.Xaml.Interop.IBindableIterable) GetIterable()).First())); - - private sealed class NonGenericToGenericIterator : global::Windows.Foundation.Collections.IIterator - { - private readonly IBindableIterator iterator; - - public NonGenericToGenericIterator(IBindableIterator iterator) => this.iterator = iterator; - - public object _Current => iterator.Current; - public bool HasCurrent => iterator.HasCurrent; - public bool _MoveNext() { return iterator.MoveNext(); } - public uint GetMany(ref object[] items) => throw new NotSupportedException(); - } - } - - public sealed class ToAbiHelper : IBindableIterable - { - private readonly IEnumerable m_enumerable; - - internal ToAbiHelper(IEnumerable enumerable) => m_enumerable = enumerable; - - IBindableIterator IBindableIterable.First() => MakeBindableIterator(m_enumerable.GetEnumerator()); - - internal static IBindableIterator MakeBindableIterator(IEnumerator enumerator) => - new Generic.IEnumerator.ToAbiHelper(new NonGenericToGenericEnumerator(enumerator)); - - private sealed class NonGenericToGenericEnumerator : IEnumerator - { - private readonly IEnumerator enumerator; - - public NonGenericToGenericEnumerator(IEnumerator enumerator) => this.enumerator = enumerator; - - public object Current => enumerator.Current; - public bool MoveNext() { return enumerator.MoveNext(); } - public void Reset() { enumerator.Reset(); } - public void Dispose() { } - } - } + public void Clear() + { + _vector.Clear(); + } - public static readonly IntPtr AbiToProjectionVftablePtr; - static IEnumerable() - { - AbiToProjectionVftablePtr = ComWrappersSupport.AllocateVtableMemory(typeof(IEnumerable), sizeof(IInspectable.Vftbl) + sizeof(IntPtr) * 1); - *(IInspectable.Vftbl*)AbiToProjectionVftablePtr = IInspectable.Vftbl.AbiToProjectionVftable; - ((delegate* unmanaged[Stdcall]*)AbiToProjectionVftablePtr)[6] = &Do_Abi_First_0; + public bool IsFixedSize { get => false; } + + public bool IsReadOnly { get => false; } + + public int IndexOf(object item) + { + uint index; + bool exists = _vector.IndexOf(item, out index); + + if (!exists) + return -1; + + if (((uint)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(nameof(index)); + + InsertAtHelper(_vector, (uint)index, item); + } + + public void Remove(object item) + { + uint index; + bool exists = _vector.IndexOf(item, out index); + + if (exists) + { + if (((uint)int.MaxValue) < index) + { + throw new InvalidOperationException(WinRTRuntimeErrorStrings.InvalidOperation_CollectionBackingListTooLarge); + } + + RemoveAtHelper(_vector, index); + } + } + + public void RemoveAt(int index) + { + if (index < 0) + throw new ArgumentOutOfRangeException(nameof(index)); + + RemoveAtHelper(_vector, (uint)index); + } + + private static object GetAt(IBindableVectorAdapter _this, uint index) + { + try + { + return _this.GetAt(index); + + // We delegate bounds checking to the underlying collection and if it detected a fault, + // we translate it to the right exception: + } + catch (Exception ex) + { + if (ExceptionHelpers.E_BOUNDS == ex.HResult) + throw new ArgumentOutOfRangeException(nameof(index)); + throw; + } + } + + private static void SetAt(IBindableVectorAdapter _this, uint index, object value) + { + try + { + _this.SetAt(index, value); + + // We delegate bounds checking to the underlying collection and if it detected a fault, + // we translate it to the right exception: + } + catch (Exception ex) + { + if (ExceptionHelpers.E_BOUNDS == ex.HResult) + throw new ArgumentOutOfRangeException(nameof(index)); + throw; + } + } + + private static void InsertAtHelper(IBindableVectorAdapter _this, uint index, object item) + { + try + { + _this.InsertAt(index, item); + + // We delegate bounds checking to the underlying collection and if it detected a fault, + // we translate it to the right exception: + } + catch (Exception ex) + { + if (ExceptionHelpers.E_BOUNDS == ex.HResult) + throw new ArgumentOutOfRangeException(nameof(index)); + throw; + } + } + + private static void RemoveAtHelper(IBindableVectorAdapter _this, uint index) + { + try + { + _this.RemoveAt(index); + + // We delegate bounds checking to the underlying collection and if it detected a fault, + // we translate it to the right exception: + } + catch (Exception ex) + { + if (ExceptionHelpers.E_BOUNDS == ex.HResult) + throw new ArgumentOutOfRangeException(nameof(index)); + throw; + } + } + + public IEnumerator GetEnumerator() + { + return ((IEnumerable)(IWinRTObject)_vector).GetEnumerator(); + } } - [UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })] - private static unsafe int Do_Abi_First_0(IntPtr thisPtr, IntPtr* result) + public sealed class ToAbiHelper : WUX.IBindableVector, MUX.IBindableVector, IBindableVectorAdapter { - *result = default; - try + private global::System.Collections.IList _list; + + public ToAbiHelper(global::System.Collections.IList list) => _list = list; + + public object GetAt(uint index) { - var __this = global::WinRT.ComWrappersSupport.FindObject(thisPtr); - var iterator = ToAbiHelper.MakeBindableIterator(__this.GetEnumerator()); - *result = MarshalInterface.FromManaged(iterator); + EnsureIndexInt32(index, _list.Count); + + try + { + return _list[(int)index]; + } + catch (ArgumentOutOfRangeException ex) + { + throw ex.GetExceptionForHR(ExceptionHelpers.E_BOUNDS, WinRTRuntimeErrorStrings.ArgumentOutOfRange_Index); + } } - catch (Exception __exception__) + + public uint Size { get => (uint)_list.Count; } + + IBindableVectorViewAdapter IBindableVectorAdapter.GetView() { - global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); - return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); + return new ListToBindableVectorViewAdapter(_list); } - return 0; - } - - internal static ObjectReference ObjRefFromAbi(IntPtr thisPtr) - { - if (thisPtr == IntPtr.Zero) - { - return null; - } - return ObjectReference.FromAbi(thisPtr); - } - - private static FromAbiHelper _AbiHelper(IWinRTObject _this) - { - return (FromAbiHelper)_this.GetOrCreateTypeHelperData(typeof(global::System.Collections.IEnumerable).TypeHandle, - () => new FromAbiHelper((global::System.Collections.IEnumerable)_this)); - } - - unsafe global::Microsoft.UI.Xaml.Interop.IBindableIterator global::Microsoft.UI.Xaml.Interop.IBindableIterable.First() - { - var _obj = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.IEnumerable).TypeHandle); - var ThisPtr = _obj.ThisPtr; - IntPtr __retval = default; - try - { - global::WinRT.ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]**)ThisPtr)[6](ThisPtr, &__retval)); - return MarshalInterface.FromAbi(__retval); - } - finally - { - MarshalInterface.DisposeAbi(__retval); - } - } - - IEnumerator global::System.Collections.IEnumerable.GetEnumerator() - { - return _AbiHelper((IWinRTObject)this).GetEnumerator(); - } - } - - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] -#if EMBED - internal -#else - public -#endif - static class IEnumerable_Delegates - { - public unsafe delegate int First_0(IntPtr thisPtr, IntPtr* result); - } -#if EMBED - internal -#else - public -#endif - static class IListMethods - { - public static Guid IID { get; } = new Guid(new global::System.ReadOnlySpan(new byte[] { 0xDE, 0xE7, 0x3D, 0x39, 0xD0, 0x6F, 0x0D, 0x4C, 0xBB, 0x71, 0x47, 0x24, 0x4A, 0x11, 0x3E, 0x93 })); + WUX.IBindableVectorView WUX.IBindableVector.GetView() + { + return new ListToBindableVectorViewAdapter(_list); + } - public static IntPtr AbiToProjectionVftablePtr => IList.AbiToProjectionVftablePtr; - } + MUX.IBindableVectorView MUX.IBindableVector.GetView() + { + return new ListToBindableVectorViewAdapter(_list); + } + + public bool IndexOf(object value, out uint index) + { + int ind = _list.IndexOf(value); + + if (-1 == ind) + { + index = 0; + return false; + } - [DynamicInterfaceCastableImplementation] - [Guid("393DE7DE-6FD0-4C0D-BB71-47244A113E93")] - internal unsafe interface IList : global::System.Collections.IList, global::Microsoft.UI.Xaml.Interop.IBindableVector - { - public static string GetGuidSignature() => GuidGenerator.GetSignature(typeof(IList)); - - public sealed class FromAbiHelper : global::System.Collections.IList - { - private readonly global::Microsoft.UI.Xaml.Interop.IBindableVector _vector; - - public FromAbiHelper(global::Microsoft.UI.Xaml.Interop.IBindableVector vector) - { - _vector = vector; - } - - public bool IsSynchronized => false; - - public object SyncRoot { get => this; } - - public int Count - { - get - { - uint size = _vector.Size; - if (((uint)int.MaxValue) < size) - { - throw new InvalidOperationException(WinRTRuntimeErrorStrings.InvalidOperation_CollectionBackingListTooLarge); - } - - return (int)size; - } - } - - public void CopyTo(Array array, int arrayIndex) - { - if (array == null) - throw new ArgumentNullException(nameof(array)); - - // ICollection expects the destination array to be single-dimensional. - if (array.Rank != 1) - throw new ArgumentException(WinRTRuntimeErrorStrings.Arg_RankMultiDimNotSupported); - - int destLB = array.GetLowerBound(0); - int srcLen = Count; - int destLen = array.GetLength(0); - - if (arrayIndex < destLB) - throw new ArgumentOutOfRangeException(nameof(arrayIndex)); - - // Does the dimension in question have sufficient space to copy the expected number of entries? - // We perform this check before valid index check to ensure the exception message is in sync with - // the following snippet that uses regular framework code: - // - // ArrayList list = new ArrayList(); - // list.Add(1); - // Array items = Array.CreateInstance(typeof(object), new int[] { 1 }, new int[] { -1 }); - // list.CopyTo(items, 0); - - if (srcLen > (destLen - (arrayIndex - destLB))) - throw new ArgumentException(WinRTRuntimeErrorStrings.Argument_InsufficientSpaceToCopyCollection); - - if (arrayIndex - destLB > destLen) - throw new ArgumentException(WinRTRuntimeErrorStrings.Argument_IndexOutOfArrayBounds); - - // We need to verify the index as we; - for (uint i = 0; i < srcLen; i++) - { - array.SetValue(_vector.GetAt(i), i + arrayIndex); - } - } - - public object this[int index] - { - get => Indexer_Get(index); - set => Indexer_Set(index, value); - } - - internal object Indexer_Get(int index) - { - if (index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); - - return GetAt(_vector, (uint)index); - } - - internal void Indexer_Set(int index, object value) - { - if (index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); - - SetAt(_vector, (uint)index, value); - } - - public int Add(object value) - { - _vector.Append(value); - - uint size = _vector.Size; - if (((uint)int.MaxValue) < size) - { - throw new InvalidOperationException(WinRTRuntimeErrorStrings.InvalidOperation_CollectionBackingListTooLarge); - } - - return (int)(size - 1); - } - - public bool Contains(object item) - { - return _vector.IndexOf(item, out _); - } - - public void Clear() - { - _vector.Clear(); - } - - public bool IsFixedSize { get => false; } - - public bool IsReadOnly { get => false; } - - public int IndexOf(object item) - { - uint index; - bool exists = _vector.IndexOf(item, out index); - - if (!exists) - return -1; - - if (((uint)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(nameof(index)); - - InsertAtHelper(_vector, (uint)index, item); - } - - public void Remove(object item) - { - uint index; - bool exists = _vector.IndexOf(item, out index); - - if (exists) - { - if (((uint)int.MaxValue) < index) - { - throw new InvalidOperationException(WinRTRuntimeErrorStrings.InvalidOperation_CollectionBackingListTooLarge); - } - - RemoveAtHelper(_vector, index); - } - } - - public void RemoveAt(int index) - { - if (index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); - - RemoveAtHelper(_vector, (uint)index); - } - - private static object GetAt(global::Microsoft.UI.Xaml.Interop.IBindableVector _this, uint index) - { - try - { - return _this.GetAt(index); - - // We delegate bounds checking to the underlying collection and if it detected a fault, - // we translate it to the right exception: - } - catch (Exception ex) - { - if (ExceptionHelpers.E_BOUNDS == ex.HResult) - throw new ArgumentOutOfRangeException(nameof(index)); - throw; - } - } - - private static void SetAt(global::Microsoft.UI.Xaml.Interop.IBindableVector _this, uint index, object value) - { - try - { - _this.SetAt(index, value); - - // We delegate bounds checking to the underlying collection and if it detected a fault, - // we translate it to the right exception: - } - catch (Exception ex) - { - if (ExceptionHelpers.E_BOUNDS == ex.HResult) - throw new ArgumentOutOfRangeException(nameof(index)); - throw; - } - } - - private static void InsertAtHelper(global::Microsoft.UI.Xaml.Interop.IBindableVector _this, uint index, object item) - { - try - { - _this.InsertAt(index, item); - - // We delegate bounds checking to the underlying collection and if it detected a fault, - // we translate it to the right exception: - } - catch (Exception ex) - { - if (ExceptionHelpers.E_BOUNDS == ex.HResult) - throw new ArgumentOutOfRangeException(nameof(index)); - throw; - } - } - - private static void RemoveAtHelper(global::Microsoft.UI.Xaml.Interop.IBindableVector _this, uint index) - { - try - { - _this.RemoveAt(index); - - // We delegate bounds checking to the underlying collection and if it detected a fault, - // we translate it to the right exception: - } - catch (Exception ex) - { - if (ExceptionHelpers.E_BOUNDS == ex.HResult) - throw new ArgumentOutOfRangeException(nameof(index)); - throw; - } - } - - public IEnumerator GetEnumerator() - { - return ((IEnumerable)(IWinRTObject)_vector).GetEnumerator(); - } - } - - public sealed class ToAbiHelper : IBindableVector - { - private global::System.Collections.IList _list; - - 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 ex) - { - throw ex.GetExceptionForHR(ExceptionHelpers.E_BOUNDS, WinRTRuntimeErrorStrings.ArgumentOutOfRange_Index); - } - } - - public uint Size { get => (uint)_list.Count; } - - IBindableVectorView IBindableVector.GetView() - { - return new ListToBindableVectorViewAdapter(_list); - } - - public bool IndexOf(object value, out uint index) - { - int ind = _list.IndexOf(value); - - if (-1 == ind) - { - index = 0; - return false; - } - - index = (uint)ind; - return true; - } - - public void SetAt(uint index, object value) - { - EnsureIndexInt32(index, _list.Count); - - try - { - _list[(int)index] = value; - } - catch (ArgumentOutOfRangeException ex) - { - throw ex.GetExceptionForHR(ExceptionHelpers.E_BOUNDS, WinRTRuntimeErrorStrings.ArgumentOutOfRange_Index); - } - } - - public void InsertAt(uint index, object value) - { - // Inserting at an index one past the end of the list is equivalent to appending - // so we need to ensure that we're within (0, count + 1). - EnsureIndexInt32(index, _list.Count + 1); - - try - { - _list.Insert((int)index, value); - } - catch (ArgumentOutOfRangeException ex) - { - // Change error code to match what WinRT expects - ex.SetHResult(ExceptionHelpers.E_BOUNDS); - throw; - } - } - - public void RemoveAt(uint index) - { - EnsureIndexInt32(index, _list.Count); - - try - { - _list.RemoveAt((int)index); - } - catch (ArgumentOutOfRangeException ex) - { - // Change error code to match what WinRT expects - ex.SetHResult(ExceptionHelpers.E_BOUNDS); - throw; - } - } - - public void Append(object value) - { - _list.Add(value); - } - - public void RemoveAtEnd() - { - if (_list.Count == 0) - { - Exception e = new InvalidOperationException(WinRTRuntimeErrorStrings.InvalidOperation_CannotRemoveLastFromEmptyCollection); - e.SetHResult(ExceptionHelpers.E_BOUNDS); - throw e; - } - - uint size = (uint)_list.Count; - RemoveAt(size - 1); - } - - public void Clear() - { - _list.Clear(); - } - - private static void EnsureIndexInt32(uint index, int listCapacity) - { - // We use '<=' and not '<' becasue int.MaxValue == index would imply - // that Size > int.MaxValue: - if (((uint)int.MaxValue) <= index || index >= (uint)listCapacity) - { - Exception e = new ArgumentOutOfRangeException(nameof(index), WinRTRuntimeErrorStrings.ArgumentOutOfRange_IndexLargerThanMaxValue); - e.SetHResult(ExceptionHelpers.E_BOUNDS); - throw e; - } - } - - public IEnumerator GetEnumerator() => _list.GetEnumerator(); - - /// A Windows Runtime IBindableVectorView implementation that wraps around a managed IList exposing - /// it to Windows runtime interop. - internal sealed class ListToBindableVectorViewAdapter : IBindableVectorView - { - private readonly global::System.Collections.IList list; - - internal ListToBindableVectorViewAdapter(global::System.Collections.IList list) - { - if (list == null) - throw new ArgumentNullException(nameof(list)); - this.list = list; - } - - private static void EnsureIndexInt32(uint index, int listCapacity) - { - // We use '<=' and not '<' becasue int.MaxValue == index would imply - // that Size > int.MaxValue: - if (((uint)int.MaxValue) <= index || index >= (uint)listCapacity) - { - Exception e = new ArgumentOutOfRangeException(nameof(index), WinRTRuntimeErrorStrings.ArgumentOutOfRange_IndexLargerThanMaxValue); - e.SetHResult(ExceptionHelpers.E_BOUNDS); - throw e; - } - } - - public IBindableIterator First() => - IEnumerable.ToAbiHelper.MakeBindableIterator(list.GetEnumerator()); - - public object GetAt(uint index) - { - EnsureIndexInt32(index, list.Count); - - try - { - return list[(int)index]; - } - catch (ArgumentOutOfRangeException ex) - { - throw ex.GetExceptionForHR(ExceptionHelpers.E_BOUNDS, WinRTRuntimeErrorStrings.ArgumentOutOfRange_Index); - } - } - - public uint Size => (uint)list.Count; - - public bool IndexOf(object value, out uint index) - { - int ind = list.IndexOf(value); - - if (-1 == ind) - { - index = 0; - return false; - } - - index = (uint)ind; - return true; - } - - public IEnumerator GetEnumerator() => list.GetEnumerator(); - } + index = (uint)ind; + return true; + } + + public void SetAt(uint index, object value) + { + EnsureIndexInt32(index, _list.Count); + + try + { + _list[(int)index] = value; + } + catch (ArgumentOutOfRangeException ex) + { + throw ex.GetExceptionForHR(ExceptionHelpers.E_BOUNDS, WinRTRuntimeErrorStrings.ArgumentOutOfRange_Index); + } + } + + public void InsertAt(uint index, object value) + { + // Inserting at an index one past the end of the list is equivalent to appending + // so we need to ensure that we're within (0, count + 1). + EnsureIndexInt32(index, _list.Count + 1); + + try + { + _list.Insert((int)index, value); + } + catch (ArgumentOutOfRangeException ex) + { + // Change error code to match what WinRT expects + ex.SetHResult(ExceptionHelpers.E_BOUNDS); + throw; + } + } + + public void RemoveAt(uint index) + { + EnsureIndexInt32(index, _list.Count); + + try + { + _list.RemoveAt((int)index); + } + catch (ArgumentOutOfRangeException ex) + { + // Change error code to match what WinRT expects + ex.SetHResult(ExceptionHelpers.E_BOUNDS); + throw; + } + } + + public void Append(object value) + { + _list.Add(value); + } + + public void RemoveAtEnd() + { + if (_list.Count == 0) + { + Exception e = new InvalidOperationException(WinRTRuntimeErrorStrings.InvalidOperation_CannotRemoveLastFromEmptyCollection); + e.SetHResult(ExceptionHelpers.E_BOUNDS); + throw e; + } + + uint size = (uint)_list.Count; + RemoveAt(size - 1); + } + + public void Clear() + { + _list.Clear(); + } + + private static void EnsureIndexInt32(uint index, int listCapacity) + { + // We use '<=' and not '<' becasue int.MaxValue == index would imply + // that Size > int.MaxValue: + if (((uint)int.MaxValue) <= index || index >= (uint)listCapacity) + { + Exception e = new ArgumentOutOfRangeException(nameof(index), WinRTRuntimeErrorStrings.ArgumentOutOfRange_IndexLargerThanMaxValue); + e.SetHResult(ExceptionHelpers.E_BOUNDS); + throw e; + } + } + + public IEnumerator GetEnumerator() => _list.GetEnumerator(); + + /// A Windows Runtime IBindableVectorView implementation that wraps around a managed IList exposing + /// it to Windows runtime interop. + internal sealed class ListToBindableVectorViewAdapter : WUX.IBindableVectorView, MUX.IBindableVectorView, IBindableVectorViewAdapter + { + private readonly global::System.Collections.IList list; + + internal ListToBindableVectorViewAdapter(global::System.Collections.IList list) + { + if (list == null) + throw new ArgumentNullException(nameof(list)); + this.list = list; + } + + private static void EnsureIndexInt32(uint index, int listCapacity) + { + // We use '<=' and not '<' becasue int.MaxValue == index would imply + // that Size > int.MaxValue: + if (((uint)int.MaxValue) <= index || index >= (uint)listCapacity) + { + Exception e = new ArgumentOutOfRangeException(nameof(index), WinRTRuntimeErrorStrings.ArgumentOutOfRange_IndexLargerThanMaxValue); + e.SetHResult(ExceptionHelpers.E_BOUNDS); + throw e; + } + } + + public object GetAt(uint index) + { + EnsureIndexInt32(index, list.Count); + + try + { + return list[(int)index]; + } + catch (ArgumentOutOfRangeException ex) + { + throw ex.GetExceptionForHR(ExceptionHelpers.E_BOUNDS, WinRTRuntimeErrorStrings.ArgumentOutOfRange_Index); + } + } + + public uint Size => (uint)list.Count; + + public bool IndexOf(object value, out uint index) + { + int ind = list.IndexOf(value); + + if (-1 == ind) + { + index = 0; + return false; + } + + index = (uint)ind; + return true; + } + + public IEnumerator GetEnumerator() => list.GetEnumerator(); + } } - public static readonly IntPtr AbiToProjectionVftablePtr; + public static readonly IntPtr AbiToProjectionVftablePtr; static IList() { - AbiToProjectionVftablePtr = ComWrappersSupport.AllocateVtableMemory(typeof(IList), sizeof(IInspectable.Vftbl) + sizeof(IntPtr) * 10); - *(IInspectable.Vftbl*)AbiToProjectionVftablePtr = IInspectable.Vftbl.AbiToProjectionVftable; + AbiToProjectionVftablePtr = ComWrappersSupport.AllocateVtableMemory(typeof(IList), sizeof(IInspectable.Vftbl) + sizeof(IntPtr) * 10); + *(IInspectable.Vftbl*)AbiToProjectionVftablePtr = IInspectable.Vftbl.AbiToProjectionVftable; ((delegate* unmanaged[Stdcall]*)AbiToProjectionVftablePtr)[6] = &Do_Abi_GetAt_0; - ((delegate* unmanaged[Stdcall]*)AbiToProjectionVftablePtr)[7] = &Do_Abi_get_Size_1; - ((delegate* unmanaged[Stdcall]*)AbiToProjectionVftablePtr)[8] = &Do_Abi_GetView_2; - ((delegate* unmanaged[Stdcall]*)AbiToProjectionVftablePtr)[9] = &Do_Abi_IndexOf_3; - ((delegate* unmanaged[Stdcall]*)AbiToProjectionVftablePtr)[10] = &Do_Abi_SetAt_4; - ((delegate* unmanaged[Stdcall]*)AbiToProjectionVftablePtr)[11] = &Do_Abi_InsertAt_5; - ((delegate* unmanaged[Stdcall]*)AbiToProjectionVftablePtr)[12] = &Do_Abi_RemoveAt_6; - ((delegate* unmanaged[Stdcall]*)AbiToProjectionVftablePtr)[13] = &Do_Abi_Append_7; - ((delegate* unmanaged[Stdcall]*)AbiToProjectionVftablePtr)[14] = &Do_Abi_RemoveAtEnd_8; + ((delegate* unmanaged[Stdcall]*)AbiToProjectionVftablePtr)[7] = &Do_Abi_get_Size_1; + ((delegate* unmanaged[Stdcall]*)AbiToProjectionVftablePtr)[8] = Projections.UiXamlModeSetting is Projections.UiXamlMode.WindowsUiXaml ? &Do_Wux_Abi_GetView_2 : &Do_Mux_Abi_GetView_2; + ((delegate* unmanaged[Stdcall]*)AbiToProjectionVftablePtr)[9] = &Do_Abi_IndexOf_3; + ((delegate* unmanaged[Stdcall]*)AbiToProjectionVftablePtr)[10] = &Do_Abi_SetAt_4; + ((delegate* unmanaged[Stdcall]*)AbiToProjectionVftablePtr)[11] = &Do_Abi_InsertAt_5; + ((delegate* unmanaged[Stdcall]*)AbiToProjectionVftablePtr)[12] = &Do_Abi_RemoveAt_6; + ((delegate* unmanaged[Stdcall]*)AbiToProjectionVftablePtr)[13] = &Do_Abi_Append_7; + ((delegate* unmanaged[Stdcall]*)AbiToProjectionVftablePtr)[14] = &Do_Abi_RemoveAtEnd_8; ((delegate* unmanaged[Stdcall]*)AbiToProjectionVftablePtr)[15] = &Do_Abi_Clear_9; } private static readonly ConditionalWeakTable _adapterTable = new(); - private static IBindableVector FindAdapter(IntPtr thisPtr) + private static IBindableVectorAdapter FindAdapter(IntPtr thisPtr) { var __this = global::WinRT.ComWrappersSupport.FindObject(thisPtr); return _adapterTable.GetValue(__this, (list) => new ToAbiHelper(list)); @@ -1031,14 +805,32 @@ private static unsafe int Do_Abi_GetAt_0(IntPtr thisPtr, uint index, IntPtr* res } [UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })] - private static unsafe int Do_Abi_GetView_2(IntPtr thisPtr, IntPtr* result) + private static unsafe int Do_Wux_Abi_GetView_2(IntPtr thisPtr, IntPtr* result) { - global::Microsoft.UI.Xaml.Interop.IBindableVectorView __result = default; + IBindableVectorViewAdapter __result = default; *result = default; try { __result = FindAdapter(thisPtr).GetView(); - *result = MarshalInterface.FromManaged(__result); + *result = MarshalInterface.FromManaged((WUX.IBindableVectorView)__result); + } + catch (Exception __exception__) + { + global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); + return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); + } + return 0; + } + + [UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })] + private static unsafe int Do_Mux_Abi_GetView_2(IntPtr thisPtr, IntPtr* result) + { + IBindableVectorViewAdapter __result = default; + *result = default; + try + { + __result = FindAdapter(thisPtr).GetView(); + *result = MarshalInterface.FromManaged((MUX.IBindableVectorView)__result); } catch (Exception __exception__) { @@ -1177,202 +969,211 @@ private static unsafe int Do_Abi_get_Size_1(IntPtr thisPtr, uint* value) return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); } return 0; - } - - internal static ObjectReference ObjRefFromAbi(IntPtr thisPtr) - { - if (thisPtr == IntPtr.Zero) - { - return null; - } - return ObjectReference.FromAbi(thisPtr); - } - - internal static FromAbiHelper _VectorToList(IWinRTObject _this) - { - return (FromAbiHelper)_this.GetOrCreateTypeHelperData(typeof(global::System.Collections.IList).TypeHandle, - () => new FromAbiHelper((global::Microsoft.UI.Xaml.Interop.IBindableVector)_this)); - } - - unsafe object global::Microsoft.UI.Xaml.Interop.IBindableVector.GetAt(uint index) - { - var _obj = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.IList).TypeHandle); - var ThisPtr = _obj.ThisPtr; - IntPtr __retval = default; - try - { - global::WinRT.ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]**)ThisPtr)[6](ThisPtr, index, &__retval)); - return MarshalInspectable.FromAbi(__retval); - } - finally - { - MarshalInspectable.DisposeAbi(__retval); - } - } - - unsafe global::Microsoft.UI.Xaml.Interop.IBindableVectorView global::Microsoft.UI.Xaml.Interop.IBindableVector.GetView() - { - var _obj = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.IList).TypeHandle); - var ThisPtr = _obj.ThisPtr; - IntPtr __retval = default; - try - { - global::WinRT.ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]**)ThisPtr)[8](ThisPtr, &__retval)); - return MarshalInterface.FromAbi(__retval); - } - finally - { - MarshalInterface.DisposeAbi(__retval); - } - } - - unsafe bool global::Microsoft.UI.Xaml.Interop.IBindableVector.IndexOf(object value, out uint index) - { - var _obj = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.IList).TypeHandle); - var ThisPtr = _obj.ThisPtr; - ObjectReferenceValue __value = default; - uint __index = default; - byte __retval = default; - try - { + } + + internal static ObjectReference ObjRefFromAbi(IntPtr thisPtr) + { + if (thisPtr == IntPtr.Zero) + { + return null; + } + return ObjectReference.FromAbi(thisPtr); + } + + internal static FromAbiHelper _VectorToList(IWinRTObject _this) + { + IBindableVectorAdapter adapter = null; + if (Projections.UiXamlModeSetting is Projections.UiXamlMode.WindowsUiXaml) + { + adapter = new WuxBindableVectorAdapter((WUX.IBindableVector)_this); + } + else + { + adapter = new MuxBindableVectorAdapter((MUX.IBindableVector)_this); + } + return (FromAbiHelper)_this.GetOrCreateTypeHelperData(typeof(global::System.Collections.IList).TypeHandle, + () => new FromAbiHelper(adapter)); + } + + unsafe object global::Windows.UI.Xaml.Interop.IBindableVector.GetAt(uint index) + { + var _obj = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.IList).TypeHandle); + var ThisPtr = _obj.ThisPtr; + IntPtr __retval = default; + try + { + global::WinRT.ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]**)ThisPtr)[6](ThisPtr, index, &__retval)); + return MarshalInspectable.FromAbi(__retval); + } + finally + { + MarshalInspectable.DisposeAbi(__retval); + } + } + + unsafe global::Windows.UI.Xaml.Interop.IBindableVectorView global::Windows.UI.Xaml.Interop.IBindableVector.GetView() + { + var _obj = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.IList).TypeHandle); + var ThisPtr = _obj.ThisPtr; + IntPtr __retval = default; + try + { + global::WinRT.ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]**)ThisPtr)[8](ThisPtr, &__retval)); + return MarshalInterface.FromAbi(__retval); + } + finally + { + MarshalInterface.DisposeAbi(__retval); + } + } + + unsafe bool global::Windows.UI.Xaml.Interop.IBindableVector.IndexOf(object value, out uint index) + { + var _obj = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.IList).TypeHandle); + var ThisPtr = _obj.ThisPtr; + ObjectReferenceValue __value = default; + uint __index = default; + byte __retval = default; + try + { __value = MarshalInspectable.CreateMarshaler2(value); - global::WinRT.ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]**)ThisPtr)[9](ThisPtr, MarshalInspectable.GetAbi(__value), &__index, &__retval)); - index = __index; - return __retval != 0; - } - finally - { - MarshalInspectable.DisposeMarshaler(__value); - } - } - - unsafe void global::Microsoft.UI.Xaml.Interop.IBindableVector.SetAt(uint index, object value) - { - var _obj = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.IList).TypeHandle); - var ThisPtr = _obj.ThisPtr; - ObjectReferenceValue __value = default; - try - { + global::WinRT.ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]**)ThisPtr)[9](ThisPtr, MarshalInspectable.GetAbi(__value), &__index, &__retval)); + index = __index; + return __retval != 0; + } + finally + { + MarshalInspectable.DisposeMarshaler(__value); + } + } + + unsafe void global::Windows.UI.Xaml.Interop.IBindableVector.SetAt(uint index, object value) + { + var _obj = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.IList).TypeHandle); + var ThisPtr = _obj.ThisPtr; + ObjectReferenceValue __value = default; + try + { __value = MarshalInspectable.CreateMarshaler2(value); - global::WinRT.ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]**)ThisPtr)[10](ThisPtr, index, MarshalInspectable.GetAbi(__value))); - } - finally - { - MarshalInspectable.DisposeMarshaler(__value); - } - } - - unsafe void global::Microsoft.UI.Xaml.Interop.IBindableVector.InsertAt(uint index, object value) - { - var _obj = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.IList).TypeHandle); - var ThisPtr = _obj.ThisPtr; - ObjectReferenceValue __value = default; - try - { + global::WinRT.ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]**)ThisPtr)[10](ThisPtr, index, MarshalInspectable.GetAbi(__value))); + } + finally + { + MarshalInspectable.DisposeMarshaler(__value); + } + } + + unsafe void global::Windows.UI.Xaml.Interop.IBindableVector.InsertAt(uint index, object value) + { + var _obj = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.IList).TypeHandle); + var ThisPtr = _obj.ThisPtr; + ObjectReferenceValue __value = default; + try + { __value = MarshalInspectable.CreateMarshaler2(value); - global::WinRT.ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]**)ThisPtr)[11](ThisPtr, index, MarshalInspectable.GetAbi(__value))); - } - finally - { - MarshalInspectable.DisposeMarshaler(__value); - } - } - - unsafe void global::Microsoft.UI.Xaml.Interop.IBindableVector.RemoveAt(uint index) - { - var _obj = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.IList).TypeHandle); + global::WinRT.ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]**)ThisPtr)[11](ThisPtr, index, MarshalInspectable.GetAbi(__value))); + } + finally + { + MarshalInspectable.DisposeMarshaler(__value); + } + } + + unsafe void global::Windows.UI.Xaml.Interop.IBindableVector.RemoveAt(uint index) + { + var _obj = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.IList).TypeHandle); + var ThisPtr = _obj.ThisPtr; + global::WinRT.ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]**)ThisPtr)[12](ThisPtr, index)); + } + + unsafe void global::Windows.UI.Xaml.Interop.IBindableVector.Append(object value) + { + var _obj = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.IList).TypeHandle); var ThisPtr = _obj.ThisPtr; - global::WinRT.ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]**)ThisPtr)[12](ThisPtr, index)); - } - - unsafe void global::Microsoft.UI.Xaml.Interop.IBindableVector.Append(object value) - { - var _obj = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.IList).TypeHandle); - var ThisPtr = _obj.ThisPtr; - ObjectReferenceValue __value = default; - try - { + ObjectReferenceValue __value = default; + try + { __value = MarshalInspectable.CreateMarshaler2(value); - global::WinRT.ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]**)ThisPtr)[13](ThisPtr, MarshalInspectable.GetAbi(__value))); - } - finally - { - MarshalInspectable.DisposeMarshaler(__value); - } - } - - unsafe void global::Microsoft.UI.Xaml.Interop.IBindableVector.RemoveAtEnd() - { - var _obj = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.IList).TypeHandle); + global::WinRT.ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]**)ThisPtr)[13](ThisPtr, MarshalInspectable.GetAbi(__value))); + } + finally + { + MarshalInspectable.DisposeMarshaler(__value); + } + } + + unsafe void global::Windows.UI.Xaml.Interop.IBindableVector.RemoveAtEnd() + { + var _obj = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.IList).TypeHandle); var ThisPtr = _obj.ThisPtr; - global::WinRT.ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]**)ThisPtr)[14](ThisPtr)); - } - - unsafe void global::Microsoft.UI.Xaml.Interop.IBindableVector.Clear() - { - var _obj = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.IList).TypeHandle); + global::WinRT.ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]**)ThisPtr)[14](ThisPtr)); + } + + unsafe void global::Windows.UI.Xaml.Interop.IBindableVector.Clear() + { + var _obj = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.IList).TypeHandle); var ThisPtr = _obj.ThisPtr; - global::WinRT.ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]**)ThisPtr)[15](ThisPtr)); - } - - unsafe uint global::Microsoft.UI.Xaml.Interop.IBindableVector.Size - { - get - { - var _obj = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.IList).TypeHandle); - var ThisPtr = _obj.ThisPtr; + global::WinRT.ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]**)ThisPtr)[15](ThisPtr)); + } + + unsafe uint global::Windows.UI.Xaml.Interop.IBindableVector.Size + { + get + { + var _obj = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::System.Collections.IList).TypeHandle); + var ThisPtr = _obj.ThisPtr; uint __retval = default; - global::WinRT.ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]**)ThisPtr)[7](ThisPtr, &__retval)); - return __retval; - } - } - - object global::System.Collections.IList.this[int index] - { - get => _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; - - int global::System.Collections.IList.Add(object value) => _VectorToList((IWinRTObject)this).Add(value); - - void global::System.Collections.IList.Clear() => _VectorToList((IWinRTObject)this).Clear(); - - bool global::System.Collections.IList.Contains(object value) => _VectorToList((IWinRTObject)this).Contains(value); - - int global::System.Collections.IList.IndexOf(object value) => _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() => _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 unsafe delegate int SetAt_4(IntPtr thisPtr, uint index, IntPtr value); - public unsafe delegate int InsertAt_5(IntPtr thisPtr, uint index, IntPtr value); - public unsafe delegate int RemoveAt_6(IntPtr thisPtr, uint index); - public unsafe delegate int Append_7(IntPtr thisPtr, IntPtr value); - public unsafe delegate int RemoveAtEnd_8(IntPtr thisPtr); - public unsafe delegate int Clear_9(IntPtr thisPtr); - } -} + global::WinRT.ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]**)ThisPtr)[7](ThisPtr, &__retval)); + return __retval; + } + } + + object global::System.Collections.IList.this[int index] + { + get => _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; + + int global::System.Collections.IList.Add(object value) => _VectorToList((IWinRTObject)this).Add(value); + + void global::System.Collections.IList.Clear() => _VectorToList((IWinRTObject)this).Clear(); + + bool global::System.Collections.IList.Contains(object value) => _VectorToList((IWinRTObject)this).Contains(value); + + int global::System.Collections.IList.IndexOf(object value) => _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() => _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 unsafe delegate int SetAt_4(IntPtr thisPtr, uint index, IntPtr value); + public unsafe delegate int InsertAt_5(IntPtr thisPtr, uint index, IntPtr value); + public unsafe delegate int RemoveAt_6(IntPtr thisPtr, uint index); + public unsafe delegate int Append_7(IntPtr thisPtr, IntPtr value); + public unsafe delegate int RemoveAtEnd_8(IntPtr thisPtr); + public unsafe delegate int Clear_9(IntPtr thisPtr); + } +} diff --git a/src/WinRT.Runtime/Projections/ICommand.net5.cs b/src/WinRT.Runtime/Projections/ICommand.net5.cs index 8f6ca008a..1f4c89b8c 100644 --- a/src/WinRT.Runtime/Projections/ICommand.net5.cs +++ b/src/WinRT.Runtime/Projections/ICommand.net5.cs @@ -20,6 +20,7 @@ static class ICommandMethods public static IntPtr AbiToProjectionVftablePtr => ICommand.Vftbl.AbiToProjectionVftablePtr; } + // ICommand has the same IID for both Windows.UI.Xaml.Input.ICommand and Microsoft.UI.Xaml.Input.ICommand, so we can use one interface definition for both without marking it as a WUX/MUX type. [EditorBrowsable(EditorBrowsableState.Never)] [Guid("E5AF3542-CA67-4081-995B-709DD13792DF")] [DynamicInterfaceCastableImplementation] diff --git a/src/WinRT.Runtime/Projections/ICustomPropertyProvider.net5.cs b/src/WinRT.Runtime/Projections/ICustomPropertyProvider.net5.cs index ca33a3457..0684e4cf5 100644 --- a/src/WinRT.Runtime/Projections/ICustomPropertyProvider.net5.cs +++ b/src/WinRT.Runtime/Projections/ICustomPropertyProvider.net5.cs @@ -6,6 +6,8 @@ using System.Runtime.InteropServices; using WinRT; +// These types have the same GUIDs in both Microsoft.UI.Xaml and Windows.UI.Xaml, +// so we don't need to duplicate them for the internal usage here as they can be transparently used by both WUX and MUX. namespace Microsoft.UI.Xaml.Data { [global::WinRT.WindowsRuntimeType] diff --git a/src/WinRT.Runtime/Projections/IEnumerable.net5.cs b/src/WinRT.Runtime/Projections/IEnumerable.net5.cs index 7e7626a86..5b1f2467c 100644 --- a/src/WinRT.Runtime/Projections/IEnumerable.net5.cs +++ b/src/WinRT.Runtime/Projections/IEnumerable.net5.cs @@ -907,7 +907,7 @@ public static void DisposeAbi(IntPtr abi) => // In IEnumerator<> scenarios, we use this as a helper for the implementation and don't actually use it to // create a CCW. [global::WinRT.WinRTExposedType(typeof(IBindableIteratorTypeDetails))] - public sealed class ToAbiHelper : global::Windows.Foundation.Collections.IIterator, global::Microsoft.UI.Xaml.Interop.IBindableIterator + public sealed class ToAbiHelper : global::Windows.Foundation.Collections.IIterator, global::Microsoft.UI.Xaml.Interop.IBindableIterator, global::Windows.UI.Xaml.Interop.IBindableIterator { private readonly global::System.Collections.Generic.IEnumerator m_enumerator; private bool m_firstItem = true; @@ -998,6 +998,11 @@ public uint GetMany(ref T[] items) public bool MoveNext() => _MoveNext(); uint global::Microsoft.UI.Xaml.Interop.IBindableIterator.GetMany(ref object[] items) + { + // Should not be called. + throw new NotImplementedException(); + } + uint global::Windows.UI.Xaml.Interop.IBindableIterator.GetMany(ref object[] items) { // Should not be called. throw new NotImplementedException(); diff --git a/src/WinRT.Runtime/Projections/INotifyCollectionChanged.net5.cs b/src/WinRT.Runtime/Projections/INotifyCollectionChanged.net5.cs index 7c0d94350..3d7334c5c 100644 --- a/src/WinRT.Runtime/Projections/INotifyCollectionChanged.net5.cs +++ b/src/WinRT.Runtime/Projections/INotifyCollectionChanged.net5.cs @@ -5,6 +5,7 @@ using System.ComponentModel; using System.Runtime.InteropServices; using WinRT; +using WinRT.Interop; namespace ABI.System.Collections.Specialized { @@ -45,11 +46,21 @@ public static unsafe (Action Projections.UiXamlModeSetting == Projections.UiXamlMode.WindowsUiXaml + ? "{CF75D69C-F2F4-486B-B302-BB4C09BAEBFA}" + : typeof(INotifyCollectionChanged).GUID.ToString("B"); + + [Guid("530155E1-28A5-5693-87CE-30724D95A06D")] + [WuxMuxProjectedType] public struct Vftbl - { + { + public static string GetGuidSignature() + => INotifyCollectionChanged.GetGuidSignature(); + internal IInspectable.Vftbl IInspectableVftbl; private delegate* unmanaged _add_CollectionChanged_0; diff --git a/src/WinRT.Runtime/Projections/INotifyPropertyChanged.net5.cs b/src/WinRT.Runtime/Projections/INotifyPropertyChanged.net5.cs index 576c284f8..dd5322408 100644 --- a/src/WinRT.Runtime/Projections/INotifyPropertyChanged.net5.cs +++ b/src/WinRT.Runtime/Projections/INotifyPropertyChanged.net5.cs @@ -4,6 +4,7 @@ using System; using System.Runtime.InteropServices; using WinRT; +using WinRT.Interop; namespace ABI.System.ComponentModel { @@ -21,12 +22,22 @@ static class INotifyPropertyChangedMethods [DynamicInterfaceCastableImplementation] [Guid("90B17601-B065-586E-83D9-9ADC3A695284")] + [WuxMuxProjectedType] internal unsafe interface INotifyPropertyChanged : global::System.ComponentModel.INotifyPropertyChanged { + public static string GetGuidSignature() + => Projections.UiXamlModeSetting == Projections.UiXamlMode.WindowsUiXaml + ? "{cf75d69c-f2f4-486b-b302-bb4c09baebfa}" + : typeof(INotifyPropertyChanged).GUID.ToString("B"); + [Guid("90B17601-B065-586E-83D9-9ADC3A695284")] - [StructLayout(LayoutKind.Sequential)] + [StructLayout(LayoutKind.Sequential)] + [WuxMuxProjectedType] public struct Vftbl - { + { + public static string GetGuidSignature() + => INotifyPropertyChanged.GetGuidSignature(); + internal IInspectable.Vftbl IInspectableVftbl; private delegate* unmanaged _add_PropertyChanged_0; diff --git a/src/WinRT.Runtime/Projections/Microsoft.UI.Xaml.Bindable.net5.cs b/src/WinRT.Runtime/Projections/Microsoft.UI.Xaml.Bindable.net5.cs new file mode 100644 index 000000000..95397bad6 --- /dev/null +++ b/src/WinRT.Runtime/Projections/Microsoft.UI.Xaml.Bindable.net5.cs @@ -0,0 +1,367 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using WinRT; +using WinRT.Interop; + + +#pragma warning disable 0169 // warning CS0169: The field '...' is never used +#pragma warning disable 0649 // warning CS0169: Field '...' is never assigned to + +namespace Microsoft.UI.Xaml.Interop +{ + [global::WinRT.WindowsRuntimeType] + [Guid("036D2C08-DF29-41AF-8AA2-D774BE62BA6F")] + [global::WinRT.WindowsRuntimeHelperType(typeof(global::ABI.Microsoft.UI.Xaml.Interop.IBindableIterable))] + internal interface IBindableIterable + { + IBindableIterator First(); + } + [global::WinRT.WindowsRuntimeType] + [Guid("6A1D6C07-076D-49F2-8314-F52C9C9A8331")] + [global::WinRT.WindowsRuntimeHelperType(typeof(global::ABI.Microsoft.UI.Xaml.Interop.IBindableIterator))] + internal interface IBindableIterator + { + bool MoveNext(); + // GetMany is not implemented by IBindableIterator, but it is here + // for compat purposes with WinUI where there are scenarios they do + // reinterpret_cast from IBindableIterator to IIterable. It is + // the last function in the vftable and shouldn't be called by anyone. + // If called, it will return NotImplementedException. + uint GetMany(ref object[] items); + object Current { get; } + bool HasCurrent { get; } + } + [global::WinRT.WindowsRuntimeType] + [Guid("393DE7DE-6FD0-4C0D-BB71-47244A113E93")] + internal interface IBindableVector : IEnumerable + { + 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(); + uint Size { get; } + } + [global::WinRT.WindowsRuntimeType] + [Guid("346DD6E7-976E-4BC3-815D-ECE243BC0F33")] + [global::WinRT.WindowsRuntimeHelperType(typeof(global::ABI.Microsoft.UI.Xaml.Interop.IBindableVectorView))] + internal interface IBindableVectorView : IEnumerable + { + object GetAt(uint index); + bool IndexOf(object value, out uint index); + uint Size { get; } + } +} + +namespace ABI.Microsoft.UI.Xaml.Interop +{ + [DynamicInterfaceCastableImplementation] + [Guid("036D2C08-DF29-41AF-8AA2-D774BE62BA6F")] + internal unsafe interface IBindableIterable : global::Microsoft.UI.Xaml.Interop.IBindableIterable, ABI.System.Collections.IEnumerable + { + + } + + [DynamicInterfaceCastableImplementation] + [Guid("6A1D6C07-076D-49F2-8314-F52C9C9A8331")] + internal unsafe interface IBindableIterator : global::Microsoft.UI.Xaml.Interop.IBindableIterator + { + public static readonly IntPtr AbiToProjectionVftablePtr; + static IBindableIterator() + { + AbiToProjectionVftablePtr = ComWrappersSupport.AllocateVtableMemory(typeof(IBindableIterator), sizeof(IInspectable.Vftbl) + sizeof(IntPtr) * 4); + *(IInspectable.Vftbl*)AbiToProjectionVftablePtr = IInspectable.Vftbl.AbiToProjectionVftable; + ((delegate* unmanaged[Stdcall]*)AbiToProjectionVftablePtr)[6] = &Do_Abi_get_Current_0; + ((delegate* unmanaged[Stdcall]*)AbiToProjectionVftablePtr)[7] = &Do_Abi_get_HasCurrent_1; + ((delegate* unmanaged[Stdcall]*)AbiToProjectionVftablePtr)[8] = &Do_Abi_MoveNext_2; + ((delegate* unmanaged[Stdcall]*)AbiToProjectionVftablePtr)[9] = &Do_Abi_GetMany_3; + } + + [UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })] + private static unsafe int Do_Abi_MoveNext_2(IntPtr thisPtr, byte* result) + { + bool __result = default; + *result = default; + try + { + __result = global::WinRT.ComWrappersSupport.FindObject(thisPtr).MoveNext(); + *result = (byte)(__result ? 1 : 0); + } + catch (Exception __exception__) + { + global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); + return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); + } + return 0; + } + + [UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })] + private static unsafe int Do_Abi_GetMany_3(IntPtr thisPtr, int __itemsSize, IntPtr items, uint* result) + { + *result = default; + + try + { + // Should never be called. + throw new NotImplementedException(); + } + catch (Exception __exception__) + { + global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); + return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); + } + } + + [UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })] + private static unsafe int Do_Abi_get_Current_0(IntPtr thisPtr, IntPtr* value) + { + object __value = default; + *value = default; + try + { + __value = global::WinRT.ComWrappersSupport.FindObject(thisPtr).Current; + *value = MarshalInspectable.FromManaged(__value); + } + catch (Exception __exception__) + { + global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); + return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); + } + return 0; + } + + [UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })] + private static unsafe int Do_Abi_get_HasCurrent_1(IntPtr thisPtr, byte* value) + { + bool __value = default; + *value = default; + try + { + __value = global::WinRT.ComWrappersSupport.FindObject(thisPtr).HasCurrent; + *value = (byte)(__value ? 1 : 0); + } + catch (Exception __exception__) + { + global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); + return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); + } + return 0; + } + + internal static ObjectReference FromAbi(IntPtr thisPtr) => ObjectReference.FromAbi(thisPtr); + + unsafe bool global::Microsoft.UI.Xaml.Interop.IBindableIterator.MoveNext() + { + var _obj = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Microsoft.UI.Xaml.Interop.IBindableIterator).TypeHandle); + var ThisPtr = _obj.ThisPtr; + byte __retval = default; + global::WinRT.ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]**)ThisPtr)[8](ThisPtr, &__retval)); + return __retval != 0; + } + + unsafe uint global::Microsoft.UI.Xaml.Interop.IBindableIterator.GetMany(ref object[] items) + { + // Should never be called. + throw new NotImplementedException(); + } + + unsafe object global::Microsoft.UI.Xaml.Interop.IBindableIterator.Current + { + get + { + var _obj = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Microsoft.UI.Xaml.Interop.IBindableIterator).TypeHandle); + var ThisPtr = _obj.ThisPtr; + IntPtr __retval = default; + try + { + global::WinRT.ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]**)ThisPtr)[6](ThisPtr, &__retval)); + return MarshalInspectable.FromAbi(__retval); + } + finally + { + MarshalInspectable.DisposeAbi(__retval); + } + } + } + + unsafe bool global::Microsoft.UI.Xaml.Interop.IBindableIterator.HasCurrent + { + get + { + var _obj = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Microsoft.UI.Xaml.Interop.IBindableIterator).TypeHandle); + var ThisPtr = _obj.ThisPtr; + byte __retval = default; + global::WinRT.ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]**)ThisPtr)[7](ThisPtr, &__retval)); + return __retval != 0; + } + } + + } + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.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 unsafe interface IBindableVectorView : global::Microsoft.UI.Xaml.Interop.IBindableVectorView + { + public static readonly IntPtr AbiToProjectionVftablePtr; + static IBindableVectorView() + { + AbiToProjectionVftablePtr = ComWrappersSupport.AllocateVtableMemory(typeof(IBindableVectorView), sizeof(IInspectable.Vftbl) + sizeof(IntPtr) * 3); + *(IInspectable.Vftbl*)AbiToProjectionVftablePtr = IInspectable.Vftbl.AbiToProjectionVftable; + ((delegate* unmanaged[Stdcall]*)AbiToProjectionVftablePtr)[6] = &Do_Abi_GetAt_0; + ((delegate* unmanaged[Stdcall]*)AbiToProjectionVftablePtr)[7] = &Do_Abi_get_Size_1; + ((delegate* unmanaged[Stdcall]*)AbiToProjectionVftablePtr)[8] = &Do_Abi_IndexOf_2; + } + + [UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })] + private static unsafe int Do_Abi_GetAt_0(IntPtr thisPtr, uint index, IntPtr* result) + { + object __result = default; + + try + { + __result = global::WinRT.ComWrappersSupport.FindObject(thisPtr).GetAt(index); + *result = MarshalInspectable.FromManaged(__result); + + } + catch (Exception __exception__) + { + global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); + return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); + } + return 0; + } + + [UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })] + private static unsafe int Do_Abi_IndexOf_2(IntPtr thisPtr, IntPtr value, uint* index, byte* returnValue) + { + bool __returnValue = default; + + *index = default; + *returnValue = default; + uint __index = default; + + try + { + __returnValue = global::WinRT.ComWrappersSupport.FindObject(thisPtr).IndexOf(MarshalInspectable.FromAbi(value), out __index); + *index = __index; + *returnValue = (byte)(__returnValue ? 1 : 0); + + } + catch (Exception __exception__) + { + global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); + return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); + } + return 0; + } + + [UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })] + private static unsafe int Do_Abi_get_Size_1(IntPtr thisPtr, uint* value) + { + uint __value = default; + + *value = default; + + try + { + __value = global::WinRT.ComWrappersSupport.FindObject(thisPtr).Size; + *value = __value; + + } + catch (Exception __exception__) + { + global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); + return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); + } + return 0; + } + + internal static ObjectReference FromAbi(IntPtr thisPtr) => ObjectReference.FromAbi(thisPtr); + + private static readonly global::System.Runtime.CompilerServices.ConditionalWeakTable _helperTable = new(); + + unsafe object global::Microsoft.UI.Xaml.Interop.IBindableVectorView.GetAt(uint index) + { + var _obj = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Microsoft.UI.Xaml.Interop.IBindableIterator).TypeHandle); + var ThisPtr = _obj.ThisPtr; + IntPtr __retval = default; + try + { + global::WinRT.ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]**)ThisPtr)[6](ThisPtr, index, &__retval)); + return MarshalInspectable.FromAbi(__retval); + } + finally + { + MarshalInspectable.DisposeAbi(__retval); + } + } + + unsafe bool global::Microsoft.UI.Xaml.Interop.IBindableVectorView.IndexOf(object value, out uint index) + { + var _obj = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Microsoft.UI.Xaml.Interop.IBindableIterator).TypeHandle); + var ThisPtr = _obj.ThisPtr; + ObjectReferenceValue __value = default; + uint __index = default; + byte __retval = default; + try + { + __value = MarshalInspectable.CreateMarshaler2(value); + global::WinRT.ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]**)ThisPtr)[8]( + ThisPtr, + MarshalInspectable.GetAbi(__value), + &__index, + &__retval)); + index = __index; + return __retval != 0; + } + finally + { + MarshalInspectable.DisposeMarshaler(__value); + } + } + + unsafe uint global::Microsoft.UI.Xaml.Interop.IBindableVectorView.Size + { + get + { + var _obj = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Microsoft.UI.Xaml.Interop.IBindableIterator).TypeHandle); + var ThisPtr = _obj.ThisPtr; + uint __retval = default; + global::WinRT.ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]**)ThisPtr)[7](ThisPtr, &__retval)); + return __retval; + } + } + + IEnumerator IEnumerable.GetEnumerator() + { + return _helperTable.GetValue((IWinRTObject)this, + (enumerable) => new ABI.System.Collections.IEnumerable.AdaptiveFromAbiHelper(enumerable) + ).GetEnumerator(); + } + } + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.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); + } +} diff --git a/src/WinRT.Runtime/Projections/Bindable.netstandard2.0.cs b/src/WinRT.Runtime/Projections/Microsoft.UI.Xaml.Bindable.netstandard2.0.cs similarity index 100% rename from src/WinRT.Runtime/Projections/Bindable.netstandard2.0.cs rename to src/WinRT.Runtime/Projections/Microsoft.UI.Xaml.Bindable.netstandard2.0.cs diff --git a/src/WinRT.Runtime/Projections/NotifyCollectionChangedAction.cs b/src/WinRT.Runtime/Projections/NotifyCollectionChangedAction.cs index b6ccf1bc7..62d5af9f4 100644 --- a/src/WinRT.Runtime/Projections/NotifyCollectionChangedAction.cs +++ b/src/WinRT.Runtime/Projections/NotifyCollectionChangedAction.cs @@ -1,10 +1,15 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +using WinRT; + namespace ABI.System.Collections.Specialized { static class NotifyCollectionChangedAction { - public static string GetGuidSignature() => "enum(Microsoft.UI.Xaml.Interop.NotifyCollectionChangedAction;i4)"; + public static string GetGuidSignature() => + Projections.UiXamlModeSetting == Projections.UiXamlMode.WindowsUiXaml + ? "enum(Windows.UI.Xaml.Interop.NotifyCollectionChangedAction;i4)" + : "enum(Microsoft.UI.Xaml.Interop.NotifyCollectionChangedAction;i4)"; } } diff --git a/src/WinRT.Runtime/Projections/NotifyCollectionChangedEventArgs.cs b/src/WinRT.Runtime/Projections/NotifyCollectionChangedEventArgs.cs index 2cc04a771..e0000593c 100644 --- a/src/WinRT.Runtime/Projections/NotifyCollectionChangedEventArgs.cs +++ b/src/WinRT.Runtime/Projections/NotifyCollectionChangedEventArgs.cs @@ -1,279 +1,376 @@ // Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -using ABI.Microsoft.UI.Xaml.Interop; -using System; -using System.ComponentModel; -using System.Runtime.InteropServices; -using WinRT; -using WinRT.Interop; - -namespace ABI.Microsoft.UI.Xaml.Interop -{ - [global::WinRT.ObjectReferenceWrapper(nameof(_obj))] - [Guid("DA049FF2-D2E0-5FE8-8C7B-F87F26060B6F")] - internal sealed unsafe class INotifyCollectionChangedEventArgs - { - [Guid("DA049FF2-D2E0-5FE8-8C7B-F87F26060B6F")] - [StructLayout(LayoutKind.Sequential)] - public struct Vftbl - { - internal IInspectable.Vftbl IInspectableVftbl; - private void* _get_Action_0; - public delegate* unmanaged[Stdcall] get_Action_0 => (delegate* unmanaged[Stdcall])_get_Action_0; - private void* _get_NewItems_1; - public delegate* unmanaged[Stdcall] get_NewItems_1 => (delegate* unmanaged[Stdcall])_get_NewItems_1; - private void* _get_OldItems_2; - public delegate* unmanaged[Stdcall] get_OldItems_2 => (delegate* unmanaged[Stdcall])_get_OldItems_2; - private void* _get_NewStartingIndex_3; - public delegate* unmanaged[Stdcall] get_NewStartingIndex_3 => (delegate* unmanaged[Stdcall])_get_NewStartingIndex_3; - private void* _get_OldStartingIndex_4; - public delegate* unmanaged[Stdcall] get_OldStartingIndex_4 => (delegate* unmanaged[Stdcall])_get_OldStartingIndex_4; - } - internal static ObjectReference FromAbi(IntPtr thisPtr) => ObjectReference.FromAbi(thisPtr); - - public static implicit operator INotifyCollectionChangedEventArgs(IObjectReference obj) => (obj != null) ? new INotifyCollectionChangedEventArgs(obj) : null; - private readonly ObjectReference _obj; - public IObjectReference ObjRef { get => _obj; } - public IntPtr ThisPtr => _obj.ThisPtr; - public ObjectReference AsInterface() => _obj.As(); - public A As() => _obj.AsType(); - public INotifyCollectionChangedEventArgs(IObjectReference obj) : this(obj.As()) { } - internal INotifyCollectionChangedEventArgs(ObjectReference obj) - { - _obj = obj; - } - - public unsafe global::System.Collections.Specialized.NotifyCollectionChangedAction Action - { - get - { - global::System.Collections.Specialized.NotifyCollectionChangedAction __retval = default; - global::WinRT.ExceptionHelpers.ThrowExceptionForHR(_obj.Vftbl.get_Action_0(ThisPtr, &__retval)); - return __retval; - } - } - - public unsafe global::System.Collections.IList NewItems - { - get - { - IntPtr __retval = default; - try - { - global::WinRT.ExceptionHelpers.ThrowExceptionForHR(_obj.Vftbl.get_NewItems_1(ThisPtr, &__retval)); - return MarshalInterface.FromAbi(__retval); - } - finally - { - MarshalInterface.DisposeAbi(__retval); - } - } - } - - public unsafe int NewStartingIndex - { - get - { - int __retval = default; - global::WinRT.ExceptionHelpers.ThrowExceptionForHR(_obj.Vftbl.get_NewStartingIndex_3(ThisPtr, &__retval)); - return __retval; - } - } - - public unsafe global::System.Collections.IList OldItems - { - get - { - IntPtr __retval = default; - try - { - global::WinRT.ExceptionHelpers.ThrowExceptionForHR(_obj.Vftbl.get_OldItems_2(ThisPtr, &__retval)); - return MarshalInterface.FromAbi(__retval); - } - finally - { - MarshalInterface.DisposeAbi(__retval); - } - } - } - - public unsafe int OldStartingIndex - { - get - { - int __retval = default; - global::WinRT.ExceptionHelpers.ThrowExceptionForHR(_obj.Vftbl.get_OldStartingIndex_4(ThisPtr, &__retval)); - return __retval; - } - } - } - - [global::WinRT.ObjectReferenceWrapper(nameof(_obj))] - [Guid("5108EBA4-4892-5A20-8374-A96815E0FD27")] - internal sealed unsafe class WinRTNotifyCollectionChangedEventArgsRuntimeClassFactory - { - [Guid("5108EBA4-4892-5A20-8374-A96815E0FD27")] - [StructLayout(LayoutKind.Sequential)] - public struct Vftbl - { - internal IInspectable.Vftbl IInspectableVftbl; - private void* _CreateInstanceWithAllParameters_0; - public delegate* unmanaged[Stdcall] CreateInstanceWithAllParameters_0 => (delegate* unmanaged[Stdcall])_CreateInstanceWithAllParameters_0; - } - public static ObjectReference FromAbi(IntPtr thisPtr) => ObjectReference.FromAbi(thisPtr); - - public static implicit operator WinRTNotifyCollectionChangedEventArgsRuntimeClassFactory(IObjectReference obj) => (obj != null) ? new WinRTNotifyCollectionChangedEventArgsRuntimeClassFactory(obj) : null; - public static implicit operator WinRTNotifyCollectionChangedEventArgsRuntimeClassFactory(ObjectReference obj) => (obj != null) ? new WinRTNotifyCollectionChangedEventArgsRuntimeClassFactory(obj) : null; - private readonly ObjectReference _obj; - public IntPtr ThisPtr => _obj.ThisPtr; - public ObjectReference AsInterface() => _obj.As(); - public A As() => _obj.AsType(); - public WinRTNotifyCollectionChangedEventArgsRuntimeClassFactory(IObjectReference obj) : this(obj.As()) { } - public WinRTNotifyCollectionChangedEventArgsRuntimeClassFactory(ObjectReference obj) - { - _obj = obj; - } - - public unsafe IObjectReference CreateInstanceWithAllParameters(global::System.Collections.Specialized.NotifyCollectionChangedAction action, global::System.Collections.IList newItems, global::System.Collections.IList oldItems, int newIndex, int oldIndex, object baseInterface, out IObjectReference innerInterface) - { - ObjectReferenceValue __newItems = default; - ObjectReferenceValue __oldItems = default; - ObjectReferenceValue __baseInterface = default; - IntPtr __innerInterface = default; - IntPtr __retval = default; - try - { - __newItems = MarshalInterface.CreateMarshaler2(newItems); - __oldItems = MarshalInterface.CreateMarshaler2(oldItems); - __baseInterface = MarshalInspectable.CreateMarshaler2(baseInterface); - global::WinRT.ExceptionHelpers.ThrowExceptionForHR(_obj.Vftbl.CreateInstanceWithAllParameters_0(ThisPtr, action, MarshalInterface.GetAbi(__newItems), MarshalInterface.GetAbi(__oldItems), newIndex, oldIndex, MarshalInspectable.GetAbi(__baseInterface), &__innerInterface, &__retval)); - innerInterface = ObjectReference.FromAbi(__innerInterface); - return ObjectReference.FromAbi(__retval); - } - finally - { - MarshalInterface.DisposeMarshaler(__newItems); - MarshalInterface.DisposeMarshaler(__oldItems); - MarshalInspectable.DisposeMarshaler(__baseInterface); - MarshalInspectable.DisposeAbi(__innerInterface); - MarshalInspectable.DisposeAbi(__retval); - } +// Licensed under the MIT License. + +using ABI.Microsoft.UI.Xaml.Interop; +using System; +using System.ComponentModel; +using System.Runtime.InteropServices; +using WinRT; +using WinRT.Interop; + +namespace ABI.Microsoft.UI.Xaml.Interop +{ + [global::WinRT.ObjectReferenceWrapper(nameof(_obj))] + [Guid("DA049FF2-D2E0-5FE8-8C7B-F87F26060B6F")] + [WuxMuxProjectedType] + internal sealed unsafe class INotifyCollectionChangedEventArgs + { + public static string GetGuidSignature() + => Projections.UiXamlModeSetting == Projections.UiXamlMode.WindowsUiXaml + ? "{4cf68d33-e3f2-4964-b85e-945b4f7e2f21}" + : typeof(INotifyCollectionChangedEventArgs).GUID.ToString("B"); + + [Guid("DA049FF2-D2E0-5FE8-8C7B-F87F26060B6F")] + [StructLayout(LayoutKind.Sequential)] + [WuxMuxProjectedType] + public struct Vftbl + { + public static string GetGuidSignature() + => INotifyCollectionChangedEventArgs.GetGuidSignature(); + + internal IInspectable.Vftbl IInspectableVftbl; + private void* _get_Action_0; + public delegate* unmanaged[Stdcall] get_Action_0 => (delegate* unmanaged[Stdcall])_get_Action_0; + private void* _get_NewItems_1; + public delegate* unmanaged[Stdcall] get_NewItems_1 => (delegate* unmanaged[Stdcall])_get_NewItems_1; + private void* _get_OldItems_2; + public delegate* unmanaged[Stdcall] get_OldItems_2 => (delegate* unmanaged[Stdcall])_get_OldItems_2; + private void* _get_NewStartingIndex_3; + public delegate* unmanaged[Stdcall] get_NewStartingIndex_3 => (delegate* unmanaged[Stdcall])_get_NewStartingIndex_3; + private void* _get_OldStartingIndex_4; + public delegate* unmanaged[Stdcall] get_OldStartingIndex_4 => (delegate* unmanaged[Stdcall])_get_OldStartingIndex_4; + } + internal static ObjectReference FromAbi(IntPtr thisPtr) => ObjectReference.FromAbi(thisPtr); + + public static implicit operator INotifyCollectionChangedEventArgs(IObjectReference obj) => (obj != null) ? new INotifyCollectionChangedEventArgs(obj) : null; + private readonly ObjectReference _obj; + public IObjectReference ObjRef { get => _obj; } + public IntPtr ThisPtr => _obj.ThisPtr; + public ObjectReference AsInterface() => _obj.As(); + public A As() => _obj.AsType(); + public INotifyCollectionChangedEventArgs(IObjectReference obj) : this(obj.As()) { } + internal INotifyCollectionChangedEventArgs(ObjectReference obj) + { + _obj = obj; } - 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 __newItems = default; - ObjectReferenceValue __oldItems = default; - IntPtr __innerInterface = default; - IntPtr __retval = default; - try - { - __newItems = MarshalInterface.CreateMarshaler2(newItems); - __oldItems = MarshalInterface.CreateMarshaler2(oldItems); - global::WinRT.ExceptionHelpers.ThrowExceptionForHR(_obj.Vftbl.CreateInstanceWithAllParameters_0(ThisPtr, action, MarshalInterface.GetAbi(__newItems), MarshalInterface.GetAbi(__oldItems), newIndex, oldIndex, IntPtr.Zero, &__innerInterface, &__retval)); - return new ObjectReferenceValue(__retval); - } - finally - { - __newItems.Dispose(); - __oldItems.Dispose(); - MarshalInspectable.DisposeAbi(__innerInterface); - } - } - } -} - -namespace ABI.System.Collections.Specialized -{ - [EditorBrowsable(EditorBrowsableState.Never)] - [StructLayout(LayoutKind.Sequential)] -#if EMBED - internal -#else - public -#endif - struct NotifyCollectionChangedEventArgs + public unsafe global::System.Collections.Specialized.NotifyCollectionChangedAction Action + { + get + { + global::System.Collections.Specialized.NotifyCollectionChangedAction __retval = default; + global::WinRT.ExceptionHelpers.ThrowExceptionForHR(_obj.Vftbl.get_Action_0(ThisPtr, &__retval)); + return __retval; + } + } + + public unsafe global::System.Collections.IList NewItems + { + get + { + IntPtr __retval = default; + try + { + global::WinRT.ExceptionHelpers.ThrowExceptionForHR(_obj.Vftbl.get_NewItems_1(ThisPtr, &__retval)); + return MarshalInterface.FromAbi(__retval); + } + finally + { + MarshalInterface.DisposeAbi(__retval); + } + } + } + + public unsafe int NewStartingIndex + { + get + { + int __retval = default; + global::WinRT.ExceptionHelpers.ThrowExceptionForHR(_obj.Vftbl.get_NewStartingIndex_3(ThisPtr, &__retval)); + return __retval; + } + } + + public unsafe global::System.Collections.IList OldItems + { + get + { + IntPtr __retval = default; + try + { + global::WinRT.ExceptionHelpers.ThrowExceptionForHR(_obj.Vftbl.get_OldItems_2(ThisPtr, &__retval)); + return MarshalInterface.FromAbi(__retval); + } + finally + { + MarshalInterface.DisposeAbi(__retval); + } + } + } + + public unsafe int OldStartingIndex + { + get + { + int __retval = default; + global::WinRT.ExceptionHelpers.ThrowExceptionForHR(_obj.Vftbl.get_OldStartingIndex_4(ThisPtr, &__retval)); + return __retval; + } + } + } + + internal interface IWinRTNotifyCollectionChangedEventArgsRuntimeClassFactory { - private static WinRTNotifyCollectionChangedEventArgsRuntimeClassFactory Instance = ActivationFactory.Get("Microsoft.UI.Xaml.Interop.NotifyCollectionChangedEventArgs"); - - public static IObjectReference CreateMarshaler(global::System.Collections.Specialized.NotifyCollectionChangedEventArgs value) - { - if (value is null) - { - return null; - } - - return Instance.CreateInstanceWithAllParameters(value.Action, value.NewItems, value.OldItems, value.NewStartingIndex, value.OldStartingIndex, null, out _); + IObjectReference CreateInstanceWithAllParameters(global::System.Collections.Specialized.NotifyCollectionChangedAction action, global::System.Collections.IList newItems, global::System.Collections.IList oldItems, int newIndex, int oldIndex, object baseInterface, out IObjectReference innerInterface); + ObjectReferenceValue CreateInstanceWithAllParameters(global::System.Collections.Specialized.NotifyCollectionChangedAction action, global::System.Collections.IList newItems, global::System.Collections.IList oldItems, int newIndex, int oldIndex); + } + + [global::WinRT.ObjectReferenceWrapper(nameof(_obj))] + [Guid("5108EBA4-4892-5A20-8374-A96815E0FD27")] + internal sealed unsafe class MUXNotifyCollectionChangedEventArgsRuntimeClassFactory : IWinRTNotifyCollectionChangedEventArgsRuntimeClassFactory + { + [Guid("5108EBA4-4892-5A20-8374-A96815E0FD27")] + [StructLayout(LayoutKind.Sequential)] + public struct Vftbl + { + internal IInspectable.Vftbl IInspectableVftbl; + private void* _CreateInstanceWithAllParameters_0; + public delegate* unmanaged[Stdcall] CreateInstanceWithAllParameters_0 => (delegate* unmanaged[Stdcall])_CreateInstanceWithAllParameters_0; + } + public static ObjectReference FromAbi(IntPtr thisPtr) => ObjectReference.FromAbi(thisPtr); + + public static implicit operator MUXNotifyCollectionChangedEventArgsRuntimeClassFactory(IObjectReference obj) => (obj != null) ? new MUXNotifyCollectionChangedEventArgsRuntimeClassFactory(obj) : null; + public static implicit operator MUXNotifyCollectionChangedEventArgsRuntimeClassFactory(ObjectReference obj) => (obj != null) ? new MUXNotifyCollectionChangedEventArgsRuntimeClassFactory(obj) : null; + private readonly ObjectReference _obj; + public IntPtr ThisPtr => _obj.ThisPtr; + public ObjectReference AsInterface() => _obj.As(); + public A As() => _obj.AsType(); + public MUXNotifyCollectionChangedEventArgsRuntimeClassFactory(IObjectReference obj) : this(obj.As()) { } + public MUXNotifyCollectionChangedEventArgsRuntimeClassFactory(ObjectReference obj) + { + _obj = obj; } - public static ObjectReferenceValue CreateMarshaler2(global::System.Collections.Specialized.NotifyCollectionChangedEventArgs value) - { - if (value is null) - { - return new ObjectReferenceValue(); - } - - return Instance.CreateInstanceWithAllParameters(value.Action, value.NewItems, value.OldItems, value.NewStartingIndex, value.OldStartingIndex); - } - - public static IntPtr GetAbi(IObjectReference m) => m?.ThisPtr ?? IntPtr.Zero; - - public static global::System.Collections.Specialized.NotifyCollectionChangedEventArgs FromAbi(IntPtr ptr) - { - if (ptr == IntPtr.Zero) - { - return null; - } - - INotifyCollectionChangedEventArgs args = INotifyCollectionChangedEventArgs.FromAbi(ptr); - return CreateNotifyCollectionChangedEventArgs(args.Action, args.NewItems, args.OldItems, args.NewStartingIndex, args.OldStartingIndex); - } - - 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) => - 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 static unsafe 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 is null) - { - return IntPtr.Zero; - } - return CreateMarshaler2(value).Detach(); - } - - public static void DisposeMarshaler(IObjectReference m) { m?.Dispose(); } + public unsafe IObjectReference CreateInstanceWithAllParameters(global::System.Collections.Specialized.NotifyCollectionChangedAction action, global::System.Collections.IList newItems, global::System.Collections.IList oldItems, int newIndex, int oldIndex, object baseInterface, out IObjectReference innerInterface) + { + ObjectReferenceValue __newItems = default; + ObjectReferenceValue __oldItems = default; + ObjectReferenceValue __baseInterface = default; + IntPtr __innerInterface = default; + IntPtr __retval = default; + try + { + __newItems = MarshalInterface.CreateMarshaler2(newItems); + __oldItems = MarshalInterface.CreateMarshaler2(oldItems); + __baseInterface = MarshalInspectable.CreateMarshaler2(baseInterface); + global::WinRT.ExceptionHelpers.ThrowExceptionForHR(_obj.Vftbl.CreateInstanceWithAllParameters_0(ThisPtr, action, MarshalInterface.GetAbi(__newItems), MarshalInterface.GetAbi(__oldItems), newIndex, oldIndex, MarshalInspectable.GetAbi(__baseInterface), &__innerInterface, &__retval)); + innerInterface = ObjectReference.FromAbi(__innerInterface); + return ObjectReference.FromAbi(__retval); + } + finally + { + MarshalInterface.DisposeMarshaler(__newItems); + MarshalInterface.DisposeMarshaler(__oldItems); + MarshalInspectable.DisposeMarshaler(__baseInterface); + MarshalInspectable.DisposeAbi(__innerInterface); + MarshalInspectable.DisposeAbi(__retval); + } + } + + 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 __newItems = default; + ObjectReferenceValue __oldItems = default; + IntPtr __innerInterface = default; + IntPtr __retval = default; + try + { + __newItems = MarshalInterface.CreateMarshaler2(newItems); + __oldItems = MarshalInterface.CreateMarshaler2(oldItems); + global::WinRT.ExceptionHelpers.ThrowExceptionForHR(_obj.Vftbl.CreateInstanceWithAllParameters_0(ThisPtr, action, MarshalInterface.GetAbi(__newItems), MarshalInterface.GetAbi(__oldItems), newIndex, oldIndex, IntPtr.Zero, &__innerInterface, &__retval)); + return new ObjectReferenceValue(__retval); + } + finally + { + __newItems.Dispose(); + __oldItems.Dispose(); + MarshalInspectable.DisposeAbi(__innerInterface); + } + } + } + + [global::WinRT.ObjectReferenceWrapper(nameof(_obj))] + [Guid("b30c3e3a-df8d-44a5-9a38-7ac0d08ce63d")] + internal sealed unsafe class WUXNotifyCollectionChangedEventArgsRuntimeClassFactory : IWinRTNotifyCollectionChangedEventArgsRuntimeClassFactory + { + [Guid("b30c3e3a-df8d-44a5-9a38-7ac0d08ce63d")] + [StructLayout(LayoutKind.Sequential)] + public struct Vftbl + { + internal IInspectable.Vftbl IInspectableVftbl; + private void* _CreateInstanceWithAllParameters_0; + public delegate* unmanaged[Stdcall] CreateInstanceWithAllParameters_0 => (delegate* unmanaged[Stdcall])_CreateInstanceWithAllParameters_0; + } + public static ObjectReference FromAbi(IntPtr thisPtr) => ObjectReference.FromAbi(thisPtr); + + public static implicit operator WUXNotifyCollectionChangedEventArgsRuntimeClassFactory(IObjectReference obj) => (obj != null) ? new WUXNotifyCollectionChangedEventArgsRuntimeClassFactory(obj) : null; + public static implicit operator WUXNotifyCollectionChangedEventArgsRuntimeClassFactory(ObjectReference obj) => (obj != null) ? new WUXNotifyCollectionChangedEventArgsRuntimeClassFactory(obj) : null; + private readonly ObjectReference _obj; + public IntPtr ThisPtr => _obj.ThisPtr; + public ObjectReference AsInterface() => _obj.As(); + public A As() => _obj.AsType(); + public WUXNotifyCollectionChangedEventArgsRuntimeClassFactory(IObjectReference obj) : this(obj.As()) { } + public WUXNotifyCollectionChangedEventArgsRuntimeClassFactory(ObjectReference obj) + { + _obj = obj; + } + + public unsafe IObjectReference CreateInstanceWithAllParameters(global::System.Collections.Specialized.NotifyCollectionChangedAction action, global::System.Collections.IList newItems, global::System.Collections.IList oldItems, int newIndex, int oldIndex, object baseInterface, out IObjectReference innerInterface) + { + ObjectReferenceValue __newItems = default; + ObjectReferenceValue __oldItems = default; + ObjectReferenceValue __baseInterface = default; + IntPtr __innerInterface = default; + IntPtr __retval = default; + try + { + __newItems = MarshalInterface.CreateMarshaler2(newItems); + __oldItems = MarshalInterface.CreateMarshaler2(oldItems); + __baseInterface = MarshalInspectable.CreateMarshaler2(baseInterface); + global::WinRT.ExceptionHelpers.ThrowExceptionForHR(_obj.Vftbl.CreateInstanceWithAllParameters_0(ThisPtr, action, MarshalInterface.GetAbi(__newItems), MarshalInterface.GetAbi(__oldItems), newIndex, oldIndex, MarshalInspectable.GetAbi(__baseInterface), &__innerInterface, &__retval)); + innerInterface = ObjectReference.FromAbi(__innerInterface); + return ObjectReference.FromAbi(__retval); + } + finally + { + MarshalInterface.DisposeMarshaler(__newItems); + MarshalInterface.DisposeMarshaler(__oldItems); + MarshalInspectable.DisposeMarshaler(__baseInterface); + MarshalInspectable.DisposeAbi(__innerInterface); + MarshalInspectable.DisposeAbi(__retval); + } + } + + 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 __newItems = default; + ObjectReferenceValue __oldItems = default; + IntPtr __innerInterface = default; + IntPtr __retval = default; + try + { + __newItems = MarshalInterface.CreateMarshaler2(newItems); + __oldItems = MarshalInterface.CreateMarshaler2(oldItems); + global::WinRT.ExceptionHelpers.ThrowExceptionForHR(_obj.Vftbl.CreateInstanceWithAllParameters_0(ThisPtr, action, MarshalInterface.GetAbi(__newItems), MarshalInterface.GetAbi(__oldItems), newIndex, oldIndex, IntPtr.Zero, &__innerInterface, &__retval)); + return new ObjectReferenceValue(__retval); + } + finally + { + __newItems.Dispose(); + __oldItems.Dispose(); + MarshalInspectable.DisposeAbi(__innerInterface); + } + } + } +} + +namespace ABI.System.Collections.Specialized +{ + [EditorBrowsable(EditorBrowsableState.Never)] + [StructLayout(LayoutKind.Sequential)] +#if EMBED + internal +#else + public +#endif + struct NotifyCollectionChangedEventArgs + { + private static IWinRTNotifyCollectionChangedEventArgsRuntimeClassFactory Instance = + Projections.UiXamlModeSetting == Projections.UiXamlMode.WindowsUiXaml + ? new WUXNotifyCollectionChangedEventArgsRuntimeClassFactory(ActivationFactory.Get("Windows.UI.Xaml.Interop.NotifyCollectionChangedEventArgs")) + : new MUXNotifyCollectionChangedEventArgsRuntimeClassFactory(ActivationFactory.Get("Microsoft.UI.Xaml.Interop.NotifyCollectionChangedEventArgs")); + + public static IObjectReference CreateMarshaler(global::System.Collections.Specialized.NotifyCollectionChangedEventArgs value) + { + if (value is null) + { + return null; + } + + return Instance.CreateInstanceWithAllParameters(value.Action, value.NewItems, value.OldItems, value.NewStartingIndex, value.OldStartingIndex, null, out _); + } + + public static ObjectReferenceValue CreateMarshaler2(global::System.Collections.Specialized.NotifyCollectionChangedEventArgs value) + { + if (value is null) + { + return new ObjectReferenceValue(); + } + + return Instance.CreateInstanceWithAllParameters(value.Action, value.NewItems, value.OldItems, value.NewStartingIndex, value.OldStartingIndex); + } + + public static IntPtr GetAbi(IObjectReference m) => m?.ThisPtr ?? IntPtr.Zero; + + public static global::System.Collections.Specialized.NotifyCollectionChangedEventArgs FromAbi(IntPtr ptr) + { + if (ptr == IntPtr.Zero) + { + return null; + } + + INotifyCollectionChangedEventArgs args = INotifyCollectionChangedEventArgs.FromAbi(ptr); + return CreateNotifyCollectionChangedEventArgs(args.Action, args.NewItems, args.OldItems, args.NewStartingIndex, args.OldStartingIndex); + } + + 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) => + 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 static unsafe 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 is 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 unsafe MarshalInterfaceHelper.MarshalerArray CreateMarshalerArray(global::System.Collections.Specialized.NotifyCollectionChangedEventArgs[] array) => MarshalInterfaceHelper.CreateMarshalerArray2(array, CreateMarshaler2); - public static (int length, IntPtr data) GetAbiArray(object box) => MarshalInterfaceHelper.GetAbiArray(box); - public static unsafe global::System.Collections.Specialized.NotifyCollectionChangedEventArgs[] FromAbiArray(object box) => 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) => MarshalInterfaceHelper.FromManagedArray(array, FromManaged); - public static void DisposeMarshalerArray(MarshalInterfaceHelper.MarshalerArray array) => MarshalInterfaceHelper.DisposeMarshalerArray(array); - public static unsafe void DisposeAbiArray(object box) => MarshalInspectable.DisposeAbiArray(box); - - public static string GetGuidSignature() - { - return "rc(Microsoft.UI.Xaml.Interop.NotifyCollectionChangedEventArgs;{4cf68d33-e3f2-4964-b85e-945b4f7e2f21})"; - } - } -} + public static unsafe MarshalInterfaceHelper.MarshalerArray CreateMarshalerArray(global::System.Collections.Specialized.NotifyCollectionChangedEventArgs[] array) => MarshalInterfaceHelper.CreateMarshalerArray2(array, CreateMarshaler2); + public static (int length, IntPtr data) GetAbiArray(object box) => MarshalInterfaceHelper.GetAbiArray(box); + public static unsafe global::System.Collections.Specialized.NotifyCollectionChangedEventArgs[] FromAbiArray(object box) => 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) => MarshalInterfaceHelper.FromManagedArray(array, FromManaged); + public static void DisposeMarshalerArray(MarshalInterfaceHelper.MarshalerArray array) => MarshalInterfaceHelper.DisposeMarshalerArray(array); + public static unsafe void DisposeAbiArray(object box) => MarshalInspectable.DisposeAbiArray(box); + + public static string GetGuidSignature() + { + if (Projections.UiXamlModeSetting == Projections.UiXamlMode.WindowsUiXaml) + { + return "rc(Windows.UI.Xaml.Interop.NotifyCollectionChangedEventArgs;{4cf68d33-e3f2-4964-b85e-945b4f7e2f21})"; + } + return "rc(Microsoft.UI.Xaml.Interop.NotifyCollectionChangedEventArgs;{4cf68d33-e3f2-4964-b85e-945b4f7e2f21})"; + } + } +} diff --git a/src/WinRT.Runtime/Projections/NotifyCollectionChangedEventHandler.cs b/src/WinRT.Runtime/Projections/NotifyCollectionChangedEventHandler.cs index 1d39d310d..aaf4f8181 100644 --- a/src/WinRT.Runtime/Projections/NotifyCollectionChangedEventHandler.cs +++ b/src/WinRT.Runtime/Projections/NotifyCollectionChangedEventHandler.cs @@ -41,11 +41,15 @@ static unsafe NotifyCollectionChangedEventHandler() var nativeVftbl = ComWrappersSupport.AllocateVtableMemory(typeof(NotifyCollectionChangedEventHandler), Marshal.SizeOf()); Marshal.StructureToPtr(AbiToProjectionVftable, nativeVftbl, false); AbiToProjectionVftablePtr = nativeVftbl; + + IID = Projections.UiXamlModeSetting == Projections.UiXamlMode.WindowsUiXaml + ? Guid.Parse("ca10b37c-f382-4591-8557-5e24965279b0") + : typeof(global::ABI.System.Collections.Specialized.NotifyCollectionChangedEventHandler).GUID; } public static global::System.Delegate AbiInvokeDelegate { get; } - private static readonly Guid IID = new(0x8B0909DC, 0x2005, 0x5D93, 0xBF, 0x8A, 0x72, 0x5F, 0x01, 0x7B, 0xAA, 0x8D); + private static readonly Guid IID; public static unsafe IObjectReference CreateMarshaler(global::System.Collections.Specialized.NotifyCollectionChangedEventHandler managedDelegate) => managedDelegate is null ? null : MarshalDelegate.CreateMarshaler(managedDelegate, IID); diff --git a/src/WinRT.Runtime/Projections/PropertyChangedEventArgs.cs b/src/WinRT.Runtime/Projections/PropertyChangedEventArgs.cs index 4529aff6c..86586a85c 100644 --- a/src/WinRT.Runtime/Projections/PropertyChangedEventArgs.cs +++ b/src/WinRT.Runtime/Projections/PropertyChangedEventArgs.cs @@ -18,10 +18,15 @@ internal unsafe struct IPropertyChangedEventArgsVftbl public delegate* unmanaged[Stdcall] get_PropertyName_0 => (delegate* unmanaged[Stdcall])_get_PropertyName_0; } + internal interface IWinRTPropertyChangedEventArgsRuntimeClassFactory + { + IObjectReference CreateInstance(string name, object baseInterface, out IObjectReference innerInterface); + ObjectReferenceValue CreateInstance(string name); + } [global::WinRT.ObjectReferenceWrapper(nameof(_obj))] [Guid("7C0C27A8-0B41-5070-B160-FC9AE960A36C")] - internal sealed unsafe class WinRTPropertyChangedEventArgsRuntimeClassFactory + internal sealed unsafe class MUXPropertyChangedEventArgsRuntimeClassFactory : IWinRTPropertyChangedEventArgsRuntimeClassFactory { [Guid("7C0C27A8-0B41-5070-B160-FC9AE960A36C")] [StructLayout(LayoutKind.Sequential)] @@ -33,14 +38,14 @@ public struct Vftbl } public static ObjectReference FromAbi(IntPtr thisPtr) => ObjectReference.FromAbi(thisPtr); - public static implicit operator WinRTPropertyChangedEventArgsRuntimeClassFactory(IObjectReference obj) => (obj != null) ? new WinRTPropertyChangedEventArgsRuntimeClassFactory(obj) : null; - public static implicit operator WinRTPropertyChangedEventArgsRuntimeClassFactory(ObjectReference obj) => (obj != null) ? new WinRTPropertyChangedEventArgsRuntimeClassFactory(obj) : null; + public static implicit operator MUXPropertyChangedEventArgsRuntimeClassFactory(IObjectReference obj) => (obj != null) ? new MUXPropertyChangedEventArgsRuntimeClassFactory(obj) : null; + public static implicit operator MUXPropertyChangedEventArgsRuntimeClassFactory(ObjectReference obj) => (obj != null) ? new MUXPropertyChangedEventArgsRuntimeClassFactory(obj) : null; private readonly ObjectReference _obj; public IntPtr ThisPtr => _obj.ThisPtr; public ObjectReference AsInterface() => _obj.As(); public A As() => _obj.AsType(); - public WinRTPropertyChangedEventArgsRuntimeClassFactory(IObjectReference obj) : this(obj.As()) { } - public WinRTPropertyChangedEventArgsRuntimeClassFactory(ObjectReference obj) + public MUXPropertyChangedEventArgsRuntimeClassFactory(IObjectReference obj) : this(obj.As()) { } + public MUXPropertyChangedEventArgsRuntimeClassFactory(ObjectReference obj) { _obj = obj; } @@ -87,7 +92,78 @@ public unsafe ObjectReferenceValue CreateInstance(string name) MarshalInspectable.DisposeAbi(__innerInterface); } } + } + + + + [global::WinRT.ObjectReferenceWrapper(nameof(_obj))] + [Guid("4f33a9a0-5cf4-47a4-b16f-d7faaf17457e")] + internal sealed unsafe class WUXPropertyChangedEventArgsRuntimeClassFactory : IWinRTPropertyChangedEventArgsRuntimeClassFactory + { + [Guid("4f33a9a0-5cf4-47a4-b16f-d7faaf17457e")] + [StructLayout(LayoutKind.Sequential)] + public struct Vftbl + { + internal IInspectable.Vftbl IInspectableVftbl; + private void* _CreateInstance_0; + public delegate* unmanaged[Stdcall] CreateInstance_0 => (delegate* unmanaged[Stdcall])_CreateInstance_0; + } + public static ObjectReference FromAbi(IntPtr thisPtr) => ObjectReference.FromAbi(thisPtr); + public static implicit operator WUXPropertyChangedEventArgsRuntimeClassFactory(IObjectReference obj) => (obj != null) ? new WUXPropertyChangedEventArgsRuntimeClassFactory(obj) : null; + public static implicit operator WUXPropertyChangedEventArgsRuntimeClassFactory(ObjectReference obj) => (obj != null) ? new WUXPropertyChangedEventArgsRuntimeClassFactory(obj) : null; + private readonly ObjectReference _obj; + public IntPtr ThisPtr => _obj.ThisPtr; + public ObjectReference AsInterface() => _obj.As(); + public A As() => _obj.AsType(); + public WUXPropertyChangedEventArgsRuntimeClassFactory(IObjectReference obj) : this(obj.As()) { } + public WUXPropertyChangedEventArgsRuntimeClassFactory(ObjectReference obj) + { + _obj = obj; + } + + public unsafe IObjectReference CreateInstance(string name, object baseInterface, out IObjectReference innerInterface) + { + IObjectReference __baseInterface = default; + IntPtr __innerInterface = default; + IntPtr __retval = default; + try + { + MarshalString.Pinnable __name = new(name); + fixed (void* ___name = __name) + { + __baseInterface = MarshalInspectable.CreateMarshaler(baseInterface); + global::WinRT.ExceptionHelpers.ThrowExceptionForHR(_obj.Vftbl.CreateInstance_0(ThisPtr, MarshalString.GetAbi(ref __name), MarshalInspectable.GetAbi(__baseInterface), &__innerInterface, &__retval)); + innerInterface = ObjectReference.FromAbi(__innerInterface); + return ObjectReference.Attach(ref __retval); + } + } + finally + { + MarshalInspectable.DisposeMarshaler(__baseInterface); + MarshalInspectable.DisposeAbi(__innerInterface); + MarshalInspectable.DisposeAbi(__retval); + } + } + + public unsafe ObjectReferenceValue CreateInstance(string name) + { + IntPtr __innerInterface = default; + IntPtr __retval = default; + try + { + MarshalString.Pinnable __name = new(name); + fixed (void* ___name = __name) + { + global::WinRT.ExceptionHelpers.ThrowExceptionForHR(_obj.Vftbl.CreateInstance_0(ThisPtr, MarshalString.GetAbi(ref __name), IntPtr.Zero, &__innerInterface, &__retval)); + return new ObjectReferenceValue(__retval); + } + } + finally + { + MarshalInspectable.DisposeAbi(__innerInterface); + } + } } } @@ -102,7 +178,10 @@ namespace ABI.System.ComponentModel #endif unsafe struct PropertyChangedEventArgs { - private static ABI.Microsoft.UI.Xaml.Data.WinRTPropertyChangedEventArgsRuntimeClassFactory Instance = ActivationFactory.Get("Microsoft.UI.Xaml.Data.PropertyChangedEventArgs"); + private static ABI.Microsoft.UI.Xaml.Data.IWinRTPropertyChangedEventArgsRuntimeClassFactory Instance = + Projections.UiXamlModeSetting == Projections.UiXamlMode.WindowsUiXaml + ? new ABI.Microsoft.UI.Xaml.Data.WUXPropertyChangedEventArgsRuntimeClassFactory(ActivationFactory.Get("Windows.UI.Xaml.Data.PropertyChangedEventArgs")) + : new ABI.Microsoft.UI.Xaml.Data.MUXPropertyChangedEventArgsRuntimeClassFactory(ActivationFactory.Get("Microsoft.UI.Xaml.Data.PropertyChangedEventArgs")); public static IObjectReference CreateMarshaler(global::System.ComponentModel.PropertyChangedEventArgs value) { @@ -136,6 +215,8 @@ public static ObjectReferenceValue CreateMarshaler2(global::System.ComponentMode IntPtr propertyName = IntPtr.Zero; try { + // We can use the Microsoft.UI.Xaml.Data.IPropertyChangedEventArgsVftbl here in both WUX and MUX because the vtables are laid out the same and we know + // that we have either a MUX or WUX IPropertyChangedEventArgs pointer in ptr. ExceptionHelpers.ThrowExceptionForHR((**(ABI.Microsoft.UI.Xaml.Data.IPropertyChangedEventArgsVftbl**)ptr).get_PropertyName_0(ptr, &propertyName)); return new global::System.ComponentModel.PropertyChangedEventArgs(MarshalString.FromAbi(propertyName)); } @@ -172,6 +253,11 @@ public static IntPtr FromManaged(global::System.ComponentModel.PropertyChangedEv public static string GetGuidSignature() { + if (Projections.UiXamlModeSetting == Projections.UiXamlMode.WindowsUiXaml) + { + return "rc(Windows.UI.Xaml.Data.NotifyPropertyChangedEventArgs;{4f33a9a0-5cf4-47a4-b16f-d7faaf17457e})"; + } + return "rc(Microsoft.UI.Xaml.Data.NotifyPropertyChangedEventArgs;{4f33a9a0-5cf4-47a4-b16f-d7faaf17457e})"; } } diff --git a/src/WinRT.Runtime/Projections/PropertyChangedEventHandler.cs b/src/WinRT.Runtime/Projections/PropertyChangedEventHandler.cs index 28334aadd..2faf769a7 100644 --- a/src/WinRT.Runtime/Projections/PropertyChangedEventHandler.cs +++ b/src/WinRT.Runtime/Projections/PropertyChangedEventHandler.cs @@ -40,11 +40,14 @@ static unsafe PropertyChangedEventHandler() var nativeVftbl = ComWrappersSupport.AllocateVtableMemory(typeof(PropertyChangedEventHandler), Marshal.SizeOf()); Marshal.StructureToPtr(AbiToProjectionVftable, nativeVftbl, false); AbiToProjectionVftablePtr = nativeVftbl; + IID = Projections.UiXamlModeSetting == Projections.UiXamlMode.WindowsUiXaml + ? Guid.Parse("50f19c16-0a22-4d8e-a089-1ea9951657d2") + : typeof(global::System.ComponentModel.PropertyChangedEventHandler).GUID; } public static global::System.Delegate AbiInvokeDelegate { get; } - private static readonly Guid IID = new(0xE3DE52F6, 0x1E32, 0x5DA6, 0xBB, 0x2D, 0xB5, 0xB6, 0x09, 0x6C, 0x96, 0x2D); + private static readonly Guid IID; public static unsafe IObjectReference CreateMarshaler(global::System.ComponentModel.PropertyChangedEventHandler managedDelegate) => managedDelegate is null ? null : MarshalDelegate.CreateMarshaler(managedDelegate, IID); diff --git a/src/WinRT.Runtime/Projections/Windows.UI.Xaml.Bindable.net5.cs b/src/WinRT.Runtime/Projections/Windows.UI.Xaml.Bindable.net5.cs new file mode 100644 index 000000000..7f54e9b25 --- /dev/null +++ b/src/WinRT.Runtime/Projections/Windows.UI.Xaml.Bindable.net5.cs @@ -0,0 +1,367 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using WinRT; +using WinRT.Interop; + + +#pragma warning disable 0169 // warning CS0169: The field '...' is never used +#pragma warning disable 0649 // warning CS0169: Field '...' is never assigned to + +namespace Windows.UI.Xaml.Interop +{ + [global::WinRT.WindowsRuntimeType] + [Guid("036D2C08-DF29-41AF-8AA2-D774BE62BA6F")] + [global::WinRT.WindowsRuntimeHelperType(typeof(global::ABI.Windows.UI.Xaml.Interop.IBindableIterable))] + internal interface IBindableIterable + { + IBindableIterator First(); + } + [global::WinRT.WindowsRuntimeType] + [Guid("6A1D6C07-076D-49F2-8314-F52C9C9A8331")] + [global::WinRT.WindowsRuntimeHelperType(typeof(global::ABI.Windows.UI.Xaml.Interop.IBindableIterator))] + internal interface IBindableIterator + { + bool MoveNext(); + // GetMany is not implemented by IBindableIterator, but it is here + // for compat purposes with WinUI where there are scenarios they do + // reinterpret_cast from IBindableIterator to IIterable. It is + // the last function in the vftable and shouldn't be called by anyone. + // If called, it will return NotImplementedException. + uint GetMany(ref object[] items); + object Current { get; } + bool HasCurrent { get; } + } + [global::WinRT.WindowsRuntimeType] + [Guid("393DE7DE-6FD0-4C0D-BB71-47244A113E93")] + internal interface IBindableVector : IEnumerable + { + 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(); + uint Size { get; } + } + [global::WinRT.WindowsRuntimeType] + [Guid("346DD6E7-976E-4BC3-815D-ECE243BC0F33")] + [global::WinRT.WindowsRuntimeHelperType(typeof(global::ABI.Windows.UI.Xaml.Interop.IBindableVectorView))] + internal interface IBindableVectorView : IEnumerable + { + object GetAt(uint index); + bool IndexOf(object value, out uint index); + uint Size { get; } + } +} + +namespace ABI.Windows.UI.Xaml.Interop +{ + [DynamicInterfaceCastableImplementation] + [Guid("036D2C08-DF29-41AF-8AA2-D774BE62BA6F")] + internal unsafe interface IBindableIterable : global::Windows.UI.Xaml.Interop.IBindableIterable, ABI.System.Collections.IEnumerable + { + + } + + [DynamicInterfaceCastableImplementation] + [Guid("6A1D6C07-076D-49F2-8314-F52C9C9A8331")] + internal unsafe interface IBindableIterator : global::Windows.UI.Xaml.Interop.IBindableIterator + { + public static readonly IntPtr AbiToProjectionVftablePtr; + static IBindableIterator() + { + AbiToProjectionVftablePtr = ComWrappersSupport.AllocateVtableMemory(typeof(IBindableIterator), sizeof(IInspectable.Vftbl) + sizeof(IntPtr) * 4); + *(IInspectable.Vftbl*)AbiToProjectionVftablePtr = IInspectable.Vftbl.AbiToProjectionVftable; + ((delegate* unmanaged[Stdcall]*)AbiToProjectionVftablePtr)[6] = &Do_Abi_get_Current_0; + ((delegate* unmanaged[Stdcall]*)AbiToProjectionVftablePtr)[7] = &Do_Abi_get_HasCurrent_1; + ((delegate* unmanaged[Stdcall]*)AbiToProjectionVftablePtr)[8] = &Do_Abi_MoveNext_2; + ((delegate* unmanaged[Stdcall]*)AbiToProjectionVftablePtr)[9] = &Do_Abi_GetMany_3; + } + + [UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })] + private static unsafe int Do_Abi_MoveNext_2(IntPtr thisPtr, byte* result) + { + bool __result = default; + *result = default; + try + { + __result = global::WinRT.ComWrappersSupport.FindObject(thisPtr).MoveNext(); + *result = (byte)(__result ? 1 : 0); + } + catch (Exception __exception__) + { + global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); + return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); + } + return 0; + } + + [UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })] + private static unsafe int Do_Abi_GetMany_3(IntPtr thisPtr, int __itemsSize, IntPtr items, uint* result) + { + *result = default; + + try + { + // Should never be called. + throw new NotImplementedException(); + } + catch (Exception __exception__) + { + global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); + return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); + } + } + + [UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })] + private static unsafe int Do_Abi_get_Current_0(IntPtr thisPtr, IntPtr* value) + { + object __value = default; + *value = default; + try + { + __value = global::WinRT.ComWrappersSupport.FindObject(thisPtr).Current; + *value = MarshalInspectable.FromManaged(__value); + } + catch (Exception __exception__) + { + global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); + return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); + } + return 0; + } + + [UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })] + private static unsafe int Do_Abi_get_HasCurrent_1(IntPtr thisPtr, byte* value) + { + bool __value = default; + *value = default; + try + { + __value = global::WinRT.ComWrappersSupport.FindObject(thisPtr).HasCurrent; + *value = (byte)(__value ? 1 : 0); + } + catch (Exception __exception__) + { + global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); + return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); + } + return 0; + } + + internal static ObjectReference FromAbi(IntPtr thisPtr) => ObjectReference.FromAbi(thisPtr); + + unsafe bool global::Windows.UI.Xaml.Interop.IBindableIterator.MoveNext() + { + var _obj = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Windows.UI.Xaml.Interop.IBindableIterator).TypeHandle); + var ThisPtr = _obj.ThisPtr; + byte __retval = default; + global::WinRT.ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]**)ThisPtr)[8](ThisPtr, &__retval)); + return __retval != 0; + } + + unsafe uint global::Windows.UI.Xaml.Interop.IBindableIterator.GetMany(ref object[] items) + { + // Should never be called. + throw new NotImplementedException(); + } + + unsafe object global::Windows.UI.Xaml.Interop.IBindableIterator.Current + { + get + { + var _obj = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Windows.UI.Xaml.Interop.IBindableIterator).TypeHandle); + var ThisPtr = _obj.ThisPtr; + IntPtr __retval = default; + try + { + global::WinRT.ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]**)ThisPtr)[6](ThisPtr, &__retval)); + return MarshalInspectable.FromAbi(__retval); + } + finally + { + MarshalInspectable.DisposeAbi(__retval); + } + } + } + + unsafe bool global::Windows.UI.Xaml.Interop.IBindableIterator.HasCurrent + { + get + { + var _obj = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Windows.UI.Xaml.Interop.IBindableIterator).TypeHandle); + var ThisPtr = _obj.ThisPtr; + byte __retval = default; + global::WinRT.ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]**)ThisPtr)[7](ThisPtr, &__retval)); + return __retval != 0; + } + } + + } + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.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 unsafe interface IBindableVectorView : global::Windows.UI.Xaml.Interop.IBindableVectorView + { + public static readonly IntPtr AbiToProjectionVftablePtr; + static IBindableVectorView() + { + AbiToProjectionVftablePtr = ComWrappersSupport.AllocateVtableMemory(typeof(IBindableVectorView), sizeof(IInspectable.Vftbl) + sizeof(IntPtr) * 3); + *(IInspectable.Vftbl*)AbiToProjectionVftablePtr = IInspectable.Vftbl.AbiToProjectionVftable; + ((delegate* unmanaged[Stdcall]*)AbiToProjectionVftablePtr)[6] = &Do_Abi_GetAt_0; + ((delegate* unmanaged[Stdcall]*)AbiToProjectionVftablePtr)[7] = &Do_Abi_get_Size_1; + ((delegate* unmanaged[Stdcall]*)AbiToProjectionVftablePtr)[8] = &Do_Abi_IndexOf_2; + } + + [UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })] + private static unsafe int Do_Abi_GetAt_0(IntPtr thisPtr, uint index, IntPtr* result) + { + object __result = default; + + try + { + __result = global::WinRT.ComWrappersSupport.FindObject(thisPtr).GetAt(index); + *result = MarshalInspectable.FromManaged(__result); + + } + catch (Exception __exception__) + { + global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); + return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); + } + return 0; + } + + [UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })] + private static unsafe int Do_Abi_IndexOf_2(IntPtr thisPtr, IntPtr value, uint* index, byte* returnValue) + { + bool __returnValue = default; + + *index = default; + *returnValue = default; + uint __index = default; + + try + { + __returnValue = global::WinRT.ComWrappersSupport.FindObject(thisPtr).IndexOf(MarshalInspectable.FromAbi(value), out __index); + *index = __index; + *returnValue = (byte)(__returnValue ? 1 : 0); + + } + catch (Exception __exception__) + { + global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); + return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); + } + return 0; + } + + [UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })] + private static unsafe int Do_Abi_get_Size_1(IntPtr thisPtr, uint* value) + { + uint __value = default; + + *value = default; + + try + { + __value = global::WinRT.ComWrappersSupport.FindObject(thisPtr).Size; + *value = __value; + + } + catch (Exception __exception__) + { + global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); + return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); + } + return 0; + } + + internal static ObjectReference FromAbi(IntPtr thisPtr) => ObjectReference.FromAbi(thisPtr); + + private static readonly global::System.Runtime.CompilerServices.ConditionalWeakTable _helperTable = new(); + + unsafe object global::Windows.UI.Xaml.Interop.IBindableVectorView.GetAt(uint index) + { + var _obj = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Windows.UI.Xaml.Interop.IBindableIterator).TypeHandle); + var ThisPtr = _obj.ThisPtr; + IntPtr __retval = default; + try + { + global::WinRT.ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]**)ThisPtr)[6](ThisPtr, index, &__retval)); + return MarshalInspectable.FromAbi(__retval); + } + finally + { + MarshalInspectable.DisposeAbi(__retval); + } + } + + unsafe bool global::Windows.UI.Xaml.Interop.IBindableVectorView.IndexOf(object value, out uint index) + { + var _obj = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Windows.UI.Xaml.Interop.IBindableIterator).TypeHandle); + var ThisPtr = _obj.ThisPtr; + ObjectReferenceValue __value = default; + uint __index = default; + byte __retval = default; + try + { + __value = MarshalInspectable.CreateMarshaler2(value); + global::WinRT.ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]**)ThisPtr)[8]( + ThisPtr, + MarshalInspectable.GetAbi(__value), + &__index, + &__retval)); + index = __index; + return __retval != 0; + } + finally + { + MarshalInspectable.DisposeMarshaler(__value); + } + } + + unsafe uint global::Windows.UI.Xaml.Interop.IBindableVectorView.Size + { + get + { + var _obj = ((IWinRTObject)this).GetObjectReferenceForType(typeof(global::Windows.UI.Xaml.Interop.IBindableIterator).TypeHandle); + var ThisPtr = _obj.ThisPtr; + uint __retval = default; + global::WinRT.ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]**)ThisPtr)[7](ThisPtr, &__retval)); + return __retval; + } + } + + IEnumerator IEnumerable.GetEnumerator() + { + return _helperTable.GetValue((IWinRTObject)this, + (enumerable) => new ABI.System.Collections.IEnumerable.AdaptiveFromAbiHelper(enumerable) + ).GetEnumerator(); + } + } + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.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); + } +} diff --git a/src/cswinrt/cswinrt.vcxproj.filters b/src/cswinrt/cswinrt.vcxproj.filters index 57e31721d..b06989e5d 100644 --- a/src/cswinrt/cswinrt.vcxproj.filters +++ b/src/cswinrt/cswinrt.vcxproj.filters @@ -51,6 +51,21 @@ {369a6d8a-43e6-48af-82c1-bb2e555909a4} + + {22aeef74-f4df-40f4-a18f-8053ac54f966} + + + {bb545b29-ba72-4949-b044-790f57ba17a5} + + + {8451fa83-9750-4aec-ae8c-a4149c4b98a6} + + + {98453be9-888b-4032-b5cd-4034b17197c9} + + + {03980bb6-f657-4c07-a456-5b4774de5773} + @@ -174,6 +189,24 @@ strings + + strings\additions\Windows.UI.Xaml.Controls.Primitives + + + strings\additions\Windows.UI.Xaml.Media.Animation + + + strings\additions\Windows.UI.Xaml.Media.Media3D + + + strings\additions\Windows.UI.Xaml.Media + + + strings\additions\Windows.UI.Xaml + + + strings\additions\Windows.UI.Xaml + diff --git a/src/cswinrt/helpers.h b/src/cswinrt/helpers.h index 8e43f270f..93b1ce916 100644 --- a/src/cswinrt/helpers.h +++ b/src/cswinrt/helpers.h @@ -670,7 +670,7 @@ namespace cswinrt } mapped_types[] = { // Make sure to keep this table consistent with the registrations in WinRT.Runtime/Projections.cs - // and the reverse mapping in WinRT.SourceGenerator/WinRTTypeWriter.cs. + // and the reverse mapping in WinRT.SourceGenerator/TypeMapper.cs. // This table can include both the MUX and WUX types as only one will be selected at runtime. // NOTE: Must keep namespaces sorted (outer) and abi type names sorted (inner) { "Microsoft.UI.Xaml", diff --git a/src/cswinrt/strings/additions/Windows.UI.Xaml.Controls/Windows.UI.Xaml.Controls.Primitives.cs b/src/cswinrt/strings/additions/Windows.UI.Xaml.Controls/Windows.UI.Xaml.Controls.Primitives.cs index 8326013d9..ec28e9295 100644 --- a/src/cswinrt/strings/additions/Windows.UI.Xaml.Controls/Windows.UI.Xaml.Controls.Primitives.cs +++ b/src/cswinrt/strings/additions/Windows.UI.Xaml.Controls/Windows.UI.Xaml.Controls.Primitives.cs @@ -3,7 +3,7 @@ namespace Windows.UI.Xaml.Controls.Primitives { using global::Windows.Foundation; - [global::WinRT.WindowsRuntimeType("Microsoft.UI")] + [global::WinRT.WindowsRuntimeType("Windows.UI.Xaml")] [global::WinRT.WindowsRuntimeHelperType(typeof(global::ABI.Windows.UI.Xaml.Controls.Primitives.GeneratorPosition))] [StructLayout(LayoutKind.Sequential)] #if EMBED diff --git a/src/cswinrt/strings/additions/Windows.UI.Xaml.Media.Animation/Windows.UI.Xaml.Media.Animation.cs b/src/cswinrt/strings/additions/Windows.UI.Xaml.Media.Animation/Windows.UI.Xaml.Media.Animation.cs index 789928089..259898959 100644 --- a/src/cswinrt/strings/additions/Windows.UI.Xaml.Media.Animation/Windows.UI.Xaml.Media.Animation.cs +++ b/src/cswinrt/strings/additions/Windows.UI.Xaml.Media.Animation/Windows.UI.Xaml.Media.Animation.cs @@ -3,7 +3,7 @@ namespace Windows.UI.Xaml.Media.Animation { using global::Windows.Foundation; - [global::WinRT.WindowsRuntimeType("Microsoft.UI")] + [global::WinRT.WindowsRuntimeType("Windows.UI.Xaml")] [global::WinRT.WindowsRuntimeHelperType(typeof(global::ABI.Windows.UI.Xaml.Media.Animation.KeyTime))] [StructLayout(LayoutKind.Sequential)] #if EMBED @@ -78,7 +78,7 @@ public TimeSpan TimeSpan } } - [global::WinRT.WindowsRuntimeType("Microsoft.UI")] + [global::WinRT.WindowsRuntimeType("Windows.UI.Xaml")] #if EMBED internal #else @@ -91,7 +91,7 @@ enum RepeatBehaviorType Forever } - [global::WinRT.WindowsRuntimeType("Microsoft.UI")] + [global::WinRT.WindowsRuntimeType("Windows.UI.Xaml")] [global::WinRT.WindowsRuntimeHelperType(typeof(global::ABI.Windows.UI.Xaml.Media.Animation.RepeatBehavior))] [StructLayout(LayoutKind.Sequential)] #if EMBED diff --git a/src/cswinrt/strings/additions/Windows.UI.Xaml.Media.Media3D/Windows.UI.Xaml.Media.Media3D.cs b/src/cswinrt/strings/additions/Windows.UI.Xaml.Media.Media3D/Windows.UI.Xaml.Media.Media3D.cs index 84e3837ff..98dfb069e 100644 --- a/src/cswinrt/strings/additions/Windows.UI.Xaml.Media.Media3D/Windows.UI.Xaml.Media.Media3D.cs +++ b/src/cswinrt/strings/additions/Windows.UI.Xaml.Media.Media3D/Windows.UI.Xaml.Media.Media3D.cs @@ -3,7 +3,7 @@ namespace Windows.UI.Xaml.Media.Media3D { using global::Windows.Foundation; - [global::WinRT.WindowsRuntimeType("Microsoft.UI")] + [global::WinRT.WindowsRuntimeType("Windows.UI.Xaml")] [global::WinRT.WindowsRuntimeHelperType(typeof(global::ABI.Windows.UI.Xaml.Media.Media3D.Matrix3D))] [StructLayout(LayoutKind.Sequential)] #if EMBED diff --git a/src/cswinrt/strings/additions/Windows.UI.Xaml.Media/Windows.UI.Xaml.Media.cs b/src/cswinrt/strings/additions/Windows.UI.Xaml.Media/Windows.UI.Xaml.Media.cs index a731d74fb..b156e5104 100644 --- a/src/cswinrt/strings/additions/Windows.UI.Xaml.Media/Windows.UI.Xaml.Media.cs +++ b/src/cswinrt/strings/additions/Windows.UI.Xaml.Media/Windows.UI.Xaml.Media.cs @@ -3,7 +3,7 @@ namespace Windows.UI.Xaml.Media { using global::Windows.Foundation; - [global::WinRT.WindowsRuntimeType("Microsoft.UI")] + [global::WinRT.WindowsRuntimeType("Windows.UI.Xaml")] [global::WinRT.WindowsRuntimeHelperType(typeof(global::ABI.Windows.UI.Xaml.Media.Matrix))] [StructLayout(LayoutKind.Sequential)] #if EMBED diff --git a/src/cswinrt/strings/additions/Windows.UI.Xaml/Windows.UI.Xaml.cs b/src/cswinrt/strings/additions/Windows.UI.Xaml/Windows.UI.Xaml.cs index 1ec6ea03d..341d016d6 100644 --- a/src/cswinrt/strings/additions/Windows.UI.Xaml/Windows.UI.Xaml.cs +++ b/src/cswinrt/strings/additions/Windows.UI.Xaml/Windows.UI.Xaml.cs @@ -3,7 +3,7 @@ namespace Windows.UI.Xaml { using global::Windows.Foundation; - [global::WinRT.WindowsRuntimeType("Microsoft.UI")] + [global::WinRT.WindowsRuntimeType("Windows.UI.Xaml")] [global::WinRT.WindowsRuntimeHelperType(typeof(global::ABI.Windows.UI.Xaml.CornerRadius))] [StructLayout(LayoutKind.Sequential)] #if EMBED @@ -151,7 +151,7 @@ public double BottomLeft } } - [global::WinRT.WindowsRuntimeType("Microsoft.UI")] + [global::WinRT.WindowsRuntimeType("Windows.UI.Xaml")] #if EMBED internal #else @@ -164,7 +164,7 @@ enum GridUnitType Star, } - [global::WinRT.WindowsRuntimeType("Microsoft.UI")] + [global::WinRT.WindowsRuntimeType("Windows.UI.Xaml")] [global::WinRT.WindowsRuntimeHelperType(typeof(global::ABI.Windows.UI.Xaml.GridLength))] [StructLayout(LayoutKind.Sequential)] #if EMBED @@ -282,7 +282,7 @@ internal string ToString(global::System.Globalization.CultureInfo cultureInfo) } } - [global::WinRT.WindowsRuntimeType("Microsoft.UI")] + [global::WinRT.WindowsRuntimeType("Windows.UI.Xaml")] [global::WinRT.WindowsRuntimeHelperType(typeof(global::ABI.Windows.UI.Xaml.Thickness))] [StructLayout(LayoutKind.Sequential)] #if EMBED @@ -396,7 +396,7 @@ public override int GetHashCode() } } - [global::WinRT.WindowsRuntimeType("Microsoft.UI")] + [global::WinRT.WindowsRuntimeType("Windows.UI.Xaml")] #if EMBED internal #else @@ -409,7 +409,7 @@ enum DurationType Forever } - [global::WinRT.WindowsRuntimeType("Microsoft.UI")] + [global::WinRT.WindowsRuntimeType("Windows.UI.Xaml")] [global::WinRT.WindowsRuntimeHelperType(typeof(global::ABI.Windows.UI.Xaml.Duration))] [StructLayout(LayoutKind.Sequential)] #if EMBED