public BaseTypeNodeImpl(ITreeNodeGroup treeNodeGroup, ITypeDefOrRef typeDefOrRef, bool isBaseType) { TreeNodeGroup = treeNodeGroup; this.isBaseType = isBaseType; // Keep weak refs to them so we won't prevent removed modules from being GC'd. weakRefTypeDefOrRef = new WeakReference(typeDefOrRef); weakRefResolvedTypeDef = new WeakReference(null); }
static bool IsReferencedBy(TypeDef type, ITypeDefOrRef typeRef, int depth) { if (depth >= 30) return false; // TODO: move it to a better place after adding support for more cases. if (type == null) return false; if (typeRef == null) return false; if (type == typeRef) return true; if (type.Name != typeRef.Name) return false; if (type.Namespace != typeRef.Namespace) return false; if (type.DeclaringType != null || typeRef.DeclaringType != null) { if (type.DeclaringType == null || typeRef.DeclaringType == null) return false; if (!IsReferencedBy(type.DeclaringType, typeRef.DeclaringType, depth + 1)) return false; } return true; }
public TypeDefOrRefSignature(ITypeDefOrRef type, bool isValueType) { if (type == null) throw new ArgumentNullException("type"); Type = type; IsValueType = isValueType; }
TypeInstanceResolver getTypeInstance(ITypeDefOrRef typeRef) { TypeInstanceResolver instance; if (!typeRefToInstance.TryGetValue(typeRef, out instance)) typeRefToInstance[typeRef] = instance = new TypeInstanceResolver(type, typeRef); return instance; }
public static EventDefOptions Create(UTF8String name, ITypeDefOrRef eventType) { return new EventDefOptions { Attributes = 0, Name = name, EventType = eventType, }; }
bool IsGenericParam(ITypeDefOrRef tdr) { var ts = tdr as TypeSpec; if (ts == null) return false; var sig = ts.TypeSig.RemovePinnedAndModifiers(); return sig is GenericSig; }
public GenericInstanceTypeSignature(ITypeDefOrRef genericType) { if (genericType == null) throw new ArgumentNullException("genericType"); GenericType = genericType; GenericArguments = new List<TypeSignature>(); }
public void AddInitializeArrayCode(Block block, int start, int numToRemove, ITypeDefOrRef elementType, byte[] data) { int index = start; block.Replace(index++, numToRemove, Instruction.CreateLdcI4(data.Length / elementType.ToTypeSig().ElementType.GetPrimitiveSize())); block.Insert(index++, OpCodes.Newarr.ToInstruction(elementType)); block.Insert(index++, OpCodes.Dup.ToInstruction()); block.Insert(index++, OpCodes.Ldtoken.ToInstruction((IField)Create(data))); block.Insert(index++, OpCodes.Call.ToInstruction((IMethod)InitializeArrayMethod)); }
public GenericParamOptions(GenericParam gp) { this.Number = gp.Number; this.Flags = gp.Flags; this.Name = gp.Name; this.Kind = gp.Kind; this.GenericParamConstraints.AddRange(gp.GenericParamConstraints); this.CustomAttributes.AddRange(gp.CustomAttributes); }
public BaseTypesEntryNode(ITypeDefOrRef tr, bool isInterface) { if (tr == null) throw new ArgumentNullException("tr"); this.tr = tr; this.def = tr.ResolveTypeDef(); this.isInterface = isInterface; this.LazyLoading = true; }
public GenericParamOptions(GenericParam gp) { Number = gp.Number; Flags = gp.Flags; Name = gp.Name; Kind = gp.Kind; GenericParamConstraints.AddRange(gp.GenericParamConstraints); CustomAttributes.AddRange(gp.CustomAttributes); }
public static ITypeDefOrRef Create(ITypeDefOrRef type, IList<TypeSig> genericArgs) { if (genericArgs == null || genericArgs.Count == 0) return type; var ts = type as TypeSpec; if (ts == null) return type; var newSig = Create(ts.TypeSig, genericArgs); return newSig == ts.TypeSig ? type : new TypeSpecUser(newSig); }
public ExceptionHandlerOptions(Dictionary<object, object> ops, ExceptionHandler eh) { this.TryStart = (InstructionVM)BodyUtils.TryGetVM(ops, eh.TryStart); this.TryEnd = (InstructionVM)BodyUtils.TryGetVM(ops, eh.TryEnd); this.FilterStart = (InstructionVM)BodyUtils.TryGetVM(ops, eh.FilterStart); this.HandlerStart = (InstructionVM)BodyUtils.TryGetVM(ops, eh.HandlerStart); this.HandlerEnd = (InstructionVM)BodyUtils.TryGetVM(ops, eh.HandlerEnd); this.CatchType = eh.CatchType; this.HandlerType = eh.HandlerType; }
static ITypeDefOrRef GetNonGenericTypeRef(ITypeDefOrRef typeRef) { var ts = typeRef as TypeSpec; if (ts == null) return typeRef; var gis = ts.TryGetGenericInstSig(); if (gis == null || gis.GenericType == null) return typeRef; return gis.GenericType.TypeDefOrRef; }
public EventDefOptions(EventDef evt) { this.Attributes = evt.Attributes; this.Name = evt.Name; this.EventType = evt.EventType; this.AddMethod = evt.AddMethod; this.InvokeMethod = evt.InvokeMethod; this.RemoveMethod = evt.RemoveMethod; this.OtherMethods.AddRange(evt.OtherMethods); this.CustomAttributes.AddRange(evt.CustomAttributes); }
static bool IsMarkupExtensions(ITypeDefOrRef def) { while (def != null) { if (def.Namespace == "OmniXaml" && def.Name.String == "MarkupExtension") return true; def = def.GetBaseType(); } return false; }
public EventDefOptions(EventDef evt) { Attributes = evt.Attributes; Name = evt.Name; EventType = evt.EventType; AddMethod = evt.AddMethod; InvokeMethod = evt.InvokeMethod; RemoveMethod = evt.RemoveMethod; OtherMethods.AddRange(evt.OtherMethods); CustomAttributes.AddRange(evt.CustomAttributes); }
public static TypeDefOptions Create(UTF8String ns, UTF8String name, ITypeDefOrRef baseType, bool isNestedType) { return new TypeDefOptions { Attributes = (isNestedType ? TypeAttributes.NestedPublic : TypeAttributes.Public) | TypeAttributes.AutoLayout | TypeAttributes.Class | TypeAttributes.AnsiClass, Namespace = ns ?? UTF8String.Empty, Name = name ?? UTF8String.Empty, PackingSize = null, ClassSize = null, BaseType = baseType, }; }
public Type resolve(ITypeDefOrRef typeRef) { var resolver = getTypeResolver(typeRef); if (resolver != null) return resolver.type; var ts = typeRef as TypeSpec; if (ts != null && ts.TypeSig is GenericSig) return typeof(MGenericParameter); return null; }
static bool Compare(ITypeDefOrRef type, UTF8String expNs, UTF8String expName) { if (type == null) return false; var tr = type as TypeRef; if (tr != null) return tr.Namespace == expNs && tr.Name == expName; var td = type as TypeDef; if (td != null) return td.Namespace == expNs && td.Name == expName; return false; }
public static void RenderType(ITypeDefOrRef type, Graphics g, Rectangle bounds) { var typeDef = type as TypeDef; if (typeDef == null) { g.DrawImageUnscaledAndClipped(Resources.GetResource<Image>("Icons.ObjModel.type.png"), bounds); return; } Image icon, visibility; icon = Resources.GetResource<Image>("Icons.ObjModel.type.png"); if (typeDef.IsInterface) { icon = Resources.GetResource<Image>("Icons.ObjModel.interface.png"); } else if (typeDef.BaseType != null) { if (typeDef.IsEnum) { icon = Resources.GetResource<Image>("Icons.ObjModel.enum.png"); } else if (typeDef.IsValueType && !typeDef.IsAbstract) { icon = Resources.GetResource<Image>("Icons.ObjModel.valuetype.png"); } else if (typeDef.IsDelegate()) { icon = Resources.GetResource<Image>("Icons.ObjModel.delegate.png"); } } switch (typeDef.Visibility) { case TypeAttributes.NotPublic: case TypeAttributes.NestedAssembly: case TypeAttributes.NestedFamANDAssem: visibility = Resources.GetResource<Image>("Icons.ObjModel.internal.png"); break; case TypeAttributes.NestedPrivate: visibility = Resources.GetResource<Image>("Icons.ObjModel.private.png"); break; case TypeAttributes.NestedFamily: visibility = Resources.GetResource<Image>("Icons.ObjModel.protected.png"); break; case TypeAttributes.NestedFamORAssem: visibility = Resources.GetResource<Image>("Icons.ObjModel.famasm.png"); break; case TypeAttributes.Public: case TypeAttributes.NestedPublic: default: visibility = null; break; } g.DrawImageUnscaledAndClipped(icon, bounds); if (visibility != null) g.DrawImageUnscaledAndClipped(visibility, bounds); }
public ExceptionInfo(int tryStart, int tryEnd, int filterStart, int handlerStart, int handlerEnd, ITypeDefOrRef catchType, ExceptionHandlerType handlerType) { if (tryStart > tryEnd || filterStart > handlerStart || tryStart < 0 || tryEnd < 0 || filterStart < 0 || handlerStart < 0 || handlerEnd < 0) throw new ApplicationException("Invalid start/end/filter/handler indexes"); this.tryStart = tryStart; this.tryEnd = tryEnd; this.filterStart = filterStart == handlerStart ? -1 : filterStart; this.handlerStart = handlerStart; this.handlerEnd = handlerEnd; this.catchType = catchType; this.handlerType = handlerType; }
public TypeDef ResolveType(ITypeDefOrRef type) { if (type == null) return null; type = GetNonGenericTypeRef(type); var typeDef = type as TypeDef; if (typeDef != null) return typeDef; var tr = type as TypeRef; if (tr != null) return tr.Resolve(); return null; }
/// <summary> /// Resolve an IField from its name and the resolved delcaring type. /// </summary> /// <param name="declaringType">Declaring type</param> /// <param name="fieldName">Field name</param> /// <returns>IField, or null if none found</returns> public IField ResolveField(ITypeDefOrRef declaringType, String fieldName) { if (declaringType is TypeSpec) return ResolveField(declaringType as TypeSpec, fieldName); TypeDef typeDef = null; if (declaringType is TypeDef) typeDef = declaringType as TypeDef; else if (declaringType is TypeRef) typeDef = (declaringType as TypeRef).ResolveTypeDef(); if (typeDef != null) return this.Importer.Import(typeDef.FindField(fieldName)); else return null; }
public TypeDefOptions(TypeDef type) { this.Attributes = type.Attributes; this.Namespace = type.Namespace; this.Name = type.Name; if (type.ClassLayout == null) { PackingSize = null; ClassSize = null; } else { PackingSize = type.ClassLayout.PackingSize; ClassSize = type.ClassLayout.ClassSize; } this.BaseType = type.BaseType; this.CustomAttributes.AddRange(type.CustomAttributes); this.DeclSecurities.AddRange(type.DeclSecurities); this.GenericParameters.AddRange(type.GenericParameters); this.Interfaces.AddRange(type.Interfaces); }
TypeResolver GetTypeResolver(ITypeDefOrRef typeRef) { if (typeRef == null) return null; var scopeType = typeRef.ScopeType; var key = scopeType.Namespace + "." + scopeType.TypeName; List<TypeResolver> list; if (!types.TryGetValue(key, out list)) return null; if (scopeType is TypeDef) { foreach (var resolver in list) { if (resolver.type.MetadataToken == scopeType.MDToken.Raw) return resolver; } } foreach (var resolver in list) { if (ResolverUtils.CompareTypes(resolver.type, scopeType)) return resolver; } return null; }
static MethodDef GetMethod(ModuleDef module, IMethod method, ITypeDefOrRef declaringType) { if (method == null) return null; if (method is MethodDef) return (MethodDef)method; return GetMethod(GetType(module, declaringType), method); }
public static TypeDef GetType(ModuleDef module, ITypeDefOrRef type) { var td = type as TypeDef; if (td == null) { var tr = type as TypeRef; if (tr != null) { var trAsm = tr.DefinitionAssembly; var modAsm = module.Assembly; if (trAsm != null && modAsm != null && trAsm.Name == modAsm.Name) td = tr.Resolve(); } } return td != null && td.Module == module ? td : null; }
static ConstantType GetConstantType(TypeSig type, out ITypeDefOrRef enumType) { enumType = null; var t = type.RemovePinnedAndModifiers(); switch (t.GetElementType()) { case ElementType.Boolean: return ConstantType.Boolean; case ElementType.Char: return ConstantType.Char; case ElementType.I1: return ConstantType.SByte; case ElementType.U1: return ConstantType.Byte; case ElementType.I2: return ConstantType.Int16; case ElementType.U2: return ConstantType.UInt16; case ElementType.I4: return ConstantType.Int32; case ElementType.U4: return ConstantType.UInt32; case ElementType.I8: return ConstantType.Int64; case ElementType.U8: return ConstantType.UInt64; case ElementType.R4: return ConstantType.Single; case ElementType.R8: return ConstantType.Double; case ElementType.String: return ConstantType.String; case ElementType.Object: return ConstantType.Object; case ElementType.ValueType: case ElementType.Class: var tdr = ((ClassOrValueTypeSig)t).TypeDefOrRef; if (tdr.IsSystemType()) return ConstantType.Type; enumType = tdr; return ConstantType.Enum; case ElementType.SZArray: var elemType = t.Next.RemovePinnedAndModifiers(); switch (elemType.GetElementType()) { case ElementType.Boolean: return ConstantType.BooleanArray; case ElementType.Char: return ConstantType.CharArray; case ElementType.I1: return ConstantType.SByteArray; case ElementType.U1: return ConstantType.ByteArray; case ElementType.I2: return ConstantType.Int16Array; case ElementType.U2: return ConstantType.UInt16Array; case ElementType.I4: return ConstantType.Int32Array; case ElementType.U4: return ConstantType.UInt32Array; case ElementType.I8: return ConstantType.Int64Array; case ElementType.U8: return ConstantType.UInt64Array; case ElementType.R4: return ConstantType.SingleArray; case ElementType.R8: return ConstantType.DoubleArray; case ElementType.String: return ConstantType.StringArray; case ElementType.Object: return ConstantType.ObjectArray; case ElementType.ValueType: case ElementType.Class: tdr = ((ClassOrValueTypeSig)elemType).TypeDefOrRef; if (tdr.IsSystemType()) return ConstantType.TypeArray; enumType = tdr; return ConstantType.EnumArray; } break; } Debug.Fail(string.Format("Unsupported CA named type: {0}", type)); return ConstantType.Object; }
void CreateAssemblyQualifiedName(ITypeDefOrRef typeDefOrRef) { if (typeDefOrRef is TypeRef) CreateAssemblyQualifiedName((TypeRef)typeDefOrRef); else if (typeDefOrRef is TypeDef) CreateAssemblyQualifiedName((TypeDef)typeDefOrRef); else if (typeDefOrRef is TypeSpec) CreateAssemblyQualifiedName((TypeSpec)typeDefOrRef); else sb.Append(NULLVALUE); }
protected override void TypeToString(IDecompilerOutput output, ITypeDefOrRef t, bool includeNamespace, IHasCustomAttribute attributeProvider = null) => t.WriteTo(output, includeNamespace ? ILNameSyntax.TypeName : ILNameSyntax.ShortTypeName);
/// <summary> /// Returns the base type of <paramref name="tdr"/> /// </summary> /// <param name="tdr">The type</param> /// <returns>The base type or <c>null</c> if there's no base type, or if /// we couldn't resolve a <see cref="TypeRef"/></returns> public static ITypeDefOrRef GetBaseType(this ITypeDefOrRef tdr) { return(tdr.GetBaseType(false)); }