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


C# Assembly.GetCustomAttribute方法代码示例

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


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

示例1: EnrichPackageFromAssembly

        /// <summary>
        /// Enriches the package from assembly.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="assembly">The assembly.</param>
        /// <returns></returns>
        public static DnnPackage EnrichPackageFromAssembly(this DnnPackage source, Assembly assembly)
        {
            // Package friendly name: if empty set from the AssemblyTitle attribute or defaults to the package name.
            if (string.IsNullOrWhiteSpace(source.FriendlyName))
            {
                var titleAttribute = assembly.GetCustomAttribute<AssemblyTitleAttribute>();
                source.FriendlyName = titleAttribute != null && !string.IsNullOrWhiteSpace(titleAttribute.Title) ? titleAttribute.Title : source.Name;
            }

            // Package description: if empty set from AssemblyDescription attribute or defaults to the package name.
            if (string.IsNullOrWhiteSpace(source.Description))
            {
                var descriptionAttribute = assembly.GetCustomAttribute<AssemblyDescriptionAttribute>();
                source.Description = descriptionAttribute != null && !string.IsNullOrWhiteSpace(descriptionAttribute.Description) ? descriptionAttribute.Description : source.Name;
            }

            // Package owner
            var owner = assembly.GetCustomAttribute<AssemblyCompanyAttribute>();
            if (owner != null)
            {
                source.Owner.Organisation = owner.Company;
            }

            var companyInfo = assembly.GetCustomAttribute<AssemblyCompanyInfoAttribute>();
            if (companyInfo != null)
            {
                source.Owner.Email = companyInfo.EmailAddress;
                source.Owner.Url = companyInfo.Url;
            }

            return source;
        }
开发者ID:JKeetman,项目名称:MSBuild-for-DNN,代码行数:38,代码来源:PackageExtensions.cs

示例2: InstallerScriptableSqlAssembly

 public InstallerScriptableSqlAssembly(Assembly assembly)
 {
     var assemblyAttribute = assembly.GetCustomAttribute<AssemblyTitleAttribute>();
     Name = assemblyAttribute.Title;
     Path = assembly.Location;
     Assembly = assembly;
 }
开发者ID:shahargv,项目名称:redisql,代码行数:7,代码来源:InstallerScriptableSqlAssembly.cs

示例3: ComputeAssemblyHash

        private static void ComputeAssemblyHash(Assembly assembly, HashSet<Assembly> assemblies, StringBuilder outputString)
        {
            if (assemblies.Contains(assembly))
                return;

            outputString.Append(assembly.FullName);

            var attribute = assembly.GetCustomAttribute<AssemblyFileVersionAttribute>();
            if (attribute != null)
            {
                outputString.Append(",").Append(attribute.Version);
                outputString.AppendLine();
            }

            assemblies.Add(assembly);
            foreach (var referencedAssemblyName in assembly.GetReferencedAssemblies())
            {
                // Avoid processing system assemblies
                // TODO: Scan what is actually in framework folders (and unify it with ProcessDataSerializerGlobalAttributes)
                if (referencedAssemblyName.Name == "mscorlib" || referencedAssemblyName.Name.StartsWith("System")
                    || referencedAssemblyName.FullName.Contains("PublicKeyToken=31bf3856ad364e35")) // Signed with Microsoft public key (likely part of system libraries)
                    continue;

                var assemblyRef = Assembly.Load(referencedAssemblyName);
                ComputeAssemblyHash(assemblyRef, assemblies, outputString);
            }
        }
开发者ID:Powerino73,项目名称:paradox,代码行数:27,代码来源:AssemblyHash.cs

示例4: DiscoverFactory

			public IProxyFactory DiscoverFactory (Assembly assembly)
			{
				var factoryType = assembly.GetCustomAttribute<ProxyFactoryAttribute>()?.FactoryType;
				if (factoryType == null)
					throw new NotSupportedException ();

				return (IProxyFactory)Activator.CreateInstance (factoryType);
			}
开发者ID:moq,项目名称:moq.proxy,代码行数:8,代码来源:ProxyFactoryDiscoverer.cs

示例5: FromAssembly

        // Public Methods 

        public static AssemblyTranslationInfo FromAssembly(Assembly assembly, TranslationInfo translationInfo)
        {
            if (assembly == null)
                return null;
            var ati = new AssemblyTranslationInfo();
            {
                ati._assembly = assembly;

                var moduleIncludeConst = assembly.GetCustomAttribute<ModuleIncludeConstAttribute>();
                if (moduleIncludeConst != null)
                {
                    ati._includePathConstOrVarName = (moduleIncludeConst.ConstOrVarName ?? "").Trim();
                    if (ati._includePathConstOrVarName.StartsWith("$"))
                    {

                    }
                    else
                    {
                        ati._includePathConstOrVarName = "\\" + ati._includePathConstOrVarName.TrimStart('\\');
                    }
                }
                ati._rootPath = GetRootPath(assembly);

                var phpPackageSource = assembly.GetCustomAttribute<PhpPackageSourceAttribute>();
                if (phpPackageSource != null)
                {
                    ati._phpPackageSourceUri = phpPackageSource.SourceUri;
                    ati._phpPackagePathStrip = phpPackageSource.StripArchivePath;
                }
                {
                    var configModule = assembly.GetCustomAttribute<ConfigModuleAttribute>();
                    if (configModule != null)
                        ati.ConfigModuleName = configModule.Name;
                }
                {
                    var defaultTimezone = assembly.GetCustomAttribute<DefaultTimezoneAttribute>();
                    if (defaultTimezone != null)
                        ati._defaultTimezone = defaultTimezone.Timezone;
                }
            }
            ati._libraryName = LibNameFromAssembly(assembly);
            ati._phpIncludePathExpression = GetDefaultIncludePath(ati, translationInfo);
            return ati;
        }
开发者ID:exaphaser,项目名称:cs2php,代码行数:46,代码来源:AssemblyTranslationInfo.cs

示例6: GetAssemblyInformationalVersion

        static string GetAssemblyInformationalVersion(Assembly assembly)
        {
            var attribute = assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>();
            if (attribute != null)
            {
                return attribute.InformationalVersion;
            }

            return GetAssemblyFileVersion(assembly);
        }
开发者ID:MassTransit,项目名称:MassTransit,代码行数:10,代码来源:BusHostInfo.cs

示例7: AddAssembly

 /// <summary>
 /// Adds extensions specified within the assembly attribute into the table.
 /// </summary>
 /// <param name="ass">The assembly to be added.</param>
 public void AddAssembly(Assembly ass)
 {
     if (AddAssembly(ass.GetName()))
     {
         var attr = ass.GetCustomAttribute<PhpExtensionAttribute>();
         if (attr != null)
         {
             EnsureExtensions(attr.Extensions);
         }
     }
 }
开发者ID:iolevel,项目名称:peachpie,代码行数:15,代码来源:ExtensionsTable.cs

示例8: CreatePluginFromAssembly

		private Plugin CreatePluginFromAssembly(Assembly assembly)
		{
			PluginAttribute attr = assembly.GetCustomAttribute<PluginAttribute>();
			if (attr == null)
			{
				throw new ArgumentException($"Assembly '{assembly.FullName}' doesn't have a PluginAssemblyAttribute", "assembly");
			}
			DependencyContainer.RegisterType(attr.PluginClass, new ContainerControlledLifetimeManager());
			var overrides = new DependencyOverrides();
			overrides.Add(typeof(PluginManager), Manager);
			return (Plugin)DependencyContainer.Resolve(attr.PluginClass, overrides);
		}
开发者ID:maritaria,项目名称:HotBot,代码行数:12,代码来源:AssemblyPluginLoader.cs

示例9: Create

        public Endpoint Create(Assembly modelsAssembly)
        {
            var endpoint = new Endpoint();
            endpoint.Name = modelsAssembly.GetName().Name;
            endpoint.AssemblyGuid = Guid.Parse(modelsAssembly.GetCustomAttribute<GuidAttribute>().Value);
            endpoint.AssemblyVersion = modelsAssembly.GetName().Version.ToString();

            BuildEndpointRoutes(endpoint);

            // models must be built after routes
            BuildEndpointModels(endpoint, modelsAssembly);

            return endpoint;
        }
开发者ID:tjb042,项目名称:Archipelago,代码行数:14,代码来源:EndpointFactory.cs

示例10: GetAssemblyFileVersion

        static string GetAssemblyFileVersion(Assembly assembly)
        {
            var attribute = assembly.GetCustomAttribute<AssemblyFileVersionAttribute>();
            if (attribute != null)
            {
                return attribute.Version;
            }

            var assemblyLocation = assembly.Location;
            if (assemblyLocation != null)
                return FileVersionInfo.GetVersionInfo(assemblyLocation).FileVersion;

            return "Unknown";
        }
开发者ID:MassTransit,项目名称:MassTransit,代码行数:14,代码来源:BusHostInfo.cs

示例11: CalculateStatus

        private TranslatedSummaryState CalculateStatus(Assembly a, CultureInfo ci)
        {
            var fileName = LocalizedAssembly.TranslationFileName(a, ci);

            if (!System.IO.File.Exists(fileName))
                return TranslatedSummaryState.None;

            var target = DescriptionManager.GetLocalizedAssembly(a, ci);

            CultureInfo defaultCulture = CultureInfo.GetCultureInfo(a.GetCustomAttribute<DefaultAssemblyCultureAttribute>().DefaultCulture);
            var master = DescriptionManager.GetLocalizedAssembly(a, defaultCulture);

            var result = TranslationSynchronizer.GetMergeChanges(target, master, new List<LocalizedAssembly>());

            if (result.Any())
                return TranslatedSummaryState.Pending;

            return TranslatedSummaryState.Completed;
        }
开发者ID:mapacheL,项目名称:extensions,代码行数:19,代码来源:TranslationController.cs

示例12: Import

        public void Import(Assembly assembly)
        {
            if (assembly == null) throw Error.ArgumentNull("assembly");

#if PORTABLE45
			if (assembly.GetCustomAttribute<NotMappedAttribute>() != null) return;
#else
            if (Attribute.GetCustomAttribute(assembly, typeof(NotMappedAttribute)) != null) return;
#endif

#if PORTABLE45
			IEnumerable<Type> exportedTypes = assembly.ExportedTypes;
#else
			Type[] exportedTypes = assembly.GetExportedTypes();
#endif
			foreach (Type type in exportedTypes)
            {
                // Don't import types marked with [NotMapped]
#if PORTABLE45
				if (type.GetTypeInfo().GetCustomAttribute<NotMappedAttribute>() != null) continue;
#else
                if (Attribute.GetCustomAttribute(type, typeof(NotMappedAttribute)) != null) continue;
#endif

				if (type.IsEnum())
                {
                    // Map an enumeration
                    if (EnumMapping.IsMappableEnum(type))
                        ImportEnum(type);
                    else
                        Message.Info("Skipped enum {0} while doing inspection: not recognized as representing a FHIR enumeration", type.Name);
                }
                else
                {
                    // Map a Fhir Datatype
                    if (ClassMapping.IsMappableType(type))
                        ImportType(type);
                    else
                        Message.Info("Skipped type {0} while doing inspection: not recognized as representing a FHIR type", type.Name);
                }
            }
        }
开发者ID:tiloc,项目名称:fhir-net-api,代码行数:42,代码来源:ModelInspector.cs

示例13: GetRootPath

 public static string GetRootPath(Assembly assembly)
 {
     var rootPathAttribute = assembly.GetCustomAttribute<RootPathAttribute>();
     if (rootPathAttribute == null)
         return string.Empty;
     var result = (rootPathAttribute.Path ?? "").Replace("\\", "/").TrimEnd('/').TrimStart('/') + "/";
     while (result.Contains("//"))
         result = result.Replace("//", "/");
     return result;
 }
开发者ID:exaphaser,项目名称:cs2php,代码行数:10,代码来源:AssemblyTranslationInfo.cs

示例14: GetAppVersion

        /// <summary>
        /// Gets the application version from the assembly.
        /// </summary>
        /// <param name="appAssembly">The application assembly containing the
        ///                           <see cref="AppManifestAttribute"/>.</param>
        /// <returns>
        /// The application version.
        /// </returns>
        protected virtual Version GetAppVersion(Assembly appAssembly)
        {
            var appManifestAttribute = appAssembly.GetCustomAttribute<AppManifestAttribute>();
            var version = appManifestAttribute?.AppVersion;

            Version appVersion;
            if (!Version.TryParse(version, out appVersion))
            {
                version = appAssembly.GetCustomAttribute<AssemblyVersionAttribute>()?.Version
                          ?? appAssembly.GetCustomAttribute<AssemblyFileVersionAttribute>()?.Version
                          ?? appAssembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion;

                if (!Version.TryParse(version, out appVersion))
                {
                    appVersion = VersionZero;
                }
            }

            return appVersion;
        }
开发者ID:raimu,项目名称:kephas,代码行数:28,代码来源:AppManifestBase.cs

示例15: GetLambda

 private BigO GetLambda(Assembly assembly)
 {
     var a = assembly.GetCustomAttribute<LambdaAttribute>();
     return a == null ? BigO.Squared : a.Lambda;
 }
开发者ID:T-Becker,项目名称:SortVis,代码行数:5,代码来源:FrmMain.cs


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