本文整理匯總了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;
}
示例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 ();
}
示例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");
}
}
}
示例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 &&
//.........這裏部分代碼省略.........
示例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 "";
}
示例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);
}
}
}
示例7: GetCustomAttributes
public static IList<CustomAttributeData> GetCustomAttributes(Assembly target)
{
return GetData(target.GetCustomAttributes(true));
}
示例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);
}
}
示例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");
//.........這裏部分代碼省略.........