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


C# AssemblyName.SetPublicKey方法代码示例

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


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

示例1: EmittedAssembly

        public EmittedAssembly(string name, string rootNamespace, Version version, CultureInfo culture
			, byte[] publicKey, byte[] publicKeyToken)
        {
            Contracts.Require.IsNotNull("name", name);
            Contracts.Require.IsNotEmpty("name", name);
            Contracts.Require.IsNotNull("rootNamespace", rootNamespace);
            Contracts.Require.IsNotEmpty("rootNamespace", name);
            Contracts.Require.IsNotNull("version", version);
            Contracts.Require.IsNotNull("culture", culture);

            this._classes = new Dictionary<string, EmittedClass>();
            this.RootNamespace = rootNamespace ?? name;
            _assemName = new AssemblyName(name);
            _assemName.Version = version;
            _assemName.CultureInfo = culture;
            _assemName.SetPublicKey(publicKey);
            _assemName.SetPublicKeyToken(publicKeyToken);
            #if DEBUG
            this._assembly = AppDomain.CurrentDomain.DefineDynamicAssembly(_assemName, AssemblyBuilderAccess.RunAndSave);
            this._module = this._assembly.DefineDynamicModule(name, name + ".dll", false);
            #else
            this._assembly = AppDomain.CurrentDomain.DefineDynamicAssembly(_assemName, AssemblyBuilderAccess.Run);
            this._module = this._assembly.DefineDynamicModule(name, name + ".dll", false);
            #endif
        }
开发者ID:rreynolds-yp,项目名称:csharp-swift-consoleclient,代码行数:25,代码来源:EmittedAssembly.cs

示例2: CreateProxyModule

		private static ModuleBuilder CreateProxyModule() {
			AssemblyName name = new AssemblyName("AutoMapper.Proxies");
            name.SetPublicKey(privateKey);
            name.SetPublicKeyToken(privateKeyToken);
            //AssemblyBuilder builder = AppDomain.CurrentDomain.DefineDynamicAssembly(name, AssemblyBuilderAccess.Run);
			AssemblyBuilder builder = AppDomain.CurrentDomain.DefineDynamicAssembly(name, AssemblyBuilderAccess.Run);
			return builder.DefineDynamicModule("AutoMapper.Proxies.emit");
		}
开发者ID:dennyli,项目名称:HandySolution,代码行数:8,代码来源:ProxyGenerator.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: GetName

        // Returns cached copy of the name. Caller has to create a clone before mutating the name.
        public AssemblyName GetName()
        {
            if (_assemblyName == null)
            {
                MetadataReader metadataReader = this.MetadataReader;

                AssemblyName an = new AssemblyName();
                an.Name = metadataReader.GetString(_assemblyDefinition.Name);
                an.Version = _assemblyDefinition.Version;
                an.SetPublicKey(metadataReader.GetBlobBytes(_assemblyDefinition.PublicKey));

                an.CultureName = metadataReader.GetString(_assemblyDefinition.Culture);
                an.ContentType = GetContentTypeFromAssemblyFlags(_assemblyDefinition.Flags);

                _assemblyName = an;
            }

            return _assemblyName;
        }
开发者ID:shahid-pk,项目名称:corert,代码行数:20,代码来源:EcmaAssembly.cs

示例6: Build

        public static BuildManager Build(IBuildManager buildManager)
        {
            // Locate the MVC assembly
            var mvcAssembly = Assembly.GetAssembly(typeof(Controller));

            // Locate the InternalsVisibleTo attribute and create a public key token that matches the one specified.
            var internalsVisisbleTo = mvcAssembly.GetCustomAttributes(typeof(InternalsVisibleToAttribute), true).Cast<InternalsVisibleToAttribute>().First();
            var internalsVisisbleToAssemblyName = internalsVisisbleTo.AssemblyName.Split(",".ToCharArray())[0];
            var internalsVisisbleToPublicKeyString = internalsVisisbleTo.AssemblyName.Split("=".ToCharArray())[1];
            var internalsVisisbleToPublicKey = ToBytes(internalsVisisbleToPublicKeyString);

            // Get the domain of our current thread to host the new fake assembly
            var domain = Thread.GetDomain();

            // Create a fake assembly name with the appropriate assembly name and public key token set
            var assemblyName = new AssemblyName(internalsVisisbleToAssemblyName);
            assemblyName.SetPublicKey(internalsVisisbleToPublicKey);

            // Define and host the assembly in the domain
            var assemblyBuilder = domain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.RunAndSave);
            var moduleBuilder = assemblyBuilder.DefineDynamicModule(assemblyName.Name, string.Format("{0}.dll", assemblyName.Name));
            
            // Create a new type that inherits from our BuildManager class and implements the MVC IBuildManager interface
            var buildManagerInterface = mvcAssembly.GetType("System.Web.Mvc.IBuildManager", true);
            var buildManagerTypeBuilder = moduleBuilder.DefineType(Guid.NewGuid().ToString(), TypeAttributes.NotPublic | TypeAttributes.Class, typeof(BuildManager), new[] { buildManagerInterface });
            var buildManagerTypeCtorBuilder = buildManagerTypeBuilder.DefineConstructor(MethodAttributes.Public, CallingConventions.ExplicitThis | CallingConventions.HasThis, new[] { typeof(IBuildManager) });
            buildManagerTypeCtorBuilder.DefineParameter(1, ParameterAttributes.None, "buildManager");

            // Call the base constructor with the mocked IBuildManager interface
            var buildManagerTypeCtorEmitter = buildManagerTypeCtorBuilder.GetILGenerator();
            buildManagerTypeCtorEmitter.Emit(OpCodes.Nop);
            buildManagerTypeCtorEmitter.Emit(OpCodes.Ldarg_0);
            buildManagerTypeCtorEmitter.Emit(OpCodes.Ldarg_1);
            buildManagerTypeCtorEmitter.Emit(OpCodes.Call, typeof(BuildManager).GetConstructors(BindingFlags.NonPublic | BindingFlags.Instance).Single());
            buildManagerTypeCtorEmitter.Emit(OpCodes.Ret);
            
            var buildManagerMockType = buildManagerTypeBuilder.CreateType();

            // Magic!
            var buildManagerMock = Activator.CreateInstance(buildManagerMockType, new object[] { buildManager }) as BuildManager;
            return buildManagerMock;
        }
开发者ID:stevenlauwers22,项目名称:AspNet.NoMvcAndTinyControllers,代码行数:42,代码来源:BuildManagerBuilder.cs

示例7: CreateAssemblyName

        private static AssemblyName CreateAssemblyName(MetadataName name, MetadataName culture, Version version, AssemblyNameFlags flags, byte[] publicKeyOrToken) {
            var result = new AssemblyName();

            result.Name = name.ToString();
            if (!culture.IsEmpty) {
                result.CultureInfo = new CultureInfo(culture.ToString());
            }

            result.Version = version;
            result.Flags = flags;

            if (publicKeyOrToken.Length != 0) {
                if ((result.Flags & AssemblyNameFlags.PublicKey) != 0) {
                    result.SetPublicKey(publicKeyOrToken);
                } else {
                    result.SetPublicKeyToken(publicKeyOrToken);
                }
            }

            return result;
        }
开发者ID:madpilot,项目名称:ironruby,代码行数:21,代码来源:MetadataExtensions.cs

示例8: ToAssemblyName

        // CultureInfo is not portable.

        /// <summary>
        /// Converts this identity to <see cref="AssemblyName"/>.
        /// </summary>
        /// <returns>A new instance of <see cref="AssemblyName"/>.</returns>
        /// <exception cref="System.Globalization.CultureNotFoundException">The culture specified in <see cref="AssemblyIdentity.CultureName"/> is not available on the current platform.</exception>
        public static AssemblyName ToAssemblyName(this AssemblyIdentity identity)
        {
            var result = new AssemblyName();
            result.Name = identity.Name;
            result.Version = identity.Version;
            result.Flags = identity.Flags;
            result.ContentType = identity.ContentType;
            result.CultureInfo = CultureInfo.GetCultureInfo(identity.CultureName);

            if (identity.PublicKey.Length > 0)
            {
                result.SetPublicKey(identity.PublicKey.ToArray());
            }

            if (!identity.PublicKeyToken.IsDefault)
            {
                result.SetPublicKeyToken(identity.PublicKeyToken.ToArray());
            }

            return result;
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:28,代码来源:AssemblyIdentityExtensions.cs

示例9: ConstructAssemblyName

 private AssemblyName ConstructAssemblyName(IntPtr asmMetaPtr, char[] asmNameBuf, uint asmNameLength, IntPtr pubKeyPtr, uint pubKeyBytes, uint flags)
 {
     ASSEMBLYMETADATA assemblymetadata = (ASSEMBLYMETADATA) Marshal.PtrToStructure(asmMetaPtr, typeof(ASSEMBLYMETADATA));
     AssemblyName name = new AssemblyName {
         Name = new string(asmNameBuf, 0, ((int) asmNameLength) - 1),
         Version = new Version(assemblymetadata.usMajorVersion, assemblymetadata.usMinorVersion, assemblymetadata.usBuildNumber, assemblymetadata.usRevisionNumber)
     };
     string str = Marshal.PtrToStringUni(assemblymetadata.rpLocale);
     name.CultureInfo = new CultureInfo(str);
     if (pubKeyBytes > 0)
     {
         byte[] destination = new byte[pubKeyBytes];
         Marshal.Copy(pubKeyPtr, destination, 0, (int) pubKeyBytes);
         if ((flags & 1) != 0)
         {
             name.SetPublicKey(destination);
             return name;
         }
         name.SetPublicKeyToken(destination);
     }
     return name;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:22,代码来源:AssemblyMetaDataImport.cs

示例10: ToAssemblyName

        /// <summary>
        /// Converts <see cref="IAssemblyName"/> to <see cref="AssemblyName"/> with possibly missing name components.
        /// </summary>
        /// <returns>
        /// An <see cref="AssemblyName"/> whose fields are be null if not present in <paramref name="nameObject"/>.
        /// </returns>
        internal static AssemblyName ToAssemblyName(FusionAssemblyIdentity.IAssemblyName nameObject)
        {
            var result = new AssemblyName();
            result.Name = FusionAssemblyIdentity.GetName(nameObject);
            result.Version = FusionAssemblyIdentity.GetVersion(nameObject);

            var cultureName = FusionAssemblyIdentity.GetCulture(nameObject);
            result.CultureInfo = (cultureName != null) ? new CultureInfo(cultureName) : null;

            byte[] publicKey = FusionAssemblyIdentity.GetPublicKey(nameObject);
            if (publicKey != null && publicKey.Length != 0)
            {
                result.SetPublicKey(publicKey);
            }
            else
            {
                result.SetPublicKeyToken(FusionAssemblyIdentity.GetPublicKeyToken(nameObject));
            }

            result.Flags = FusionAssemblyIdentity.GetFlags(nameObject);
            result.ContentType = FusionAssemblyIdentity.GetContentType(nameObject);
            return result;
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:29,代码来源:FusionAssemblyIdentityTests.cs

示例11: FromAssemblyDefinition

        public void FromAssemblyDefinition()
        {
            var name = new AssemblyName("foo");
            name.Flags = AssemblyNameFlags.Retargetable | AssemblyNameFlags.PublicKey | AssemblyNameFlags.EnableJITcompileOptimizer | AssemblyNameFlags.EnableJITcompileTracking;
            name.CultureInfo = new CultureInfo("en-US");
            name.ContentType = AssemblyContentType.Default;
            name.Version = new Version(1, 2, 3, 4);
            name.ProcessorArchitecture = ProcessorArchitecture.X86;

            var id = AssemblyIdentity.FromAssemblyDefinition(name);
            Assert.Equal("foo", id.Name);
            Assert.True(id.IsRetargetable);
            Assert.Equal(new Version(1, 2, 3, 4), id.Version);
            Assert.Equal(AssemblyContentType.Default, id.ContentType);
            Assert.False(id.HasPublicKey);
            Assert.False(id.IsStrongName);


            name = new AssemblyName("foo");
            name.SetPublicKey(PublicKey1);
            name.Version = new Version(1, 2, 3, 4);

            id = AssemblyIdentity.FromAssemblyDefinition(name);
            Assert.Equal("foo", id.Name);
            Assert.Equal(new Version(1, 2, 3, 4), id.Version);
            Assert.True(id.HasPublicKey);
            Assert.True(id.IsStrongName);
            AssertEx.Equal(id.PublicKey, PublicKey1);


            name = new AssemblyName("foo");
            name.ContentType = AssemblyContentType.WindowsRuntime;

            id = AssemblyIdentity.FromAssemblyDefinition(name);
            Assert.Equal("foo", id.Name);
            Assert.Equal(AssemblyContentType.WindowsRuntime, id.ContentType);
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:37,代码来源:AssemblyIdentityTests.cs

示例12: Create

		//
		// Initializes the code generator
		//
		public bool Create (AppDomain domain, AssemblyBuilderAccess access)
		{
			ResolveAssemblySecurityAttributes ();

			var an = new AssemblyName (name);

			if (public_key != null && RootContext.Target != Target.Module) {
				if (delay_sign) {
					an.SetPublicKey (public_key);
				} else {
					if (public_key.Length == 16) {
						Report.Error (1606, "Could not sign the assembly. ECMA key can only be used to delay-sign assemblies");
					} else if (private_key == null) {
						Error_AssemblySigning ("The specified key file does not have a private key");
					} else {
						an.KeyPair = private_key;
					}
				}
			}

			try {
				Builder = file_name == null ?
					domain.DefineDynamicAssembly (an, access) :
					domain.DefineDynamicAssembly (an, access, Dirname (file_name));
			} catch (ArgumentException) {
				// specified key may not be exportable outside it's container
				if (RootContext.StrongNameKeyContainer != null) {
					Report.Error (1548, "Could not access the key inside the container `" +
						RootContext.StrongNameKeyContainer + "'.");
				}
				throw;
			}

			builder_extra = new AssemblyBuilderExtension (Builder, Compiler);

			return true;
		}
开发者ID:Tak,项目名称:monodevelop-novell,代码行数:40,代码来源:assembly.cs

示例13: DoProcess

        public AssemblyBuilder DoProcess(
            Object typeLib,
            string asmFilename,
            TypeLibImporterFlags flags,
            ITypeLibImporterNotifySink notifySink,
            byte[] publicKey,
            StrongNameKeyPair keyPair,
            string asmNamespace,
            Version asmVersion,
            bool isVersion2,
            bool isPreserveSig,
            string ruleSetFileName)
        {
            m_resolver = notifySink;

            TypeLib tlb = new TypeLib((TypeLibTypes.Interop.ITypeLib)typeLib);

            if (asmNamespace == null)
            {
                asmNamespace = tlb.GetDocumentation();

                string fileName = System.IO.Path.GetFileNameWithoutExtension(asmFilename);
                if (fileName != asmNamespace)
                    asmNamespace = fileName;

                //
                // Support for GUID_ManagedName (for namespace)
                //
                string customManagedNamespace = tlb.GetCustData(CustomAttributeGuids.GUID_ManagedName) as string;
                if (customManagedNamespace != null)
                {
                    customManagedNamespace = customManagedNamespace.Trim();
                    if (customManagedNamespace.ToUpper().EndsWith(".DLL"))
                        customManagedNamespace = customManagedNamespace.Substring(0, customManagedNamespace.Length - 4);
                    else if (customManagedNamespace.ToUpper().EndsWith(".EXE"))
                        customManagedNamespace = customManagedNamespace.Substring(0, customManagedNamespace.Length - 4);

                    asmNamespace = customManagedNamespace;
                }
            }

            //
            // Check for GUID_ExportedFromComPlus
            //
            object value = tlb.GetCustData(CustomAttributeGuids.GUID_ExportedFromComPlus);
            if (value != null)
            {
                // Make this a critical failure, instead of returning null which will be ignored.
                throw new TlbImpGeneralException(Resource.FormatString("Err_CircularImport", asmNamespace), ErrorCode.Err_CircularImport);
            }

            string strModuleName = asmFilename;

            if (asmFilename.Contains("\\"))
            {
                int nIndex;
                for (nIndex = strModuleName.Length; strModuleName[nIndex - 1] != '\\'; --nIndex) ;
                strModuleName = strModuleName.Substring(nIndex);
            }

            // If the version information was not specified, then retrieve it from the typelib.
            if (asmVersion == null)
            {
                using (TypeLibAttr attr = tlb.GetLibAttr())
                {
                    asmVersion = new Version(attr.wMajorVerNum, attr.wMinorVerNum, 0, 0);
                }
            }

            // Assembly name should not have .DLL
            // while module name must contain the .DLL
            string strAsmName = String.Copy(strModuleName);
            if (strAsmName.EndsWith(".DLL", StringComparison.InvariantCultureIgnoreCase))
                strAsmName = strAsmName.Substring(0, strAsmName.Length - 4);

            AssemblyName assemblyName = new AssemblyName();
            assemblyName.Name = strAsmName;
            assemblyName.SetPublicKey(publicKey);
            assemblyName.Version = asmVersion;
            assemblyName.KeyPair = keyPair;

            m_assemblyBuilder = CreateAssemblyBuilder(assemblyName, tlb, flags);

            m_moduleBuilder = CreateModuleBuilder(m_assemblyBuilder, strModuleName);

            // Add a listener for the reflection load only resolve events.
            AppDomain currentDomain = Thread.GetDomain();
            ResolveEventHandler asmResolveHandler = ReflectionOnlyResolveAsmEvent;
            currentDomain.ReflectionOnlyAssemblyResolve += asmResolveHandler;

            ConverterSettings settings;
            settings.m_isGenerateClassInterfaces = true;
            settings.m_namespace = asmNamespace;
            settings.m_flags = flags;
            settings.m_isVersion2 = isVersion2;
            settings.m_isPreserveSig = isPreserveSig;
            RuleEngine.InitRuleEngine(new TlbImpActionManager(),
                                      new TlbImpCategoryManager(),
                                      new TlbImpConditionManager(),
                                      new TlbImpOperatorManager());
//.........这里部分代码省略.........
开发者ID:dbremner,项目名称:clrinterop,代码行数:101,代码来源:Process.cs

示例14: AssemblyBuilder

        [System.Security.SecurityCritical]  // auto-generated
        internal AssemblyBuilder(AppDomain domain,
                                 AssemblyName name,
                                 AssemblyBuilderAccess access,
                                 String dir,
                                 Evidence evidence,
                                 PermissionSet requiredPermissions,
                                 PermissionSet optionalPermissions,
                                 PermissionSet refusedPermissions,
                                 ref StackCrawlMark stackMark,
                                 IEnumerable<CustomAttributeBuilder> unsafeAssemblyAttributes,
                                 SecurityContextSource securityContextSource)
        {
            if (name == null)
                throw new ArgumentNullException("name");

            if (access != AssemblyBuilderAccess.Run
#if !FEATURE_CORECLR
                && access != AssemblyBuilderAccess.Save
                && access != AssemblyBuilderAccess.RunAndSave
#endif // !FEATURE_CORECLR
#if FEATURE_REFLECTION_ONLY_LOAD
                && access != AssemblyBuilderAccess.ReflectionOnly
#endif // FEATURE_REFLECTION_ONLY_LOAD
#if FEATURE_COLLECTIBLE_TYPES
                && access != AssemblyBuilderAccess.RunAndCollect
#endif // FEATURE_COLLECTIBLE_TYPES
                )
            {
                throw new ArgumentException(Environment.GetResourceString("Arg_EnumIllegalVal", (int)access), "access");
            }

            if (securityContextSource < SecurityContextSource.CurrentAppDomain ||
                securityContextSource > SecurityContextSource.CurrentAssembly)
            {
                throw new ArgumentOutOfRangeException("securityContextSource");
            }

            // Clone the name in case the caller modifies it underneath us.
            name = (AssemblyName)name.Clone();
            
#if !FEATURE_CORECLR
            // Set the public key from the key pair if one has been provided.
            // (Overwite any public key in the Assembly name, since it's no
            // longer valid to have a disparity).
            if (name.KeyPair != null)
                name.SetPublicKey(name.KeyPair.PublicKey);
#endif

            // If the caller is trusted they can supply identity
            // evidence for the new assembly. Otherwise we copy the
            // current grant and deny sets from the caller's assembly,
            // inject them into the new assembly and mark policy as
            // resolved. If/when the assembly is persisted and
            // reloaded, the normal rules for gathering evidence will
            // be used.
            if (evidence != null)
#pragma warning disable 618
                new SecurityPermission(SecurityPermissionFlag.ControlEvidence).Demand();
#pragma warning restore 618

#if FEATURE_COLLECTIBLE_TYPES && !FEATURE_CORECLR
            // Collectible assemblies require FullTrust. This demand may be removed if we deem the
            // feature robust enough to be used directly by untrusted API consumers.
            if (access == AssemblyBuilderAccess.RunAndCollect)
                new PermissionSet(PermissionState.Unrestricted).Demand();
#endif // FEATURE_COLLECTIBLE_TYPES && !FEATURE_CORECLR

            // Scan the assembly level attributes for any attributes which modify how we create the
            // assembly. Currently, we look for any attribute which modifies the security transparency
            // of the assembly.
            List<CustomAttributeBuilder> assemblyAttributes = null;
            DynamicAssemblyFlags assemblyFlags = DynamicAssemblyFlags.None;
            byte[] securityRulesBlob = null;
            byte[] aptcaBlob = null;
            if (unsafeAssemblyAttributes != null)
            {
                // Create a copy to ensure that it cannot be modified from another thread
                // as it is used further below.
                assemblyAttributes = new List<CustomAttributeBuilder>(unsafeAssemblyAttributes);

#pragma warning disable 618 // We deal with legacy attributes here as well for compat
                foreach (CustomAttributeBuilder attribute in assemblyAttributes)
                {
                    if (attribute.m_con.DeclaringType == typeof(SecurityTransparentAttribute))
                    {
                        assemblyFlags |= DynamicAssemblyFlags.Transparent;
                    }
                    else if (attribute.m_con.DeclaringType == typeof(SecurityCriticalAttribute))
                    {
#if !FEATURE_CORECLR
                        SecurityCriticalScope scope = SecurityCriticalScope.Everything;
                        if (attribute.m_constructorArgs != null &&
                            attribute.m_constructorArgs.Length == 1 &&
                            attribute.m_constructorArgs[0] is SecurityCriticalScope)
                        {
                            scope = (SecurityCriticalScope)attribute.m_constructorArgs[0];
                        }

                        assemblyFlags |= DynamicAssemblyFlags.Critical;
//.........这里部分代码省略.........
开发者ID:ChuangYang,项目名称:coreclr,代码行数:101,代码来源:AssemblyBuilder.cs

示例15: LoadAssemblyInternal

		private int LoadAssemblyInternal (LuaState luaState)
		{			
			try {
				string assemblyName = LuaLib.LuaToString (luaState, 1).ToString ();
				Assembly assembly = null;
				Exception exception = null;

				try {
					assembly = Assembly.Load (assemblyName);
				} catch (BadImageFormatException) {
					// The assemblyName was invalid.  It is most likely a path.
				} catch (FileNotFoundException e) {
					exception = e;
				}

#if !SILVERLIGHT
				if (assembly == null) {
					try {
						assembly = Assembly.Load (AssemblyName.GetAssemblyName (assemblyName));
					} catch (FileNotFoundException e) {
						exception = e;
					}
					if (assembly == null) {

						AssemblyName mscor = assemblies [0].GetName ();
						AssemblyName name = new AssemblyName ();
						name.Name = assemblyName;
						name.CultureInfo = mscor.CultureInfo;
						name.Version = mscor.Version;
						name.SetPublicKeyToken (mscor.GetPublicKeyToken ());
						name.SetPublicKey (mscor.GetPublicKey ());
						assembly = Assembly.Load (name);

						if (assembly != null)
							exception = null;
					}
					if (exception != null)
						ThrowError (luaState, exception);
				}
#endif
				if (assembly != null && !assemblies.Contains (assembly))
					assemblies.Add (assembly);
			} catch (Exception e) {
				ThrowError (luaState, e);
			}

			return 0;
		}
开发者ID:hanbim520,项目名称:UFLua,代码行数:48,代码来源:ObjectTranslator.cs


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