IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
ReflectionMemberSymbol.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Immutable;
3using System.Linq;
4using System.Reflection;
5
7{
8
13 {
14
15 readonly ReflectionModuleSymbol _module;
16 readonly ReflectionTypeSymbol? _type;
17 readonly MemberInfo _underlyingMember;
18
27 base(context)
28 {
29 _module = module ?? throw new ArgumentNullException(nameof(module));
30 _type = type;
31 _underlyingMember = underlyingMember ?? throw new ArgumentNullException(nameof(underlyingMember));
32 }
33
39 protected internal override ReflectionTypeSymbol ResolveTypeSymbol(Type type)
40 {
41 if (_type != null && type == _type.UnderlyingType)
42 return _type;
43 else if (type.Module == _underlyingMember.Module)
44 return _module.GetOrCreateTypeSymbol(type);
45 else
46 return base.ResolveTypeSymbol(type);
47 }
48
54 protected internal override ReflectionConstructorSymbol ResolveConstructorSymbol(ConstructorInfo ctor)
55 {
56 if (_type != null && ctor.DeclaringType == _type.UnderlyingType)
57 return _type.GetOrCreateConstructorSymbol(ctor);
58 else if (ctor.DeclaringType != null && ctor.Module == _underlyingMember.Module)
59 return _module.GetOrCreateTypeSymbol(ctor.DeclaringType).GetOrCreateConstructorSymbol(ctor);
60 else
61 return base.ResolveConstructorSymbol(ctor);
62 }
63
69 protected internal override ReflectionMethodSymbol ResolveMethodSymbol(MethodInfo method)
70 {
71 if (_type != null && method.DeclaringType == _type.UnderlyingType)
72 return _type.GetOrCreateMethodSymbol(method);
73 else if (method.DeclaringType != null && method.Module == _underlyingMember.Module)
74 return _module.GetOrCreateTypeSymbol(method.DeclaringType).GetOrCreateMethodSymbol(method);
75 else
76 return base.ResolveMethodSymbol(method);
77 }
78
84 protected internal override ReflectionFieldSymbol ResolveFieldSymbol(FieldInfo field)
85 {
86 if (_type != null && field.DeclaringType == _type.UnderlyingType)
87 return _type.GetOrCreateFieldSymbol(field);
88 else if (field.DeclaringType != null && field.Module == _underlyingMember.Module)
89 return _module.GetOrCreateTypeSymbol(field.DeclaringType).GetOrCreateFieldSymbol(field);
90 else
91 return base.ResolveFieldSymbol(field);
92 }
93
94
100 protected internal override ReflectionPropertySymbol ResolvePropertySymbol(PropertyInfo property)
101 {
102
103 if (_type != null && property.DeclaringType == _type.UnderlyingType)
104 return _type.GetOrCreatePropertySymbol(property);
105 else if (property.DeclaringType != null && property.Module == _underlyingMember.Module)
106 return _module.GetOrCreateTypeSymbol(property.DeclaringType).GetOrCreatePropertySymbol(property);
107 else
108 return base.ResolvePropertySymbol(property);
109 }
110
116 protected internal override ReflectionEventSymbol ResolveEventSymbol(EventInfo @event)
117 {
118 if (_type != null && @event.DeclaringType == _type.UnderlyingType)
119 return _type.GetOrCreateEventSymbol(@event);
120 else if (@event.DeclaringType != null && @event.Module == _underlyingMember.Module)
121 return _module.GetOrCreateTypeSymbol(@event.DeclaringType).GetOrCreateEventSymbol(@event);
122 else
123 return base.ResolveEventSymbol(@event);
124 }
125
129 internal MemberInfo UnderlyingMember => _underlyingMember;
130
134 internal ReflectionModuleSymbol ContainingModule => _module;
135
139 internal ReflectionTypeSymbol? ContainingType => _type;
140
142 public virtual IModuleSymbol Module => Context.GetOrCreateModuleSymbol(_underlyingMember.Module);
143
145 public virtual ITypeSymbol? DeclaringType => _underlyingMember.DeclaringType is Type t ? Context.GetOrCreateTypeSymbol(t) : null;
146
148 public virtual MemberTypes MemberType => _underlyingMember.MemberType;
149
151 public virtual int MetadataToken => _underlyingMember.MetadataToken;
152
154 public virtual string Name => _underlyingMember.Name;
155
157 public virtual ImmutableArray<CustomAttributeSymbol> GetCustomAttributes()
158 {
159 return ResolveCustomAttributes(_underlyingMember.GetCustomAttributesData());
160 }
161
163 public virtual ImmutableArray<CustomAttributeSymbol> GetCustomAttributes(ITypeSymbol attributeType)
164 {
165 return ResolveCustomAttributes(_underlyingMember.GetCustomAttributesData()).Where(i => i.AttributeType == attributeType).ToImmutableArray();
166 }
167
169 public virtual bool IsDefined(ITypeSymbol attributeType)
170 {
171 return _underlyingMember.IsDefined(((ReflectionTypeSymbol)attributeType).UnderlyingType);
172 }
173
174 }
175
176}
IKVM.Reflection.Module Module
IKVM.Reflection.Type Type
IKVM.Reflection.ConstructorInfo ConstructorInfo
IKVM.Reflection.EventInfo EventInfo
IKVM.Reflection.FieldInfo FieldInfo
IKVM.Reflection.MemberInfo MemberInfo
IKVM.Reflection.PropertyInfo PropertyInfo
IKVM.Reflection.MethodInfo MethodInfo
global::java.lang.invoke.LambdaForm.Name Name
Obtains information about the attributes of a member and provides access to member metadata.
virtual ImmutableArray< CustomAttributeSymbol > GetCustomAttributes(ITypeSymbol attributeType)
Returns an array of custom attributes defined on this member, identified by type, or an empty array i...
virtual ImmutableArray< CustomAttributeSymbol > GetCustomAttributes()
Returns an array of all of the custom attributes defined on this member, excluding named attributes,...
virtual bool IsDefined(ITypeSymbol attributeType)
Indicates whether one or more instance of attributeType is defined on this member.
ReflectionMemberSymbol(ReflectionSymbolContext context, ReflectionModuleSymbol module, ReflectionTypeSymbol? type, MemberInfo underlyingMember)
Initializes a new instance.
virtual int MetadataToken
Gets a value that identifies a metadata element.
virtual MemberTypes MemberType
When overridden in a derived class, gets a value indicating the type of the member - method,...
virtual ? ITypeSymbol DeclaringType
Gets the class that declares this member.
Implementation of IModuleSymbol derived from System.Reflection.
Holds references to symbols derived from System.Reflection.
ReflectionModuleSymbol GetOrCreateModuleSymbol(Module module)
Gets or creates a ReflectionModuleSymbol for the specified Module.
ReflectionTypeSymbol GetOrCreateTypeSymbol(Type type)
Gets or creates a ReflectionTypeSymbol for the specified Type.
ReflectionSymbolContext Context
Gets the associated ReflectionSymbolContext.
Obtains information about the attributes of a member and provides access to member metadata.
Performs reflection on a module.
Represents type declarations: class types, interface types, array types, value types,...