public static void Recursion()
        {
            var code          = @"
namespace RoslynSandbox
{
    using System;

    class C
    {
        public C()
        {
            Type type;
            type = type;
            var methodInfo = type.GetMethod(nameof(this.ToString));
        }
    }
}";
            var syntaxTree    = CSharpSyntaxTree.ParseText(code);
            var compilation   = CSharpCompilation.Create("test", new[] { syntaxTree }, MetadataReferences.FromAttributes());
            var semanticModel = compilation.GetSemanticModel(syntaxTree);
            var node          = syntaxTree.FindInvocation("GetMethod");
            var context       = new SyntaxNodeAnalysisContext(null, null, semanticModel, null, null, null, CancellationToken.None);

            Assert.AreEqual(false, ReflectedMember.TryGetType(node, context, out _, out _));
        }
        public static void TryGetTypeFromLocal(string typeExpression, string expected)
        {
            var code          = @"
namespace RoslynSandbox
{
    using System.Collections.Generic;
    using System.Reflection;

    class C
    {
        public C(C foo)
        {
            var type = typeof(C);
            var methodInfo = type.GetMethod(nameof(this.ToString));
        }
    }
}".AssertReplace("typeof(C)", typeExpression);
            var syntaxTree    = CSharpSyntaxTree.ParseText(code);
            var compilation   = CSharpCompilation.Create("test", new[] { syntaxTree }, MetadataReferences.FromAttributes());
            var semanticModel = compilation.GetSemanticModel(syntaxTree);
            var node          = syntaxTree.FindInvocation("GetMethod");
            var context       = new SyntaxNodeAnalysisContext(null, null, semanticModel, null, null, null, CancellationToken.None);

            Assert.AreEqual(true, ReflectedMember.TryGetType(node, context, out var type, out var instance));
            Assert.AreEqual(expected, type.MetadataName);
            Assert.AreEqual(typeExpression, instance.ToString());
        }
        public override void Render(System.Xml.XmlWriter writer)
        {
            writer.WriteStartDocument();

            writer.WriteStartElement("members");
            writer.WriteAttributeString("id", this.AssociatedEntry.Key.ToString());
            writer.WriteAttributeString("subId", this.AssociatedEntry.SubKey);
            WriteCref(this.AssociatedEntry, writer);

            string typeDisplayName = _containingType.GetDisplayName(false);
            string pageDisplayName = $"{typeDisplayName} {this.AssociatedEntry.Name}";

            writer.WriteStartElement("name");
            writer.WriteAttributeString("safename", Exporter.CreateSafeName(pageDisplayName));
            writer.WriteAttributeString("type", typeDisplayName);
            writer.WriteString(pageDisplayName);
            writer.WriteEndElement();

            // we need to write the entries that appear as children to this document map
            // entry. it is going to be easier to use the Entry elements
            writer.WriteStartElement("entries");
            switch (AssociatedEntry.SubKey.ToLower())
            {
            case "properties":
            case "fields":
            case "constants":
            case "operators":
            case "constructors":
                foreach (Entry current in AssociatedEntry.Children)
                {
                    ReflectedMember m = current.Item as ReflectedMember;
                    this.WriteEntry(writer, m, ReflectionHelper.GetDisplayName(m));
                }
                break;

            case "methods":
                // write normal methods
                foreach (Entry current in AssociatedEntry.Children)
                {
                    ReflectedMember m = current.Item as ReflectedMember;
                    WriteEntry(writer, m, ReflectionHelper.GetDisplayName(m));
                }
                // write extension methods
                var extensionMethods = from method in ((TypeRef)AssociatedEntry.Parent.Item).ExtensionMethods
                                       orderby method.Name
                                       select method;
                foreach (MethodDef currentMethod in extensionMethods)
                {
                    DisplayNameSignitureConvertor displayNameSig = new DisplayNameSignitureConvertor(currentMethod, false, true, true);
                    WriteEntry(writer, currentMethod, currentMethod.GetDisplayName(false, true), "extensionmethod");
                }
                break;
            }
            writer.WriteEndElement(); // entries
            writer.WriteEndElement();
            writer.WriteEndDocument();
        }
示例#4
0
        /// <summary>
        /// Adds the syntax block for the provided <paramref name="member"/>.
        /// </summary>
        /// <param name="member">The member to produce the syntax for.</param>
        protected void AddSyntaxBlock(ReflectedMember member)
        {
            IFormatter formatter = SyntaxFactory.Create(member, LiveDocumentorFile.Singleton.Language);

            if (formatter != null)
            {
                this.Blocks.Add(new Header2("Syntax"));
                Code c = Parser.ParseSyntax(formatter.Format());
                this.Blocks.Add(c);
            }
        }
        internal TypeRef ResolveType(AssemblyDef assembly, ReflectedMember member)
        {
            SignatureToken token = Tokens.Last();

            if (token is TypeSignatureToken)
            {
                return(((TypeSignatureToken)token).ResolveType(assembly, member));
            }
            else
            {
                return(((ElementTypeSignatureToken)token).ResolveToken(assembly));
            }
        }
示例#6
0
 // checks if the entry is a ReflectedMember or a namespace and generates the cref attribute
 // fix: change this so it only outputs when I want it to!
 protected void WriteCref(Entry entry, System.Xml.XmlWriter writer)
 {
     // see DocumentMapper to see how entry.Item is populated
     if (entry.Item is ReflectedMember && !(entry.Item is AssemblyDef))
     { // assemblies cant be cref'd
         ReflectedMember member = entry.Item as ReflectedMember;
         CRefPath        path   = CRefPath.Create(member);
         writer.WriteAttributeString("cref", path.ToString());
     }
     else if (entry.Item is KeyValuePair <string, List <TypeDef> > )
     { // this is a namespace
         writer.WriteAttributeString("cref", "N:" + ((KeyValuePair <string, List <TypeDef> >)entry.Item).Key);
     }
 }
        public NoXmlComments(ReflectedMember entry)
        {
            Resources.MergedDictionaries.Add(DocumentationResources.BaseResources);
            Style = (Style)FindResource("NoComments");

            Inlines.Add(new Run(
                            string.Format("No XML comments file found for declaring assembly '{0}'. ",
                                          System.IO.Path.GetFileName(entry.Assembly.FileName))
                            ));

            Hyperlink info = new Hyperlink(new Run("More information."));

            info.NavigateUri      = new Uri(HelpUri);
            info.RequestNavigate += info_RequestNavigate;
            Inlines.Add(info);
        }
        public TypeDetails GetTypeDetails(ReflectedMember member)
        {
            TypeDetails    details = new TypeDetails();
            SignatureToken token   = Tokens.Last();

            if (token is TypeSignatureToken)
            {
                details = ((TypeSignatureToken)token).GetTypeDetails(member);
            }
            else
            {
                details.Type = ((ElementTypeSignatureToken)token).ResolveToken(member.Assembly);
            }

            return(details);
        }
示例#9
0
        /// <summary>
        /// Initialises a new instance of the SearchResult class.
        /// </summary>
        /// <param name="relatedEntry">The entry related to this result</param>
        public SearchResult(Entry relatedEntry)
        {
            this.RelatedEntry = relatedEntry;

            _member = null;
            if (this.RelatedEntry.Item is List <ReflectedMember> )
            {
                // ignore these are list entries e.g. Properties
            }
            else if (this.RelatedEntry.Item is KeyValuePair <string, List <TypeDef> > )
            {
                // namespace
            }
            else
            {
                _member = (ReflectedMember)this.RelatedEntry.Item;
            }

            if (_member != null)
            {
                if (_member is PropertyDef)
                {
                    PropertyDef property = _member as PropertyDef;

                    string propertyName = new DisplayNameSignitureConvertor(property, false, true).Convert();

                    Name = propertyName + " in " + property.OwningType.GetDisplayName(false);
                }
                else if (_member is TypeDef)
                {
                    this.Name = ((TypeDef)_member).GetDisplayName(false);
                }
                else if (_member is MethodDef)
                {
                    this.Name = string.Format("{1} in {0}", ((MethodDef)_member).Type.GetDisplayName(false), ((MethodDef)_member).GetDisplayName(false, true));
                }
            }

            if (string.IsNullOrEmpty(this.Name))
            {
                this.Name = this.RelatedEntry.Name;
            }
        }
示例#10
0
        /// <summary>
        /// Renders the syntax block for the specified <paramref name="member"/>.
        /// </summary>
        /// <param name="member">The member to render the syntax for.</param>
        /// <param name="writer">The writer to write the syntax to.</param>
        protected void RenderSyntaxBlocks(ReflectedMember member, System.Xml.XmlWriter writer)
        {
            IFormatter formatter = SyntaxFactory.Create(member, Languages.CSharp);

            if (formatter != null)
            {
                writer.WriteStartElement("syntaxblocks");
                writer.WriteStartElement("syntax");
                writer.WriteAttributeString("language", "C#");

                foreach (SyntaxToken token in formatter.Format())
                {
                    writer.WriteStartElement(token.TokenType.ToString().ToLower());
                    writer.WriteString(token.Content);
                    writer.WriteEndElement();
                }

                writer.WriteEndElement();
                writer.WriteEndElement();
            }
        }
示例#11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="member"></param>
        /// <returns></returns>
        /// <remarks>
        /// The order in which the visibility modifiers are checked is important as
        /// they use the first 3 bits of the flag, and they can use the first bit to
        /// represent private and the 3 and 1st bit to represent public.
        /// </remarks>
        private static string GetVisibility(ReflectedMember member)
        {
            string name = "public";

            if (member is AssemblyDef)
            {
            }
            else if (member is TypeDef || member is EventDef || member is FieldDef || member is MethodDef || member is PropertyDef)
            {
                switch (member.MemberAccess)
                {
                case Visibility.Protected:
                    name = "protected";
                    break;

                case Visibility.Internal:
                    name = "sealed";
                    break;

                case Visibility.InternalProtected:
                    name = "friend";
                    break;

                case Visibility.Private:
                    name = "private";
                    break;

                case Visibility.Public:
                    name = "public";
                    break;
                }
            }

            // TODO: Handle namespaces and assemblies

            return(name);
        }
        public static void Recursion()
        {
            var code          = @"
namespace N
{
    using System;

    class C
    {
        public C()
        {
            Type type;
            type = type;
            var methodInfo = type.GetMethod(nameof(this.ToString));
        }
    }
}";
            var syntaxTree    = CSharpSyntaxTree.ParseText(code);
            var compilation   = CSharpCompilation.Create("test", new[] { syntaxTree }, Settings.Default.MetadataReferences);
            var semanticModel = compilation.GetSemanticModel(syntaxTree);
            var node          = syntaxTree.FindInvocation("GetMethod");

            Assert.AreEqual(false, ReflectedMember.TryGetType(node, semanticModel, CancellationToken.None, out _, out _));
        }
示例#13
0
        /// <summary>
        /// Obtains a name to display for the reflected member.
        /// </summary>
        /// <param name="entry">The entry.</param>
        /// <returns>A name for the ReflectedMember</returns>
        public static string GetDisplayName(ReflectedMember entry)
        {
            string displayName = string.Empty;

            if (entry is FieldDef)
            {
                displayName = ((FieldDef)entry).Name;
            }
            else if (entry is PropertyDef)
            {
                PropertyDef property = entry as PropertyDef;
                displayName = new DisplayNameSignitureConvertor(property, false, true).Convert();
            }
            else if (entry is MethodDef)
            {
                displayName = ((MethodDef)entry).GetDisplayName(false, true);
            }
            else if (entry is EventDef)
            {
                displayName = ((EventDef)entry).Name;
            }

            return(displayName);
        }
示例#14
0
 /// <summary>
 /// Initialises a new instance of the PreEntryAddedEventArgs class.
 /// </summary>
 /// <param name="member">The member being added to the document map.</param>
 public PreEntryAddedEventArgs(ReflectedMember member)
 {
     this.Member = member;
 }
示例#15
0
        /// <summary>
        /// Finds the member this <see cref="CRefPath"/> refers to in the provided type.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <returns>The found member ref.</returns>
        /// <exception cref="ArgumentNullException">When <paramref name="type"/> is null.</exception>
        public ReflectedMember FindIn(TypeDef type)
        {
            // TODO: Move to the TypeDef class
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            if (this.PathType == CRefTypes.Namespace || this.PathType == CRefTypes.Type || this.PathType == CRefTypes.Error)
            {
                throw new InvalidOperationException(string.Format("Can not find member in a type when the path type is '{0}'", this.PathType.ToString()));
            }

            ReflectedMember        member       = null;
            List <ReflectedMember> foundMembers = new List <ReflectedMember>();

            // find all potential members
            switch (this.PathType)
            {
            case CRefTypes.Event:
                foundMembers.AddRange(type.Events.FindAll(e => string.Compare(e.Name, this.ElementName, true) == 0).ToArray());
                break;

            case CRefTypes.Field:
                foundMembers.AddRange(type.Fields.FindAll(e => string.Compare(e.Name, this.ElementName, true) == 0).ToArray());
                break;

            case CRefTypes.Method:
                string elementName   = this.ElementName.Replace('#', '.');
                int    genParameters = 0;
                if (elementName.Contains('`'))
                {
                    genParameters = int.Parse(elementName.Substring(elementName.Length - 1, 1));
                    elementName   = elementName.Substring(0, elementName.IndexOf('`'));
                }
                MethodDef[] foundMethods = type.Methods.FindAll(e => string.Compare(e.Name, elementName, true) == 0).ToArray();
                if (foundMethods.Length > 1 && genParameters > 0)
                {
                    for (int i = 0; i < foundMethods.Length; i++)
                    {
                        if (foundMethods[i].GenericTypes != null && foundMethods[i].GenericTypes.Count == genParameters)
                        {
                            foundMembers.Add(foundMethods[i]);
                        }
                    }
                }
                else
                {
                    foundMembers.AddRange(foundMethods);
                }
                break;

            case CRefTypes.Property:
                foundMembers.AddRange(type.Properties.FindAll(e => string.Compare(e.Name, this.ElementName, true) == 0).ToArray());
                break;
            }

            if (foundMembers.Count == 1)
            {
                member = foundMembers[0];
            }
            else if (foundMembers.Count > 1)
            {
                // the elements will differ by the parameters, this is slow!
                foreach (ReflectedMember current in foundMembers)
                {
                    string found = CRefPath.Create(current).ToString();
                    if (string.Compare(found, this.ToString(), true) == 0)
                    {
                        member = current;
                        break;
                    }
                }
            }

            return(member);
        }
示例#16
0
 private void WriteEntry(System.Xml.XmlWriter writer, ReflectedMember entryMember, string displayName)
 {
     WriteEntry(writer, entryMember, displayName, ReflectionHelper.GetType(entryMember));
 }
示例#17
0
        public TypeDetails GetTypeDetails(ReflectedMember member)
        {
            TypeDetails details = new TypeDetails();

            if (ElementType.ElementType == ElementTypes.SZArray)
            {
                TypeSignatureToken childType = Tokens.Last() as TypeSignatureToken;
                details.ArrayOf = childType.GetTypeDetails(member);
                details.IsArray = true;
            }
            else if (
                ElementType.ElementType == ElementTypes.Class ||
                ElementType.ElementType == ElementTypes.ValueType
                )
            {
                details.Type = ElementType.ResolveToken(member.Assembly);
            }
            else if (ElementType.ElementType == ElementTypes.GenericInstance)
            {
                ElementTypeSignatureToken childType = Tokens[1] as ElementTypeSignatureToken;
                details.Type = childType.ResolveToken(member.Assembly);
                details.IsGenericInstance = true;
                details.GenericParameters = new List <TypeDetails>();
                for (int i = 3; i < GetGenericArgumentCount().Count + 3; i++)
                {
                    if (Tokens[i].TokenType == SignatureTokens.Type)
                    {
                        details.GenericParameters.Add(
                            ((TypeSignatureToken)Tokens[i]).GetTypeDetails(member)
                            );
                    }
                    else
                    {
                        TypeDetails genericParameter = new TypeDetails();
                        genericParameter.Type = ((ElementTypeSignatureToken)Tokens[i]).ResolveToken(member.Assembly);
                        details.GenericParameters.Add(genericParameter);
                    }
                }
            }
            else if (ElementType.ElementType == ElementTypes.Ptr)
            {
                if (Tokens[1].TokenType == SignatureTokens.Type)
                {
                    TypeSignatureToken childType = Tokens[1] as TypeSignatureToken;
                    details = childType.GetTypeDetails(member);
                }
                else
                {
                    ElementTypeSignatureToken childType = Tokens[1] as ElementTypeSignatureToken;
                    details.Type = childType.ResolveToken(member.Assembly);
                }
                details.IsPointer = true;
            }
            else if (ElementType.ElementType == ElementTypes.Array)
            {
                if (Tokens[1].TokenType == SignatureTokens.Type)
                {
                    TypeSignatureToken childType = Tokens[1] as TypeSignatureToken;
                    details.ArrayOf = childType.GetTypeDetails(member);
                }
                else
                {
                    ElementTypeSignatureToken childType = Tokens[1] as ElementTypeSignatureToken;
                    details.ArrayOf      = new TypeDetails();
                    details.ArrayOf.Type = childType.ResolveToken(member.Assembly);
                }
                details.IsMultidemensionalArray = true;
                details.ArrayShape = (ArrayShapeSignatureToken)Tokens.Find(t => t.TokenType == SignatureTokens.ArrayShape);
            }
            else if (ElementType.ElementType == ElementTypes.MVar)
            {
                details.Type = ResolveType(member.Assembly, member);
            }
            else if (ElementType.ElementType == ElementTypes.Var)
            {
                details.Type = ResolveType(member.Assembly, member);
            }
            else if (ElementType.Definition != null)
            {
                details.Type = ElementType.Definition as TypeRef;
            }

            return(details);
        }
 /// <summary>
 /// Instantiates the correct IFormatter implementation based on the provided
 /// <paramref name="member"/> and <paramref name="langauge"/>.
 /// </summary>
 /// <param name="member">The member to create the formatter for.</param>
 /// <param name="language">The language the formatter should be for.</param>
 /// <returns>A IFormatter implementation.</returns>
 public static IFormatter Create(ReflectedMember member, Languages language)
 {
     return(CreateFormatter(CreateSyntax(member), language));
 }
        /// <summary>
        /// Returns a correctly typed and instantiated <see cref="Syntax"/> class
        /// for the specified <paramref name="member"/>.
        /// </summary>
        /// <param name="member">The member to create a Syntax instance for.</param>
        /// <returns>The instantiated Syntax class.</returns>
        private static Syntax CreateSyntax(ReflectedMember member)
        {
            Syntax syntax = null;

            if (member is TypeDef)
            {
                TypeDef type = member as TypeDef;
                if (type.IsInterface)
                {
                    syntax = new InterfaceSyntax(type);
                }
                else if (type.IsEnumeration)
                {
                    syntax = new EnumSyntax(type);
                }
                else if (type.IsStructure)
                {
                    syntax = new StructSyntax(type);
                }
                else if (type.IsDelegate)
                {
                    syntax = new DelegateSyntax(type);
                }
                else
                {
                    syntax = new ClassSyntax(type);
                }
            }
            else if (member is FieldDef)
            {
                FieldDef field = member as FieldDef;
                if (field.IsConstant)
                {
                    syntax = new ConstantSyntax(field);
                }
                else
                {
                    syntax = new FieldSyntax(field);
                }
            }
            else if (member is MethodDef)
            {
                MethodDef method = member as MethodDef;
                if (method.IsConstructor)
                {
                    syntax = new ConstructorSyntax(method);
                }
                else if (method.IsOperator)
                {
                    syntax = new OperatorSyntax(method);
                }
                else
                {
                    syntax = new MethodSyntax(method);
                }
            }
            else if (member is EventDef)
            {
                syntax = new EventSyntax(member as EventDef);
            }
            else if (member is PropertyDef)
            {
                // A property can be a noram property or an indexor
                PropertyDef property = member as PropertyDef;
                if (property.IsIndexer())
                {
                    syntax = new IndexorSyntax(member as PropertyDef);
                }
                else
                {
                    syntax = new PropertySyntax(member as PropertyDef);
                }
            }

            return(syntax);
        }
示例#20
0
        /// <summary>
        /// Attempts to resolve the type.
        /// </summary>
        /// <param name="assembly"></param>
        /// <param name="member"></param>
        /// <returns></returns>
        internal TypeRef ResolveType(AssemblyDef assembly, ReflectedMember member)
        {
            TypeRef type = null;

            if (ElementType.ElementType == ElementTypes.SZArray)
            {
                TypeSignatureToken childType = (TypeSignatureToken)Tokens.Last();
                type = childType.ResolveType(assembly, member);
            }
            else if (
                ElementType.ElementType == ElementTypes.Class ||
                ElementType.ElementType == ElementTypes.ValueType
                )
            {
                type = (TypeRef)assembly.ResolveMetadataToken(ElementType.Token);
            }
            else if (ElementType.ElementType == ElementTypes.GenericInstance)
            {
                ElementTypeSignatureToken childType = (ElementTypeSignatureToken)Tokens[1];
                type = childType.ResolveToken(assembly);
            }
            else if (ElementType.ElementType == ElementTypes.Ptr)
            {
                if (Tokens[1].TokenType == SignatureTokens.Type)
                {
                    TypeSignatureToken childType = (TypeSignatureToken)Tokens[1];
                    type = childType.ResolveType(assembly, member);
                }
                else
                {
                    ElementTypeSignatureToken childType = (ElementTypeSignatureToken)Tokens[1];
                    type = childType.ResolveToken(assembly);
                }
            }
            else if (ElementType.ElementType == ElementTypes.Array)
            {
                if (Tokens[1].TokenType == SignatureTokens.Type)
                {
                    TypeSignatureToken childType = (TypeSignatureToken)Tokens[1];
                    type = childType.ResolveType(assembly, member);
                }
                else
                {
                    ElementTypeSignatureToken childType = (ElementTypeSignatureToken)Tokens[1];
                    type = childType.ResolveToken(assembly);
                }
            }
            else if (ElementType.ElementType == ElementTypes.MVar)
            {
                MethodDef method = member as MethodDef;
                if (method == null)
                {
                    InvalidOperationException ex = new InvalidOperationException(
                        string.Format(
                            "A MethodDef was expected for type resolution in the signiture but a {0} was provided.",
                            member.GetType().ToString()
                            ));
                    throw ex;
                }
                type = method.GenericTypes[(int)ElementType.Token];
            }
            else if (ElementType.ElementType == ElementTypes.Var)
            {
                // Anything that contains a Type property will do here
                TypeDef theType;
                if (member is MethodDef)
                {
                    // a method may define its own parameters
                    theType = (TypeDef)((MethodDef)member).Type;
                }
                else if (member is PropertyDef)
                {
                    theType = ((PropertyDef)member).OwningType;
                }
                else if (member is FieldDef)
                {
                    theType = (TypeDef)((FieldDef)member).Type;
                }
                else if (member is EventDef)
                {
                    theType = ((EventDef)member).Type;
                }
                else if (member is TypeSpec)
                {
                    theType = ((TypeSpec)member).ImplementingType;
                }
                else
                {
                    InvalidOperationException ex = new InvalidOperationException(
                        string.Format(
                            "A ReflectedMember that is contained by a TypeDef was expected for type resolution in the signiture but a {0} was provided.",
                            member.GetType().ToString()
                            ));
                    throw ex;
                }

                List <GenericTypeRef> genericParameters = theType.GenericTypes;

                if (genericParameters.Count < ElementType.Token)
                {
                    throw new InvalidOperationException("The generic token refers to a parameter that is not available.");
                }
                type = genericParameters[(int)ElementType.Token];
            }
            else if (ElementType.Definition != null)
            {
                type = (TypeRef)ElementType.Definition;
            }
            return(type);
        }
示例#21
0
        /// <summary>
        /// Searches the Document for the entry related to the specified <paramref name="path"/>.
        /// </summary>
        /// <param name="path">The CRefPath to search for.</param>
        /// <returns>The Entry if it is found else null.</returns>
        public Entry Find(CRefPath path)
        {
            if (path == null || path.PathType == CRefTypes.Error)
            {
                return(null);
            }
            if (Map.Count == 0)
            {
                return(null);
            }

            // find the level of the namespace entries
            int   level = 1;
            Entry found = Map[0];

            while (!(found.Item is KeyValuePair <string, List <TypeDef> >))
            {
                found = found.Children[0];
                level++;
            }
            found = null;

            List <Entry> namespaceEntries = new List <Entry>();   // flattend list of namespaces

            if (level == 1)
            {
                namespaceEntries.AddRange(Map);
            }
            else
            {
                for (int i = 0; i < Map.Count; i++)
                {
                    namespaceEntries.AddRange(GetAllEntriesFromLevel(level, 2, Map[i]));
                }
            }

            for (int i = 0; i < namespaceEntries.Count; i++)
            {
                Entry currentLevel = namespaceEntries[i];
                if (string.Compare(currentLevel.SubKey, path.Namespace, true) == 0)
                {
                    // if we are searching for a namespace, we are done now as we have found it
                    if (path.PathType == CRefTypes.Namespace)
                    {
                        found = currentLevel;
                        break;
                    }

                    // search the types in the namespace
                    for (int j = 0; j < currentLevel.Children.Count; j++)
                    {
                        Entry   currentTypeEntry = currentLevel.Children[j];
                        TypeDef currentType      = (TypeDef)currentTypeEntry.Item;
                        if (string.Compare(currentType.Name, path.TypeName, true) == 0)
                        {
                            // if we are searchinf for a type, we are done now
                            if (path.PathType == CRefTypes.Type)
                            {
                                found = currentTypeEntry;
                                break;
                            }

                            // find the type and do the quick type search to find the related
                            // entry. this is the quickest way.
                            ReflectedMember member = path.FindIn(currentType);
                            if (member != null)
                            {   // someone could have misspelled the member in the crefpath
                                found = currentTypeEntry.FindByKey(member.GetGloballyUniqueId(), string.Empty);
                                break;
                            }
                        }
                    }
                }
                if (found != null)
                {
                    break;
                }
            }

            return(found);
        }
示例#22
0
        /// <summary>
        /// Renders the list of defined exceptions for the specified <paramref name="member"/>.
        /// </summary>
        /// <param name="member">The member to render the exceptions for.</param>
        /// <param name="writer">The writer to write the exceptions to.</param>
        /// <param name="comment">The XmlCodeComment to read the exceptions from.</param>
        protected virtual void RenderExceptionBlock(ReflectedMember member, System.Xml.XmlWriter writer, XmlCodeComment comment)
        {
            // output documentation for expected exceptions if they are defined
            if (comment != XmlCodeComment.Empty)
            {
                List <XmlCodeElement> exceptions = comment.Elements.FindAll(node => node is ExceptionXmlCodeElement);
                if (exceptions != null && exceptions.Count > 0)
                {
                    writer.WriteStartElement("exceptions");
                    for (int i = 0; i < exceptions.Count; i++)
                    {
                        ExceptionXmlCodeElement current = (ExceptionXmlCodeElement)exceptions[i];
                        string          exceptionName   = string.Empty;
                        ReflectedMember found           = null;

                        if (current.Member.PathType != CRefTypes.Error)
                        {
                            TypeDef def = member.Assembly.FindType(current.Member.Namespace, current.Member.TypeName);
                            exceptionName = string.Format("{0}.{1}", current.Member.Namespace, current.Member.TypeName);

                            if (def != null)
                            {
                                found = def;
                                switch (current.Member.PathType)
                                {
                                // these elements are named and the type of element will
                                // not modify how it should be displayed
                                case CRefTypes.Field:
                                case CRefTypes.Property:
                                case CRefTypes.Event:
                                case CRefTypes.Namespace:
                                    break;

                                // these could be generic and so will need to modify to
                                // a more appropriate display name
                                case CRefTypes.Method:
                                    MethodDef method = current.Member.FindIn(def) as MethodDef;
                                    if (method != null)
                                    {
                                        found         = method;
                                        exceptionName = method.GetDisplayName(false);
                                    }
                                    break;

                                case CRefTypes.Type:
                                    exceptionName = def.GetDisplayName(false);
                                    break;
                                }
                            }
                        }

                        writer.WriteStartElement("exception");
                        writer.WriteStartElement("name");
                        if (found != null)
                        {
                            writer.WriteAttributeString("key", found.GetGloballyUniqueId().ToString());
                            writer.WriteAttributeString("cref", current.Member.ToString());
                        }
                        writer.WriteString(exceptionName);
                        writer.WriteEndElement();
                        writer.WriteStartElement("condition");
                        for (int j = 0; j < current.Elements.Count; j++)
                        {
                            this.Serialize(current.Elements[j], writer);
                        }
                        writer.WriteEndElement();
                        writer.WriteEndElement();
                    }
                    writer.WriteEndElement();
                }
            }
        }
示例#23
0
        public static string GetType(ReflectedMember member)
        {
            // NOTE: This code is duplicated in LiveDocumenter.Model.ElementIconConstants.GetIconFor

            string name = string.Empty;

            if (member is AssemblyDef)
            {
                name = "assembly";
            }
            else if (member is TypeDef)
            {
                name = "class";

                TypeDef typeDef = (TypeDef)member;
                if (typeDef != null)
                {
                    if (typeDef.IsInterface)
                    {
                        name = "interface";
                    }
                    else if (typeDef.IsStructure)
                    {
                        name = "structure";
                    }
                    else if (typeDef.IsDelegate)
                    {
                        name = "delegate";
                    }
                    else if (typeDef.IsEnumeration)
                    {
                        name = "enum";
                    }
                }
            }
            else if (member is EventDef)
            {
                name = "event";
            }
            else if (member is FieldDef)
            {
                name = "field";
                FieldDef fieldDef = (FieldDef)member;
                if (fieldDef.IsConstant)
                {
                    name = "constant";
                }
                else if (fieldDef.IsOperator)
                {
                    name = "operator";
                }
            }
            else if (member is MethodDef)
            {
                name = "method";
                MethodDef method = (MethodDef)member;
                if (method.IsOperator)
                {
                    name = "operator";
                }
                else if (method.IsConstructor)
                {
                    name = "constructor";
                }
            }
            else if (member is PropertyDef)
            {
                name = "properties";
            }

            return(name);
        }
示例#24
0
 /// <summary>
 /// Obtains the details of the type.
 /// </summary>
 /// <param name="member">The member to resolve against.</param>
 /// <returns>The details of the type having the specification.</returns>
 public TypeDetails GetTypeDetails(ReflectedMember member)
 {
     return(TypeToken.GetTypeDetails(member));
 }
 public bool Equals(ReflectedMember <T> x, ReflectedMember <T> y) =>
 x.Types.All(TypeConverter.NumericTypes.Contains) &&
 y.Types.All(TypeConverter.NumericTypes.Contains);
 public int GetHashCode(ReflectedMember <T> obj) => obj.GetHashCode();
示例#27
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="member"></param>
        /// <returns></returns>
        /// <remarks>
        /// The order in which the visibility modifiers are checked is important as
        /// they use the first 3 bits of the flag, and they can use the first bit to
        /// represent private and the 3 and 1st bit to represent public.
        /// </remarks>
        private static string GetIconPathFor(ReflectedMember member)
        {
            // NOTE: This code is duplicated in Documentation.Rendering.ReflectionHelper
            string name = string.Empty;

            if (member is AssemblyDef)
            {
                name = "assembly";
            }
            else if (member is TypeDef)
            {
                name = "class";
                TypeDef typeDef = (TypeDef)member;
                if (typeDef != null)
                {
                    if (typeDef.IsInterface)
                    {
                        name = "interface";
                    }
                    else if (typeDef.IsStructure)
                    {
                        name = "structure";
                    }
                    else if (typeDef.IsDelegate)
                    {
                        name = "delegate";
                    }
                    else if (typeDef.IsEnumeration)
                    {
                        name = "enum";
                    }
                }
            }
            else if (member is EventDef)
            {
                name = "event";
            }
            else if (member is FieldDef)
            {
                name = "field";
                FieldDef fieldDef = (FieldDef)member;
                if (fieldDef.IsConstant)
                {
                    name = "constant";
                }
                else if (fieldDef.IsOperator)
                {
                    name = "operator";
                }
            }
            else if (member is MethodDef)
            {
                name = "method";
                MethodDef method = (MethodDef)member;
                if (method.IsOperator)
                {
                    name = "operator";
                }
            }
            else if (member is PropertyDef)
            {
                name = "properties";
            }

            // add the visibility modifier
            if (member is TypeDef || member is EventDef || member is FieldDef || member is MethodDef || member is PropertyDef)
            {
                switch (member.MemberAccess)
                {
                case Visibility.Protected:
                    name += "_protected";
                    break;

                case Visibility.Internal:
                    name += "_sealed";
                    break;

                case Visibility.InternalProtected:
                    name += "_friend";
                    break;

                case Visibility.Private:
                    name += "_private";
                    break;

                case Visibility.Public:
                    break;
                }
            }

            // TODO: Handle namespaces and assemblies

            return(string.IsNullOrEmpty(name) ? string.Empty : string.Format(basePath, name));
        }