public MetricsReader(string fileName)
        {
            loader = new CecilLoader(true)
            {
                IncludeInternalMembers = true
            };
            namespaceMappings = new Dictionary <string, NamespaceNode>();
            typeMappings      = new Dictionary <ITypeDefinition, TypeNode>();
            methodMappings    = new Dictionary <IMethod, MethodNode>();
            fieldMappings     = new Dictionary <IField, FieldNode>();
            cecilMappings     = new Dictionary <MemberReference, IEntity>();

            compilation = new SimpleCompilation(loader.LoadAssemblyFile(fileName));

            // TODO load referenced assemblies into compilation.

            Assembly           = new AssemblyNode(compilation.MainAssembly.AssemblyName);
            assemblyDefinition = loader.GetCecilObject(compilation.MainAssembly.UnresolvedAssembly);

            foreach (var type in compilation.MainAssembly.GetAllTypeDefinitions())
            {
                ReadType(type);

                foreach (IMethod method in type.Methods)
                {
                    ReadMethod(method);
                }

                foreach (IProperty property in type.Properties)
                {
                    if (property.CanGet)
                    {
                        ReadMethod(property.Getter);
                    }
                    if (property.CanSet)
                    {
                        ReadMethod(property.Setter);
                    }
                }

                foreach (IField field in type.Fields)
                {
                    ReadField(field);
                }
            }

            foreach (var method in methodMappings.Values)
            {
                ReadInstructions(method, method.Method, loader.GetCecilObject((IUnresolvedMethod)method.Method.UnresolvedMember));
            }

            Assembly.namespaces = namespaceMappings.Values;
        }
        public List <ReferenceSegment> Decompile(TextEditorData data, ITreeNavigator navigator, bool publicOnly)
        {
            if (DomMethodNodeBuilder.HandleSourceCodeEntity(navigator, data))
            {
                return(null);
            }
            var type = CecilLoader.GetCecilObject((IUnresolvedTypeDefinition)navigator.DataItem);

            if (type == null)
            {
                return(null);
            }
            var types      = DesktopService.GetMimeTypeInheritanceChain(data.Document.MimeType);
            var codePolicy = MonoDevelop.Projects.Policies.PolicyService.GetDefaultPolicy <MonoDevelop.CSharp.Formatting.CSharpFormattingPolicy> (types);
            var settings   = new DecompilerSettings()
            {
                AnonymousMethods        = true,
                AutomaticEvents         = true,
                AutomaticProperties     = true,
                ForEachStatement        = true,
                LockStatement           = true,
                CSharpFormattingOptions = codePolicy.CreateOptions()

                                          //,
//				HideNonPublicMembers = publicOnly
            };

            return(DomMethodNodeBuilder.Decompile(data, DomMethodNodeBuilder.GetModule(navigator), type, builder =>
            {
                builder.AddType(type);
            }, settings));
        }
示例#3
0
        public List <ReferenceSegment> Decompile(TextEditorData data, ITreeNavigator navigator, bool publicOnly)
        {
            if (DomMethodNodeBuilder.HandleSourceCodeEntity(navigator, data))
            {
                return(null);
            }
            var type = CecilLoader.GetCecilObject((IUnresolvedTypeDefinition)navigator.DataItem);

            if (type == null)
            {
                return(null);
            }
            var settings = new DecompilerSettings()
            {
                AnonymousMethods     = true,
                AutomaticEvents      = true,
                AutomaticProperties  = true,
                ForEachStatement     = true,
                LockStatement        = true,
                HideNonPublicMembers = publicOnly
            };

            return(DomMethodNodeBuilder.Decompile(data, DomMethodNodeBuilder.GetModule(navigator), type, builder => {
                builder.AddType(type);
            }, settings));
        }
        List <ReferenceSegment> IAssemblyBrowserNodeBuilder.Decompile(TextEditorData data, ITreeNavigator navigator, bool publicOnly)
        {
            if (DomMethodNodeBuilder.HandleSourceCodeEntity(navigator, data))
            {
                return(null);
            }
            var field = CecilLoader.GetCecilObject((IUnresolvedField)navigator.DataItem);

            return(DomMethodNodeBuilder.Decompile(data, DomMethodNodeBuilder.GetModule(navigator), field.DeclaringType, b => b.AddField(field)));
        }
        List <ReferenceSegment> IAssemblyBrowserNodeBuilder.Disassemble(TextEditorData data, ITreeNavigator navigator)
        {
            if (DomMethodNodeBuilder.HandleSourceCodeEntity(navigator, data))
            {
                return(null);
            }
            var field = CecilLoader.GetCecilObject((IUnresolvedField)navigator.DataItem);

            return(DomMethodNodeBuilder.Disassemble(data, rd => rd.DisassembleField(field)));
        }
示例#6
0
        List <ReferenceSegment> IAssemblyBrowserNodeBuilder.GetSummary(TextEditorData data, ITreeNavigator navigator, bool publicOnly)
        {
            if (DomMethodNodeBuilder.HandleSourceCodeEntity(navigator, data))
            {
                return(null);
            }
            var property = CecilLoader.GetCecilObject((IUnresolvedProperty)navigator.DataItem);

            return(DomMethodNodeBuilder.GetSummary(data, DomMethodNodeBuilder.GetModule(navigator), property.DeclaringType, b => b.AddProperty(property)));
        }
        TypeNode ReadType(ITypeDefinition type)
        {
            if (type == null)
            {
                return(null);
            }
            TypeNode t;

            if (typeMappings.TryGetValue(type, out t))
            {
                return(t);
            }
            cecilMappings.Add(loader.GetCecilObject(type.Parts[0]), type);
            NamespaceNode ns = ReadNamespace(type.Namespace);

            typeMappings.Add(type, t = new TypeNode(type, ns));
            ns.types.Add(t);
            if (type.DeclaringTypeDefinition != null)
            {
                ReadType(type.DeclaringTypeDefinition).nestedTypes.Add(t);
            }
            return(t);
        }
示例#8
0
        public List <ReferenceSegment> Disassemble(TextEditor data, ITreeNavigator navigator)
        {
            if (DomMethodNodeBuilder.HandleSourceCodeEntity(navigator, data))
            {
                return(null);
            }
            var type = CecilLoader.GetCecilObject((IUnresolvedTypeDefinition)navigator.DataItem);

            if (type == null)
            {
                return(null);
            }

            return(DomMethodNodeBuilder.Disassemble(data, rd => rd.DisassembleType(type)));
        }
        List <ReferenceSegment> IAssemblyBrowserNodeBuilder.Disassemble(TextEditorData data, ITreeNavigator navigator)
        {
            var method = (IUnresolvedMethod)navigator.DataItem;

            if (HandleSourceCodeEntity(navigator, data))
            {
                return(null);
            }
            var cecilMethod = CecilLoader.GetCecilObject(method);

            if (cecilMethod == null)
            {
                return(null);
            }
            return(Disassemble(data, rd => rd.DisassembleMethod(cecilMethod)));
        }
        public List <ReferenceSegment> Decompile(TextEditorData data, ITreeNavigator navigator, bool publicOnly)
        {
            var method = (IUnresolvedMethod)navigator.DataItem;

            if (HandleSourceCodeEntity(navigator, data))
            {
                return(null);
            }
            var cecilMethod = CecilLoader.GetCecilObject(method);

            if (cecilMethod == null)
            {
                return(null);
            }
            return(DomMethodNodeBuilder.Decompile(data, DomMethodNodeBuilder.GetModule(navigator), cecilMethod.DeclaringType, b => b.AddMethod(cecilMethod)));
        }
示例#11
0
        List <ReferenceSegment> IAssemblyBrowserNodeBuilder.GetSummary(TextEditor data, ITreeNavigator navigator, bool publicOnly)
        {
            if (DomMethodNodeBuilder.HandleSourceCodeEntity(navigator, data))
            {
                return(null);
            }
            var type = CecilLoader.GetCecilObject((IUnresolvedTypeDefinition)navigator.DataItem);

            if (type == null)
            {
                return(null);
            }
            var types      = DesktopService.GetMimeTypeInheritanceChain(data.MimeType);
            var codePolicy = MonoDevelop.Projects.Policies.PolicyService.GetDefaultPolicy <MonoDevelop.CSharp.Formatting.CSharpFormattingPolicy> (types);
            var settings   = CreateDecompilerSettings(publicOnly, codePolicy);

            return(DomMethodNodeBuilder.GetSummary(data, DomMethodNodeBuilder.GetModule(navigator), type, builder => {
                builder.AddType(type);
            }, settings));
        }