当前位置: 首页>>代码示例>>C#>>正文


C# AssemblyName.GetPublicKey方法代码示例

本文整理汇总了C#中System.Reflection.AssemblyName.GetPublicKey方法的典型用法代码示例。如果您正苦于以下问题:C# AssemblyName.GetPublicKey方法的具体用法?C# AssemblyName.GetPublicKey怎么用?C# AssemblyName.GetPublicKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Reflection.AssemblyName的用法示例。


在下文中一共展示了AssemblyName.GetPublicKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ResolveAssembly

        private static Assembly ResolveAssembly(object sender, ResolveEventArgs args)
        {
            var requestedName = new AssemblyName(args.Name);

            if (knownAssemblies.ContainsKey(requestedName.Name))
            {
                foreach (var item in knownAssemblies[requestedName.Name])
                {
                    if (requestedName.Name == item.Item1.Name &&
                            (requestedName.Version == null || requestedName.Version == item.Item1.Version) &&
                            (requestedName.CultureInfo == null || requestedName.CultureInfo == item.Item1.CultureInfo) &&
                            (requestedName.GetPublicKey() == null || requestedName.GetPublicKey() == item.Item1.GetPublicKey()))
                    {
                        var path = Path.Combine(item.Item2, requestedName.Name + ".dll");
                        if (File.Exists(path))
                            return Assembly.LoadFrom(path);
                    }
                }
            }

            foreach (var directory in searchDirectories)
            {
                var path = Path.Combine(directory, requestedName.Name + ".dll");
                if (File.Exists(path))
                    return Assembly.LoadFrom(path);
            }

            return null;
        }
开发者ID:cpriebe,项目名称:MPExtended,代码行数:29,代码来源:AssemblyLoader.cs

示例2: 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;
 }
开发者ID:cperler,项目名称:Python-Via-Silverlight,代码行数:9,代码来源:Keggy.xaml.cs

示例3: Case5_SetPublicKey

        public void Case5_SetPublicKey()
        {
            AssemblyName n = new AssemblyName();
            byte[] barray = new byte[16];
            n.SetPublicKey(barray);

            byte[] barray_returned = n.GetPublicKey();
            Assert.NotNull(barray_returned);
            Assert.True(isEqual(barray, barray_returned));
        }
开发者ID:Rayislandstyle,项目名称:corefx,代码行数:10,代码来源:AssemblyName_MethodTests.cs

示例4: Case6_SetPublicKey

 public void Case6_SetPublicKey()
 {
     AssemblyName n = new AssemblyName();
     byte[] barray = new byte[16];
     for (int i = 0; i < barray.Length; i++)
         barray[i] = (byte)'\0';
     n.SetPublicKey(barray);
     byte[] barray_returned = n.GetPublicKey();
     Assert.NotNull(barray_returned);
     Assert.True(isEqual(barray, barray_returned));
 }
开发者ID:Rayislandstyle,项目名称:corefx,代码行数:11,代码来源:AssemblyName_MethodTests.cs

示例5: GetNormalizedStrongNameHash

        /// <summary>
        /// Uses the AssemblyName's public key to generate a hash equivalent to what
        /// StrongName.Normalize() gives.
        /// </summary>
        internal static string GetNormalizedStrongNameHash(AssemblyName name)
        {
            byte[] publicKey = name.GetPublicKey();

            // If we don't have a key, we're not strong named
            if (publicKey == null || publicKey.Length == 0)
                return null;

            // Emulate what we get from StrongName.Normalize().
            using (MemoryStream ms = new MemoryStream())
            using (BinaryWriter bw = new BinaryWriter(ms))
            {
                bw.Write(publicKey);
                bw.Write(name.Version.Major);
                bw.Write(name.Name);

                ms.Position = 0;
                return GetStrongHashSuitableForObjectName(ms);
            }
        }
开发者ID:kouvel,项目名称:corefx,代码行数:24,代码来源:IdentityHelper.cs

示例6: Serialization_WithoutStrongName

	public void Serialization_WithoutStrongName ()
	{
		an = new AssemblyName ();
		an.CodeBase = "http://www.test.com/test.dll";
		an.CultureInfo = CultureInfo.InvariantCulture;
		an.Flags = AssemblyNameFlags.None;
		an.HashAlgorithm = AssemblyHashAlgorithm.SHA1;
		an.KeyPair = null;
		an.Name = "TestAssembly2";
		an.Version = new Version (1, 5, 0, 0);
		an.VersionCompatibility = AssemblyVersionCompatibility.SameMachine;

		MemoryStream ms = new MemoryStream ();
		BinaryFormatter bf = new BinaryFormatter ();
		bf.Serialize (ms, an);

		// reset position of memorystream
		ms.Position = 0;

		// deserialze assembly name
		AssemblyName dsAssemblyName = (AssemblyName) bf.Deserialize (ms);

		// close the memorystream
		ms.Close ();

		// compare orginal and deserialized assembly name
		Assert.AreEqual (an.CodeBase, dsAssemblyName.CodeBase, "CodeBase");
		Assert.AreEqual (an.CultureInfo, dsAssemblyName.CultureInfo, "CultureInfo");
		Assert.AreEqual (an.Flags, dsAssemblyName.Flags, "Flags");
		Assert.AreEqual (an.HashAlgorithm, dsAssemblyName.HashAlgorithm, "HashAlgorithm");
		Assert.AreEqual (an.Name, dsAssemblyName.Name, "Name");
		Assert.AreEqual (an.Version, dsAssemblyName.Version, "Version");
		Assert.AreEqual (an.VersionCompatibility, dsAssemblyName.VersionCompatibility, "VersionCompatibility");
		Assert.AreEqual (an.EscapedCodeBase, dsAssemblyName.EscapedCodeBase, "EscapedCodeBase");
		Assert.AreEqual (an.FullName, dsAssemblyName.FullName, "FullName");
		Assert.AreEqual (an.ToString (), dsAssemblyName.ToString (), "ToString");
		Assert.AreEqual (an.GetPublicKey (), dsAssemblyName.GetPublicKey (), "PublicKey");
		Assert.AreEqual (an.GetPublicKeyToken (), dsAssemblyName.GetPublicKeyToken (), "PublicToken");
	}
开发者ID:wamiq,项目名称:debian-mono,代码行数:39,代码来源:AssemblyNameTest.cs

示例7: AssemblyNameInfo

		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="asmName">Assembly name info</param>
		public AssemblyNameInfo(AssemblyName asmName) {
			if (asmName == null)
				return;
			this.hashAlgId = (AssemblyHashAlgorithm)asmName.HashAlgorithm;
			this.version = asmName.Version ?? new Version(0, 0, 0, 0);
			this.flags = (AssemblyAttributes)asmName.Flags;
			this.publicKeyOrToken = (PublicKeyBase)PublicKeyBase.CreatePublicKey(asmName.GetPublicKey()) ??
							PublicKeyBase.CreatePublicKeyToken(asmName.GetPublicKeyToken());
			this.name = asmName.Name ?? string.Empty;
			this.culture = asmName.CultureInfo != null && asmName.CultureInfo.Name != null ? asmName.CultureInfo.Name : string.Empty;
		}
开发者ID:EmilZhou,项目名称:dnlib,代码行数:15,代码来源:AssemblyNameInfo.cs

示例8: Constructor1_ProcessorArchitecture

	[Category ("NotWorking")] // bug #351708
	public void Constructor1_ProcessorArchitecture ()
	{
		const string assemblyName = "TestAssembly";

		an = new AssemblyName (assemblyName + ", ProcessorArchitecture=X86");
		Assert.IsNull (an.CodeBase, "CodeBase");
		Assert.IsNull (an.CultureInfo, "CultureInfo");
		Assert.IsNull (an.EscapedCodeBase, "EscapedCodeBase");
		Assert.AreEqual (AssemblyNameFlags.None, an.Flags, "Flags");
		Assert.AreEqual ("TestAssembly", an.FullName, "FullName");
		Assert.AreEqual (AssemblyHashAlgorithm.None, an.HashAlgorithm, "HashAlgorithm");
		Assert.IsNull (an.KeyPair, "KeyPair");
		Assert.AreEqual (assemblyName, an.Name, "Name");
		Assert.AreEqual (ProcessorArchitecture.X86, an.ProcessorArchitecture, "PA");
		Assert.IsNull (an.Version, "Version");
		Assert.AreEqual (AssemblyVersionCompatibility.SameMachine, 
			an.VersionCompatibility, "VersionCompatibility");
		Assert.IsNull (an.GetPublicKey (), "GetPublicKey");
		Assert.IsNull (an.GetPublicKeyToken (), "GetPublicKeyToken");
		Assert.AreEqual ("TestAssembly", an.ToString (), "ToString");

		an = new AssemblyName (assemblyName + ", ProcessorArchitecture=mSiL");
		Assert.AreEqual (ProcessorArchitecture.MSIL, an.ProcessorArchitecture, "PA: MSIL");

		an = new AssemblyName (assemblyName + ", ProcessorArchitecture=AmD64");
		Assert.AreEqual (ProcessorArchitecture.Amd64, an.ProcessorArchitecture, "PA: Amd64");

		an = new AssemblyName (assemblyName + ", ProcessorArchitecture=iA64");
		Assert.AreEqual (ProcessorArchitecture.IA64, an.ProcessorArchitecture, "PA: IA64");
	}
开发者ID:wamiq,项目名称:debian-mono,代码行数:31,代码来源:AssemblyNameTest.cs

示例9: ApplyPolicy

		public string ApplyPolicy(string assemblyName)
		{
			AssemblyName assemblyName2 = new AssemblyName(assemblyName);
			byte[] array = assemblyName2.GetPublicKeyToken();
			if (array == null)
			{
				array = assemblyName2.GetPublicKey();
			}
			if (array == null || array.Length == 0)
			{
				return assemblyName;
			}
			return this.nApplyPolicy(assemblyName2);
		}
开发者ID:ChristianWulf,项目名称:CSharpKDMDiscoverer,代码行数:14,代码来源:AppDomain.cs

示例10: ApplyPolicy

        public String ApplyPolicy(String assemblyName)
        {
            AssemblyName asmName = new AssemblyName(assemblyName);  

            byte[] pk = asmName.GetPublicKeyToken();
            if (pk == null)
                pk = asmName.GetPublicKey();

            // Simply-named assemblies cannot have policy, so for those,
            // we simply return the passed-in assembly name.
            if ((pk == null) || (pk.Length == 0))
                return assemblyName;
            else
                return nApplyPolicy(asmName);
        }
开发者ID:Rayislandstyle,项目名称:dotnet-coreclr,代码行数:15,代码来源:AppDomain.cs

示例11: AssemblyBuilder

		internal AssemblyBuilder (AssemblyName n, string directory, AssemblyBuilderAccess access, bool corlib_internal)
		{
			/* This is obsolete now, as mcs doesn't use SRE any more */
			if ((access & COMPILER_ACCESS) != 0)
				throw new NotImplementedException ("COMPILER_ACCESS is no longer supperted, use a newer mcs.");

			if (!Enum.IsDefined (typeof (AssemblyBuilderAccess), access))
				throw new ArgumentException (string.Format (CultureInfo.InvariantCulture,
					"Argument value {0} is not valid.", (int) access),
					"access");

			name = n.Name;
			this.access = (uint)access;
			flags = (uint) n.Flags;

			// don't call GetCurrentDirectory for Run-only builders (CAS may not like that)
			if (IsSave && (directory == null || directory.Length == 0)) {
				dir = Directory.GetCurrentDirectory ();
			} else {
				dir = directory;
			}

			/* Set defaults from n */
			if (n.CultureInfo != null) {
				culture = n.CultureInfo.Name;
				versioninfo_culture = n.CultureInfo.Name;
			}
			Version v = n.Version;
			if (v != null) {
				version = v.ToString ();
			}

			if (n.KeyPair != null) {
				// full keypair is available (for signing)
				sn = n.KeyPair.StrongName ();
			} else {
				// public key is available (for delay-signing)
				byte[] pk = n.GetPublicKey ();
				if ((pk != null) && (pk.Length > 0)) {
					sn = new Mono.Security.StrongName (pk);
				}
			}

			if (sn != null)
				flags |= (uint) AssemblyNameFlags.PublicKey;

			this.corlib_internal = corlib_internal;
			if (sn != null) {
				this.pktoken = new byte[sn.PublicKeyToken.Length * 2];
				int pkti = 0;
				foreach (byte pkb in sn.PublicKeyToken) {
					string part = pkb.ToString("x2");
					this.pktoken[pkti++] = (byte)part[0];
					this.pktoken[pkti++] = (byte)part[1];
				}
			}

			basic_init (this);
		}
开发者ID:sjlangley,项目名称:mono,代码行数:59,代码来源:AssemblyBuilder.cs

示例12: ApplyPolicy

 public string ApplyPolicy(string assemblyName)
 {
     AssemblyName an = new AssemblyName(assemblyName);
     byte[] publicKeyToken = an.GetPublicKeyToken();
     if (publicKeyToken == null)
     {
         publicKeyToken = an.GetPublicKey();
     }
     if ((publicKeyToken != null) && (publicKeyToken.Length != 0))
     {
         return this.nApplyPolicy(an);
     }
     return assemblyName;
 }
开发者ID:randomize,项目名称:VimConfig,代码行数:14,代码来源:AppDomain.cs

示例13: SetPublicKeyToken

	public void SetPublicKeyToken ()
	{
		an = new AssemblyName ();
		an.SetPublicKeyToken (pk_token1);

		Assert.AreEqual (AssemblyNameFlags.None, an.Flags, "#A1");
		Assert.IsNull (an.KeyPair, "#A2");
		Assert.IsNull (an.GetPublicKey (), "#A3");
		Assert.AreEqual (pk_token1, an.GetPublicKeyToken (), "#A4");

		an.SetPublicKeyToken ((byte []) null);

		Assert.AreEqual (AssemblyNameFlags.None, an.Flags, "#B1");
		Assert.IsNull (an.KeyPair, "#B2");
		Assert.IsNull (an.GetPublicKey (), "#B3");
		Assert.IsNull (an.GetPublicKeyToken (), "#B4");

		an.SetPublicKeyToken (new byte [0]);

		Assert.AreEqual (AssemblyNameFlags.None, an.Flags, "#C1");
		Assert.IsNull (an.KeyPair, "#C2");
		Assert.IsNull (an.GetPublicKey (), "#C3");
		Assert.IsNotNull (an.GetPublicKeyToken (), "#C4");
		Assert.AreEqual (0, an.GetPublicKeyToken ().Length, "#C5");
	}
开发者ID:wamiq,项目名称:debian-mono,代码行数:25,代码来源:AssemblyNameTest.cs

示例14: SetPublicKey_PublicKey_Invalid

	public void SetPublicKey_PublicKey_Invalid ()
	{
		an = new AssemblyName ();
		an.SetPublicKey (new byte [] { 0x0b, 0x0a });
		Assert.AreEqual (new byte [] { 0x0b, 0x0a }, an.GetPublicKey (), "#1");
	}
开发者ID:wamiq,项目名称:debian-mono,代码行数:6,代码来源:AssemblyNameTest.cs

示例15: SetPublicKey

	public void SetPublicKey () 
	{
		an = new AssemblyName ();
		Assert.IsNull (an.GetPublicKey (), "#A1");
		Assert.AreEqual (AssemblyNameFlags.None, an.Flags, "#A2");
		Assert.IsNull (an.KeyPair, "#A3");
		Assert.IsNull (an.GetPublicKeyToken (), "#A4");

		an.SetPublicKey (publicKey1);

		Assert.AreEqual (publicKey1, an.GetPublicKey (), "#B1");
		Assert.AreEqual (AssemblyNameFlags.PublicKey, an.Flags, "#B2");
		Assert.IsNull (an.KeyPair, "#B3");
		Assert.AreEqual (pk_token1, an.GetPublicKeyToken (), "#B4");
		an.SetPublicKey (keyPair);
		Assert.AreEqual (keyPair, an.GetPublicKey (), "#B5");
		Assert.AreEqual (pk_token1, an.GetPublicKeyToken (), "#B6");

		an.SetPublicKey ((byte []) null);

		Assert.IsNull (an.GetPublicKey (), "#C1");
#if NET_2_0
		Assert.AreEqual (AssemblyNameFlags.None, an.Flags, "#C2");
#else
		Assert.AreEqual (AssemblyNameFlags.PublicKey, an.Flags, "#C2");
#endif
		Assert.IsNull (an.KeyPair, "#C3");
		Assert.AreEqual (pk_token1, an.GetPublicKeyToken (), "#C4");

		an.SetPublicKey (publicKey1);
		an.SetPublicKeyToken (pk_token1);
		an.SetPublicKey ((byte []) null);

		Assert.IsNull (an.GetPublicKey (), "#D1");
#if NET_2_0
		Assert.AreEqual (AssemblyNameFlags.None, an.Flags, "#D2");
#else
		Assert.AreEqual (AssemblyNameFlags.PublicKey, an.Flags, "#D2");
#endif
		Assert.IsNull (an.KeyPair, "#D3");
		Assert.AreEqual (pk_token1, an.GetPublicKeyToken (), "#D4");

		an.SetPublicKey ((byte []) null);
		an.SetPublicKeyToken (pk_token1);
		an.SetPublicKey ((byte []) null);

		Assert.IsNull (an.GetPublicKey (), "#E1");
#if NET_2_0
		Assert.AreEqual (AssemblyNameFlags.None, an.Flags, "#E2");
#else
		Assert.AreEqual (AssemblyNameFlags.PublicKey, an.Flags, "#E2");
#endif
		Assert.IsNull (an.KeyPair, "#E3");
		Assert.AreEqual (pk_token1, an.GetPublicKeyToken (), "#E4");

		an = new AssemblyName ();
		an.SetPublicKey (publicKey1);
		an.SetPublicKey ((byte []) null);
		an.SetPublicKeyToken (pk_token1);
		an.SetPublicKey ((byte []) null);

		Assert.IsNull (an.GetPublicKey (), "#F1");
		Assert.AreEqual (AssemblyNameFlags.PublicKey, an.Flags, "#F2");
		Assert.IsNull (an.KeyPair, "#F3");
		Assert.AreEqual (pk_token1, an.GetPublicKeyToken (), "#F4");

		an = new AssemblyName ();
		an.SetPublicKey (publicKey1);
		an.SetPublicKey ((byte []) null);
		an.SetPublicKeyToken (pk_token1);

		Assert.IsNull (an.GetPublicKey (), "#G1");
#if NET_2_0
		Assert.AreEqual (AssemblyNameFlags.None, an.Flags, "#G2");
#else
		Assert.AreEqual (AssemblyNameFlags.PublicKey, an.Flags, "#G2");
#endif
		Assert.IsNull (an.KeyPair, "#G3");
		Assert.AreEqual (pk_token1, an.GetPublicKeyToken (), "#G4");

		an = new AssemblyName ();
		an.SetPublicKey (new byte [0]);

		Assert.IsNotNull (an.GetPublicKey (), "#H1");
		Assert.AreEqual (0, an.GetPublicKey ().Length, "#H2");
		Assert.AreEqual (AssemblyNameFlags.PublicKey, an.Flags, "#H3");
		Assert.IsNull (an.KeyPair, "#H4");
#if NET_2_0
		Assert.IsNotNull (an.GetPublicKeyToken (), "#H5");
		Assert.AreEqual (0, an.GetPublicKeyToken ().Length, "#H6");
#else
		Assert.IsNull (an.GetPublicKeyToken (), "#H5");
#endif

		an = new AssemblyName ();
		an.SetPublicKey (publicKey1);
		Assert.AreEqual (AssemblyNameFlags.PublicKey, an.Flags, "#I1");
		an.SetPublicKey (publicKey1);
		Assert.AreEqual (AssemblyNameFlags.PublicKey, an.Flags, "#I2");

//.........这里部分代码省略.........
开发者ID:wamiq,项目名称:debian-mono,代码行数:101,代码来源:AssemblyNameTest.cs


注:本文中的System.Reflection.AssemblyName.GetPublicKey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。