本文整理汇总了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;
}
示例2: InstallerScriptableSqlAssembly
public InstallerScriptableSqlAssembly(Assembly assembly)
{
var assemblyAttribute = assembly.GetCustomAttribute<AssemblyTitleAttribute>();
Name = assemblyAttribute.Title;
Path = assembly.Location;
Assembly = assembly;
}
示例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);
}
}
示例4: DiscoverFactory
public IProxyFactory DiscoverFactory (Assembly assembly)
{
var factoryType = assembly.GetCustomAttribute<ProxyFactoryAttribute>()?.FactoryType;
if (factoryType == null)
throw new NotSupportedException ();
return (IProxyFactory)Activator.CreateInstance (factoryType);
}
示例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;
}
示例6: GetAssemblyInformationalVersion
static string GetAssemblyInformationalVersion(Assembly assembly)
{
var attribute = assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>();
if (attribute != null)
{
return attribute.InformationalVersion;
}
return GetAssemblyFileVersion(assembly);
}
示例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);
}
}
}
示例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);
}
示例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;
}
示例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";
}
示例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;
}
示例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);
}
}
}
示例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;
}
示例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;
}
示例15: GetLambda
private BigO GetLambda(Assembly assembly)
{
var a = assembly.GetCustomAttribute<LambdaAttribute>();
return a == null ? BigO.Squared : a.Lambda;
}