public static Dictionary <FieldDefinition, PropertyDefinition> GetFieldToPropertyMap(this TypeDefinition typeDefinition)
        {
            Dictionary <FieldDefinition, PropertyDefinition> result = new Dictionary <FieldDefinition, PropertyDefinition>();

            foreach (PropertyDefinition property in typeDefinition.Properties)
            {
                FieldDefinition propertyField;
                AutoImplementedPropertyMatcher matcher = new AutoImplementedPropertyMatcher(property);
                if (matcher.IsAutoImplemented(out propertyField))
                {
                    result[propertyField] = property;
                }
            }

            return(result);
        }
        private HashSet <PropertyDefinition> GetAutoImplementedProperties(TypeDefinition type)
        {
            HashSet <PropertyDefinition> result = new HashSet <PropertyDefinition>();

            if (type.HasProperties)
            {
                foreach (PropertyDefinition property in type.Properties)
                {
                    AutoImplementedPropertyMatcher matcher = new AutoImplementedPropertyMatcher(property);
                    bool isAutoImplemented = matcher.IsAutoImplemented();

                    if (isAutoImplemented)
                    {
                        result.Add(property);
                    }
                }
            }

            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);
                    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);
            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);
                        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);
                    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);
            AddGeneratedFilterMethodsToDecompiledType(decompiledType, decompiledType.TypeContext, language);

            return decompiledType;
        }