public static Dictionary <FieldDefinition, EventDefinition> GetFieldToEventMap(this TypeDefinition typeDefinition) { Dictionary <FieldDefinition, EventDefinition> result = new Dictionary <FieldDefinition, EventDefinition>(); foreach (EventDefinition @event in typeDefinition.Events) { FieldDefinition eventField; AutoImplementedEventMatcher matcher = new AutoImplementedEventMatcher(@event); if (matcher.IsAutoImplemented(out eventField)) { result[eventField] = @event; } } return(result); }
private HashSet <EventDefinition> GetAutoImplementedEvents(TypeDefinition type, ILanguage language) { HashSet <EventDefinition> result = new HashSet <EventDefinition>(); if (type.HasEvents) { foreach (EventDefinition @event in type.Events) { AutoImplementedEventMatcher matcher = new AutoImplementedEventMatcher(@event, language); bool isAutoImplemented = matcher.IsAutoImplemented(); if (isAutoImplemented) { result.Add(@event); } } } return(result); }
private HashSet<EventDefinition> GetAutoImplementedEvents(TypeDefinition type) { HashSet<EventDefinition> result = new HashSet<EventDefinition>(); if (type.HasEvents) { foreach (EventDefinition @event in type.Events) { AutoImplementedEventMatcher matcher = new AutoImplementedEventMatcher(@event); bool isAutoImplemented = matcher.IsAutoImplemented(); if (isAutoImplemented) { result.Add(@event); } } } return result; }
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); 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); AutoImplementedPropertyMatcher matcher = new AutoImplementedPropertyMatcher(propertyDefinition); bool isAutoImplemented = matcher.IsAutoImplemented(); if (isAutoImplemented) { decompiledType.TypeContext.AutoImplementedProperties.Add(propertyDefinition); } if (propertyDefinition.GetMethod != null) { //Utilities.AddDecompiledMethodToDecompiledType(propertyDefinition.GetMethod, language, decompiledType); DecompileMember(propertyDefinition.GetMethod, language, decompiledType); } if (propertyDefinition.SetMethod != null) { //Utilities.AddDecompiledMethodToDecompiledType(propertyDefinition.SetMethod, language, decompiledType); DecompileMember(propertyDefinition.SetMethod, language, decompiledType); } } } } return(decompiledTypes); }
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); }
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); 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); AutoImplementedPropertyMatcher matcher = new AutoImplementedPropertyMatcher(propertyDefinition); bool isAutoImplemented = matcher.IsAutoImplemented(); if (isAutoImplemented) { decompiledType.TypeContext.AutoImplementedProperties.Add(propertyDefinition); } if (propertyDefinition.GetMethod != null) { //Utilities.AddDecompiledMethodToDecompiledType(propertyDefinition.GetMethod, language, decompiledType); DecompileMember(propertyDefinition.GetMethod, language, decompiledType); } if (propertyDefinition.SetMethod != null) { //Utilities.AddDecompiledMethodToDecompiledType(propertyDefinition.SetMethod, language, decompiledType); DecompileMember(propertyDefinition.SetMethod, language, decompiledType); } } } } foreach (DecompiledType decompiledType in decompiledTypes.Values) { AddGeneratedFilterMethodsToDecompiledType(decompiledType, decompiledType.TypeContext, language); } return decompiledTypes; }
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; }
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); 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); 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); AutoImplementedPropertyMatcher matcher = new AutoImplementedPropertyMatcher(propertyDefinition); bool isAutoImplemented = matcher.IsAutoImplemented(); if (isAutoImplemented) { decompiledType.TypeContext.AutoImplementedProperties.Add(propertyDefinition); } if (propertyDefinition.GetMethod != null) { DecompileMember(propertyDefinition.GetMethod, language, decompiledType); } if (propertyDefinition.SetMethod != null) { DecompileMember(propertyDefinition.SetMethod, language, decompiledType); } } 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); return(decompiledType); }