public void initialize()
        {
            foreach (var kv in getMovedTypes())
            {
                var structType = kv.Key;
                structToOwners.add(structType, kv.Value);

                foreach (var ownerType in kv.Value)
                {
                    foreach (var ownerField in ownerType.Fields)
                    {
                        if (DotNetUtils.getType(module, ownerField.FieldSig.GetFieldType()) != structType)
                        {
                            continue;
                        }
                        structFieldsToFix.add(ownerField, true);
                        break;
                    }

                    var fieldsDict = new FieldDefAndDeclaringTypeDict <FieldDef>();
                    typeToFieldsDict.add(ownerType, fieldsDict);
                    foreach (var structField in structType.Fields)
                    {
                        var newField = module.UpdateRowId(new FieldDefUser(structField.Name, structField.FieldSig.Clone(), structField.Attributes));
                        ownerType.Fields.Add(newField);
                        fieldsDict.add(structField, newField);
                    }
                }
            }
        }
        IEnumerable <FieldDef> getPossibleFields(TypeDef type)
        {
            var typeToFields = new TypeDefDict <List <FieldDef> >();

            foreach (var field in type.Fields)
            {
                if (field.Attributes != FieldAttributes.Private)
                {
                    continue;
                }
                var fieldType = DotNetUtils.getType(module, field.FieldSig.GetFieldType());
                if (fieldType == null)
                {
                    continue;
                }
                if (!checkBaseType(fieldType))
                {
                    continue;
                }
                var list = typeToFields.find(fieldType);
                if (list == null)
                {
                    typeToFields.add(fieldType, list = new List <FieldDef>());
                }
                list.Add(field);
            }

            foreach (var list in typeToFields.getValues())
            {
                if (list.Count == 1)
                {
                    yield return(list[0]);
                }
            }
        }
Пример #3
0
 void initializeMethodsTypes()
 {
     foreach (var type in module.GetTypes())
     {
         if (checkMethodsType(type))
         {
             methodsTypes.add(type, true);
         }
     }
 }
Пример #4
0
 void initTokenToType()
 {
     moduleType = moduleDef.Types[0];
     foreach (var typeDef in moduleDef.GetTypes())
     {
         int  token = (int)typeDef.MDToken.Raw;
         Type type;
         try {
             type = module.ResolveType(token);
         }
         catch {
             tokenToType[token] = null;
             typeRefToType.add(typeDef, null);
             continue;
         }
         var mtype = new MType(type, typeDef);
         tokenToType[token] = mtype;
         typeRefToType.add(typeDef, mtype);
     }
 }
        void initialize(TypeDef type)
        {
            if (type.HasEvents || type.HasProperties)
            {
                return;
            }

            if (!type.IsValueType)
            {
                return;
            }
            if (type.Methods.Count != 1)
            {
                return;
            }
            var ctor = type.Methods[0];

            if (ctor.Name != ".ctor" || ctor.Body == null || ctor.IsStatic)
            {
                return;
            }
            var sig = ctor.MethodSig;

            if (sig == null || sig.Params.Count != 1)
            {
                return;
            }
            var ctorParam = sig.Params[0];

            if (type.Fields.Count != 1)
            {
                return;
            }
            var typeField = type.Fields[0];

            if (typeField.IsStatic)
            {
                return;
            }
            if (!new SigComparer().Equals(ctorParam, typeField.FieldType))
            {
                return;
            }

            typeToInfo.add(ctor.DeclaringType, new Info(ctor.DeclaringType, typeField.FieldType));
        }
Пример #6
0
        public TypeDefDict <bool> getInlinedTypes(IEnumerable <MethodDef> unusedMethods)
        {
            var unused = new MethodDefAndDeclaringTypeDict <bool>();

            foreach (var method in unusedMethods)
            {
                unused.add(method, true);
            }

            var types = new TypeDefDict <bool>();

            foreach (var type in methodsTypes.getKeys())
            {
                if (checkAllMethodsUnused(unused, type))
                {
                    types.add(type, true);
                }
            }
            return(types);
        }
        public TypeDefDict<bool> getInlinedTypes(IEnumerable<MethodDef> unusedMethods)
        {
            var unused = new MethodDefAndDeclaringTypeDict<bool>();
            foreach (var method in unusedMethods)
                unused.add(method, true);

            var types = new TypeDefDict<bool>();
            foreach (var type in methodsTypes.getKeys()) {
                if (checkAllMethodsUnused(unused, type))
                    types.add(type, true);
            }
            return types;
        }
Пример #8
0
        IEnumerable<FieldDef> getPossibleFields(TypeDef type)
        {
            var typeToFields = new TypeDefDict<List<FieldDef>>();
            foreach (var field in type.Fields) {
                if (field.Attributes != FieldAttributes.Private)
                    continue;
                var fieldType = DotNetUtils.getType(module, field.FieldSig.GetFieldType());
                if (fieldType == null)
                    continue;
                if (!checkBaseType(fieldType))
                    continue;
                var list = typeToFields.find(fieldType);
                if (list == null)
                    typeToFields.add(fieldType, list = new List<FieldDef>());
                list.Add(field);
            }

            foreach (var list in typeToFields.getValues()) {
                if (list.Count == 1)
                    yield return list[0];
            }
        }
 public void add(TypeDef type)
 {
     types.add(type, true);
 }