Beispiel #1
0
 private void ResolveInstanceFields(IEnumerable <InstanceField> instanceFields)
 {
     foreach (var instanceField in instanceFields)
     {
         if (!InstanceFields.ContainsKey(instanceField.Info.Name))
         {
             InstanceFields.Add(instanceField.Info.Name, instanceField);
         }
     }
 }
Beispiel #2
0
        public InstanceField GetInstanceFieldInfo(string fieldName)
        {
            InstanceField field;

            if (InstanceFields.TryGetValue(fieldName, out field))
            {
                return(field);
            }

            throw new FieldNotFoundException(string.Format("Instance field {0} not found in class {1}.", fieldName, Name));
        }
        internal DllTypeData(TypeDefinition def, DllConfig config)
        {
            _config = config;
            foreach (var i in def.Interfaces)
            {
                ImplementingInterfaces.Add(DllTypeRef.From(i.InterfaceType));
            }

            This = DllTypeRef.From(def);
            Type = def.IsEnum ? TypeEnum.Enum : (def.IsInterface ? TypeEnum.Interface : (def.IsValueType ? TypeEnum.Struct : TypeEnum.Class));
            Info = new TypeInfo
            {
                Refness = def.IsValueType ? Refness.ValueType : Refness.ReferenceType
            };

            if (def.BaseType != null)
            {
                Parent = DllTypeRef.From(def.BaseType);
            }

            // TODO: Parse this eventually
            TypeDefIndex = -1;

            if (_config.ParseTypeAttributes && def.HasCustomAttributes)
            {
                Attributes.AddRange(def.CustomAttributes.Select(ca => new DllAttribute(ca)).Where(a => !string.IsNullOrEmpty(a.Name)));
            }
            Layout = (ITypeData.LayoutKind)(def.Attributes & TypeAttributes.LayoutMask);
            if (_config.ParseTypeFields)
            {
                InstanceFields.AddRange(def.Fields.Where(f => !f.IsStatic).Select(f => new DllField(f)));
                StaticFields.AddRange(def.Fields.Where(f => f.IsStatic).Select(f => new DllField(f)));
            }
            if (_config.ParseTypeProperties)
            {
                Properties.AddRange(def.Properties.Select(p => new DllProperty(p)));
            }
            if (_config.ParseTypeMethods)
            {
                var mappedBaseMethods = new HashSet <MethodDefinition>();
                var methods           = def.Methods.Select(m => DllMethod.From(m, ref mappedBaseMethods)).ToList();
                // It's important that Foo.IBar.func() goes after func() (if present)
                Methods.AddRange(methods.Where(m => m.ImplementedFrom is null));
                Methods.AddRange(methods.Where(m => m.ImplementedFrom != null));
            }
        }
Beispiel #4
0
        internal void AddFields(FieldInfo[] fields)
        {
            int instanceFieldsLength = InstanceFields.Count;
            int i = 0;

            foreach (var field in fields)
            {
                if (field.AccessFlags.HasFlag(FieldAccessFlags.Static))
                {
                    StaticFields.Add(field.Name, new StaticField(field));
                }
                else
                {
                    InstanceFields.Add(field.Name, new InstanceField(field, instanceFieldsLength + i));
                    i++;
                }
            }
        }