当前位置: 首页>>代码示例>>C#>>正文


C# Assembly.GetCustomAttributes方法代码示例

本文整理汇总了C#中Assembly.GetCustomAttributes方法的典型用法代码示例。如果您正苦于以下问题:C# Assembly.GetCustomAttributes方法的具体用法?C# Assembly.GetCustomAttributes怎么用?C# Assembly.GetCustomAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Assembly的用法示例。


在下文中一共展示了Assembly.GetCustomAttributes方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetScriptName

    public static string GetScriptName(Assembly assembly)
    {
        var attr =  (from item in assembly.GetCustomAttributes(typeof(AssemblyDescriptionAttribute), true)
                     select (AssemblyDescriptionAttribute)item)
                     .FirstOrDefault();

        return attr == null ? "" : attr.Description;
    }
开发者ID:Diullei,项目名称:Storm,代码行数:8,代码来源:ReflectScript.cs

示例2: AssemblyInfo

            public AssemblyInfo(Assembly a)
            {
                if (a == null)
                throw new ArgumentNullException ("a");

                AssemblyName an = a.GetName ();
                _name = an.ToString ();

                object [] att = a.GetCustomAttributes (typeof (AssemblyTitleAttribute), false);
                _title = ((att.Length > 0) ? ((AssemblyTitleAttribute) att [0]).Title : String.Empty);

                att = a.GetCustomAttributes (typeof (AssemblyCopyrightAttribute), false);
                _copyright = ((att.Length > 0) ? ((AssemblyCopyrightAttribute) att [0]).Copyright : String.Empty);

                att = a.GetCustomAttributes (typeof (AssemblyDescriptionAttribute), false);
                _description = ((att.Length > 0) ? ((AssemblyDescriptionAttribute) att [0]).Description : String.Empty);

                _version = an.Version.ToString ();
            }
开发者ID:simas76,项目名称:scielo-dev,代码行数:19,代码来源:AssemblyInfo.cs

示例3: VerifyAssembly

    public override void VerifyAssembly (CodeDomProvider provider, Assembly asm) {
        Type genType;

        // Verifying Assembly Attributes
        if (Supports (provider, GeneratorSupport.AssemblyAttributes)) {
            object[] attributes = asm.GetCustomAttributes (true);
            bool verifiedAssemblyAttributes = VerifyAttribute (attributes, typeof (AssemblyTitleAttribute), "Title", "MyAssembly");
            verifiedAssemblyAttributes &=
                VerifyAttribute (attributes, typeof (AssemblyVersionAttribute), "Version", "1.0.6.2") ||
                asm.GetName ().Version.Equals (new Version (1, 0, 6, 2));
            if (verifiedAssemblyAttributes) {
                VerifyScenario ("CheckAssemblyAttributes");
            }
        }

        object[] customAttributes;
        object[] customAttributes2;
        object[] customAttributesAll;

        if (FindType ("MyNamespace.MyClass", asm, out genType)) {
            customAttributes    = genType.GetCustomAttributes (typeof (System.ObsoleteAttribute), true);
            customAttributes2   = genType.GetCustomAttributes (typeof (System.SerializableAttribute), true);
            customAttributesAll = genType.GetCustomAttributes (true);

#if !WHIDBEY
            if (!(provider is CSharpCodeProvider) && !(provider is VBCodeProvider) && !(provider is JScriptCodeProvider)) {
#endif
                if (customAttributes.GetLength (0) == 1 &&
                        customAttributes2.GetLength (0) >= 1 &&
                        customAttributesAll.GetLength (0) >= 3) {
                    VerifyScenario ("CheckClassAttributes");
                }
#if !WHIDBEY
            }
#endif

            // verify method attributes
            MethodInfo methodInfo = genType.GetMethod ("MyMethod");
            if (methodInfo != null &&
                    methodInfo.GetCustomAttributes (typeof (System.ObsoleteAttribute), true).GetLength (0) > 0 &&
                    methodInfo.GetCustomAttributes (typeof (System.ComponentModel.EditorAttribute), true).GetLength (0) > 0) {
                VerifyScenario ("CheckMyMethodAttributes");
            }

            // verify property attributes
            PropertyInfo propertyInfo = genType.GetProperty ("MyProperty");
            if (propertyInfo != null &&
                    propertyInfo.GetCustomAttributes (typeof (System.ObsoleteAttribute), true).GetLength (0) > 0) {
                VerifyScenario ("CheckMyPropertyAttributes");
            }

            // verify constructor attributes
            ConstructorInfo[] constructorInfo = genType.GetConstructors ();
            if (constructorInfo != null && constructorInfo.Length > 0 && !(provider is JScriptCodeProvider) &&
                    constructorInfo[0].GetCustomAttributes (typeof (System.ObsoleteAttribute), true).GetLength (0) > 0) {
                VerifyScenario ("CheckConstructorAttributes");
            }
            // verify field attributes
            FieldInfo fieldInfo = genType.GetField("myField");
            if (fieldInfo != null &&
                    fieldInfo.GetCustomAttributes (typeof (System.Xml.Serialization.XmlElementAttribute), true).GetLength (0) > 0) {
                VerifyScenario ("CheckMyFieldAttributes");
            }
        }

        // verify event attributes
        if (Supports (provider, GeneratorSupport.DeclareEvents) && FindType ("MyNamespace.Test", asm, out genType)) {
            EventInfo eventInfo = genType.GetEvent ("MyEvent");
            if (eventInfo != null &&
                    eventInfo.GetCustomAttributes (typeof (System.CLSCompliantAttribute), true).GetLength (0) > 0) {
                VerifyScenario ("CheckEventAttributes");
            }
        }
    }
开发者ID:drvink,项目名称:FSharp.Compiler.CodeDom,代码行数:74,代码来源:subsetattributestest.cs

示例4: VerifyAssembly

    public override void VerifyAssembly (CodeDomProvider provider, Assembly asm) {
        Type genType;

        // Verifying Assembly Attributes
        if (Supports (provider, GeneratorSupport.AssemblyAttributes)) {
            object[] attributes = asm.GetCustomAttributes (true);

            bool verifiedAssemblyAttributes = VerifyAttribute (attributes, typeof (AssemblyTitleAttribute), "Title", "MyAssembly");
            verifiedAssemblyAttributes &=
                VerifyAttribute (attributes, typeof (AssemblyVersionAttribute), "Version", "1.0.6.2") ||
                asm.GetName ().Version.Equals (new Version (1, 0, 6, 2));

            if (verifiedAssemblyAttributes) {
                VerifyScenario ("CheckAssemblyAttributes");
            }
        }

        object[] customAttributes;
        object[] customAttributes2;
        object[] customAttributesAll;

        if (FindType ("MyNamespace.MyClass", asm, out genType)) {
            customAttributes    = genType.GetCustomAttributes (typeof (System.ObsoleteAttribute), true);
            customAttributes2   = genType.GetCustomAttributes (typeof (System.SerializableAttribute), true);
            customAttributesAll = genType.GetCustomAttributes (true);

#if !WHIDBEY
            // see note about class attributes
            if (!(provider is CSharpCodeProvider) && !(provider is VBCodeProvider) && !(provider is JScriptCodeProvider)) {
#endif
                if (customAttributes.GetLength (0) == 1 &&
                        customAttributes2.GetLength (0) >= 1 &&
                        customAttributesAll.GetLength (0) >= 3) {
                    VerifyScenario ("CheckClassAttributes");
                }

                // verify nested class attributes
                if (Supports (provider, GeneratorSupport.NestedTypes)) {
                    Type nestedType = genType.GetNestedType ("NestedClass");
                    customAttributes = nestedType.GetCustomAttributes (typeof (System.SerializableAttribute), true);
                    if (customAttributes.GetLength (0) == 1) {
                        VerifyScenario ("CheckNestedClassAttributes");
                    }
                }
#if !WHIDBEY
            }
#endif

            // verify method attributes
            MethodInfo methodInfo = genType.GetMethod ("MyMethod");
            if (methodInfo != null &&
                    methodInfo.GetCustomAttributes (typeof (System.ObsoleteAttribute), true).GetLength (0) > 0 &&
                    methodInfo.GetCustomAttributes (typeof (System.ComponentModel.EditorAttribute), true).GetLength (0) > 0) {
                VerifyScenario ("CheckMyMethodAttributes");

                // verify parameter attributes
                ParameterInfo[] paramInfo = methodInfo.GetParameters ();
                if (paramInfo != null && paramInfo.Length >= 2 &&
                        Supports (provider, GeneratorSupport.ParameterAttributes) &&
                        paramInfo[0].GetCustomAttributes (typeof (System.Xml.Serialization.XmlElementAttribute), true).GetLength (0) > 0 &&
                        paramInfo[1].GetCustomAttributes (typeof (System.Xml.Serialization.XmlElementAttribute), true).GetLength (0) > 0) {
                    VerifyScenario ("CheckParameterAttributes");
                }
            }

            // verify property attributes
            PropertyInfo propertyInfo = genType.GetProperty ("MyProperty");
            if (propertyInfo != null &&
                    propertyInfo.GetCustomAttributes (typeof (System.ObsoleteAttribute), true).GetLength (0) > 0) {
                VerifyScenario ("CheckMyPropertyAttributes");
            }

            // verify constructor attributes
            ConstructorInfo[] constructorInfo = genType.GetConstructors ();
            if (constructorInfo != null && constructorInfo.Length > 0 && !(provider is JScriptCodeProvider) &&
                    constructorInfo[0].GetCustomAttributes (typeof (System.ObsoleteAttribute), true).GetLength (0) > 0) {
                VerifyScenario ("CheckConstructorAttributes");
            }

            // verify type constructor attributes if its supported
            if (Supports (provider, GeneratorSupport.StaticConstructors)) {
                ConstructorInfo typeInit = genType.TypeInitializer;
                if (typeInit != null &&
                    typeInit.GetCustomAttributes (typeof (System.ObsoleteAttribute), true).GetLength (0) > 0) {
                    VerifyScenario ("CheckStaticConstructorAttributes");
                }
            }
            
            // verify entry point method attributes if supported
            if (Supports (provider, GeneratorSupport.EntryPointMethod)) {
                methodInfo = asm.EntryPoint;
                if (methodInfo != null &&
                        methodInfo.GetCustomAttributes (typeof (System.ObsoleteAttribute), true).GetLength (0) > 0)
                    VerifyScenario ("CheckEntryPointMethodAttributes");
            }

            // verify delegate attributes if supported
            if (Supports (provider, GeneratorSupport.DeclareDelegates)) {
                Type delType = null;
                if (FindType ("MyNamespace.MyDelegate", asm, out delType) && delType != null &&
//.........这里部分代码省略.........
开发者ID:drvink,项目名称:FSharp.Compiler.CodeDom,代码行数:101,代码来源:attributestest.cs

示例5: method_11

	private string method_11(Assembly assembly_0, Type type_0)
	{
		try
		{
			if (type_0 == typeof(AssemblyCompanyAttribute))
			{
				AssemblyCompanyAttribute assemblyCompanyAttribute = (AssemblyCompanyAttribute)assembly_0.GetCustomAttributes(type_0, false)[0];
				string result = assemblyCompanyAttribute.Company.ToString();
				return result;
			}
			if (type_0 == typeof(AssemblyCopyrightAttribute))
			{
				AssemblyCopyrightAttribute assemblyCopyrightAttribute = (AssemblyCopyrightAttribute)assembly_0.GetCustomAttributes(type_0, false)[0];
				string result = assemblyCopyrightAttribute.Copyright.ToString();
				return result;
			}
			if (type_0 == typeof(AssemblyDescriptionAttribute))
			{
				AssemblyDescriptionAttribute assemblyDescriptionAttribute = (AssemblyDescriptionAttribute)assembly_0.GetCustomAttributes(type_0, false)[0];
				string result = assemblyDescriptionAttribute.Description.ToString();
				return result;
			}
			if (type_0 == typeof(AssemblyProductAttribute))
			{
				AssemblyProductAttribute assemblyProductAttribute = (AssemblyProductAttribute)assembly_0.GetCustomAttributes(type_0, false)[0];
				string result = assemblyProductAttribute.Product.ToString();
				return result;
			}
			if (type_0 == typeof(AssemblyTitleAttribute))
			{
				AssemblyTitleAttribute assemblyTitleAttribute = (AssemblyTitleAttribute)assembly_0.GetCustomAttributes(type_0, false)[0];
				string result = assemblyTitleAttribute.Title.ToString();
				return result;
			}
			if (type_0 == typeof(AssemblyTrademarkAttribute))
			{
				AssemblyTrademarkAttribute assemblyTrademarkAttribute = (AssemblyTrademarkAttribute)assembly_0.GetCustomAttributes(type_0, false)[0];
				string result = assemblyTrademarkAttribute.Trademark.ToString();
				return result;
			}
			if (type_0 == typeof(AssemblyVersionAttribute))
			{
				Version version = assembly_0.GetName().Version;
				string result = version.ToString().Replace("v.", "").Replace("v", "");
				return result;
			}
			if (type_0 == typeof(AssemblyName))
			{
				string result = assembly_0.GetName().Name;
				return result;
			}
		}
		catch
		{
			string result = "";
			return result;
		}
		return "";
	}
开发者ID:akordowski,项目名称:Source-Code-Nitriq,代码行数:59,代码来源:Class1.cs

示例6: WriteAssemblyAttributes

	public override void WriteAssemblyAttributes (Assembly assembly)
	{
		object [] x = assembly.GetCustomAttributes (false);
		Console.WriteLine ("Got: " + x.Length);
		foreach (object aattr in assembly.GetCustomAttributes (false)) {
			Console.WriteLine ("Got: " + aattr.GetType ().Name);
			if (aattr.GetType ().Name == "IncludeAttribute"){
				WriteDefines (sc, aattr);
				WriteIncludes (sc, aattr);
			}
		}
	}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:12,代码来源:make-map.cs

示例7: GetCustomAttributes

 public static IList<CustomAttributeData> GetCustomAttributes(Assembly target)
 {
     return GetData(target.GetCustomAttributes(true));
 }
开发者ID:jorik041,项目名称:runcs,代码行数:4,代码来源:Shims.cs

示例8: VerifyGitVersionInformationAttribute

    static void VerifyGitVersionInformationAttribute(Assembly assembly, VersionVariables versionVariables)
    {
        var gitVersionInformationAttributeData = assembly.CustomAttributes
            .FirstOrDefault(a => a.AttributeType.Name == "GitVersionInformationAttribute");

        Assert.IsNotNull(gitVersionInformationAttributeData);

        var gitVersionInformationAttributeType = gitVersionInformationAttributeData.AttributeType;
        var gitVersionInformationAttribute = assembly
            .GetCustomAttributes(gitVersionInformationAttributeType)
            .FirstOrDefault();

        Assert.IsNotNull(gitVersionInformationAttribute);

        var properties = gitVersionInformationAttributeType.GetProperties(BindingFlags.Instance | BindingFlags.Public);

        foreach (var variable in versionVariables)
        {
            Assert.IsNotNull(variable.Value);

            var property = properties.FirstOrDefault(p => p.Name == variable.Key);
            Assert.IsNotNull(property);

            var propertyValue = property.GetValue(gitVersionInformationAttribute, null);
            Assert.AreEqual(variable.Value, propertyValue, "{0} had an invalid value.", property.Name);
        }
    }
开发者ID:nick4eva,项目名称:GitVersion,代码行数:27,代码来源:AssemblyInfoBuilderTests.cs

示例9: VerifyAssembly

    public override void VerifyAssembly (CodeDomProvider provider, Assembly asm) {
        object genObject;
        Type   genType;

        // if we get to this point, Entry point method and Event declaration
        // have been successfully compiled so
        if (Supports (provider, GeneratorSupport.EntryPointMethod))
            VerifyScenario ("CheckEntryPointMethod");
        if (Supports (provider, GeneratorSupport.DeclareEvents))
            VerifyScenario ("CheckDeclareEvents");

        // Verifying Assembly Attributes
        if (Supports (provider, GeneratorSupport.AssemblyAttributes)) {
            object[] attributes = asm.GetCustomAttributes (true);
            bool verified = VerifyAttribute (attributes, typeof (AssemblyTitleAttribute), "Title", "MyAssembly");
            verified &= VerifyAttribute (attributes, typeof (AssemblyVersionAttribute), "Version", "1.0.6.2") ||
                asm.GetName ().Version.Equals (new Version (1, 0, 6, 2));
            if (verified)
                VerifyScenario ("CheckAssemblyAttributes");
        }

        AddScenario ("InstantiateTEST", "Find and instantiate TEST.");
        if (!FindAndInstantiate ("NSPC.TEST", asm, out genObject, out genType))
            return;
        VerifyScenario ("InstantiateTEST");

        // verify arrays of arrays
#if !WHIDBEY
        if (!(provider is VBCodeProvider)) {
#endif
            if (Supports (provider, GeneratorSupport.ArraysOfArrays) &&
                    VerifyMethod (genType, genObject, "ArraysOfArrays", new object[] {}, 4)) {
                VerifyScenario ("CheckArrayOfArrays");
            }
#if !WHIDBEY
        }
#endif

        // verify chained constructors
        if (Supports (provider, GeneratorSupport.ChainedConstructorArguments) &&
                VerifyMethod (genType, genObject, "ChainedConstructorUse", new object[] {}, "testingString")) {
            VerifyScenario ("CheckChainedConstructorArgs");
        }
        // verify complex expressions
        if (Supports (provider, GeneratorSupport.ComplexExpressions) &&
                VerifyMethod (genType, genObject, "ComplexExpressions", new object[] {8}, 88)) {
            VerifyScenario ("CheckComplexExpressions");
        }
        // verify enumerations
        if (Supports (provider, GeneratorSupport.DeclareEnums) &&
                VerifyMethod (genType, genObject, "OutputDecimalEnumVal", new object[] {4}, 4)) {
            VerifyScenario ("CheckDeclareEnums");
        }
        // verify interfaces
        if (Supports (provider, GeneratorSupport.DeclareInterfaces) &&
                VerifyMethod (genType, genObject, "TestSingleInterface", new object[] {4}, 4)) {
            VerifyScenario ("CheckDeclareInterfaces");
        }
        // verify nested structs
        /*if (Supports (provider, GeneratorSupport.DeclareValueTypes) &&
                VerifyMethod (genType, genObject, "NestedStructMethod", new object[] {}, 3)) {
            VerifyScenario ("CheckDeclareValueTypes");
        }*/
        // verify goto
        if (Supports (provider, GeneratorSupport.GotoStatements) &&
                VerifyMethod (genType, genObject, "GoToMethod", new object[] {0}, 7) &&
                VerifyMethod (genType, genObject, "GoToMethod", new object[] {2}, 6)) {
            VerifyScenario ("CheckGotoStatements");
        }
        // multiple interfaces
        if (Supports (provider, GeneratorSupport.DeclareInterfaces) &&
                Supports (provider, GeneratorSupport.MultipleInterfaceMembers) &&
                VerifyMethod (genType, genObject, "TestMultipleInterfaces", new object[] {6}, 0)) {
            VerifyScenario ("CheckMultipleInterfaceMembers");
        }
        // nested types
        if (Supports (provider, GeneratorSupport.NestedTypes) &&
                VerifyMethod (genType, genObject, "CallingPublicNestedScenario", new object[] {7}, 7)) {
            VerifyScenario ("CheckNestedTypes");
        }
        // parameter attributes
        MethodInfo methodInfo;
        if (Supports (provider, GeneratorSupport.ParameterAttributes)) {
            methodInfo = genType.GetMethod ("MyMethod");
            ParameterInfo[] paramInfo = methodInfo.GetParameters ();

            object[] paramAttributes = paramInfo[0].GetCustomAttributes (typeof (System.Xml.Serialization.XmlElementAttribute), true);
            if (paramAttributes.GetLength (0) == 1) {
                VerifyScenario ("CheckParameterAttributes");
            }
        }
        // public static members
        if (Supports (provider, GeneratorSupport.PublicStaticMembers) &&
                VerifyMethod (genType, genObject, "PublicStaticMethod", new object[] {}, 16)) {
            VerifyScenario ("CheckPublicStaticMembers");
        }
        // reference parameters
        if (Supports (provider, GeneratorSupport.ReferenceParameters) &&
                VerifyMethod (genType, genObject, "CallingWork", new object[] {5}, 19)) {
            VerifyScenario ("CheckReferenceParameters");
//.........这里部分代码省略.........
开发者ID:modulexcite,项目名称:powerpack-archive,代码行数:101,代码来源:generatorsupportstest.cs


注:本文中的Assembly.GetCustomAttributes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。