-
Notifications
You must be signed in to change notification settings - Fork 123
System.Type Marshaling #2129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kythant
wants to merge
124
commits into
staging/3.0
Choose a base branch
from
user/kythant/TypeHandling
base: staging/3.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
System.Type Marshaling #2129
+2,547
−699
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This reverts commit ff83e55.
Simplifies and clarifies the handling of TypeReference creation, including improved comments and restructuring for primitive and proxy types. Ensures more consistent reporting of TypeKind and streamlines marshalling info usage.
Changed the TypeReference.Name field from string? to ReadOnlySpan<char> for improved memory safety and performance. Updated marshalling logic and related references to accommodate the new type.
Added [WindowsRuntimeMetadata] attributes to ABI type classes in WinRT.Runtime2 to specify their associated Windows contracts. This improves metadata clarity and contract mapping for types such as Boolean, Byte, Char, DateTimeOffset, Double, EventHandler, Exception, Guid, Int16, Int32, Int64, Numerics types, Object, Single, String, TimeSpan, Type, UInt16, UInt32, UInt64, and Uri.
Introduces TypeMapAssociation attributes for DynamicInterfaceCastableImplementationTypeMapGroup to INotifyDataErrorInfo, IDisposable, and IServiceProvider ABI interfaces. Also adds WindowsRuntimeMetadata and WindowsRuntimeClassName attributes to their respective interface implementations for improved WinRT interop.
Added logic to TypeMarshaller to support round-tripping C# primitive types (e.g., System.SByte) that are not Windows Runtime types. This ensures such types can be resolved even if not found in the WindowsRuntimeMarshallingInfo lookup.
Replaces Debug.Assert with a NotSupportedException when the WindowsRuntimeMappedTypeAttribute is missing on the metadata provider type in both WindowsRuntimeMarshallingInfo and WindowsRuntimeMetadataInfo. This provides clearer error reporting and guidance for unexpected code generation issues.
Deleted outdated TODO comments regarding type map entries for non-generic interfaces, value types, and delegate types in TypeMarshaller. No functional code changes were made.
Introduces methods and references to handle TypeMap and TypeMapAssociation attributes for WindowsRuntimeMetadataTypeMapGroup in InteropCustomAttributeFactory and InteropReferences. This enables generation and referencing of custom attributes using the new type map group.
Reorganized conditional checks for nullable and projected types in TypeMarshaller. Ensures special handling for types that cannot be used in Nullable<T> and improves clarity by nesting projected and metadata info lookups under a single nullable check.
Introduces handling for the WindowsRuntimeMetadataTypeNameAttribute in InteropTypeDefinitionBuilder and InteropReferences. This allows proxy types to optionally emit the metadata type name attribute and reference the original managed type when required.
31c9fb6 to
1c5e5b4
Compare
Introduces handling for the WindowsRuntimeMappedMetadataAttribute in proxy type generation. Updates relevant builders and references to allow optional inclusion of mapped metadata information when generating interop types.
Introduces a static Proxy method to InteropTypeDefinitionBuilder.KeyValuePair for creating proxy types for KeyValuePair<TKey, TValue>. Updates InteropGenerator.Emit to use the new method, improving clarity and encapsulation for KeyValuePair proxy generation.
Introduces the IsGenericType property to determine if a TypeSignature represents a constructed generic type.
Introduces MetadataTypeNameGenerator to handle Windows Runtime metadata type name generation, including generic and array types. Refactors RuntimeClassNameGenerator to delegate type name formatting to the new helper, improving code reuse and maintainability. Adds error handling for unresolved types and clarifies logic for IReference wrapping.
Updated TypeMapAttributes methods in Delegate and KeyValuePair builders to accept TypeSignature instead of GenericInstanceTypeSignature. Added a static Proxy method to InteropTypeDefinitionBuilder.Delegate for delegate proxy type creation, and updated usage in InteropGenerator.Emit to use the new method.
Expanded the comment to mention that generic delegate types are also handled by using '[WindowsRuntimeMetadataTypeName]'. No code changes were made.
Corrected 'GetMetadataTyoeName' and 'AppendMetadataTyoeName' to 'GetMetadataTypeName' and 'AppendMetadataTypeName' in MetadataTypeNameGenerator and updated all references. This improves code clarity and consistency.
Introduces a new metadataTypeName parameter to TypeMapAttributes and updates all relevant builder calls to include it, defaulting to null where not required. This enables emitting additional type map attributes for metadata type mapping, supporting improved marshalling scenarios such as Windows Runtime delegate types.
Replaces the use of runtimeClassName with metadataTypeName when setting the WindowsRuntimeMetadataTypeNameAttribute. This ensures the correct type name is used in the custom attribute.
Renames proxyTypeMap* parameters to marshallingTypeMap* and adds metadataTypeMap* parameters across InteropTypeDefinitionBuilder and related builders. Updates attribute emission logic to support both marshalling and metadata type map associations, improving clarity and future extensibility.
Clarified the summary to specify proxy types are for interfaces or SZ array types. Added comments and set 'referenceMappedType' to true to ensure the '[WindowsRuntimeMappedType]' attribute is emitted, enabling 'TypeName' marshalling to retrieve the runtime class name.
Set metadataTypeMapSourceType and metadataTypeMapProxyType to appropriate values in IList, IReadOnlyList, and interface type builder methods. This ensures correct type mapping for metadata generation.
Introduces a dedicated Proxy method for SZ array types in InteropTypeDefinitionBuilder.SzArray, separating it from the interface proxy logic. Updates all call sites to use the new method for arrays and renames the parameter for interface proxies to improve clarity.
Updated the XML documentation for the proxyType parameter to reference only Proxy, removing the method signature for clarity and maintainability.
Emit '[WindowsRuntimeMetadataTypeName]' instead of a runtime class name when generating proxies for interface types. This supports mapping generic interface names during 'TypeName' marshalling, as runtime class names are not needed for interfaces.
Reorganizes the logic for handling value types in TypeMarshaller. Now, KeyValuePair<,> is explicitly checked before falling back to marshalling info for other value types, improving clarity and correctness in type selection.
Replaces global::System.Collections type references with direct type usage (e.g., IEnumerable, IEnumerator, IList) in ABI marshaller and implementation files. Refactors and exposes ComWrappersMarshallerAttribute classes as public, adds missing attributes, and introduces a new Interface helper in DynamicCustomMappedTypeMapEntriesBuilder to streamline interface mapping logic.
Annotated DataErrorsChangedEventArgs ABI type with WindowsRuntimeMappedMetadata and WindowsRuntimeMappedType attributes to improve metadata mapping and type resolution.
Extracted marshaller attribute type resolution into GetMarshallerAttributeType to reduce code duplication. Replaced ManagedOnlyTypeOrInterface with ManagedOnlyType, simplifying parameters and usage. Updated method calls and removed redundant marshaller attribute resolution logic from multiple locations.
Renamed internal builder methods for clarity, distinguishing between interface and delegate type mappings. Updated NotifyCollectionChangedEventArgs and PropertyChangedEventArgs ABI files to remove unnecessary TypeMapAssociation attributes, simplify type references, and improve marshaller and attribute declarations for consistency and maintainability.
Replaces calls to ManagedOnlyDelegateType with DelegateType for delegate type mappings, and updates related method signatures and invocations for consistency. This change streamlines delegate type handling and unifies the mapping logic.
Introduces a new private ClassType method to handle custom-mapped class types, mirroring the existing DelegateType logic. Updates relevant calls to use ClassType instead of DelegateType for class types, improving clarity and separation of concerns in type mapping.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.