Exemple #1
0
        public TypeDefWrapper(TypeDefinition typeDef, bool isExtended = false)
        {
            InnerDefinition = typeDef;

            FullName = InnerDefinition.GetFullName();

            Name      = InnerDefinition.Name;
            Namespace = InnerDefinition.Namespace;
            ClassType = InnerDefinition.GetClassType();

            var parent = InnerDefinition.GetParent();

            if (parent.HasValue)
            {
                Parent     = new TypeDefWrapper(parent.Value, true);
                ParentName = Parent.Name;
            }

            if (isExtended)
            {
                return;
            }

            var fields = InnerDefinition.GetFields();

            if (fields != null)
            {
                Fields.AddRange(fields.Select(field => (FieldDefWrapper)field)
                                .Where(w => w.Name != "<ErrorReadingField>"));
            }
            // bug Skipping invalid fields until I solve the issue

            var interfaces = InnerDefinition.GetInterfaces();

            if (interfaces != null)
            {
                foreach (var iface in interfaces)
                {
                    Interfaces.Add(new TypeDefWrapper(iface, true));
                }
            }
            InterfacesText = Interfaces.Aggregate("", (current, iface) => current + $", {iface.Name}");

            foreach (var f in Fields)
            {
                f.Parent = this;
            }
        }
Exemple #2
0
        public TypeDefWrapper(TypeDefinition typeDef, bool isExtended = false /*, bool getSubField = true*/)
        {
            InnerDefinition = typeDef;

            FullName = InnerDefinition.GetFullName();

            Name      = InnerDefinition.Name;
            Namespace = InnerDefinition.Namespace;
            ClassType = InnerDefinition.GetClassType();

            var parent = InnerDefinition.GetParent();

            if (parent.HasValue)
            {
                Parent     = new TypeDefWrapper(parent.Value, true);
                ParentName = Parent.Name;
            }

            if (isExtended)
            {
                return;
            }

            var fields = InnerDefinition.GetFields();

            // Todo: if 'FieldTypeDefinition' gets used elsewhere, consider re-implementing the following:
            //if (fields != null)
            //{
            //    foreach (var field in fields)
            //    {
            //        var fdw = new FieldDefWrapper(field, getSubField);
            //        if (fdw.Name == "<ErrorReadingField>") continue;
            //        Fields.Add(fdw);
            //    }
            //}
            if (fields != null)
            {
                Fields.AddRange(fields.Select(field => (FieldDefWrapper)field)
                                .Where(w => w.Name != "<ErrorReadingField>"));
            }
            // bug Skipping invalid fields until I solve the issue

            var interfaces = InnerDefinition.GetInterfaces();

            if (interfaces != null)
            {
                foreach (var iface in interfaces)
                {
                    Interfaces.Add(new TypeDefWrapper(iface, true));
                }
            }
            InterfacesText = Interfaces.Aggregate("", (current, iface) => current + $", {iface.Name}");

            foreach (var f in Fields)
            {
                f.Parent = this;

                // If the type is ValueType and the field is not static, then we need to shift the offset back by 0x10.
                // I'm not sure why, but in all my tests this has been validated.
                if (InnerDefinition.IsValueType)
                {
                    if (!f.HasValue)
                    {
                        f.Offset -= 0x10;
                    }
                }

                //if (f.HasValue)
                //{
                //    //if (f.ValueTypeShort == "S") f.GetValue();
                //}
            }
        }