コード例 #1
0
        public string GetMethodComments(IMethodSymbol methodSymbol)
        {
            string xmlComments = string.Empty;

            try
            {
                if (methodSymbol.ReceiverType != null && methodSymbol.ReceiverType.IsType)
                {
                    ITypeSymbol receiverType = methodSymbol.ReceiverType;
                    //var containingAssembly = new AssemblyLoader().GetAssembly(methodSymbol.ContainingAssembly.Name);
                    //Type myType1 = containingAssembly.GetType(receiverType.ToString());
                    new TypeHelper().TryFindType(receiverType.ToMetadataName(), out var myType1);
                    var containingAssembly = myType1.Assembly;

                    var parameterTypes = new List <Type>();
                    foreach (var p in methodSymbol.Parameters)
                    {
                        Assembly parmContainingAssembly = new AssemblyLoader().GetAssembly(p.Type.ContainingAssembly.Name);
                        Type     parmType = parmContainingAssembly.GetType(p.Type.ToMetadataName());
                        parameterTypes.Add(parmType);
                    }

                    var reader = new XmlDocCommentReader(containingAssembly);

                    MethodInfo methodInfo = methodSymbol.IsGenericMethod ?
                                            myType1.GetGenericMethod(methodSymbol.Name, parameterTypes.ToArray())
                        : myType1.GetMethod(methodSymbol.Name, parameterTypes.ToArray());

                    if (methodSymbol.IsExtensionMethod && methodInfo == null)
                    {
                        var extensionsMethods = (from type in containingAssembly.GetTypes()
                                                 where type.IsSealed && !type.IsGenericType && !type.IsNested
                                                 from method in type.GetMethods(BindingFlags.Static
                                                                                | BindingFlags.Public | BindingFlags.NonPublic)
                                                 where method.IsDefined(typeof(ExtensionAttribute), false)
                                                 where method.GetParameters()[0].ParameterType.Name == methodSymbol.ReceiverType.BaseType.Name &&
                                                 methodSymbol.MetadataName == method.Name
                                                 select method).ToList();
                        methodInfo = extensionsMethods.Any() ? extensionsMethods.First() : null;
                    }
                    var test = reader.GetComments(methodInfo);

                    if (test != null)
                    {
                        xmlComments = test.Element("summary").Value.TrimStart(new[] { ' ', '\t', '\n' }).Replace(Environment.NewLine, " ");
                        xmlComments = Regex.Replace(xmlComments, @"\s+", " ");
                    }
                }
            }
            catch (Exception e)
            {
                xmlComments = e.Message;
            }

            return(xmlComments);
        }
コード例 #2
0
        public void GetComments_Method()
        {
            IFile fileProxy = MockRepository.GenerateMock <IFile>();
            IXmlDocCommentReadPolicy readPolicy = MockRepository.GenerateMock <IXmlDocCommentReadPolicy>();

            MethodInfo expectedMethod   = MethodInfo.GetCurrentMethod() as MethodInfo;
            XElement   expectedComments = new XElement("comments");

            fileProxy.Expect(fp => fp.Exists(String.Empty)).Return(true);
            readPolicy.Expect(rp => rp.ReadMember(Convert.ToXmlDocCommentMember(expectedMethod))).Return(expectedComments);

            XmlDocCommentReader reader = new XmlDocCommentReader(String.Empty, fileProxy, readPolicy);

            Assert.That(reader.GetComments(expectedMethod), Is.SameAs(expectedComments));

            fileProxy.VerifyAllExpectations();
            readPolicy.VerifyAllExpectations();
        }
コード例 #3
0
        public void GetComments_Property()
        {
            IFile fileProxy = MockRepository.GenerateMock <IFile>();
            IXmlDocCommentReadPolicy readPolicy = MockRepository.GenerateMock <IXmlDocCommentReadPolicy>();

            PropertyInfo expectedProperty = typeof(Array).GetProperty("Length");
            XElement     expectedComments = new XElement("comments");

            fileProxy.Expect(fp => fp.Exists(String.Empty)).Return(true);
            readPolicy.Expect(rp => rp.ReadMember(Convert.ToXmlDocCommentMember(expectedProperty))).Return(expectedComments);

            XmlDocCommentReader reader = new XmlDocCommentReader(String.Empty, fileProxy, readPolicy);

            Assert.That(reader.GetComments(expectedProperty), Is.SameAs(expectedComments));

            fileProxy.VerifyAllExpectations();
            readPolicy.VerifyAllExpectations();
        }
コード例 #4
0
        public void GetComments_Field()
        {
            IFile fileProxy = MockRepository.GenerateMock <IFile>();
            IXmlDocCommentReadPolicy readPolicy = MockRepository.GenerateMock <IXmlDocCommentReadPolicy>();

            FieldInfo expectedField    = typeof(Int32).GetField("MaxValue", BindingFlags.Public | BindingFlags.Static);
            XElement  expectedComments = new XElement("comments");

            fileProxy.Expect(fp => fp.Exists(String.Empty)).Return(true);
            readPolicy.Expect(rp => rp.ReadMember(Convert.ToXmlDocCommentMember(expectedField))).Return(expectedComments);

            XmlDocCommentReader reader = new XmlDocCommentReader(String.Empty, fileProxy, readPolicy);

            Assert.That(reader.GetComments(expectedField), Is.SameAs(expectedComments));

            fileProxy.VerifyAllExpectations();
            readPolicy.VerifyAllExpectations();
        }
コード例 #5
0
        public void GetComments_Event()
        {
            IFile fileProxy = MockRepository.GenerateMock <IFile>();
            IXmlDocCommentReadPolicy readPolicy = MockRepository.GenerateMock <IXmlDocCommentReadPolicy>();

            EventInfo expectedEvent    = typeof(Console).GetEvent("CancelKeyPress");
            XElement  expectedComments = new XElement("comments");

            fileProxy.Expect(fp => fp.Exists(String.Empty)).Return(true);
            readPolicy.Expect(rp => rp.ReadMember(Convert.ToXmlDocCommentMember(expectedEvent))).Return(expectedComments);

            XmlDocCommentReader reader = new XmlDocCommentReader(String.Empty, fileProxy, readPolicy);

            Assert.That(reader.GetComments(expectedEvent), Is.SameAs(expectedComments));

            fileProxy.VerifyAllExpectations();
            readPolicy.VerifyAllExpectations();
        }
コード例 #6
0
        public string GetMethodComments(IMethodSymbol methodSymbol)
        {
            string xmlComments = String.Empty;

            try
            {
                if (methodSymbol.ReceiverType != null && methodSymbol.ReceiverType.IsType)
                {
                    ITypeSymbol receiverType = methodSymbol.ReceiverType;
                    //var containingAssembly = new AssemblyLoader().GetAssembly(methodSymbol.ContainingAssembly.Name);
                    //Type myType1 = containingAssembly.GetType(receiverType.ToString());
                    Type myType1;
                    new TypeHelper().TryFindType(receiverType.ToMetadataName(), out myType1);
                    var containingAssembly = myType1.Assembly;

                    var parameterTypes = new List <Type>();
                    foreach (var p in methodSymbol.Parameters)
                    {
                        Assembly parmContainingAssembly = new AssemblyLoader().GetAssembly(p.Type.ContainingAssembly.Name);
                        Type     parmType = parmContainingAssembly.GetType(p.Type.ToMetadataName());
                        parameterTypes.Add(parmType);
                    }

                    var reader = new XmlDocCommentReader(containingAssembly);

                    MethodInfo methodInfo = methodSymbol.IsGenericMethod ?
                                            myType1.GetGenericMethod(methodSymbol.Name, parameterTypes.ToArray())
                        : myType1.GetMethod(methodSymbol.Name, parameterTypes.ToArray());
                    var test = reader.GetComments(methodInfo);

                    xmlComments = test.Element("summary").Value.TrimStart(new[] { ' ', '\t', '\n' }).Replace(System.Environment.NewLine, " ");
                    xmlComments = Regex.Replace(xmlComments, @"\s+", " ");
                }
            }
            catch (Exception e)
            {
                xmlComments = e.Message;
            }

            return(xmlComments);
        }
コード例 #7
0
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
        public XElement GetComments(Type type) => _proxy.GetComments(type);
コード例 #8
0
        public void GetComments_Type()
        {
            IFile fileProxy = MockRepository.GenerateMock<IFile>();
            IXmlDocCommentReadPolicy readPolicy = MockRepository.GenerateMock<IXmlDocCommentReadPolicy>();

            Type expectedType = GetType();
            XElement expectedComments = new XElement("comments");

            fileProxy.Expect(fp => fp.Exists(String.Empty)).Return(true);
            readPolicy.Expect(rp => rp.ReadMember(Convert.ToXmlDocCommentMember(expectedType))).Return(expectedComments);

            XmlDocCommentReader reader = new XmlDocCommentReader(String.Empty, fileProxy, readPolicy);
            Assert.That(reader.GetComments(expectedType), Is.SameAs(expectedComments));

            fileProxy.VerifyAllExpectations();
            readPolicy.VerifyAllExpectations();
        }
コード例 #9
0
        public void GetComments_Field()
        {
            IFile fileProxy = MockRepository.GenerateMock<IFile>();
            IXmlDocCommentReadPolicy readPolicy = MockRepository.GenerateMock<IXmlDocCommentReadPolicy>();

            FieldInfo expectedField = typeof(Int32).GetField("MaxValue", BindingFlags.Public | BindingFlags.Static);
            XElement expectedComments = new XElement("comments");

            fileProxy.Expect(fp => fp.Exists(String.Empty)).Return(true);
            readPolicy.Expect(rp => rp.ReadMember(Convert.ToXmlDocCommentMember(expectedField))).Return(expectedComments);

            XmlDocCommentReader reader = new XmlDocCommentReader(String.Empty, fileProxy, readPolicy);
            Assert.That(reader.GetComments(expectedField), Is.SameAs(expectedComments));

            fileProxy.VerifyAllExpectations();
            readPolicy.VerifyAllExpectations();
        }
コード例 #10
0
        public void GetComments_Event()
        {
            IFile fileProxy = MockRepository.GenerateMock<IFile>();
            IXmlDocCommentReadPolicy readPolicy = MockRepository.GenerateMock<IXmlDocCommentReadPolicy>();

            EventInfo expectedEvent = typeof(Console).GetEvent("CancelKeyPress");
            XElement expectedComments = new XElement("comments");

            fileProxy.Expect(fp => fp.Exists(String.Empty)).Return(true);
            readPolicy.Expect(rp => rp.ReadMember(Convert.ToXmlDocCommentMember(expectedEvent))).Return(expectedComments);

            XmlDocCommentReader reader = new XmlDocCommentReader(String.Empty, fileProxy, readPolicy);
            Assert.That(reader.GetComments(expectedEvent), Is.SameAs(expectedComments));

            fileProxy.VerifyAllExpectations();
            readPolicy.VerifyAllExpectations();
        }
コード例 #11
0
ファイル: DocParser.cs プロジェクト: msawczyn/autohelp
        private void FindTypes(Assembly assembly, List <Namespace> namespaces)
        {
            var typesInAsm = assembly.GetLoadableTypes().Where(p => p.IsPublic || p.IsNestedPublic || p.IsVisible).ToArray();

            foreach (var type in typesInAsm)
            {
                try
                {
                    // The namespace is everything before this type name, e.g. [Docy.Core].XYZ
                    string typeNamespace = type.Namespace;

                    var nameSpace = namespaces.FirstOrDefault(n => n.Name == typeNamespace);
                    if (nameSpace == null)
                    {
                        nameSpace = new Namespace {
                            Name = typeNamespace
                        };
                        namespaces.Add(nameSpace);
                    }

                    // Comments
                    var element  = _reader.GetComments(type);
                    var comments = GetCommonTags(element);

                    var typeBase = new TypeBase
                    {
                        Namespace   = nameSpace,
                        IsAbstract  = type.IsAbstract,
                        IsPrimitive = type.IsPrimitive,
                        IsPublic    = type.IsPublic,
                        IsSealed    = type.IsSealed,
                        IsNested    = type.IsNested,
                        ParentClass = type.BaseType != null ? type.BaseType.FullName : "",
                        Parents     = GetParents(type),
                        Name        = GetTypeName(type),
                        Fullname    = GetFullTypeName(type),
                        Example     = comments.Example,
                        Remarks     = comments.Remarks,
                        Returns     = comments.Returns,
                        Summary     = comments.Summary
                    };

                    typeBase.Constructors = GetConstructors(type, typeBase);
                    typeBase.Methods      = GetMethods(type, typeBase);
                    typeBase.Properties   = GetProperties(type, typeBase);

                    if (type.IsClass)
                    {
                        if (type.BaseType != null && type.BaseType == typeof(Delegate) || type.BaseType == typeof(MulticastDelegate))
                        {
                            typeBase.ObjectType = "Delegate";
                            nameSpace.Delegates.Add(typeBase);
                        }
                        else
                        {
                            typeBase.ObjectType = "Class";
                            nameSpace.Classes.Add(typeBase);
                        }
                    }
                    else if (type.IsEnum)
                    {
                        typeBase.ObjectType = "Enumeration";
                        typeBase.Members    = GetMembers(type);
                        nameSpace.Enumerations.Add(typeBase);
                    }
                    else if (type.IsValueType)
                    {
                        typeBase.ObjectType = "Structure";
                        nameSpace.Structures.Add(typeBase);
                    }
                    else if (type.IsInterface)
                    {
                        typeBase.ObjectType = "Interface";
                        nameSpace.Interfaces.Add(typeBase);
                    }
                    else
                    {
                        typeBase.ObjectType = "Delegate";
                        // TODO: Find out how to get delegate types
                        nameSpace.Delegates.Add(typeBase);
                    }
                }
                catch (Exception ex)
                {
                    Trace.TraceError("Type {0} : Parse Problem. {1} => {2}", type, ex.Message, ex.Source);
                }
            }
        }
コード例 #12
0
 public XElement GetComments(Type type)
 {
     return(_proxy.GetComments(type));
 }