public ClassFormatterBenchmark()
        {
            AssemblyDef _assemblyDef = AssemblyDef.Create(TestFile);
            TypeDef     typeDef      = _assemblyDef.FindType(TypeNamespace, TypeName);

            _cSharpFormatter = SyntaxFactory.Create(typeDef, Languages.CSharp);
            _vbFormatter     = SyntaxFactory.Create(typeDef, Languages.VisualBasic);
        }
Example #2
0
        /// <summary>
        /// Returns a reference to the assembly to test with.
        /// </summary>
        /// <returns></returns>
        private AssemblyDef LoadAssembly()
        {
            if (this.assemblyDef == null)
            {
                this.assemblyDef = AssemblyDef.Create(System.Configuration.ConfigurationSettings.AppSettings["assembly"]);
            }

            return(this.assemblyDef);
        }
Example #3
0
        private TypeDef GetDelegateFromTestAssembly()
        {
            // having to load a entire library each time for a test is not great, need
            // to try and refactor the code to enabled this to become less painful
            string      dir         = System.AppDomain.CurrentDomain.BaseDirectory;
            AssemblyDef assemblyDef = AssemblyDef.Create(System.IO.Path.Combine(dir, TestFile));

            return(assemblyDef.FindType("DocumentationTest.AllOutputTypesClass", "D"));
        }
Example #4
0
        public DisplayNameSignatureBenchmark()
        {
            _assembly = AssemblyDef.Create(TestFile);

            CRefPath path = CRefPath.Parse(TestMethod1);

            _method1 = _assembly.FindType(path.Namespace, path.TypeName).Methods.Find(m => m.Name == path.ElementName);

            path     = CRefPath.Parse(TestMethod2);
            _method2 = _assembly.FindType(path.Namespace, path.TypeName).Methods.Find(m => m.Name == path.ElementName);
        }
        private AssemblyDef GetAssemblyDef(DocumentedAssembly current)
        {
            AssemblyDef assembly;

            if (current.LoadedAssembly == null)
            {
                assembly = AssemblyDef.Create(current.FileName);
                current.LoadedAssembly = assembly;
            }
            else
            {
                assembly = current.LoadedAssembly;
            }
            return(assembly);
        }
        public void InitialiseAssemblyDefFileUsedForTests()
        {
            string dir = System.AppDomain.CurrentDomain.BaseDirectory;

            _assemblyDef = AssemblyDef.Create(System.IO.Path.Combine(dir, TestFile));
        }
Example #7
0
        protected override Entry GenerateDocumentForAssembly(DocumentMap map, DocumentedAssembly current, ref int fileCounter)
        {
            AssemblyDef assembly = AssemblyDef.Create(current.FileName);

            current.LoadedAssembly = assembly;

            XmlCommentFile commentFile = new XmlCommentFile(current.XmlFileName, new FileSystem());

            commentFile.Load();
            ICommentSource xmlComments = commentFile; // TODO: calling load then casting is not nice

            Entry assemblyEntry = this.EntryCreator.Create(assembly, System.IO.Path.GetFileName(current.FileName), xmlComments);

            current.UniqueId           = assembly.UniqueId = fileCounter++;
            assemblyEntry.Key          = assembly.GetGloballyUniqueId();
            assemblyEntry.IsSearchable = false;
            Entry namespaceEntry = null;

            // Add the namespaces to the document map
            Dictionary <string, List <TypeDef> > typesInNamespaces = assembly.GetTypesInNamespaces();

            foreach (KeyValuePair <string, List <TypeDef> > currentNamespace in typesInNamespaces)
            {
                if (string.IsNullOrEmpty(currentNamespace.Key) || currentNamespace.Value.Count == 0)
                {
                    continue;
                }
                string namespaceSubKey = this.BuildSubkey(currentNamespace);

                namespaceEntry = Find(map, namespaceSubKey);
                if (namespaceEntry == null)
                {
                    namespaceEntry              = this.EntryCreator.Create(currentNamespace, currentNamespace.Key, xmlComments);
                    namespaceEntry.Key          = assemblyEntry.Key;
                    namespaceEntry.SubKey       = namespaceSubKey;
                    namespaceEntry.IsSearchable = false;
                }

                // Add the types from that namespace to its map
                foreach (TypeDef currentType in currentNamespace.Value)
                {
                    if (currentType.Name.StartsWith("<"))
                    {
                        continue;
                    }
                    PreEntryAddedEventArgs e = new PreEntryAddedEventArgs(currentType);
                    this.OnPreEntryAdded(e);
                    if (!e.Filter)
                    {
                        Entry typeEntry = this.EntryCreator.Create(currentType, currentType.GetDisplayName(false), xmlComments, namespaceEntry);
                        typeEntry.Key          = currentType.GetGloballyUniqueId();
                        typeEntry.IsSearchable = true;

                        // For some elements we will not want to load the child objects
                        // this is currently for System.Enum derived values.
                        if (
                            currentType.InheritsFrom != null && currentType.InheritsFrom.GetFullyQualifiedName() == "System.Enum" ||
                            currentType.IsDelegate)
                        {
                            // Ignore children
                        }
                        else
                        {
                            this.GenerateTypeMap(currentType, typeEntry, xmlComments);
                            typeEntry.Children.Sort();
                        }

                        namespaceEntry.Children.Add(typeEntry);
                    }
                }
                if (namespaceEntry.Children.Count > 0)
                {
                    namespaceEntry.Children.Sort();
                    // we still need to add here otherwise we get duplicate namespaces.
                    assemblyEntry.Children.Add(namespaceEntry);
                    if (!map.Contains(namespaceEntry))
                    {
                        map.Add(namespaceEntry);
                    }
                    else
                    {
                        // update the type list is the contianing namespace
                        KeyValuePair <string, List <TypeDef> > original = (KeyValuePair <string, List <TypeDef> >)namespaceEntry.Item;
                        original.Value.AddRange(currentNamespace.Value);
                    }
                }
            }

            map.Sort();

            // we are not interested in assemblies being used here so make them childless
            return(this.EntryCreator.Create(null, string.Empty, null));
        }
Example #8
0
        protected override Entry GenerateDocumentForAssembly(DocumentMap map, DocumentedAssembly current, ref int fileCounter)
        {
            AssemblyDef assembly = AssemblyDef.Create(current.FileName);

            current.LoadedAssembly = assembly;

            XmlCommentFile commentFile = new XmlCommentFile(current.XmlFileName, new FileSystem());

            commentFile.Load();
            ICommentSource xmlComments = commentFile; // not nice having to call load then cast we wil have to fix this


            Entry assemblyEntry = this.EntryCreator.Create(assembly, System.IO.Path.GetFileName(current.FileName), xmlComments);

            current.UniqueId           = assembly.UniqueId = fileCounter++;
            assemblyEntry.Key          = assembly.GetGloballyUniqueId();
            assemblyEntry.IsSearchable = false;

            // Add the namespaces to the document map
            Dictionary <string, List <TypeDef> > typesInNamespaces = assembly.GetTypesInNamespaces();

            foreach (KeyValuePair <string, List <TypeDef> > currentNamespace in typesInNamespaces)
            {
                if (string.IsNullOrEmpty(currentNamespace.Key) || currentNamespace.Value.Count == 0)
                {
                    continue;
                }
                string namespaceSubKey = this.BuildSubkey(currentNamespace);

                Entry namespaceEntry = this.FindByKey(map, assemblyEntry.Key, namespaceSubKey, false);
                if (namespaceEntry == null)
                {
                    namespaceEntry              = this.EntryCreator.Create(currentNamespace, currentNamespace.Key, xmlComments, assemblyEntry);
                    namespaceEntry.Key          = assemblyEntry.Key;
                    namespaceEntry.SubKey       = namespaceSubKey;
                    namespaceEntry.IsSearchable = false;
                }

                // Add the types from that namespace to its map
                foreach (TypeDef currentType in currentNamespace.Value)
                {
                    if (currentType.Name.StartsWith("<"))
                    {
                        continue;
                    }
                    PreEntryAddedEventArgs e = new PreEntryAddedEventArgs(currentType);
                    this.OnPreEntryAdded(e);
                    if (!e.Filter)
                    {
                        Entry typeEntry = this.EntryCreator.Create(currentType, currentType.GetDisplayName(false), xmlComments, namespaceEntry);
                        typeEntry.Key          = currentType.GetGloballyUniqueId();
                        typeEntry.IsSearchable = true;

                        // For some elements we will not want to load the child objects
                        // this is currently for System.Enum derived values.
                        if (
                            currentType.InheritsFrom != null && currentType.InheritsFrom.GetFullyQualifiedName() == "System.Enum" ||
                            currentType.IsDelegate)
                        {
                            // Ignore children
                        }
                        else
                        {
                            this.GenerateTypeMap(currentType, typeEntry, xmlComments);
                            typeEntry.Children.Sort();
                        }

                        namespaceEntry.Children.Add(typeEntry);
                    }
                }
                if (namespaceEntry.Children.Count > 0)
                {
                    assemblyEntry.Children.Add(namespaceEntry);
                    namespaceEntry.Children.Sort();
                }
            }

            assemblyEntry.Children.Sort();

            return(assemblyEntry);
        }
Example #9
0
 public void LoadTest()
 {
     AssemblyDef def = AssemblyDef.Create(TestFile);
 }
Example #10
0
 private void LoadAssemblyDefOnly()
 {
     AssemblyDef assembly = AssemblyDef.Create(TestFile);
 }