本文整理汇总了C#中System.Reflection.Assembly.GetCustomAttributesData方法的典型用法代码示例。如果您正苦于以下问题:C# Assembly.GetCustomAttributesData方法的具体用法?C# Assembly.GetCustomAttributesData怎么用?C# Assembly.GetCustomAttributesData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.Assembly
的用法示例。
在下文中一共展示了Assembly.GetCustomAttributesData方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Get
public static IEnumerable<ProviderAssemblyAttributeBase> Get(Assembly assembly)
{
if (assembly.ReflectionOnly)
{
foreach (var referencedAssembly in assembly.GetReferencedAssemblies())
{
if (AppDomain.CurrentDomain.ReflectionOnlyGetAssemblies().All(a => a.GetName().FullName != referencedAssembly.FullName))
{
try
{
Assembly.ReflectionOnlyLoad(referencedAssembly.FullName);
}
catch (FileNotFoundException)
{
return Enumerable.Empty<ProviderAssemblyAttributeBase>();
}
}
}
var hasAttribute = assembly.GetCustomAttributesData().Any(
cad => typeof (ProviderAssemblyAttributeBase).IsAssignableFrom(cad.Constructor.DeclaringType));
if (hasAttribute)
{
assembly = Assembly.Load(assembly.GetName());
}
else
{
return Enumerable.Empty<ProviderAssemblyAttributeBase>();
}
}
return assembly.GetCustomAttributes(typeof (ProviderAssemblyAttributeBase), false)
.Cast<ProviderAssemblyAttributeBase>();
}
示例2: GetCustomAttributes
public static IList<CustomAttributeData> GetCustomAttributes(Assembly target)
{
if (target == null)
throw new ArgumentNullException(nameof(target));
return target.GetCustomAttributesData();
}
示例3: AddListItem
public void AddListItem(Assembly info, string filename)
{
string version = "1.0";
string name = info.FullName;
var ver = info.GetCustomAttributesData();
foreach (var item in ver)
{
var t = item.Constructor.ReflectedType;
if (t == typeof(AssemblyVersionAttribute))
{
version = item.ConstructorArguments[0].Value.ToString();
}
else if (t == typeof(AssemblyTitleAttribute))
{
name = item.ConstructorArguments[0].Value.ToString();
}
}
/*if (ver.Length > 0)
{
AssemblyVersionAttribute attr = ver[0] as AssemblyVersionAttribute;
version = attr.Version.ToString();
}
var nm = info.GetCustomAttributes(typeof(AssemblyTitleAttribute), true);
if (nm.Length > 0)
{
AssemblyTitleAttribute attr = nm[0] as AssemblyTitleAttribute;
name = attr.Title;
}*/
ListViewItem ls = new ListViewItem(name);
ls.SubItems.Add(version);
ls.SubItems.Add(filename);
AssemblyList.Items.Add(ls);
}
示例4: GetCustomAttributes
public static IList<CustomAttributeData> GetCustomAttributes(Assembly target)
{
if (target == null)
throw new ArgumentNullException("target");
Contract.EndContractBlock();
return target.GetCustomAttributesData();
}
示例5: GetAssemblyConfiguration
private static string GetAssemblyConfiguration(Assembly assembly)
{
IList<CustomAttributeData> attributes = assembly.GetCustomAttributesData();
foreach (CustomAttributeData cad in attributes)
{
if (cad.Constructor.DeclaringType == typeof(AssemblyConfigurationAttribute))
{
return cad.ConstructorArguments.First().Value.ToString();
}
}
return null;
}
示例6: AssemblyAccessor
public AssemblyAccessor()
{
assemblyAttributes = new List<Attribute>();
assembly = Assembly.GetEntryAssembly();
foreach (CustomAttributeData data in assembly.GetCustomAttributesData())
{
assemblyAttributes.Add(CreateAttribute(data));
}
if (assemblyAttributes == null || assemblyAttributes.Count == 0)
{
throw new Exception(string.Format("Unable to load assembly attributes from {0}", assembly.FullName));
}
}
示例7: EnrichAssembly
public void EnrichAssembly(IProcessingContext context, Assembly asm)
{
GenerateAttributeElements(context, asm.GetCustomAttributesData());
}
示例8: AutoStartupDataForAssembly
private static IEnumerable<AutoStartupData> AutoStartupDataForAssembly(Assembly assembly)
{
foreach (var attributeData in assembly.GetCustomAttributesData())
{
if (attributeData.Constructor.DeclaringType == null)
{
continue;
}
var attributeTypeName = attributeData.Constructor.DeclaringType.Name;
if (attributeTypeName != "OwinAutoStartup" && attributeTypeName != "OwinAutoStartupAttribute")
{
continue;
}
var data = new AutoStartupData();
data = attributeData.Constructor.GetParameters().Zip(attributeData.ConstructorArguments, (a, b) => new { a, b }).Aggregate(data, (c, d) => AddValue(c, d.a.Name, d.b.ArgumentType, d.b.Value));
if (attributeData.NamedArguments != null)
{
data = attributeData.NamedArguments.Aggregate(data, (c, d) => AddValue(c, d.MemberInfo.Name, d.TypedValue.ArgumentType, d.TypedValue.Value));
}
if (data != null)
{
yield return data;
}
}
}
示例9: GetAssemblyVersion
private static string GetAssemblyVersion(Assembly assembly)
{
IList<CustomAttributeData> attributes = assembly.GetCustomAttributesData();
//foreach (CustomAttributeData cad in attributes)
//{
// if (cad.Constructor.DeclaringType == typeof(AssemblyInformationalVersionAttribute))
// {
// return cad.ConstructorArguments.First().Value.ToString();
// }
//}
foreach (CustomAttributeData cad in attributes)
{
if (cad.Constructor.DeclaringType == typeof(AssemblyFileVersionAttribute))
{
return cad.ConstructorArguments.First().Value.ToString();
}
}
Version assemblyVersion = assembly.GetName().Version;
if (assemblyVersion.Major != 0 ||
assemblyVersion.Minor != 0 ||
assemblyVersion.Revision != 0 ||
assemblyVersion.Build != 0)
{
return assembly.GetName().Version.ToString();
}
return null;
}