/// <summary> /// Get the name of an Assembly. /// </summary> /// <param name="pIAssemblyName">Pointer to an IAssemblyName interface.</param> /// <param name="wszAssemblyName">Pointer to the name of the Assembly.</param> /// <returns>Whether the function successfully executed.</returns> public uint GetAssemblyName(ref IAssemblyName pIAssemblyName, ref string wszAssemblyName) { if (pIAssemblyName == null) { return(Macros.E_FAIL); } uint uBufferSize = 0; pIAssemblyName.GetName(ref uBufferSize, null); if (uBufferSize == 0) { return(Macros.E_FAIL); } StringBuilder bob = new StringBuilder((int)uBufferSize); uint hr = pIAssemblyName.GetName(ref uBufferSize, bob); if (!Macros.SUCCEEDED(hr)) { return(Macros.E_FAIL); } wszAssemblyName = bob.ToString(); return(Macros.S_OK); }
private static string GetName(IAssemblyName name) { uint bufferSize = 255; var stringBuilder = new StringBuilder((int)bufferSize); name.GetName(ref bufferSize, stringBuilder); return stringBuilder.ToString().Trim(); }
static String GetName(IAssemblyName name) { uint bufferSize = 255; StringBuilder buffer = new StringBuilder((int)bufferSize); name.GetName(ref bufferSize, buffer); return(buffer.ToString()); }
private static string GetName(this IAssemblyName name) { uint bufferSize = 255; var buffer = new StringBuilder((int)bufferSize); name.GetName(ref bufferSize, buffer); return(buffer.ToString()); }
/// <summary> /// Converts the value of this instance to its equivalent <see cref="AssemblyName"/>. /// </summary> /// <param name="assemblyName"></param> /// <returns></returns> public static AssemblyName ToAssemblyName(this IAssemblyName assemblyName) { var result = new AssemblyName(); result.Name = assemblyName.GetName(); result.Version = assemblyName.GetVersion(); result.CultureInfo = new CultureInfo(assemblyName.GetProperty <string>(AssemblyNamePropertyId.Culture)); result.CodeBase = assemblyName.GetProperty <string>(AssemblyNamePropertyId.CodebaseUrl); result.SetPublicKey(assemblyName.GetProperty <byte[]>(AssemblyNamePropertyId.PublicKey)); result.SetPublicKeyToken(assemblyName.GetProperty <byte[]>(AssemblyNamePropertyId.PublicKeyToken)); // Bug: The following line will always return null, why? And how to fix this? // assemblyName.GetProperty<object>(AssemblyNamePropertyId.ProcessorIdArray); // A workaround is available by using the displayname of the IAssemblyName var tmp = assemblyName.GetDisplayName(DisplayNameFlags.ProcessArchitecture); tmp = tmp.Substring(tmp.LastIndexOf('=') + 1); if (Enum.IsDefined(typeof(ProcessorArchitecture), tmp)) { result.ProcessorArchitecture = (ProcessorArchitecture)Enum.Parse(typeof(ProcessorArchitecture), tmp); } return(result); }
/// <summary> /// Gets the name. /// </summary> /// <param name="name">The name.</param> /// <returns></returns> public static String GetName(IAssemblyName name) { uint bufferSize = 255; var buffer = new StringBuilder((int) bufferSize); name.GetName(ref bufferSize, buffer); return buffer.ToString(); }