/// <summary> /// Checks whether <paramref name="asm"/> appears to be the core library (eg. /// mscorlib, System.Runtime or corefx) /// </summary> /// <param name="asm">The assembly</param> public static bool IsCorLib(this IAssembly asm) { string asmName; return(asm != null && UTF8String.IsNullOrEmpty(asm.Culture) && ((asmName = UTF8String.ToSystemStringOrEmpty(asm.Name)).Equals("mscorlib", StringComparison.OrdinalIgnoreCase) || asmName.Equals("System.Runtime", StringComparison.OrdinalIgnoreCase) || asmName.Equals("corefx", StringComparison.OrdinalIgnoreCase))); }
/// <summary> /// Constructor /// </summary> /// <param name="assembly">Assembly</param> public AssemblyRefUser(IAssembly assembly) { if (assembly == null) { throw new ArgumentNullException("asmName"); } this.version = assembly.Version ?? new Version(0, 0, 0, 0); this.publicKeyOrToken = assembly.PublicKeyOrToken; this.name = UTF8String.IsNullOrEmpty(assembly.Name) ? UTF8String.Empty : assembly.Name; this.culture = assembly.Culture; this.attributes = (int)((publicKeyOrToken is PublicKey ? AssemblyAttributes.PublicKey : AssemblyAttributes.None) | assembly.ContentType); }
/// <summary> /// Constructor /// </summary> /// <param name="asm">The assembly</param> public AssemblyNameInfo(IAssembly asm) { if (asm == null) { return; } var asmDef = asm as AssemblyDef; this.hashAlgId = asmDef == null ? 0 : asmDef.HashAlgorithm; this.version = asm.Version ?? new Version(0, 0, 0, 0); this.flags = asm.Attributes; this.publicKeyOrToken = asm.PublicKeyOrToken; this.name = UTF8String.IsNullOrEmpty(asm.Name) ? UTF8String.Empty : asm.Name; this.culture = UTF8String.IsNullOrEmpty(asm.Culture) ? UTF8String.Empty : asm.Culture; }
/// <summary> /// Returns an assembly name string /// </summary> /// <param name="name">Simple assembly name</param> /// <param name="version">Version or <c>null</c></param> /// <param name="culture">Culture or <c>null</c></param> /// <param name="publicKey">Public key / public key token or <c>null</c></param> /// <param name="attributes">Assembly attributes</param> /// <returns>An assembly name string</returns> internal static string GetAssemblyNameString(UTF8String name, Version version, UTF8String culture, PublicKeyBase publicKey, AssemblyAttributes attributes) { var sb = new StringBuilder(); foreach (var c in UTF8String.ToSystemStringOrEmpty(name)) { if (c == ',' || c == '=') { sb.Append('\\'); } sb.Append(c); } if (version != null) { sb.Append(", Version="); sb.Append(CreateVersionWithNoUndefinedValues(version).ToString()); } if ((object)culture != null) { sb.Append(", Culture="); sb.Append(UTF8String.IsNullOrEmpty(culture) ? "neutral" : culture.String); } sb.Append(", "); sb.Append(publicKey == null || publicKey is PublicKeyToken ? "PublicKeyToken=" : "PublicKey="); sb.Append(publicKey == null ? "null" : publicKey.ToString()); if ((attributes & AssemblyAttributes.Retargetable) != 0) { sb.Append(", Retargetable=Yes"); } if ((attributes & AssemblyAttributes.ContentType_Mask) == AssemblyAttributes.ContentType_WindowsRuntime) { sb.Append(", ContentType=WindowsRuntime"); } return(sb.ToString()); }
private static Info?GetInfo(TypeDef td) { if (td == null) { return(null); } if (td.IsWindowsRuntime) { return(null); } UTF8String scope = null, identifier = null; var tia = td.CustomAttributes.Find("System.Runtime.InteropServices.TypeIdentifierAttribute"); if (tia != null) { if (tia.ConstructorArguments.Count >= 2) { if (tia.ConstructorArguments[0].Type.GetElementType() != ElementType.String) { return(null); } if (tia.ConstructorArguments[1].Type.GetElementType() != ElementType.String) { return(null); } scope = tia.ConstructorArguments[0].Value as UTF8String ?? tia.ConstructorArguments[0].Value as string; identifier = tia.ConstructorArguments[1].Value as UTF8String ?? tia.ConstructorArguments[1].Value as string; } } else { var mod = td.Module; var asm = mod == null ? null : mod.Assembly; if (asm == null) { return(null); } bool isTypeLib = asm.CustomAttributes.IsDefined("System.Runtime.InteropServices.ImportedFromTypeLibAttribute") || asm.CustomAttributes.IsDefined("System.Runtime.InteropServices.PrimaryInteropAssemblyAttribute"); if (!isTypeLib) { return(null); } } if (UTF8String.IsNull(identifier)) { CustomAttribute gca; if (td.IsInterface && td.IsImport) { gca = td.CustomAttributes.Find("System.Runtime.InteropServices.GuidAttribute"); } else { var mod = td.Module; var asm = mod == null ? null : mod.Assembly; if (asm == null) { return(null); } gca = asm.CustomAttributes.Find("System.Runtime.InteropServices.GuidAttribute"); } if (gca == null) { return(null); } if (gca.ConstructorArguments.Count < 1) { return(null); } if (gca.ConstructorArguments[0].Type.GetElementType() != ElementType.String) { return(null); } scope = gca.ConstructorArguments[0].Value as UTF8String ?? gca.ConstructorArguments[0].Value as string; var ns = td.Namespace; var name = td.Name; if (UTF8String.IsNullOrEmpty(ns)) { identifier = name; } else if (UTF8String.IsNullOrEmpty(name)) { identifier = new UTF8String(Concat(ns.Data, (byte)'.', empty)); } else { identifier = new UTF8String(Concat(ns.Data, (byte)'.', name.Data)); } } return(new Info(scope, identifier)); }