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]); } } }
void InitializeMethodsTypes() { foreach (var type in module.GetTypes()) { if (CheckMethodsType(type)) { methodsTypes.Add(type, true); } } }
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)); }
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 void Add(TypeDef type) => types.Add(type, true);
public void Add(MTypeDef t) => types.Add(t);
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 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; }