Exemple #1
0
        public void GetMemberSignature_Property()
        {
            var propertyInfo   = typeof(MemberSignatureTestClass).GetProperty("ProtectedProperty", BindingFlags.Instance | BindingFlags.NonPublic);
            var output         = _memberSignatureUtility.GetMemberSignature(propertyInfo);
            var expectedOutput = _outputFormatter.CreatePropertyMarkup(propertyInfo.Name, propertyInfo.PropertyType);

            Assert.That(output.ToString(), Is.EqualTo(expectedOutput.ToString()));
        }
        public void GenerateXml_PropertyWithGetAndSet_Overridden()
        {
            var reportGenerator = CreateMemberReportGenerator(typeof(ClassWithProperty), new InvolvedType(typeof(ClassWithProperty)));
            var property        = typeof(ClassWithProperty).GetProperty("PropertyName");
            var output          = reportGenerator.GenerateXml();

            var expectedOutput = new XElement(
                "Members",
                new XElement(
                    "Member",
                    new XAttribute("id", "0"),
                    new XAttribute("type", MemberTypes.Constructor),
                    new XAttribute("name", ".ctor"),
                    new XAttribute("is-declared-by-this-class", true),
                    _outputFormatter.CreateModifierMarkup("", "public"),
                    _outputFormatter.CreateConstructorMarkup("ClassWithProperty", new ParameterInfo[0])
                    ),
                new XElement(
                    "Member",
                    new XAttribute("id", "1"),
                    new XAttribute("type", MemberTypes.Method),
                    new XAttribute("name", "DoSomething"),
                    new XAttribute("is-declared-by-this-class", true),
                    _outputFormatter.CreateModifierMarkup("", "public override"),
                    _outputFormatter.CreateMethodMarkup("DoSomething", typeof(void), new ParameterInfo[0])
                    ),
                new XElement(
                    "Member",
                    new XAttribute("id", "2"),
                    new XAttribute("type", MemberTypes.Property),
                    new XAttribute("name", "PropertyName"),
                    new XAttribute("is-declared-by-this-class", true),
                    _outputFormatter.CreateModifierMarkup("", "public override"),
                    _outputFormatter.CreatePropertyMarkup("PropertyName", typeof(string)),
                    new XElement(
                        "SubMember",
                        new XAttribute("id", "3"),
                        new XAttribute("type", MemberTypes.Method),
                        new XAttribute("name", "get_PropertyName"),
                        _outputFormatter.CreateModifierMarkup("", "public override"),
                        _outputFormatter.CreateMethodMarkup("get_PropertyName", typeof(string), new ParameterInfo[0])
                        ),
                    new XElement(
                        "SubMember",
                        new XAttribute("id", "4"),
                        new XAttribute("type", MemberTypes.Method),
                        new XAttribute("name", "set_PropertyName"),
                        _outputFormatter.CreateModifierMarkup("", "public override"),
                        _outputFormatter.CreateMethodMarkup("set_PropertyName", typeof(void), property.GetSetMethod().GetParameters())
                        )
                    )
                );

            XElementComparisonHelper.Compare(output, expectedOutput);
        }
        public XElement GetMemberSignature(MemberInfo memberInfo)
        {
            ArgumentUtility.CheckNotNull("memberInfo", memberInfo);

            switch (memberInfo.MemberType)
            {
            case MemberTypes.Method:
                var methodInfo = (MethodInfo)memberInfo;
                return(_outputFormatter.CreateMethodMarkup(methodInfo.Name, methodInfo.ReturnType, methodInfo.GetParameters(), methodInfo.GetGenericArguments()));

            case MemberTypes.Constructor:
                var constructorInfo = (ConstructorInfo)memberInfo;
                return(_outputFormatter.CreateConstructorMarkup(_outputFormatter.GetConstructorName(memberInfo.DeclaringType), constructorInfo.GetParameters()));

            case MemberTypes.Event:
                var eventInfo = (EventInfo)memberInfo;
                return(_outputFormatter.CreateEventMarkup(eventInfo.Name, eventInfo.EventHandlerType));

            case MemberTypes.Field:
                var fieldInfo = (FieldInfo)memberInfo;
                return(_outputFormatter.CreateFieldMarkup(fieldInfo.Name, fieldInfo.FieldType));

            case MemberTypes.Property:
                var propertyInfo = (PropertyInfo)memberInfo;
                return(_outputFormatter.CreatePropertyMarkup(propertyInfo.Name, propertyInfo.PropertyType));

            case MemberTypes.NestedType:
                var nestedType = (Type)memberInfo;
                return(_outputFormatter.CreateNestedTypeMarkup(nestedType));

            case MemberTypes.Custom:
            case MemberTypes.TypeInfo:
                return(null);

            default:
                throw new Exception("unknown member type");
            }
        }