本文整理汇总了C#中System.Reflection.Assembly.GetAssemblyName方法的典型用法代码示例。如果您正苦于以下问题:C# Assembly.GetAssemblyName方法的具体用法?C# Assembly.GetAssemblyName怎么用?C# Assembly.GetAssemblyName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.Assembly
的用法示例。
在下文中一共展示了Assembly.GetAssemblyName方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetResourceNames
private static IReadOnlyList<string> GetResourceNames( Assembly assembly, string resourceName )
{
Contract.Requires( assembly != null );
Contract.Requires( !string.IsNullOrEmpty( resourceName ) );
Contract.Ensures( Contract.Result<IReadOnlyList<string>>() != null );
Contract.Ensures( Contract.ForAll( Contract.Result<IReadOnlyList<string>>(), name => !string.IsNullOrEmpty( name ) ) );
// XAML resources are stored in the *.g.resources element
var manifestKey = XamlResourcesFormat.FormatInvariant( assembly.GetAssemblyName() );
IReadOnlyList<string> resourceNames;
// look up cached resource names
if ( xamlResources.TryGetValue( manifestKey, out resourceNames ) )
return resourceNames;
// no resources
if ( !assembly.GetManifestResourceNames().Contains( manifestKey, StringComparer.Ordinal ) )
throw new IOException( ExceptionMessage.MissingResourceException.FormatDefault( resourceName ) );
// prevent cache from group exponentially
if ( xamlResources.Count > 100 )
xamlResources.Clear();
using ( var stream = assembly.GetManifestResourceStream( manifestKey ) )
{
var reader = new System.Resources.ResourceReader( stream );
resourceNames = new List<string>( reader.Cast<System.Collections.DictionaryEntry>().Select( entry => (string) entry.Key ) );
}
// cache resource names so the manifest doesn't have to be reloaded
xamlResources[manifestKey] = resourceNames;
return resourceNames;
}
示例2: ResourceUri
public static Uri ResourceUri(string resource, string subfolder = "Icons", Assembly assembly = null)
{
assembly = assembly ?? typeof(ResourceHelper).Assembly;
return new Uri(string.Format(
"pack://application:,,,/{0};component/{1}/{2}",
assembly.GetAssemblyName(),
subfolder,
resource));
}
示例3: GetVersionFromAssembly
private string GetVersionFromAssembly(Assembly assembly) {
if (assembly == null)
return null;
string version = assembly.GetInformationalVersion();
if (String.IsNullOrEmpty(version) || String.Equals(version, "0.0.0.0"))
version = assembly.GetFileVersion();
if (String.IsNullOrEmpty(version) || String.Equals(version, "0.0.0.0"))
version = assembly.GetVersion();
if (String.IsNullOrEmpty(version) || String.Equals(version, "0.0.0.0")) {
var assemblyName = assembly.GetAssemblyName();
version = assemblyName != null ? assemblyName.Version.ToString() : null;
}
return !String.IsNullOrEmpty(version) && !String.Equals(version, "0.0.0.0") ? version : null;
}
示例4: WithIcon
public StandardMenuItem WithIcon(Assembly source, string path)
{
var manager = IoC.Get<IResourceService>();
var iconSource = manager.GetBitmap(path, source.GetAssemblyName());
if (source != null)
Icon = new Image
{
Source = iconSource,
Width = 16,
Height = 16
};
return this;
}
示例5: ToComponentUri
/// <summary>Converts the path to a resource into a fully qualified component URI (eg "/assembly;component/Images/MyImage.png").</summary>
/// <param name="resourcePath">
/// The path to the resource from the root of the project.<BR/>
/// This may, or may not, contain a leading '/' character.<BR/>
/// For example: "Images/MyImage.png"<BR/>
/// </param>
/// <param name="assembly">The assembly the resource is within.</param>
/// <returns>A fully qualified URI.</returns>
public static Uri ToComponentUri(this string resourcePath, Assembly assembly)
{
resourcePath = resourcePath.TrimStart("/".ToCharArray());
var url = string.Format("/{0};component/{1}", assembly.GetAssemblyName(), resourcePath);
return new Uri(url, UriKind.Relative);
}
示例6: ResolveResourceName
private static string ResolveResourceName( Assembly assembly, string resourceName )
{
Contract.Requires( assembly != null );
Contract.Requires( !string.IsNullOrEmpty( resourceName ) );
Contract.Ensures( !string.IsNullOrEmpty( Contract.Result<string>() ) );
var manifestResources = GetResourceNames( assembly, resourceName );
var resourceNames = MatchResourceNames( manifestResources, resourceName );
// must be exactly one resource
// NOTE: WPF and Silverlight throw different exceptions for missing resources; match the behavior
if ( !resourceNames.Any() )
throw new IOException( ExceptionMessage.MissingResourceException.FormatDefault( resourceName ) );
else if ( resourceNames.Count > 1 )
throw new IOException( ExceptionMessage.AmbiguousResourceException.FormatDefault( resourceName, assembly.GetAssemblyName(), resourceNames.Count ) );
return resourceNames[0];
}
示例7: WithIcon
public StandardToolBarItem WithIcon(Assembly source, string path)
{
var manager = IoC.Get<IResourceManager>();
Icon = manager.GetBitmap(path, source.GetAssemblyName());
return this;
}
示例8: WithIcon
public StandardMenuItem WithIcon(Assembly source, string path)
{
var manager = IoC.Get<IResourceManager>();
var iconSource = manager.GetBitmap(path, source.GetAssemblyName());
//IconSource = new Uri(path, UriKind.Relative);
IconSource = new Uri("pack://application:,,,/"+source.GetAssemblyName() + ";component/" + path, UriKind.RelativeOrAbsolute);
if (source != null)
Icon = new Image
{
Source = iconSource,
Width = 16,
Height = 16
};
return this;
}