/// <summary> /// Checks whether given <see cref="CILAssemblyName"/> represents assembly from .NET framework based on its public key. /// </summary> /// <param name="aName">The <see cref="CILAssemblyName"/>.</param> /// <returns><c>true</c> if <paramref name="aName"/> is not <c>null</c> and its public key matches the standard public key.</returns> /// <remarks> /// ECMA-335 (p. 116) defines the standard public key to be the following 16 bytes <c>00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00</c>. /// The resulting public key token is the following 8 bytes: <c>b7 7a 5c 56 19 34 e0 89</c>. /// </remarks> public static Boolean HasStandardPublicKey(this CILAssemblyName aName) { return(aName != null && aName.PublicKey != null && ((aName.Flags.IsFullPublicKey() && aName.PublicKey.Length == DOT_NET_PUBLIC_KEY_BYTES.Length && DOT_NET_PUBLIC_KEY_BYTES.SequenceEqual(aName.PublicKey)) || (!aName.Flags.IsFullPublicKey() && aName.PublicKey.Length == DOT_NET_PUBLIC_KEY_TOKEN_BYTES.Length && DOT_NET_PUBLIC_KEY_TOKEN_BYTES.SequenceEqual(aName.PublicKey)) )); }
public Boolean TryGetMappedAssembly(CILAssemblyName name, out CILAssembly assembly) { Lazy <CILAssembly> lazy; var retVal = this._assemblies.TryGetValue(name, out lazy); assembly = retVal ? lazy.Value : null; return(retVal); }
private CILAssembly LoadFunction(CILModule module, CILAssemblyName aName) { return(this._loadedAssemblies.GetOrAdd(this._portableLibDirectory + aName.Name + ".dll", pathArg => { using (var stream = this._streamOpener(pathArg)) { return module.ReflectionContext.LoadAssembly(stream, this._loadArgs); } })); }
/// <summary> /// Returns <c>true</c> if <see cref="CILElementWithSimpleName.Name"/>, <see cref="CILAssemblyName.Culture"/>, <see cref="CILAssemblyName.MajorVersion"/>, <see cref="CILAssemblyName.MinorVersion"/>, <see cref="CILAssemblyName.BuildNumber"/> and <see cref="CILAssemblyName.Revision"/> all match for both <paramref name="thisName"/> and <paramref name="other"/>. /// </summary> /// <param name="thisName">First assembly name.</param> /// <param name="other">Second assembly name.</param> /// <returns><c>true</c> if <see cref="CILElementWithSimpleName.Name"/>, <see cref="CILAssemblyName.Culture"/>, <see cref="CILAssemblyName.MajorVersion"/>, <see cref="CILAssemblyName.MinorVersion"/>, <see cref="CILAssemblyName.BuildNumber"/> and <see cref="CILAssemblyName.Revision"/> all match for both <paramref name="thisName"/> and <paramref name="other"/>; <c>false</c> otherwise.</returns> public static Boolean CorePropertiesEqual(this CILAssemblyName thisName, CILAssemblyName other) { return(Object.ReferenceEquals(thisName, other) || ( thisName != null && other != null && Object.Equals(thisName.Name, other.Name) && thisName.MajorVersion == other.MajorVersion && thisName.MinorVersion == other.MinorVersion && thisName.BuildNumber == other.BuildNumber && thisName.Revision == other.Revision && Object.Equals(thisName.Culture, other.Culture))); }
internal CILAssemblyImpl( CILReflectionContextImpl ctx, Int32 anID, System.Reflection.Assembly ass ) : base(ctx, anID, CILElementKind.Assembly, () => new CustomAttributeDataEventArgs(ctx, ass)) { ArgumentValidator.ValidateNotNull("Assembly", ass); InitFields( ref this.name, ref this.modules, ref this.forwardedTypes, ref this.mainModule, () => { var result = CILAssemblyName.Parse(ass.FullName); var args = new AssemblyNameEventArgs(ass); ctx.LaunchAssemblyNameLoadEvent(args); var info = args.AssemblyNameInfo; if (info != null) { result.HashAlgorithm = info.Item1; result.Flags = info.Item2; if (info.Item3 != null) { result.PublicKey = info.Item3; if (result.PublicKey.IsNullOrEmpty()) { // .NET for some reason returns PublicKey-flag set, even with no public key... result.Flags = result.Flags & ~(AssemblyFlags.PublicKey); } } } return(result); }, () => ctx.CollectionsFactory.NewListProxy <CILModule>(ass .GetModules() .Select(module => ctx.Cache.GetOrAdd(module)) .ToList()), () => { // TODO seems that getting type forward info is not really possible via C# managed reflection API? throw new NotImplementedException(); }, () => ctx.Cache.GetOrAdd(ass.ManifestModule) ); }
private System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args) { Console.WriteLine("SL BUILD trying to resolve " + args.Name + " using SL runtime directory " + this._slRuntimeDir + "."); // This only gets invoked in Silverlight builds System.Reflection.Assembly result = null; CILAssemblyName aName; if (CILAssemblyName.TryParse(args.Name, out aName)) { var suitablePath = Path.Combine(this._slRuntimeDir, aName.Name + ".dll"); if (File.Exists(suitablePath)) { result = System.Reflection.Assembly.LoadFrom(suitablePath); } } return(result); }
public Boolean IsMapped(CILAssemblyName an) { return(this._assemblies.ContainsKey(an)); }
/// <summary> /// Returns textual representation of the culture information contained in <paramref name="name"/>. If the <see cref="CILAssemblyName.Culture"/> returns <c>null</c> or empty string, this method returns string "neutral". Otherwise it returns the result of <see cref="CILAssemblyName.Culture"/>. /// </summary> /// <param name="name">The assembly name containing culture information.</param> /// <returns>Textual representation of the culture information contained in <paramref name="name"/>.</returns> /// <exception cref="ArgumentNullException">If <paramref name="name"/> is <c>null</c>.</exception> public static String GetCultureString(this CILAssemblyName name) { ArgumentValidator.ValidateNotNull("Assembly name", name); return(String.IsNullOrEmpty(name.Culture) ? "neutral" : name.Culture); }
/// <summary> /// Gets textual representation of the version information contained in <paramref name="name"/>. The format is: "<c><major>.<minor>.<build>.<revision></c>". /// </summary> /// <param name="name">The assembly name containing version information.</param> /// <returns>Textual representation of the version information contained in <paramref name="name"/>.</returns> /// <exception cref="ArgumentNullException">If <paramref name="name"/> is <c>null</c>.</exception> public static String GetVersionString(this CILAssemblyName name) { ArgumentValidator.ValidateNotNull("Assembly name", name); return(name.MajorVersion + VERSION_NUMBER_SEPARATOR + name.MinorVersion + VERSION_NUMBER_SEPARATOR + name.BuildNumber + VERSION_NUMBER_SEPARATOR + name.Revision); }