public void Add(List <Namespace> namespaces, DocumentedMethod association) { if (association.Method == null) { return; } DeclaredType type = FindType(association, namespaces); DeclaredType methodReturnType = null; if (association.Method.MemberType == MemberTypes.Method) { methodReturnType = DeclaredType.Unresolved( IdentifierFor.Type(((MethodInfo)association.Method).ReturnType), ((MethodInfo)association.Method).ReturnType, Namespace.Unresolved(IdentifierFor.Namespace(((MethodInfo)association.Method).ReturnType.Namespace))); } Method doc = Method.Unresolved( IdentifierFor.Method(association.Method, association.TargetType), type, association.Method, methodReturnType); ParseSummary(association, doc); ParseRemarks(association, doc); ParseValue(association, doc); ParseReturns(association, doc); ParseExample(association, doc); foreach (ParameterInfo parameter in association.Method.GetParameters()) { DeclaredType reference = DeclaredType.Unresolved( IdentifierFor.Type(parameter.ParameterType), parameter.ParameterType, Namespace.Unresolved(IdentifierFor.Namespace(parameter.ParameterType.Namespace))); var docParam = new MethodParameter(parameter.Name, parameter.IsOptional, parameter.DefaultValue, reference); ParseParamSummary(association, docParam); doc.AddParameter(docParam); } if (_matchedAssociations.ContainsKey(association.Name)) { return; // weird case when a type has the same method declared twice } _matchedAssociations.Add(association.Name, doc); if (type == null) { return; } type.AddMethod(doc); }
public static IEnumerable <IDocumentationMember> ReflectMembersForDocumenting(IEnumerable <Type> types) { foreach (var type in types) { if (type.IsSpecialName) { continue; } if (type.Name.StartsWith("__")) { continue; // probably a lambda generated class } yield return(new ReflectedType(IdentifierFor.Type(type), type)); foreach (var method in type.GetMethods()) { if (method.IsSpecialName || (method.DeclaringType != null && method.DeclaringType.Name.Equals("Object"))) { continue; //skip object base methods and special names } yield return(new ReflectedMethod(IdentifierFor.Method(method, type), method, type)); } foreach (var constructor in type.GetConstructors()) { yield return(new ReflectedMethod(IdentifierFor.Method(constructor, type), constructor, type)); } foreach (var property in type.GetProperties(BindingFlags.Static | BindingFlags.Public)) { yield return(new ReflectedProperty(IdentifierFor.Property(property, type, true), property, type, true)); } foreach (var property in type.GetProperties(BindingFlags.Instance | BindingFlags.Public)) { yield return(new ReflectedProperty(IdentifierFor.Property(property, type, false), property, type, false)); } foreach (var ev in type.GetEvents()) { yield return(new ReflectedEvent(IdentifierFor.Event(ev, type), ev, type)); } if (type.IsEnum) { foreach (var member in type.GetMembers(BindingFlags.Static | BindingFlags.Public)) { yield return(new ReflectedEnum(IdentifierFor.Enum(member, type), member, type)); } } else { foreach (var field in type.GetFields()) { yield return(new ReflectedField(IdentifierFor.Field(field, type), field, type)); } } } }
public void should_match_method_with_parameters() { var undocumentedMembers = DocumentableMemberFinder.ReflectMembersForDocumenting(new[] { typeof(First), typeof(Second), typeof(Third) }); var snippets = new[] { @"<member name=""M:Example.Second.SecondMethod2(System.String,System.Int32)"" />".ToNode() }; var members = DocumentationXmlMatcher.MatchDocumentationToMembers(undocumentedMembers, snippets); var method = Method <Second>(x => x.SecondMethod2(null, 0)); var member = members.FirstOrDefault(x => x.Name == IdentifierFor.Method(method, typeof(Second))) as DocumentedMethod; member.ShouldNotBeNull(); member.Xml.ShouldEqual(snippets[0]); ((MethodInfo)member.Method).ShouldEqual <Second>(x => x.SecondMethod2("", 0)); }
public void should_match_method_with_array_parameter() { var undocumentedMembers = DocumentableMemberFinder.ReflectMembersForDocumenting(new[] { typeof(ClassWithOverload) }); var snippets = new[] { @"<member name=""M:Example.ClassWithOverload.MethodWithArray(System.String[])"" />".ToNode() }; var members = DocumentationXmlMatcher.MatchDocumentationToMembers(undocumentedMembers, snippets); var method = Method <ClassWithOverload>(x => x.MethodWithArray(null)); var member = members.FirstOrDefault(x => x.Name == IdentifierFor.Method(method, typeof(ClassWithOverload))) as DocumentedMethod; member.ShouldNotBeNull(); member.Xml.ShouldEqual(snippets[0]); member.Method.ShouldEqual(method); }
public void should_match_generic_method_having_multiple_generic_arguments_which_are_used_by_a_generic_parameter() { var undocumentedMembers = DocumentableMemberFinder.ReflectMembersForDocumenting(new[] { typeof(HasGenericMethods) }); var snippets = new[] { @"<member name=""M:Example.HasGenericMethods.DoWithLookup``2(System.Collections.Generic.IDictionary{``0,``1},``0)"" />".ToNode() }; var members = DocumentationXmlMatcher.MatchDocumentationToMembers(undocumentedMembers, snippets); var method = Method <HasGenericMethods>(x => x.DoWithLookup <string, string>(null, null)); var member = members.FirstOrDefault(x => x.Name == IdentifierFor.Method(method, typeof(HasGenericMethods))) as DocumentedMethod; member.ShouldNotBeNull(); member.Xml.ShouldEqual(snippets[0]); member.Method.ShouldBeSameAs(method); }
public void should_match_generic_method_having_generic_parameter_which_has_type_defined_by_another_generic_type() { var undocumentedMembers = DocumentableMemberFinder.ReflectMembersForDocumenting(new[] { typeof(HasGenericMethods) }); var snippets = new[] { @"<member name=""M:Example.HasGenericMethods.Evaluate``1(System.Collections.Generic.IDictionary{System.String,System.Linq.Expressions.Expression{System.Func{``0,System.Object}}},System.Int32)"" />".ToNode() }; var members = DocumentationXmlMatcher.MatchDocumentationToMembers(undocumentedMembers, snippets); var method = Method <HasGenericMethods>(x => x.Evaluate <string>(null, 0)); var member = members.FirstOrDefault(x => x.Name == IdentifierFor.Method(method, typeof(HasGenericMethods))) as DocumentedMethod; member.ShouldNotBeNull(); member.Xml.ShouldEqual(snippets[0]); member.Method.ShouldBeSameAs(method); }
public void should_match_generic_method_having_generic_parameter() { var undocumentedMembers = DocumentableMemberFinder.ReflectMembersForDocumenting(new[] { typeof(HasGenericMethods) }); var snippets = new[] { @"<member name=""M:Example.HasGenericMethods.Do``1(``0)"" />".ToNode() }; var members = DocumentationXmlMatcher.MatchDocumentationToMembers(undocumentedMembers, snippets); var method = typeof(HasGenericMethods).GetMethod("Do"); var member = members.FirstOrDefault(x => x.Name == IdentifierFor.Method(method, typeof(HasGenericMethods))) as DocumentedMethod; member.ShouldNotBeNull(); member.Xml.ShouldEqual(snippets[0]); member.Method.ShouldBeSameAs(method); }
public void should_match_generic_method_on_a_generic_type_having_a_different_generic_argument() { var undocumentedMembers = DocumentableMemberFinder.ReflectMembersForDocumenting(new[] { typeof(First), typeof(GenericDefinition <>), typeof(GenericDefinition <,>) }); var snippets = new[] { @"<member name=""M:Example.GenericDefinition`1.BMethod``1"" />".ToNode() }; var members = DocumentationXmlMatcher.MatchDocumentationToMembers(undocumentedMembers, snippets); var method = typeof(GenericDefinition <>).GetMethod("BMethod"); var member = members.FirstOrDefault(x => x.Name == IdentifierFor.Method(method, typeof(GenericDefinition <>))) as DocumentedMethod; member.ShouldNotBeNull(); member.Xml.ShouldEqual(snippets[0]); member.Method.ShouldBeSameAs(method); }
public void should_match_nongeneric_method_on_a_generic_type() { var undocumentedMembers = DocumentableMemberFinder.ReflectMembersForDocumenting(new[] { typeof(First), typeof(GenericDefinition <>), typeof(GenericDefinition <,>) }); var snippets = new[] { @"<member name=""M:Example.GenericDefinition`1.AMethod"" />".ToNode() }; var members = DocumentationXmlMatcher.MatchDocumentationToMembers(undocumentedMembers, snippets); var method = Method <GenericDefinition <object> >(x => x.AMethod()); var member = members.FirstOrDefault(x => x.Name == IdentifierFor.Method(method, typeof(GenericDefinition <>))) as DocumentedMethod; member.ShouldNotBeNull(); member.Xml.ShouldEqual(snippets[0]); member.Method.Name.ShouldEqual("AMethod"); member.Method.IsGenericMethod.ShouldBeFalse(); }
public void ShouldHaveMethodsInTypes() { var model = new DocumentationModelBuilder(StubParser, new EventAggregator()); var members = new IDocumentationMember[] { Type <Second>(@"<member name=""T:Example.Second"" />"), Method <Second>(@"<member name=""M:Example.Second.SecondMethod"" />", x => x.SecondMethod()), Method <Second>(@"<member name=""M:Example.Second.SecondMethod2(System.String,System.Int32)"" />", x => x.SecondMethod2(null, 0)) }; var namespaces = model.CombineToTypeHierarchy(members); var method = Method <Second>(x => x.SecondMethod()); var method2 = Method <Second>(x => x.SecondMethod2(null, 0)); namespaces[0].Types[0].Methods .ShouldContain(x => x.IsIdentifiedBy(IdentifierFor.Method(method, typeof(Second)))) .ShouldContain(x => x.IsIdentifiedBy(IdentifierFor.Method(method2, typeof(Second)))); }
public static IEnumerable <IDocumentationMember> ReflectMembersForDocumenting(IEnumerable <Type> types) { foreach (var type in types) { if (type.IsSpecialName) { continue; } if (type.Name.StartsWith("__")) { continue; // probably a lambda generated class } yield return(new ReflectedType(IdentifierFor.Type(type), type)); foreach (var method in type.GetMethods()) { if (method.IsSpecialName) { continue; } yield return(new ReflectedMethod(IdentifierFor.Method(method, type), method, type)); } foreach (var constructor in type.GetConstructors()) { yield return(new ReflectedMethod(IdentifierFor.Method(constructor, type), constructor, type)); } foreach (var property in type.GetProperties()) { yield return(new ReflectedProperty(IdentifierFor.Property(property, type), property, type)); } foreach (var ev in type.GetEvents()) { yield return(new ReflectedEvent(IdentifierFor.Event(ev, type), ev, type)); } foreach (var field in type.GetFields()) { yield return(new ReflectedField(IdentifierFor.Field(field, type), field, type)); } } }
protected DocumentedMethod Method <T>(string xml, Expression <Action <T> > methodAction) { var method = ((MethodCallExpression)methodAction.Body).Method; return(new DocumentedMethod(IdentifierFor.Method(method, typeof(T)), xml.ToNode(), method, typeof(T))); }
protected static Method Method <T>(string name) { return(new Method(IdentifierFor.Method(typeof(T).GetMethod(name), typeof(T)), Type <T>())); }
public static Method method_for <T>(this T instance, Expression <Action <T> > method_signature) { return(new Method(IdentifierFor.Method(Method(method_signature), typeof(T)), null)); }
private IDocumentationMember find_member <T>(string methodName) { var method = typeof(T).GetMethod(methodName); return(members.FirstOrDefault(x => x.Name == IdentifierFor.Method(method, typeof(T)))); }
private IDocumentationMember find_member <T>(Expression <Action> methodAction) { var method = ((MethodCallExpression)methodAction.Body).Method; return(members.FirstOrDefault(x => x.Name == IdentifierFor.Method(method, typeof(T)))); }