public ITypeInformation ResolveReference(AssemblyInformation ctx, EntityHandle handle) { if (handle.Kind == HandleKind.TypeDefinition) { return(ctx.TryGetType((TypeDefinitionHandle)handle)); } if (handle.Kind == HandleKind.TypeReference) { var reference = ctx.Reader.GetTypeReference((TypeReferenceHandle)handle); if (reference.Name.IsNil || reference.Namespace.IsNil) { return(null); } if (reference.ResolutionScope.Kind == HandleKind.AssemblyReference) { var ns = ctx.Reader.GetString(reference.Namespace); var name = ctx.Reader.GetString(reference.Name); var asmref = ctx.Reader.GetAssemblyReference((AssemblyReferenceHandle)reference.ResolutionScope); var asmname = ctx.Reader.GetString(asmref.Name); AssemblyInformation asm; if (!_assemblies.TryGetValue(asmname, out asm)) { return(new UnresolvedTypeInformation(ns, name)); } return ((ITypeInformation)asm.TryGetType(ns + "." + name) ?? new UnresolvedTypeInformation(ns, name)); } //TODO: implement other resolution scoles } //TODO: Implement type specification handling return(null); }
public TypeInformation(AssemblyInformation assembly, TypeDefinitionHandle handle) { Assembly = assembly; _def = assembly.Reader.GetTypeDefinition(handle); var r = assembly.Reader; Name = r.GetString(_def.Name); Namespace = r.GetString(_def.Namespace); FullName = Namespace + "." + Name; IsInterface = (_def.Attributes & TypeAttributes.Interface) != 0; IsPublic = (_def.Attributes & TypeAttributes.Public) != 0; IsStatic = (_def.Attributes & (TypeAttributes.Abstract | TypeAttributes.Sealed)) != 0; if (_def.BaseType.Kind == HandleKind.TypeReference) { var baseRef = r.GetTypeReference((TypeReferenceHandle)_def.BaseType); if (r.GetString(baseRef.Name) == "Enum" && r.GetString(baseRef.Namespace) == "System") { IsEnum = true; var values = new List <string>(); foreach (var fhandle in _def.GetFields()) { var field = r.GetFieldDefinition(fhandle); if ((field.Attributes & FieldAttributes.RTSpecialName) != 0) { continue; } values.Add(r.GetString(field.Name)); } EnumValues = values.ToArray(); } } }
public void Add(LoadedAssembly asm) { _rawAsms.Add(asm.AssemblyName, asm); var nfo = new AssemblyInformation(asm, this); _assemblies[nfo.Name] = nfo; _readersToAsms[asm.Reader] = nfo; }
public MethodInformation(AssemblyInformation asm, MethodDefinitionHandle handle) { _asm = asm; _def = asm.Reader.GetMethodDefinition(handle); IsStatic = (_def.Attributes & MethodAttributes.Static) != 0; IsPublic = (_def.Attributes & MethodAttributes.Public) == MethodAttributes.Public; Name = asm.Reader.GetString(_def.Name); }
public CustomAttributeInformation(AssemblyInformation asm, CustomAttributeHandle handle) { _asm = asm; _ca = asm.Reader.GetCustomAttribute(handle); if (_ca.Constructor.Kind == HandleKind.MethodDefinition) { var mdef = asm.Reader.GetMethodDefinition((MethodDefinitionHandle)_ca.Constructor); var tdef = asm.Reader.GetTypeDefinition(mdef.GetDeclaringType()); TypeFullName = asm.Reader.GetString(tdef.Namespace) + "." + asm.Reader.GetString(tdef.Name); } else { var mref = asm.Reader.GetMemberReference((MemberReferenceHandle)_ca.Constructor); if (mref.Parent.Kind == HandleKind.TypeReference) { var tref = asm.Reader.GetTypeReference((TypeReferenceHandle)mref.Parent); TypeFullName = asm.Reader.GetString(tref.Namespace) + "." + asm.Reader.GetString(tref.Name); } } }
public PropertyInformation(AssemblyInformation assembly, TypeDefinition tdef, PropertyDefinitionHandle handle) { var def = assembly.Reader.GetPropertyDefinition(handle); Name = assembly.Reader.GetString(def.Name); MethodInformation build(MethodDefinitionHandle mh) => mh.IsNil ? default(MethodInformation) : new MethodInformation(assembly, mh); var accessors = def.GetAccessors(); var getter = build(accessors.Getter); var setter = build(accessors.Setter); HasPublicSetter = setter?.IsPublic ?? false; HasPublicGetter = getter?.IsPublic ?? false; TypeFullName = getter?.ReturnTypeFullName ?? setter?.Parameters[0].TypeFullName; IsStatic = getter?.IsStatic ?? setter?.IsStatic ?? false; }
public PropertyInformation(AssemblyInformation assembly, TypeDefinition tdef, PropertyDefinitionHandle handle) { var def = assembly.Reader.GetPropertyDefinition(handle); Name = assembly.Reader.GetString(def.Name); var accessors = def.GetAccessors(); MethodInformation accessor; if (!accessors.Setter.IsNil) { accessor = new MethodInformation(assembly, accessors.Setter); HasPublicSetter = accessor.IsPublic; TypeFullName = accessor.Parameters[0].TypeFullName; } else { accessor = new MethodInformation(assembly, accessors.Getter); TypeFullName = accessor.ReturnTypeFullName; } IsStatic = accessor.IsStatic; }