Esempio n. 1
0
        public void CustomAttributes(Type type, string expectedToString)
        {
            MethodInfo          methodInfo    = GetMethod(typeof(MI_SubClass), "MethodWithAttributes");
            CustomAttributeData attributeData = methodInfo.CustomAttributes.First(attribute => attribute.AttributeType.Equals(type));

            Assert.Equal(expectedToString, attributeData.ToString());
        }
Esempio n. 2
0
        public static void CustomAttributes(Type type, string expectedToString)
        {
            FieldInfo           fieldInfo     = GetField(typeof(FieldInfoTests), "fieldWithAttributes");
            CustomAttributeData attributeData = fieldInfo.CustomAttributes.First(attribute => attribute.AttributeType.Equals(type));

            Assert.Equal(expectedToString, attributeData.ToString());
        }
        public static void TestCustomAttributeDetails(Type type, string expectedToString)
        {
            FieldInfo           fi            = GetField("MyField");
            CustomAttributeData attributeData = fi.CustomAttributes.First(attribute => attribute.AttributeType.Equals(type));

            Assert.Equal(expectedToString, attributeData.ToString());
        }
Esempio n. 4
0
        public AttributeDetail(RootDetail parent, CustomAttributeData cad)
            : base(parent, cad.Constructor.DeclaringType.FullName)
        {
            _declaration = cad.ToString();

            CodeStringBuilder csb = new CodeStringBuilder();

            AppendAttributesDeclaration(csb);

            csb.AppendType(cad.Constructor.DeclaringType);

            using (var e = cad.ConstructorArguments.GetEnumerator())
            {
                if (e.MoveNext())
                {
                    csb.AppendText("(");
                    csb.AppendQuotedValue(e.Current.Value);
                    while (e.MoveNext())
                    {
                        csb.AppendText(", ");
                        csb.AppendQuotedValue(e.Current.Value);
                    }
                    csb.AppendText(")");
                }
            }

            _declaration         = csb.ToString();
            _declarationHtml     = csb.ToHtmlString();
            _declarationMarkdown = csb.ToMarkdownString();

            if (cad.AttributeType.IsAssignableFrom(typeof(ExtensionAttribute)))
            {
                AttributeType = AttributeType.Extension;
                AppendInCode  = false;
            }
            else if (cad.AttributeType.IsAssignableFrom(typeof(ObsoleteAttribute)))
            {
                AttributeType = AttributeType.Obsolete;
            }
            else if (cad.AttributeType.IsAssignableFrom(typeof(CompilerGeneratedAttribute)))
            {
                AttributeType = AttributeType.CompilerGenerated;
                AppendInCode  = false;
            }
        }
        public AttributeDetail(RootDetail parent, CustomAttributeData cad)
            : base(parent, cad.Constructor.DeclaringType.FullName)
        {
            _declaration = cad.ToString();

            CodeStringBuilder csb = new CodeStringBuilder();

            AppendAttributesDeclaration(csb);

            csb.AppendType(cad.Constructor.DeclaringType);

            if (cad.ConstructorArguments.Count > 0)
            {
                csb.AppendText("(");
                csb.AppendQuotedValue(cad.ConstructorArguments[0].Value);
                csb.AppendText(")");
            }

            _declaration     = csb.ToString();
            _declarationHtml = csb.ToHtmlString();
        }
 public override string ToString()
 {
     return(_attribute.ToString());
 }