本文整理汇总了C#中GenerationContext.CreateType方法的典型用法代码示例。如果您正苦于以下问题:C# GenerationContext.CreateType方法的具体用法?C# GenerationContext.CreateType怎么用?C# GenerationContext.CreateType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GenerationContext
的用法示例。
在下文中一共展示了GenerationContext.CreateType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Generate
/// <summary>
/// Generates a <see cref="DomainService"/> proxy type.
/// </summary>
/// <param name="domainServiceContract">The <see cref="DomainService"/> contract type to implement.</param>
/// <param name="domainService">The <see cref="DomainService"/> type to generate a proxy for.</param>
/// <returns>Returns a <see cref="DomainService"/> proxy type.</returns>
public static Type Generate(Type domainServiceContract, Type domainService)
{
if (domainServiceContract == null)
{
throw new ArgumentNullException("domainServiceContract");
}
if (domainService == null)
{
throw new ArgumentNullException("domainService");
}
// Verify 'domainServiceContract' is actually a public interface.
if (!domainServiceContract.IsInterface || (!domainServiceContract.IsPublic && !domainServiceContract.IsNestedPublic))
{
string message = string.Format(CultureInfo.CurrentCulture, Resource.DomainServiceProxyGenerator_ExpectedPublicType, domainServiceContract);
throw new ArgumentException(message, "domainServiceContract");
}
// Verify 'domainService' is actually a public type.
if (!domainService.IsPublic && !domainService.IsNestedPublic)
{
string message = string.Format(CultureInfo.CurrentCulture, Resource.DomainServiceProxyGenerator_ExpectedPublicType, domainService);
throw new ArgumentException(message, "domainService");
}
// Create a new context
GenerationContext context = new GenerationContext(domainServiceContract, domainService);
// Define the proxy type
DefineProxyType(context);
// Implement required internal state fields
ImplementInternalStateFields(context);
// Implement required internal static fields
ImplementInternalStaticFields(context);
// Implement IDisposable
ImplementIDisposable(context);
// Implement domainServiceContract (ex: expected to be DomainService operations such as 'GetCustomers(...)')
GenerateOperationMethods(context);
// If you build it, They will come.
Type proxyType = context.CreateType();
#if EMIT_DYNAMIC_ASSEMBLY
// Save the assembly to disk
SaveAssembly();
#endif
return proxyType;
}