當前位置: 首頁>>代碼示例>>C#>>正文


C# ModuleDefinition.DefineClass方法代碼示例

本文整理匯總了C#中Mono.Cecil.ModuleDefinition.DefineClass方法的典型用法代碼示例。如果您正苦於以下問題:C# ModuleDefinition.DefineClass方法的具體用法?C# ModuleDefinition.DefineClass怎麽用?C# ModuleDefinition.DefineClass使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Mono.Cecil.ModuleDefinition的用法示例。


在下文中一共展示了ModuleDefinition.DefineClass方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: DefineNestedType

        /// <summary>
        /// Defines the nested type that will instantiate the actual singleton service instance.
        /// </summary>
        /// <param name="module">The module that will host the singleton type.</param>
        /// <param name="singletonType">The singleton type.</param>
        /// <param name="instanceField">The field that will hold the singleton instance.</param>
        /// <param name="serviceMap">The service map that contains the list of dependencies in the application.</param>
        /// <param name="implementation">The implementation that will instantiate the dependency.</param>
        /// <param name="dependency">The dependency that will be instantiated by the singleton.</param>
        /// <param name="targetMethod">The method that will be used to instantiate the actual service instance.</param>
        private void DefineNestedType(ModuleDefinition module, TypeDefinition singletonType, FieldDefinition instanceField, IDictionary<IDependency, IImplementation> serviceMap, IImplementation implementation, IDependency dependency, MethodDefinition targetMethod)
        {
            var objectType = module.ImportType(typeof (object));
            var nestedName = string.Format("Nested-{0}", dependency.GetHashCode());

            const TypeAttributes nestedAttributes = TypeAttributes.NestedFamORAssem | TypeAttributes.Sealed | TypeAttributes.AutoClass | TypeAttributes.Class | TypeAttributes.AnsiClass;
            var nestedType = module.DefineClass(nestedName, "Hiro.Containers.Internal", nestedAttributes, objectType);
            singletonType.NestedTypes.Add(nestedType);

            nestedType.Fields.Add(instanceField);

            // Emit the static constructor body
            var cctor = DefineNestedConstructors(module, nestedType);

            EmitSingletonInstantiation(dependency, implementation, serviceMap, instanceField, cctor, module, targetMethod);
        }
開發者ID:philiplaureano,項目名稱:Hiro,代碼行數:26,代碼來源:SingletonEmitter.cs

示例2: AddDefaultSingletonConstructor

        /// <summary>
        /// Adds a default constructor to the singleton type.
        /// </summary>
        /// <param name="module">The module that will host the singleton type.</param>
        /// <param name="singletonName">The name of the singleton.</param>
        /// <param name="typeAttributes">The type attributes that describes the singleton type.</param>
        /// <param name="objectType">The object ty pe.</param>
        /// <returns>A <see cref="TypeDefinition"/> that represents the singleton type.</returns>
        private static TypeDefinition AddDefaultSingletonConstructor(ModuleDefinition module, string singletonName, TypeAttributes typeAttributes, TypeReference objectType)
        {
            // Add a default constructor and make it private
            var singletonType = module.DefineClass(singletonName, "Hiro.Containers.Internal", typeAttributes, objectType);

            singletonType.AddDefaultConstructor();
            var constructor = singletonType.GetDefaultConstructor();

            constructor.IsFamilyOrAssembly = true;

            return singletonType;
        }
開發者ID:philiplaureano,項目名稱:Hiro,代碼行數:20,代碼來源:SingletonEmitter.cs


注:本文中的Mono.Cecil.ModuleDefinition.DefineClass方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。