本文整理汇总了C#中System.Reflection.Assembly.GetHashCode方法的典型用法代码示例。如果您正苦于以下问题:C# Assembly.GetHashCode方法的具体用法?C# Assembly.GetHashCode怎么用?C# Assembly.GetHashCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.Assembly
的用法示例。
在下文中一共展示了Assembly.GetHashCode方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetLoggingConfiguration
/// <summary>
/// 根据程序集获取日志记录器配置信息。
/// </summary>
/// <param name="assembly">程序集。</param>
/// <returns>日志配置。</returns>
public object GetLoggingConfiguration(Assembly assembly)
{
if (assembly == null)
throw new ArgumentNullException("assembly");
return _cacheManager.Get(assembly.GetHashCode(), ctx =>
{
var stream = GetLoggingConfigurationStream(assembly);
if (stream == null)
return new XmlLoggingConfiguration(_defaultConfigurationPath);
using (stream)
{
var document = XDocument.Load(stream);
var nlogElement = document.Element(XName.Get("nlog", "http://www.nlog-project.org/schemas/NLog.xsd"));
//组合规则。
CombineRules(assembly, document);
//组合目标。
CombineTargets(nlogElement);
using (var stringReader = new StringReader(document.ToString()))
{
var xmlReader = XmlReader.Create(stringReader);
return new XmlLoggingConfiguration(xmlReader, null);
}
}
});
}
示例2: CreateWebResourceUrlCacheKey
/// <devdoc>
/// Create a cache key for the UrlCache.
///
/// requirement: If assembly1 and assembly2 represent the same assembly,
/// then they must be the same object; otherwise this method will fail to generate
/// a unique cache key.
/// </devdoc>
private static int CreateWebResourceUrlCacheKey(Assembly assembly, string resourceName,
bool htmlEncoded, bool forSubstitution, bool enableCdn, bool debuggingEnabled, bool secureConnection) {
int hashCode = HashCodeCombiner.CombineHashCodes(
assembly.GetHashCode(),
resourceName.GetHashCode(),
htmlEncoded.GetHashCode(),
forSubstitution.GetHashCode(),
enableCdn.GetHashCode());
return HashCodeCombiner.CombineHashCodes(hashCode,
debuggingEnabled.GetHashCode(),
secureConnection.GetHashCode());
}
示例3: GetAssemblyName
private static string GetAssemblyName(Assembly asm)
{
var key = asm.GetHashCode();
lock (AssemblyNameCache)
{
string name;
if (!AssemblyNameCache.TryGetValue(key, out name))
{
name = asm.GetName().Name;
AssemblyNameCache[key] = name;
}
return name;
}
}
示例4: CreateResourceUrl
static string CreateResourceUrl (Assembly assembly, string resourceName, bool notifyScriptLoaded)
{
string aname = assembly == currAsm ? "s" : assembly.GetName ().FullName;
string apath = assembly.Location;
string atime = String.Empty;
string extra = String.Empty;
#if SYSTEM_WEB_EXTENSIONS
extra = String.Concat (QueryParamSeparator, "n=", notifyScriptLoaded ? "t" : "f");
#endif
#if TARGET_JVM
atime = String.Format ("{0}t={1}", QueryParamSeparator, assembly.GetHashCode ());
#else
if (apath != String.Empty)
atime = String.Concat (QueryParamSeparator, "t=", File.GetLastWriteTimeUtc (apath).Ticks);
#endif
string href = HandlerFileName + "?d=" + EncryptAssemblyResource (aname, resourceName) + atime + extra;
HttpContext ctx = HttpContext.Current;
if (ctx != null && ctx.Request != null) {
string appPath = VirtualPathUtility.AppendTrailingSlash (ctx.Request.ApplicationPath);
href = appPath + href;
}
return href;
}
示例5: GetResourceInfo
/// <summary>
/// Get the info about the resource that in the assembly
/// </summary>
/// <param name="assembly"></param>
/// <param name="resourceName"></param>
/// <returns></returns>
private static Quadruplet<bool, bool, string, bool> GetResourceInfo(Assembly assembly, string resourceName)
{
// Create a unique cache key
int cacheKey = Util.CombineHashCodes(assembly.GetHashCode(), resourceName.GetHashCode());
Quadruplet<bool, bool, string, bool> resourceInfo = _webResourceCache[cacheKey] as Quadruplet<bool, bool, string, bool>;
// Assembly info was not in the cache
if (resourceInfo == null)
{
bool first = false;
bool second = false;
string third = string.Empty;
bool forth = false;
object[] customAttributes = assembly.GetCustomAttributes(false);
for (int j = 0; j < customAttributes.Length; j++)
{
WebResourceAttribute attribute = customAttributes[j] as WebResourceAttribute;
if ((attribute != null) && string.Equals(attribute.WebResource, resourceName, StringComparison.Ordinal))
{
first = true;
second = attribute.PerformSubstitution;
third = attribute.ContentType;
forth = Util.IsContentTypeCompressible(attribute.ContentType);
break;
}
}
resourceInfo = new Quadruplet<bool, bool, string, bool>(first, second, third, forth);
_webResourceCache[cacheKey] = resourceInfo;
}
return resourceInfo;
}
示例6: GetResourceInfo
/// <summary>
/// Get the info about the resource that in the assembly
/// </summary>
/// <param name="assembly"></param>
/// <param name="resourceName"></param>
/// <returns></returns>
protected static Quadruplet<bool, bool, string, bool> GetResourceInfo(Assembly assembly, string resourceName)
{
// Create a unique cache key
var cacheKey = CombineHashCodes(assembly.GetHashCode(), resourceName.GetHashCode());
var resourceInfo = WebResourceCache[cacheKey] as Quadruplet<bool, bool, string, bool>;
// Assembly info was not in the cache
if (resourceInfo == null)
{
var first = false;
var second = false;
var third = string.Empty;
var forth = false;
var customAttributes = assembly.GetCustomAttributes(false);
for (var j = 0; j < customAttributes.Length; j++)
{
var attribute = customAttributes[j] as WebResourceAttribute;
if ((attribute == null) || !string.Equals(attribute.WebResource, resourceName, StringComparison.Ordinal)) continue;
first = true;
second = attribute.PerformSubstitution;
third = attribute.ContentType;
forth = CompressionModuleHelper.IsContentTypeCompressible(attribute.ContentType);
break;
}
resourceInfo = new Quadruplet<bool, bool, string, bool>(first, second, third, forth);
WebResourceCache[cacheKey] = resourceInfo;
}
return resourceInfo;
}
示例7: SetScriptReflection
internal static void SetScriptReflection(Assembly assembly, string location)
{
Environment.SetEnvironmentVariable("location:" + assembly.GetHashCode(), location);
string source = null;
//Note assembly can contain only single AssemblyDescriptionAttribute
foreach (AssemblyDescriptionAttribute attribute in assembly.GetCustomAttributes(typeof(AssemblyDescriptionAttribute), true))
source = attribute.Description;
//check if executing the primary script and not hosted execution ("CSScriptRuntime" == null)
if (Environment.GetEnvironmentVariable("CSScriptRuntime") != null && source == Environment.GetEnvironmentVariable("EntryScript"))
Environment.SetEnvironmentVariable("EntryScriptAssembly", location);
}
示例8: PutAssemblyTypesInCache
// Recursively check for types with GTypeNameAttribute and put them in TypeCache,
// but only if gstreamer-sharp is in the chain of referenced assemblies.
private static void PutAssemblyTypesInCache(Assembly asm)
{
// If already visited, return immediately
if (AssemblyTypesInCache.ContainsKey(asm.GetHashCode ()))
return;
// Add with false to avoid chasing circular dependencies
AssemblyTypesInCache.Add (asm.GetHashCode (), false);
// Result is true for gstreamer-sharp or if a referenced assembly results in true
bool result = asm.GetName().Name.Equals("gstreamer-sharp");
foreach (AssemblyName ref_name in asm.GetReferencedAssemblies ()) {
try {
Assembly ref_asm = Assembly.Load (ref_name);
PutAssemblyTypesInCache (ref_asm);
result = result | AssemblyTypesInCache[ref_asm.GetHashCode ()];
} catch {
/* Failure to load a referenced assembly is not an error */
}
}
// Add types with GTypeNameAttribute in TypeCache
if (result) {
AssemblyTypesInCache[asm.GetHashCode ()] = true;
Type[] ts;
try {
ts = asm.GetTypes ();
} catch (ReflectionTypeLoadException e) {
ts = e.Types;
}
foreach (Type t in ts) {
if (t != null && t.IsDefined (typeof (GTypeNameAttribute), false)) {
GTypeNameAttribute gattr = (GTypeNameAttribute) Attribute.GetCustomAttribute (t, typeof (GTypeNameAttribute), false);
TypeCache[gattr.TypeName] = t;
}
}
}
}