Inheritance: TypeReference, IMemberDefinition, ISecurityDeclarationProvider
示例#1
0
 public MethodTable LoadType(TypeDefinition typeDef)
 {
     if (!_loadedTypes.ContainsKey(typeDef.MetadataToken))
     {
         _loadedTypes[typeDef.MetadataToken] = MethodTableBuilder.BuildMethodTable(this, typeDef);
     }
     return _loadedTypes[typeDef.MetadataToken];
 }
示例#2
0
		public void RemovePropertiesRange (TypeDefinition type)
		{
			Properties.Remove (type.token.RID);
		}
示例#3
0
		public bool TryGetPropertiesRange (TypeDefinition type, out Range range)
		{
			return Properties.TryGetValue (type.token.RID, out range);
		}
示例#4
0
		public void RemoveInterfaceMapping (TypeDefinition type)
		{
			Interfaces.Remove (type.token.RID);
		}
示例#5
0
		public bool TryGetInterfaceMapping (TypeDefinition type, out MetadataToken [] mapping)
		{
			return Interfaces.TryGetValue (type.token.RID, out mapping);
		}
示例#6
0
		public void RemoveReverseNestedTypeMapping (TypeDefinition type)
		{
			ReverseNestedTypes.Remove (type.token.RID);
		}
示例#7
0
        private MethodDesc[] CreateMethodSlotsFromTypeDef(TypeDefinition typeDef)
        {
            var methods = new List<MethodDefinition>();

            methods.AddRange(GetVirtualMethodDefsFromTypeDef(typeDef)); // virtual
            methods.AddRange(typeDef.Methods.Where(x => !x.IsVirtual && !x.IsStatic)); // non-virtual
            methods.AddRange(typeDef.Methods.Where(x => x.IsStatic)); // static

            return methods
                    .Select((x, i) =>
                    {
                        var methodDesc = _classLoader.LookupMethodDescFromMethodDef(x);
                        if (methodDesc == null)
                        {
                            methodDesc = new MethodDesc()
                            {
                                MdToken = x.MetadataToken,
                                Name = x.FullName,
                                Definition = x,
                                Slot = i
                            };
                            _classLoader.RegisterMethodDesc(x, methodDesc);
                        }
                        return methodDesc;
                    })
                    .ToArray();
        }
示例#8
0
		static TypeDefinition BinaryRangeSearch (TypeDefinition [] types, uint rid, bool field)
		{
			int min = 0;
			int max = types.Length - 1;
			while (min <= max) {
				int mid = min + ((max - min) / 2);
				var type = types [mid];
				var range = field ? type.fields_range : type.methods_range;

				if (rid < range.Start)
					max = mid - 1;
				else if (rid >= range.Start + range.Length)
					min = mid + 1;
				else
					return type;
			}

			return null;
		}
示例#9
0
		public void AddTypeDefinition (TypeDefinition type)
		{
			Types [type.token.RID - 1] = type;
		}
示例#10
0
		public static bool TryGetPrimitiveElementType (TypeDefinition type, out ElementType etype)
		{
			etype = ElementType.None;

			if (type.Namespace != "System")
				return false;

			Row<ElementType, bool> primitive_data;
			if (TryGetPrimitiveData (type, out primitive_data) && primitive_data.Col1.IsPrimitive ()) {
				etype = primitive_data.Col1;
				return true;
			}

			return false;
		}
示例#11
0
		MethodDefinition GetMethod (TypeDefinition type, MethodReference reference)
		{
			while (type != null) {
				var method = GetMethod (type.Methods, reference);
				if (method != null)
					return method;

				if (type.BaseType == null)
					return null;

				type = Resolve (type.BaseType);
			}

			return null;
		}
示例#12
0
		FieldDefinition GetField (TypeDefinition type, FieldReference reference)
		{
			while (type != null) {
				var field = GetField (type.Fields, reference);
				if (field != null)
					return field;

				if (type.BaseType == null)
					return null;

				type = Resolve (type.BaseType);
			}

			return null;
		}
示例#13
0
 public static MethodTable BuildMethodTable(ClassLoader classLoader, TypeDefinition typeDef)
 {
     return new MethodTableBuilder(classLoader, typeDef).BuildMethodTable();
 }
示例#14
0
 public MethodTableBuilder(ClassLoader classLoader, TypeDefinition typeDef)
 {
     _classLoader = classLoader;
     _typeDefinition = typeDef;
 }
示例#15
0
		public bool TryGetEventsRange (TypeDefinition type, out Range range)
		{
			return Events.TryGetValue (type.token.RID, out range);
		}
示例#16
0
		public void RemoveEventsRange (TypeDefinition type)
		{
			Events.Remove (type.token.RID);
		}
示例#17
0
		public bool TryGetNestedTypeMapping (TypeDefinition type, out uint [] mapping)
		{
			return NestedTypes.TryGetValue (type.token.RID, out mapping);
		}
示例#18
0
		public bool TryGetReverseNestedTypeMapping (TypeDefinition type, out uint declaring)
		{
			return ReverseNestedTypes.TryGetValue (type.token.RID, out declaring);
		}
示例#19
0
        private MethodDefinition[] GetVirtualMethodDefsFromTypeDef(TypeDefinition typeDef)
        {
            var methods = new List<MethodDefinition>();
            var declaredMethods = typeDef.Methods.Where(x => x.IsVirtual && !x.IsStatic && !x.DeclaringType.IsInterface).ToArray();
            var nonOverrideMethods = new List<MethodDefinition>();
            if (typeDef.BaseType != null)
            {
                var parentMethods = GetVirtualMethodDefsFromTypeDef(typeDef.BaseType.Resolve());

                for (var i = 0; i < declaredMethods.Length; i++)
                {
                    var declMethod = declaredMethods[i];
                    var overrided = false;

                    for (var j = 0; j < parentMethods.Length; j++)
                    {
                        var parentMethod = parentMethods[j];

                        if (parentMethod.Name == declMethod.Name /* && ... */)
                        {
                            parentMethods[j] = declMethod;
                            overrided = true;
                            break;
                        }
                    }

                    if (!overrided)
                    {
                        nonOverrideMethods.Add(declMethod);
                    }
                }
                methods.AddRange(parentMethods); // virtual (parent/override)
                methods.AddRange(nonOverrideMethods); // virtual
            }
            else
            {
                methods.AddRange(declaredMethods); // virtual
            }
            return methods.ToArray();
        }