コード例 #1
0
ファイル: MethodInfoTests.cs プロジェクト: yang123vc/corefx
        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());
        }
コード例 #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());
        }
コード例 #3
0
        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());
        }
コード例 #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;
            }
        }
コード例 #5
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);

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

            _declaration     = csb.ToString();
            _declarationHtml = csb.ToHtmlString();
        }
コード例 #6
0
 public override string ToString()
 {
     return(_attribute.ToString());
 }