-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GenericTypeParameterBuilder implementation and save a generic typ…
…e into assembly. (#85658) * Save a type with generic type parameters * Update GenericParameterAttribute in test that causing a class contraint
- Loading branch information
Showing
6 changed files
with
297 additions
and
62 deletions.
There are no files selected for viewing
This file contains 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 file contains 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
132 changes: 132 additions & 0 deletions
132
...ries/System.Reflection.Emit/src/System/Reflection/Emit/GenericTypeParameterBuilderImpl.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Collections.Generic; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Globalization; | ||
|
||
namespace System.Reflection.Emit | ||
{ | ||
internal sealed class GenericTypeParameterBuilderImpl : GenericTypeParameterBuilder | ||
{ | ||
private readonly string _name; | ||
private readonly TypeBuilderImpl _type; | ||
private readonly int _genParamPosition; | ||
private GenericParameterAttributes _genParamAttributes; | ||
private bool _isGenericMethodParameter; | ||
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] | ||
private Type? _parent; | ||
|
||
internal List<CustomAttributeWrapper>? _customAttributes; | ||
internal List<Type>? _interfaces; | ||
|
||
internal GenericTypeParameterBuilderImpl(string name, int genParamPosition, TypeBuilderImpl typeBuilder) | ||
{ | ||
_name = name; | ||
_genParamPosition = genParamPosition; | ||
_type = typeBuilder; | ||
_isGenericMethodParameter = false; | ||
} | ||
|
||
protected override void SetBaseTypeConstraintCore([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type? baseTypeConstraint) | ||
{ | ||
_parent = baseTypeConstraint; | ||
|
||
if (_parent != null) | ||
{ | ||
_interfaces ??= new List<Type>(); | ||
_interfaces.Add(_parent); | ||
} | ||
} | ||
|
||
protected override void SetCustomAttributeCore(ConstructorInfo con, ReadOnlySpan<byte> binaryAttribute) | ||
{ | ||
_customAttributes ??= new List<CustomAttributeWrapper>(); | ||
_customAttributes.Add(new CustomAttributeWrapper(con, binaryAttribute)); | ||
} | ||
|
||
protected override void SetGenericParameterAttributesCore(GenericParameterAttributes genericParameterAttributes) => | ||
_genParamAttributes = genericParameterAttributes; | ||
|
||
protected override void SetInterfaceConstraintsCore(params Type[]? interfaceConstraints) | ||
{ | ||
if (interfaceConstraints != null) | ||
{ | ||
_interfaces ??= new List<Type>(interfaceConstraints.Length); | ||
_interfaces.AddRange(interfaceConstraints); | ||
} | ||
} | ||
|
||
public override Type[] GetGenericParameterConstraints() => | ||
_interfaces == null ? EmptyTypes : _interfaces.ToArray(); | ||
public override bool IsGenericTypeParameter => !_isGenericMethodParameter; | ||
public override bool IsGenericMethodParameter => _isGenericMethodParameter; | ||
public override int GenericParameterPosition => _genParamPosition; | ||
public override GenericParameterAttributes GenericParameterAttributes => _genParamAttributes; | ||
public override string Name => _name; | ||
public override Module Module => _type.Module; | ||
public override Assembly Assembly => _type.Assembly; | ||
public override string? FullName => null; | ||
public override string? Namespace => null; | ||
public override string? AssemblyQualifiedName => null; | ||
public override Type UnderlyingSystemType => this; | ||
public override bool IsGenericTypeDefinition => false; | ||
public override bool IsGenericType => false; | ||
public override bool IsGenericParameter => true; | ||
public override bool IsConstructedGenericType => false; | ||
public override bool ContainsGenericParameters => _type.ContainsGenericParameters; | ||
public override MethodBase? DeclaringMethod => throw new NotImplementedException(); | ||
public override Type? BaseType => _parent; | ||
public override RuntimeTypeHandle TypeHandle => throw new NotSupportedException(); | ||
public override Guid GUID => throw new NotSupportedException(); | ||
protected override bool IsArrayImpl() => false; | ||
protected override bool IsByRefImpl() => false; | ||
protected override bool IsPointerImpl() => false; | ||
protected override bool IsPrimitiveImpl() => false; | ||
protected override bool IsCOMObjectImpl() => false; | ||
protected override bool HasElementTypeImpl() => false; | ||
protected override TypeAttributes GetAttributeFlagsImpl() => TypeAttributes.Public; | ||
public override Type GetElementType() => throw new NotSupportedException(); | ||
public override object[] GetCustomAttributes(bool inherit) => throw new NotSupportedException(); | ||
public override object[] GetCustomAttributes(Type attributeType, bool inherit) => throw new NotSupportedException(); | ||
public override bool IsDefined(Type attributeType, bool inherit) => throw new NotSupportedException(); | ||
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] | ||
protected override ConstructorInfo GetConstructorImpl(BindingFlags bindingAttr, Binder? binder, CallingConventions callConvention, Type[] types, ParameterModifier[]? modifiers) => throw new NotSupportedException(); | ||
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] | ||
public override ConstructorInfo[] GetConstructors(BindingFlags bindingAttr) => throw new NotSupportedException(); | ||
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.NonPublicMethods)] | ||
protected override MethodInfo GetMethodImpl(string name, BindingFlags bindingAttr, Binder? binder, CallingConventions callConvention, Type[]? types, ParameterModifier[]? modifiers) => throw new NotSupportedException(); | ||
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.NonPublicMethods)] | ||
public override MethodInfo[] GetMethods(BindingFlags bindingAttr) => throw new NotSupportedException(); | ||
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)] | ||
public override FieldInfo GetField(string name, BindingFlags bindingAttr) => throw new NotSupportedException(); | ||
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)] | ||
public override FieldInfo[] GetFields(BindingFlags bindingAttr) => throw new NotSupportedException(); | ||
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] | ||
[return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] | ||
public override Type GetInterface(string name, bool ignoreCase) => throw new NotSupportedException(); | ||
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] | ||
public override Type[] GetInterfaces() => throw new NotSupportedException(); | ||
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicEvents | DynamicallyAccessedMemberTypes.NonPublicEvents)] | ||
public override EventInfo GetEvent(string name, BindingFlags bindingAttr) => throw new NotSupportedException(); | ||
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicEvents)] | ||
public override EventInfo[] GetEvents() => throw new NotSupportedException(); | ||
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.NonPublicProperties)] | ||
protected override PropertyInfo GetPropertyImpl(string name, BindingFlags bindingAttr, Binder? binder, Type? returnType, Type[]? types, ParameterModifier[]? modifiers) => throw new NotSupportedException(); | ||
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.NonPublicProperties)] | ||
public override PropertyInfo[] GetProperties(BindingFlags bindingAttr) => throw new NotSupportedException(); | ||
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicNestedTypes | DynamicallyAccessedMemberTypes.NonPublicNestedTypes)] | ||
public override Type[] GetNestedTypes(BindingFlags bindingAttr) => throw new NotSupportedException(); | ||
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicNestedTypes | DynamicallyAccessedMemberTypes.NonPublicNestedTypes)] | ||
public override Type GetNestedType(string name, BindingFlags bindingAttr) => throw new NotSupportedException(); | ||
[DynamicallyAccessedMembers(TypeBuilderImpl.GetAllMembers)] | ||
public override MemberInfo[] GetMember(string name, MemberTypes type, BindingFlags bindingAttr) => throw new NotSupportedException(); | ||
public override InterfaceMapping GetInterfaceMap([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.NonPublicMethods)] Type interfaceType) => throw new NotSupportedException(); | ||
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicEvents | DynamicallyAccessedMemberTypes.NonPublicEvents)] | ||
public override EventInfo[] GetEvents(BindingFlags bindingAttr) => throw new NotSupportedException(); | ||
[DynamicallyAccessedMembers(TypeBuilderImpl.GetAllMembers)] | ||
public override MemberInfo[] GetMembers(BindingFlags bindingAttr) => throw new NotSupportedException(); | ||
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] | ||
public override object InvokeMember(string name, BindingFlags invokeAttr, Binder? binder, object? target, object?[]? args, ParameterModifier[]? modifiers, CultureInfo? culture, string[]? namedParameters) => throw new NotSupportedException(); | ||
} | ||
} |
Oops, something went wrong.