本文整理汇总了C#中System.Reflection.AssemblyName.GetPublicKeyToken方法的典型用法代码示例。如果您正苦于以下问题:C# AssemblyName.GetPublicKeyToken方法的具体用法?C# AssemblyName.GetPublicKeyToken怎么用?C# AssemblyName.GetPublicKeyToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.AssemblyName
的用法示例。
在下文中一共展示了AssemblyName.GetPublicKeyToken方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RoundTrip
private void RoundTrip(AssemblyName name, bool testFullName = true)
{
AssemblyName rtName;
FusionAssemblyIdentity.IAssemblyName obj;
if (testFullName)
{
string fullName = name.FullName;
obj = FusionAssemblyIdentity.ToAssemblyNameObject(fullName);
rtName = ToAssemblyName(obj);
Assert.Equal(name.Name, rtName.Name);
Assert.Equal(name.Version, rtName.Version);
Assert.Equal(name.CultureInfo, rtName.CultureInfo);
Assert.Equal(name.GetPublicKeyToken(), rtName.GetPublicKeyToken());
Assert.Equal(name.Flags, rtName.Flags);
Assert.Equal(name.ContentType, rtName.ContentType);
string displayName = FusionAssemblyIdentity.GetDisplayName(obj, FusionAssemblyIdentity.ASM_DISPLAYF.FULL);
Assert.Equal(fullName, displayName);
}
obj = FusionAssemblyIdentity.ToAssemblyNameObject(name);
rtName = ToAssemblyName(obj);
Assert.Equal(name.Name, rtName.Name);
Assert.Equal(name.Version, rtName.Version);
Assert.Equal(name.CultureInfo, rtName.CultureInfo);
Assert.Equal(name.GetPublicKeyToken(), rtName.GetPublicKeyToken());
Assert.Equal(name.Flags, rtName.Flags);
Assert.Equal(name.ContentType, rtName.ContentType);
}
示例2: FilterOnPkt
private static IEnumerable<Assembly> FilterOnPkt(IEnumerable<Assembly> assemblies, AssemblyName assmName)
{
if (assmName.GetPublicKeyToken() != null)
{
var r = assemblies.Where(a => a.GetName().GetPublicKeyToken().SequenceEqual(assmName.GetPublicKeyToken()));
if (!r.Any())
return assemblies;
else
return r;
}
return assemblies;
}
示例3: CurrentDomain_AssemblyResolve
static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
if (!args.Name.StartsWith(prefix))
return null;
var name = new AssemblyName(args.Name.Substring(prefix.Length));
if (name.GetPublicKeyToken() != null && name.GetPublicKeyToken().Length > 0)
return null;
name.SetPublicKeyToken(publicKeyToken);
name.Version = vsVersion;
Debug.WriteLine("Ref12: Redirecting load of " + args.Name + ",\tfrom " + (args.RequestingAssembly == null ? "(unknown)" : args.RequestingAssembly.FullName));
return Assembly.Load(name);
}
示例4: TryGetPregeneratedPInvoke
/// <summary>
/// Returns pregenerated interop code for given PInvoke method if one exist
/// </summary>
public static MethodDesc TryGetPregeneratedPInvoke(MethodDesc method)
{
Debug.Assert(method.IsPInvoke);
var metadataType = (MetadataType)method.OwningType;
var module = metadataType.Module;
var assemblyName = ((IAssemblyDesc)module).GetName();
var interopAssemblyName = new AssemblyName();
interopAssemblyName.Name = assemblyName.Name + AssemblyNameSuffix;
interopAssemblyName.Version = assemblyName.Version;
interopAssemblyName.SetPublicKeyToken(interopAssemblyName.GetPublicKeyToken());
interopAssemblyName.CultureName = assemblyName.CultureName;
interopAssemblyName.ContentType = assemblyName.ContentType;
var interopModule = module.Context.ResolveAssembly(interopAssemblyName, false);
if (interopModule == null)
return null;
var pregeneratedMethod = GetMatchingMethod(interopModule, method);
if (pregeneratedMethod == null)
{
// TODO: Better error message
throw new MissingMemberException("Missing method in " + interopAssemblyName.Name + ":" + method.ToString());
}
return pregeneratedMethod;
}
示例5: AddName
public void AddName(AssemblyName name)
{
ListViewItem item = new ListViewItem(name.Name);
item.SubItems.Add(name.Version.ToString());
StringBuilder builder = new StringBuilder();
byte[] publicKey = name.GetPublicKeyToken();
if (publicKey == null)
{
item.SubItems.Add("null");
}
else
{
foreach (byte b in publicKey)
{
builder.AppendFormat("{0:X02}", b);
}
item.SubItems.Add(builder.ToString());
}
item.Tag = name;
Items.Add(item);
}
示例6: AssemblyQualifiedNameEquals
internal static bool AssemblyQualifiedNameEquals(Type t1, Type t2)
{
if (object.ReferenceEquals(t1, null))
{
return object.ReferenceEquals(t2, null);
}
if (object.ReferenceEquals(t2, null))
{
return false;
}
if (t1.FullName != t2.FullName)
{
return false;
}
if (t1.Assembly.FullName == t2.Assembly.FullName)
{
return true;
}
AssemblyName name = new AssemblyName(t1.Assembly.FullName);
AssemblyName name2 = new AssemblyName(t2.Assembly.FullName);
if (!(name.Name == name2.Name))
{
return IsWindowsBaseToSystemXamlComparison(t1.Assembly, t2.Assembly, name, name2);
}
return (name.CultureInfo.Equals(name2.CultureInfo) && SafeSecurityHelper.IsSameKeyToken(name.GetPublicKeyToken(), name2.GetPublicKeyToken()));
}
示例7: SetAssemblyName
public void SetAssemblyName(AssemblyName assemblyName)
{
Name = assemblyName.Name;
Version = assemblyName.Version.ToString();
Culture = (assemblyName.CultureInfo == null) ? string.Empty : assemblyName.CultureInfo.Name;
PublicKeyToken = ToHexString(assemblyName.GetPublicKeyToken());
ProcessorArchitecture = assemblyName.ProcessorArchitecture;
}
示例8: MonoAssemblyName
public MonoAssemblyName(string name, string directory)
{
AssemblyName assemblyName = new AssemblyName(name);
this.name = assemblyName.Name;
version = assemblyName.Version;
cultureInfo = assemblyName.CultureInfo;
publicKeyToken = assemblyName.GetPublicKeyToken();
this.directory = directory;
}
示例9: LookupFullName
protected string LookupFullName(string name)
{
AssemblyName asm = new AssemblyName(name);
if (asm.Version != null || asm.GetPublicKeyToken() != null || asm.GetPublicKey() != null)
{
return name;
}
return _assemblyFullNames.ContainsKey(name.ToLower()) ? _assemblyFullNames[name.ToLower()] : name;
}
示例10: AssemblyNameEquals
internal static bool AssemblyNameEquals(AssemblyName thisName, AssemblyName thatName)
{
if ((thisName.Name == null) || (thatName.Name == null))
{
return false;
}
if (!thatName.Name.Equals(thisName.Name))
{
return false;
}
Version version = thatName.Version;
if (((version != null) && (version != emptyVersion)) && (version != thisName.Version))
{
return false;
}
CultureInfo cultureInfo = thatName.CultureInfo;
if ((cultureInfo != null) && !cultureInfo.Equals(CultureInfo.InvariantCulture))
{
CultureInfo parent = thisName.CultureInfo;
if (parent == null)
{
return false;
}
while (!cultureInfo.Equals(parent))
{
parent = parent.Parent;
if (parent.Equals(CultureInfo.InvariantCulture))
{
return false;
}
}
}
byte[] publicKeyToken = thatName.GetPublicKeyToken();
if ((publicKeyToken != null) && (publicKeyToken.Length != 0))
{
byte[] buffer2 = thisName.GetPublicKeyToken();
if (buffer2 == null)
{
return false;
}
if (publicKeyToken.Length != buffer2.Length)
{
return false;
}
for (int i = 0; i < publicKeyToken.Length; i++)
{
if (publicKeyToken[i] != buffer2[i])
{
return false;
}
}
}
return true;
}
示例11: TryRedirect
private static bool TryRedirect(AssemblyName name, byte[] token, int major, int minor, int revision, int build)
{
var version = new Version(major, minor, revision, build);
if (KeysEqual(name.GetPublicKeyToken(), token) && name.Version < version)
{
name.Version = version;
return true;
}
return false;
}
示例12: DefinitionIdentity
public DefinitionIdentity(AssemblyName asmName)
{
this._idComPtr = System.Deployment.Internal.Isolation.IsolationInterop.IdentityAuthority.CreateDefinition();
this["name"] = asmName.Name;
this["version"] = asmName.Version.ToString();
if (asmName.CultureInfo != null)
{
this["culture"] = asmName.CultureInfo.Name;
}
byte[] publicKeyToken = asmName.GetPublicKeyToken();
if ((publicKeyToken != null) && (publicKeyToken.Length > 0))
{
this["publicKeyToken"] = HexString.FromBytes(publicKeyToken);
}
}
示例13: AssemblyName
int IComparer.Compare(object lhs, object rhs)
{
AssemblyName assemblyName = new AssemblyName((string)lhs);
AssemblyName assemblyName2 = (AssemblyName)rhs;
int num = string.Compare(assemblyName.Name, assemblyName2.Name, StringComparison.OrdinalIgnoreCase);
if (num != 0)
{
return num;
}
byte[] publicKeyToken = assemblyName.GetPublicKeyToken();
byte[] publicKeyToken2 = assemblyName2.GetPublicKeyToken();
if (publicKeyToken == null)
{
return -1;
}
if (publicKeyToken2 == null)
{
return 1;
}
if (publicKeyToken.Length < publicKeyToken2.Length)
{
return -1;
}
if (publicKeyToken.Length > publicKeyToken2.Length)
{
return 1;
}
for (int i = 0; i < publicKeyToken.Length; i++)
{
byte b = publicKeyToken[i];
byte b2 = publicKeyToken2[i];
if (b < b2)
{
return -1;
}
if (b > b2)
{
return 1;
}
}
return 0;
}
示例14: AreWeReferringToTheSameAssembly
private bool AreWeReferringToTheSameAssembly(AssemblyName simple, AssemblyName fullyQualified)
{
var result = simple.Name == fullyQualified.Name;
if (simple.Version != null)
result &= simple.Version <= fullyQualified.Version;
if (simple.ProcessorArchitecture != ProcessorArchitecture.None)
{
result &= simple.ProcessorArchitecture == fullyQualified.ProcessorArchitecture;
}
if (simple.CultureInfo != null)
{
result &= simple.CultureInfo.Equals(fullyQualified.CultureInfo);
}
if (simple.GetPublicKeyToken() != null)
{
result &= simple.GetPublicKeyToken().SequenceEqual(fullyQualified.GetPublicKeyToken());
}
return result;
}
示例15: Matches
/// <summary>
/// Matches the name of <paramref name="assembly"/> with <paramref name="assemblyNameToMatch"/>.
/// </summary>
/// <param name="assembly">The assembly to match.</param>
/// <param name="assemblyNameToMatch">The assembly name to match.</param>
/// <returns><see langword="true"/> if the name matches; otherwise <see langword="false"/>.</returns>
public static bool Matches(Assembly assembly, AssemblyName assemblyNameToMatch)
{
if (assembly == null) return false;
if (assemblyNameToMatch == null) return false;
var assemblyName = assembly.GetName();
if (assemblyName.Name == assemblyNameToMatch.Name)
{
if (assemblyNameToMatch.Version != null &&
assemblyNameToMatch.Version.CompareTo(assemblyName.Version) != 0)
{
return false;
}
byte[] requestedAsmPublicKeyToken = assemblyNameToMatch.GetPublicKeyToken();
if (requestedAsmPublicKeyToken != null)
{
byte[] cachedAssemblyPublicKeyToken = assemblyName.GetPublicKeyToken();
if (Convert.ToBase64String(requestedAsmPublicKeyToken) != Convert.ToBase64String(cachedAssemblyPublicKeyToken))
{
return false;
}
}
var requestedAssemblyCulture = assemblyNameToMatch.CultureInfo;
if (requestedAssemblyCulture != null && requestedAssemblyCulture.LCID != CultureInfo.InvariantCulture.LCID)
{
if (assemblyName.CultureInfo.LCID != requestedAssemblyCulture.LCID)
{
return false;
}
}
return true;
}
return false;
}