Ejemplo n.º 1
0
        protected static DeclaredType FindType(IDocumentationMember association, List <Namespace> namespaces)
        {
            var typeName   = IdentifierFor.Type(association.TargetType);
            var identifier = IdentifierFor.Namespace(association.TargetType.Namespace);

            return(namespaces.Find(x => x.IsIdentifiedBy(identifier)).Types.FirstOrDefault(x => x.IsIdentifiedBy(typeName)));
        }
Ejemplo n.º 2
0
        public void Add(List <Namespace> namespaces, DocumentedEnum association)
        {
            if (association.Member == null)
            {
                return;
            }

            DeclaredType type = FindType(association, namespaces);

            var doc = Enumeration.Unresolved(
                IdentifierFor.Enum(association.Member, association.TargetType), type);

            //var evalue = Enum.Parse(association.Value.GetType(), association.Value.ToString());
            if (association.Value is uint)
            {
                doc.EnumValue = "0x" + ((uint)association.Value).ToString("X");
            }
            if (association.Value is int)
            {
                doc.EnumValue = ((int)association.Value).ToString();
            }

            ParseSummary(association, doc);
            ParseRemarks(association, doc);
            ParseExample(association, doc);

            _matchedAssociations[association.Name] = doc;
            type.AddEnum(doc);
        }
Ejemplo n.º 3
0
        public static DeclaredType Unresolved(TypeIdentifier typeIdentifier, Type declaration, Namespace ns)
        {
            var declaredType = new DeclaredType(typeIdentifier, ns)
            {
                IsResolved = false, declaration = declaration
            };

            if (declaration.BaseType != null)
            {
                declaredType.ParentType = Unresolved(
                    IdentifierFor.Type(declaration.BaseType),
                    declaration.BaseType,
                    Namespace.Unresolved(IdentifierFor.Namespace(declaration.BaseType.Namespace)));
            }

            IEnumerable <Type> interfaces = GetInterfaces(declaration);

            foreach (Type face in interfaces)
            {
                declaredType.Interfaces.Add(
                    Unresolved(IdentifierFor.Type(face), face, Namespace.Unresolved(IdentifierFor.Namespace(face.Namespace))));
            }

            return(declaredType);
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            var  rnd = new Random();
            long carId, empId;

            carId = empId = rnd.Next();

            IdentifierFor <Employee> employeeIdentifier = (empId);

            employeeIdentifier = (Guid.NewGuid());

            var carIdentifier = new IdentifierFor <Car>(carId);

            var carwash = new Carwash();

            carwash.Hire(employeeIdentifier);

            carwash.Assign(empId, carId);
            carwash.Assign(carId, empId);

            Console.WriteLine(employeeIdentifier);
            Console.WriteLine((long)employeeIdentifier);

            Console.WriteLine(carIdentifier);
            Console.WriteLine((long)carIdentifier);

            Console.WriteLine(employeeIdentifier.Equals(employeeIdentifier));

            Console.WriteLine(employeeIdentifier.Equals(carIdentifier));

            Console.WriteLine(employeeIdentifier == employeeIdentifier);

            // Console.ReadLine();
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        static DeclaredType to_type_in_namespace(this Type type, Namespace ns)
        {
            var declaredType = new DeclaredType(IdentifierFor.Type(type), ns);

            ns.AddType(declaredType);

            return(declaredType);
        }
Ejemplo n.º 7
0
        public void should_parse_argument_list_with_generic_of_generic()
        {
            var input         = "System.Linq.Expressions.Expression{System.Func{``0,System.Object}}";
            var parameterList = IdentifierFor.ExtractMethodArgumentTypes(input).ToArray();

            parameterList.Length.ShouldEqual(1);
            parameterList[0].ShouldEqual("System.Linq.Expressions.Expression{System.Func{``0,System.Object}}");
        }
Ejemplo n.º 8
0
        protected DeclaredType Type <T>(Namespace ns)
        {
            var type = new DeclaredType(IdentifierFor.Type(typeof(T)), ns);

            ns.AddType(type);

            return(type);
        }
Ejemplo n.º 9
0
        public void should_parse_argument_list_with_single_nongeneric()
        {
            var input         = "System.Int32";
            var parameterList = IdentifierFor.ExtractMethodArgumentTypes(input);

            parameterList.Count().ShouldEqual(1);
            parameterList.First().ShouldEqual("System.Int32");
        }
Ejemplo n.º 10
0
        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));
                    }
                }
            }
        }
Ejemplo n.º 11
0
        public void should_parse_argument_list_with_multiple_nongenerics()
        {
            var input         = "System.Int32,System.String";
            var parameterList = IdentifierFor.ExtractMethodArgumentTypes(input).ToArray();

            parameterList.Length.ShouldEqual(2);
            parameterList[0].ShouldEqual("System.Int32");
            parameterList[1].ShouldEqual("System.String");
        }
Ejemplo n.º 12
0
        public void should_parse_argument_list_with_generic_with_multiple_arguments()
        {
            var input         = "Foo{``0,``1},Bar{``1}";
            var parameterList = IdentifierFor.ExtractMethodArgumentTypes(input).ToArray();

            parameterList.Length.ShouldEqual(2);
            parameterList[0].ShouldEqual("Foo{``0,``1}");
            parameterList[1].ShouldEqual("Bar{``1}");
        }
Ejemplo n.º 13
0
        public void should_parse_argument_list_with_two_out_parameters()
        {
            var input         = "System.Int32@,System.Double@";
            var parameterList = IdentifierFor.ExtractMethodArgumentTypes(input).ToArray();

            parameterList.Length.ShouldEqual(2);
            parameterList[0].ShouldEqual("System.Int32");
            parameterList[1].ShouldEqual("System.Double");
        }
        private IDocumentationMember find_member <T>(Expression <Func <T, object> > propertyOrField)
        {
            var member = ((MemberExpression)propertyOrField.Body).Member;

            if (member is PropertyInfo)
            {
                return(members.FirstOrDefault(x => x.Name == IdentifierFor.Property((PropertyInfo)member, typeof(T))));
            }

            return(members.FirstOrDefault(x => x.Name == IdentifierFor.Field((FieldInfo)member, typeof(T))));
        }
Ejemplo n.º 15
0
        public void should_match_type()
        {
            var undocumentedMembers = DocumentableMemberFinder.ReflectMembersForDocumenting(new[] { typeof(First), typeof(Second), typeof(Third) });
            var snippets            = new[] { @"<member name=""T:Example.Second"" />".ToNode() };
            var members             = DocumentationXmlMatcher.MatchDocumentationToMembers(undocumentedMembers, snippets);

            var member = members.FirstOrDefault(x => x.Name == IdentifierFor.Type(typeof(Second))) as DocumentedType;

            member.ShouldNotBeNull();
            member.Xml.ShouldEqual(snippets[0]);
            member.TargetType.ShouldEqual(typeof(Second));
        }
Ejemplo n.º 16
0
        public void should_match_type_with_multiple_generic_arguments()
        {
            var undocumentedMembers = DocumentableMemberFinder.ReflectMembersForDocumenting(new[] { typeof(First), typeof(GenericDefinition <>), typeof(GenericDefinition <,>) });
            var snippets            = new[] { @"<member name=""T:Example.GenericDefinition`2"" />".ToNode() };
            var members             = DocumentationXmlMatcher.MatchDocumentationToMembers(undocumentedMembers, snippets);

            var member = members.FirstOrDefault(x => x.Name == IdentifierFor.Type(typeof(GenericDefinition <,>))) as DocumentedType;

            member.ShouldNotBeNull();
            member.Xml.ShouldEqual(snippets[0]);
            member.TargetType.ShouldEqual(typeof(GenericDefinition <,>));
        }
Ejemplo n.º 17
0
        public void should_match_event()
        {
            var undocumentedMembers = DocumentableMemberFinder.ReflectMembersForDocumenting(new[] { typeof(First), typeof(Second), typeof(Third) });
            var snippets            = new[] { @"<member name=""E:Example.Second.AnEvent"" />".ToNode() };
            var members             = DocumentationXmlMatcher.MatchDocumentationToMembers(undocumentedMembers, snippets);
            var ev = Event <Second>("AnEvent");

            var member = members.FirstOrDefault(x => x.Name == IdentifierFor.Event(ev, typeof(Second))) as DocumentedEvent;

            member.ShouldNotBeNull();
            member.Xml.ShouldEqual(snippets[0]);
            member.Event.ShouldEqual(ev);
        }
Ejemplo n.º 18
0
        static void MatchMethod(List <IDocumentationMember> members, XmlNode node)
        {
            Identifier member = IdentifierFor.XmlString(node.Attributes["name"].Value);

            for (int i = 0; i < members.Count; i++)
            {
                var reflected = members[i] as ReflectedMethod;
                if (reflected != null && reflected.Match(member))
                {
                    members[i] = new DocumentedMethod(reflected.Name, node, reflected.Method, reflected.TargetType);
                }
            }
        }
Ejemplo n.º 19
0
        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);
        }
Ejemplo n.º 20
0
        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);
        }
Ejemplo n.º 21
0
        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);
        }
Ejemplo n.º 22
0
        public void ShouldBuildNamespaces()
        {
            var model   = new DocumentationModelBuilder(StubParser, new EventAggregator());
            var members = new[]
            {
                Type <First>(@"<member name=""T:Example.First"" />"),
                Type <DeepFirst>(@"<member name=""T:Example.Deep.DeepFirst"" />"),
            };
            var namespaces = model.CombineToTypeHierarchy(members);

            namespaces.ShouldContain(x => x.IsIdentifiedBy(IdentifierFor.Namespace("Example")));
            namespaces.ShouldContain(x => x.IsIdentifiedBy(IdentifierFor.Namespace("Example.Deep")));
        }
Ejemplo n.º 23
0
        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);
        }
Ejemplo n.º 24
0
        public void should_match_property()
        {
            var undocumentedMembers = DocumentableMemberFinder.ReflectMembersForDocumenting(new[] { typeof(First), typeof(Second), typeof(Third) });
            var snippets            = new[] { @"<member name=""P:Example.Second.SecondProperty"" />".ToNode() };
            var members             = DocumentationXmlMatcher.MatchDocumentationToMembers(undocumentedMembers, snippets);
            var property            = Property <Second>(x => x.SecondProperty);

            var member = members.FirstOrDefault(x => x.Name == IdentifierFor.Property(property, typeof(Second))) as DocumentedProperty;

            member.ShouldNotBeNull();
            member.Xml.ShouldEqual(snippets[0]);
            member.Property.ShouldEqual <Second>(x => x.SecondProperty);
        }
Ejemplo n.º 25
0
        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));
        }
Ejemplo n.º 26
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);
        }
Ejemplo n.º 27
0
        public void ShouldHaveEventsInTypes()
        {
            var model   = new DocumentationModelBuilder(StubParser, new EventAggregator());
            var members = new IDocumentationMember[]
            {
                Type <Second>(@"<member name=""T:Example.Second"" />"),
                Event <Second>(@"<member name=""E:Example.Second.AnEvent"" />", "AnEvent"),
            };
            var namespaces = model.CombineToTypeHierarchy(members);
            var ev         = typeof(Second).GetEvent("AnEvent");

            namespaces[0].Types[0].Events.ShouldContain(x => x.IsIdentifiedBy(IdentifierFor.Event(ev, typeof(Second))));
        }
Ejemplo n.º 28
0
        public void ShouldHaveEventsInTypes()
        {
            var model   = new DocumentationModelBuilder(StubParser, new EventAggregator());
            var members = new IDocumentationMember[]
            {
                Type <Second>(@"<member name=""T:Example.Second"" />"),
                Field <Second>(@"<member name=""F:Example.Second.aField"" />", x => x.aField),
            };
            var namespaces = model.CombineToTypeHierarchy(members);
            var field      = Field <Second>(x => x.aField);

            namespaces[0].Types[0].Fields
            .ShouldContain(x => x.IsIdentifiedBy(IdentifierFor.Field(field, typeof(Second))));
        }
Ejemplo n.º 29
0
        static void MatchType(List <IDocumentationMember> members, XmlNode node)
        {
            var identifier = IdentifierFor.XmlString(node.Attributes["name"].Value);
            var positionOfUndocumentedType = members.FindIndex(m =>
            {
                var reflected = m as ReflectedType;
                return(reflected != null && reflected.Match(identifier));
            });

            if (positionOfUndocumentedType >= 0)
            {
                members[positionOfUndocumentedType] = new DocumentedType(identifier, node, members[positionOfUndocumentedType].TargetType);
            }
        }
Ejemplo n.º 30
0
        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();
        }