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


C# Assembly.GetCustomAttributesData方法代码示例

本文整理汇总了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>();
 }
开发者ID:JohnFunari,项目名称:Simple.Data,代码行数:32,代码来源:ProviderAssemblyAttributeBase.cs

示例2: GetCustomAttributes

        public static IList<CustomAttributeData> GetCustomAttributes(Assembly target)
        {
            if (target == null)
                throw new ArgumentNullException(nameof(target));

            return target.GetCustomAttributesData();
        }
开发者ID:tijoytom,项目名称:corert,代码行数:7,代码来源:LegacyCustomAttributeApis.cs

示例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);
        }
开发者ID:r-bel,项目名称:glorg2,代码行数:34,代码来源:ReferencesEditor.cs

示例4: GetCustomAttributes

        public static IList<CustomAttributeData> GetCustomAttributes(Assembly target)
        {
            if (target == null)
                throw new ArgumentNullException("target");
            Contract.EndContractBlock();

            return target.GetCustomAttributesData();
        }
开发者ID:enavro,项目名称:coreclr,代码行数:8,代码来源:CustomAttribute.cs

示例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;
 }
开发者ID:modulexcite,项目名称:FieldLog,代码行数:12,代码来源:PdbReader.cs

示例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));
            }
        }
开发者ID:manuelnelson,项目名称:VisualStudioProjectRenamer,代码行数:15,代码来源:AssemblyAccessor.cs

示例7: EnrichAssembly

 public void EnrichAssembly(IProcessingContext context, Assembly asm)
 {
     GenerateAttributeElements(context, asm.GetCustomAttributesData());
 }
开发者ID:abclassic,项目名称:LBi.LostDoc,代码行数:4,代码来源:AttributeDataEnricher.cs

示例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;
                }
            }
        }
开发者ID:CharlieBP,项目名称:owin-hosting,代码行数:29,代码来源:AutoStartupInfrastructure.cs

示例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;
 }
开发者ID:modulexcite,项目名称:FieldLog,代码行数:27,代码来源:PdbReader.cs


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