本文整理汇总了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);
}
示例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;
}