public static Dictionary <FieldDefinition, PropertyDefinition> GetFieldToPropertyMap(this TypeDefinition typeDefinition, ILanguage language) { Dictionary <FieldDefinition, PropertyDefinition> result = new Dictionary <FieldDefinition, PropertyDefinition>(); foreach (PropertyDefinition property in typeDefinition.Properties) { FieldDefinition propertyField; PropertyDecompiler matcher = new PropertyDecompiler(property, language); if (matcher.IsAutoImplemented(out propertyField)) { result[propertyField] = property; } } return(result); }
private DecompiledType GetDecompiledType(IMemberDefinition member, ILanguage language) { TypeDefinition declaringType = Utilities.GetDeclaringTypeOrSelf(member); DecompiledType decompiledType = new DecompiledType(declaringType); Queue <IMemberDefinition> decompilationQueue = new Queue <IMemberDefinition>(); decompilationQueue.Enqueue(member); while (decompilationQueue.Count > 0) { IMemberDefinition currentMember = decompilationQueue.Dequeue(); if (currentMember is TypeDefinition && currentMember == member) { TypeDefinition currentType = (currentMember as TypeDefinition); List <IMemberDefinition> members = Utilities.GetTypeMembers(currentType, language, propertyFields: decompiledType.TypeContext.GetFieldToPropertyMap(language).Keys); foreach (IMemberDefinition typeMember in members) { decompilationQueue.Enqueue(typeMember); } } if (currentMember is MethodDefinition) { DecompileMember(currentMember as MethodDefinition, language, decompiledType); } if (currentMember is EventDefinition) { EventDefinition eventDefinition = (currentMember as EventDefinition); AutoImplementedEventMatcher matcher = new AutoImplementedEventMatcher(eventDefinition, language); bool isAutoImplemented = matcher.IsAutoImplemented(); if (isAutoImplemented) { decompiledType.TypeContext.AutoImplementedEvents.Add(eventDefinition); } if (eventDefinition.AddMethod != null) { DecompileMember(eventDefinition.AddMethod, language, decompiledType); } if (eventDefinition.RemoveMethod != null) { DecompileMember(eventDefinition.RemoveMethod, language, decompiledType); } if (eventDefinition.InvokeMethod != null) { DecompileMember(eventDefinition.InvokeMethod, language, decompiledType); } } if (currentMember is PropertyDefinition) { PropertyDefinition propertyDefinition = (currentMember as PropertyDefinition); CachedDecompiledMember getMethod; CachedDecompiledMember setMethod; bool isAutoImplemented; PropertyDecompiler propertyDecompiler = new PropertyDecompiler(propertyDefinition, language, this.renameInvalidMembers, this.cacheService, decompiledType.TypeContext); propertyDecompiler.ExceptionThrown += OnExceptionThrown; propertyDecompiler.Decompile(out getMethod, out setMethod, out isAutoImplemented); propertyDecompiler.ExceptionThrown -= OnExceptionThrown; if (isAutoImplemented) { decompiledType.TypeContext.AutoImplementedProperties.Add(propertyDefinition); } if (getMethod != null) { AddDecompiledMemberToDecompiledType(getMethod, decompiledType); } if (setMethod != null) { AddDecompiledMemberToDecompiledType(setMethod, decompiledType); } foreach (MethodDefinition exceptionWhileDecompiling in propertyDecompiler.ExceptionsWhileDecompiling) { this.ExceptionsWhileDecompiling.Add(exceptionWhileDecompiling); } } if (currentMember is FieldDefinition) { FieldDefinition currentField = currentMember as FieldDefinition; /// Decompile all the constructors, that can set default values to the field. /// For instance fields decompile only instance constructors. /// For static fields decompile only static constructors. foreach (MethodDefinition method in currentMember.DeclaringType.Methods) { if (method.IsConstructor && currentField.IsStatic == method.IsStatic) { DecompileConstructorChain(method, language, decompiledType); break; } } } } decompiledType.TypeContext.ExplicitlyImplementedMembers = GetExplicitlyImplementedInterfaceMethods(declaringType, language); AddGeneratedFilterMethodsToDecompiledType(decompiledType, decompiledType.TypeContext, language); return(decompiledType); }
protected Dictionary <string, DecompiledType> GetNestedDecompiledTypes(TypeDefinition type, ILanguage language) { Dictionary <string, DecompiledType> decompiledTypes = new Dictionary <string, DecompiledType>(); Queue <IMemberDefinition> decompilationQueue = new Queue <IMemberDefinition>(); decompilationQueue.Enqueue(type); while (decompilationQueue.Count > 0) { IMemberDefinition currentMember = decompilationQueue.Dequeue(); if (currentMember is TypeDefinition) { TypeDefinition currentType = (currentMember as TypeDefinition); decompiledTypes.Add(currentType.FullName, new DecompiledType(currentType)); //List<IMemberDefinition> members = Utilities.GetTypeMembers(currentType); List <IMemberDefinition> members = Utilities.GetTypeMembersToDecompile(currentType); foreach (IMemberDefinition member in members) { decompilationQueue.Enqueue(member); } } else { TypeDefinition currentType = currentMember.DeclaringType; DecompiledType decompiledType; if (!decompiledTypes.TryGetValue(currentType.FullName, out decompiledType)) { throw new Exception("Type missing from nested types decompilation cache."); } if (currentMember is MethodDefinition) { MethodDefinition method = currentMember as MethodDefinition; DecompileMember(method, language, decompiledType); //Utilities.AddDecompiledMethodToDecompiledType(method, language, decompiledType); } if (currentMember is EventDefinition) { EventDefinition eventDefinition = (currentMember as EventDefinition); AutoImplementedEventMatcher matcher = new AutoImplementedEventMatcher(eventDefinition, language); bool isAutoImplemented = matcher.IsAutoImplemented(); if (isAutoImplemented) { decompiledType.TypeContext.AutoImplementedEvents.Add(eventDefinition); } if (eventDefinition.AddMethod != null) { //Utilities.AddDecompiledMethodToDecompiledType(eventDefinition.AddMethod, language, decompiledType); DecompileMember(eventDefinition.AddMethod, language, decompiledType); } if (eventDefinition.RemoveMethod != null) { //Utilities.AddDecompiledMethodToDecompiledType(eventDefinition.RemoveMethod, language, decompiledType); DecompileMember(eventDefinition.RemoveMethod, language, decompiledType); } if (eventDefinition.InvokeMethod != null) { //Utilities.AddDecompiledMethodToDecompiledType(eventDefinition.InvokeMethod, language, decompiledType); DecompileMember(eventDefinition.InvokeMethod, language, decompiledType); } } if (currentMember is PropertyDefinition) { PropertyDefinition propertyDefinition = (currentMember as PropertyDefinition); CachedDecompiledMember getMethod; CachedDecompiledMember setMethod; bool isAutoImplemented; PropertyDecompiler propertyDecompiler = new PropertyDecompiler(propertyDefinition, language, renameInvalidMembers, this.cacheService, decompiledType.TypeContext); propertyDecompiler.ExceptionThrown += OnExceptionThrown; propertyDecompiler.Decompile(out getMethod, out setMethod, out isAutoImplemented); propertyDecompiler.ExceptionThrown -= OnExceptionThrown; if (isAutoImplemented) { decompiledType.TypeContext.AutoImplementedProperties.Add(propertyDefinition); } if (getMethod != null) { AddDecompiledMemberToDecompiledType(getMethod, decompiledType); } if (setMethod != null) { AddDecompiledMemberToDecompiledType(setMethod, decompiledType); } foreach (MethodDefinition exceptionWhileDecompiling in propertyDecompiler.ExceptionsWhileDecompiling) { this.ExceptionsWhileDecompiling.Add(exceptionWhileDecompiling); } } } } foreach (DecompiledType decompiledType in decompiledTypes.Values) { AddGeneratedFilterMethodsToDecompiledType(decompiledType, decompiledType.TypeContext, language); } return(decompiledTypes); }
private DecompiledType GetDecompiledType(IMemberDefinition member, ILanguage language) { V_0 = Utilities.GetDeclaringTypeOrSelf(member); V_1 = new DecompiledType(V_0); V_2 = new Queue <IMemberDefinition>(); V_2.Enqueue(member); Label0: while (V_2.get_Count() > 0) { V_3 = V_2.Dequeue(); if (V_3 as TypeDefinition != null && (object)V_3 == (object)member) { V_4 = Utilities.GetTypeMembers(V_3 as TypeDefinition, language, true, null, null, null, V_1.get_TypeContext().GetFieldToPropertyMap(language).get_Keys()).GetEnumerator(); try { while (V_4.MoveNext()) { V_5 = V_4.get_Current(); V_2.Enqueue(V_5); } } finally { ((IDisposable)V_4).Dispose(); } } if (V_3 as MethodDefinition != null) { this.DecompileMember(V_3 as MethodDefinition, language, V_1); } if (V_3 as EventDefinition != null) { V_6 = V_3 as EventDefinition; if ((new AutoImplementedEventMatcher(V_6, language)).IsAutoImplemented()) { dummyVar0 = V_1.get_TypeContext().get_AutoImplementedEvents().Add(V_6); } if (V_6.get_AddMethod() != null) { this.DecompileMember(V_6.get_AddMethod(), language, V_1); } if (V_6.get_RemoveMethod() != null) { this.DecompileMember(V_6.get_RemoveMethod(), language, V_1); } if (V_6.get_InvokeMethod() != null) { this.DecompileMember(V_6.get_InvokeMethod(), language, V_1); } } if (V_3 as PropertyDefinition != null) { V_7 = V_3 as PropertyDefinition; stackVariable52 = new PropertyDecompiler(V_7, language, this.renameInvalidMembers, this.cacheService, V_1.get_TypeContext()); stackVariable52.add_ExceptionThrown(new EventHandler <Exception>(this.OnExceptionThrown)); stackVariable52.Decompile(out V_8, out V_9, out V_10); stackVariable52.remove_ExceptionThrown(new EventHandler <Exception>(this.OnExceptionThrown)); if (V_10) { dummyVar1 = V_1.get_TypeContext().get_AutoImplementedProperties().Add(V_7); } if (V_8 != null) { this.AddDecompiledMemberToDecompiledType(V_8, V_1); } if (V_9 != null) { this.AddDecompiledMemberToDecompiledType(V_9, V_1); } V_11 = stackVariable52.get_ExceptionsWhileDecompiling().GetEnumerator(); try { while (V_11.MoveNext()) { V_12 = V_11.get_Current(); this.get_ExceptionsWhileDecompiling().Add(V_12); } } finally { if (V_11 != null) { V_11.Dispose(); } } } if (V_3 as FieldDefinition == null) { continue; } V_13 = V_3 as FieldDefinition; V_14 = V_3.get_DeclaringType().get_Methods().GetEnumerator(); try { while (V_14.MoveNext()) { V_15 = V_14.get_Current(); if (!V_15.get_IsConstructor() || V_13.get_IsStatic() != V_15.get_IsStatic()) { continue; } this.DecompileConstructorChain(V_15, language, V_1); goto Label0; } } finally { V_14.Dispose(); } } V_1.get_TypeContext().set_ExplicitlyImplementedMembers(this.GetExplicitlyImplementedInterfaceMethods(V_0, language)); this.AddGeneratedFilterMethodsToDecompiledType(V_1, V_1.get_TypeContext(), language); return(V_1); }
private DecompiledType GetDecompiledType(IMemberDefinition member, ILanguage language) { TypeDefinition declaringType = Utilities.GetDeclaringTypeOrSelf(member); DecompiledType decompiledType = new DecompiledType(declaringType); Queue<IMemberDefinition> decompilationQueue = new Queue<IMemberDefinition>(); decompilationQueue.Enqueue(member); while (decompilationQueue.Count > 0) { IMemberDefinition currentMember = decompilationQueue.Dequeue(); if (currentMember is TypeDefinition && currentMember == member) { TypeDefinition currentType = (currentMember as TypeDefinition); List<IMemberDefinition> members = Utilities.GetTypeMembers(currentType, language, propertyFields: decompiledType.TypeContext.GetFieldToPropertyMap(language).Keys); foreach (IMemberDefinition typeMember in members) { decompilationQueue.Enqueue(typeMember); } } if (currentMember is MethodDefinition) { DecompileMember(currentMember as MethodDefinition, language, decompiledType); } if (currentMember is EventDefinition) { EventDefinition eventDefinition = (currentMember as EventDefinition); AutoImplementedEventMatcher matcher = new AutoImplementedEventMatcher(eventDefinition, language); bool isAutoImplemented = matcher.IsAutoImplemented(); if (isAutoImplemented) { decompiledType.TypeContext.AutoImplementedEvents.Add(eventDefinition); } if (eventDefinition.AddMethod != null) { DecompileMember(eventDefinition.AddMethod, language, decompiledType); } if (eventDefinition.RemoveMethod != null) { DecompileMember(eventDefinition.RemoveMethod, language, decompiledType); } if (eventDefinition.InvokeMethod != null) { DecompileMember(eventDefinition.InvokeMethod, language, decompiledType); } } if (currentMember is PropertyDefinition) { PropertyDefinition propertyDefinition = (currentMember as PropertyDefinition); CachedDecompiledMember getMethod; CachedDecompiledMember setMethod; bool isAutoImplemented; PropertyDecompiler propertyDecompiler = new PropertyDecompiler(propertyDefinition, language, this.renameInvalidMembers, this.cacheService, decompiledType.TypeContext); propertyDecompiler.ExceptionThrown += OnExceptionThrown; propertyDecompiler.Decompile(out getMethod, out setMethod, out isAutoImplemented); propertyDecompiler.ExceptionThrown -= OnExceptionThrown; if (isAutoImplemented) { decompiledType.TypeContext.AutoImplementedProperties.Add(propertyDefinition); } if (getMethod != null) { AddDecompiledMemberToDecompiledType(getMethod, decompiledType); } if (setMethod != null) { AddDecompiledMemberToDecompiledType(setMethod, decompiledType); } foreach (MethodDefinition exceptionWhileDecompiling in propertyDecompiler.ExceptionsWhileDecompiling) { this.ExceptionsWhileDecompiling.Add(exceptionWhileDecompiling); } } if (currentMember is FieldDefinition) { FieldDefinition currentField = currentMember as FieldDefinition; /// Decompile all the constructors, that can set default values to the field. /// For instance fields decompile only instance constructors. /// For static fields decompile only static constructors. foreach (MethodDefinition method in currentMember.DeclaringType.Methods) { if (method.IsConstructor && currentField.IsStatic == method.IsStatic) { DecompileConstructorChain(method, language, decompiledType); break; } } } } decompiledType.TypeContext.ExplicitlyImplementedMembers = GetExplicitlyImplementedInterfaceMethods(declaringType, language); AddGeneratedFilterMethodsToDecompiledType(decompiledType, decompiledType.TypeContext, language); return decompiledType; }
protected Dictionary<string, DecompiledType> GetNestedDecompiledTypes(TypeDefinition type, ILanguage language) { Dictionary<string, DecompiledType> decompiledTypes = new Dictionary<string, DecompiledType>(); Queue<IMemberDefinition> decompilationQueue = new Queue<IMemberDefinition>(); decompilationQueue.Enqueue(type); while (decompilationQueue.Count > 0) { IMemberDefinition currentMember = decompilationQueue.Dequeue(); if (currentMember is TypeDefinition) { TypeDefinition currentType = (currentMember as TypeDefinition); decompiledTypes.Add(currentType.FullName, new DecompiledType(currentType)); //List<IMemberDefinition> members = Utilities.GetTypeMembers(currentType); List<IMemberDefinition> members = Utilities.GetTypeMembersToDecompile(currentType); foreach (IMemberDefinition member in members) { decompilationQueue.Enqueue(member); } } else { TypeDefinition currentType = currentMember.DeclaringType; DecompiledType decompiledType; if (!decompiledTypes.TryGetValue(currentType.FullName, out decompiledType)) { throw new Exception("Type missing from nested types decompilation cache."); } if (currentMember is MethodDefinition) { MethodDefinition method = currentMember as MethodDefinition; DecompileMember(method, language, decompiledType); //Utilities.AddDecompiledMethodToDecompiledType(method, language, decompiledType); } if (currentMember is EventDefinition) { EventDefinition eventDefinition = (currentMember as EventDefinition); AutoImplementedEventMatcher matcher = new AutoImplementedEventMatcher(eventDefinition, language); bool isAutoImplemented = matcher.IsAutoImplemented(); if (isAutoImplemented) { decompiledType.TypeContext.AutoImplementedEvents.Add(eventDefinition); } if (eventDefinition.AddMethod != null) { //Utilities.AddDecompiledMethodToDecompiledType(eventDefinition.AddMethod, language, decompiledType); DecompileMember(eventDefinition.AddMethod, language, decompiledType); } if (eventDefinition.RemoveMethod != null) { //Utilities.AddDecompiledMethodToDecompiledType(eventDefinition.RemoveMethod, language, decompiledType); DecompileMember(eventDefinition.RemoveMethod, language, decompiledType); } if (eventDefinition.InvokeMethod != null) { //Utilities.AddDecompiledMethodToDecompiledType(eventDefinition.InvokeMethod, language, decompiledType); DecompileMember(eventDefinition.InvokeMethod, language, decompiledType); } } if (currentMember is PropertyDefinition) { PropertyDefinition propertyDefinition = (currentMember as PropertyDefinition); CachedDecompiledMember getMethod; CachedDecompiledMember setMethod; bool isAutoImplemented; PropertyDecompiler propertyDecompiler = new PropertyDecompiler(propertyDefinition, language, renameInvalidMembers, this.cacheService, decompiledType.TypeContext); propertyDecompiler.ExceptionThrown += OnExceptionThrown; propertyDecompiler.Decompile(out getMethod, out setMethod, out isAutoImplemented); propertyDecompiler.ExceptionThrown -= OnExceptionThrown; if (isAutoImplemented) { decompiledType.TypeContext.AutoImplementedProperties.Add(propertyDefinition); } if (getMethod != null) { AddDecompiledMemberToDecompiledType(getMethod, decompiledType); } if (setMethod != null) { AddDecompiledMemberToDecompiledType(setMethod, decompiledType); } foreach (MethodDefinition exceptionWhileDecompiling in propertyDecompiler.ExceptionsWhileDecompiling) { this.ExceptionsWhileDecompiling.Add(exceptionWhileDecompiling); } } } } foreach (DecompiledType decompiledType in decompiledTypes.Values) { AddGeneratedFilterMethodsToDecompiledType(decompiledType, decompiledType.TypeContext, language); } return decompiledTypes; }