WCF 관심사에 대한 기존 인터페이스를 기반으로 인터페이스를 만들고 있지만 "DefineParameter"매개 변수 이름을 설정하지 않았습니다 (생성 된 형식의 메서드 매개 변수에는 이름이 없음).
그 이유를 알 수 있습니까?MethodBuilder.DefineParameter가 매개 변수 이름을 설정할 수없는 이유는 무엇입니까?
public static Type MakeWcfInterface(Type iService)
{
AssemblyName assemblyName = new AssemblyName(String.Format("{0}_DynamicWcf", iService.FullName));
String moduleName = String.Format("{0}.dll", assemblyName.Name);
String ns = iService.Namespace;
if (!String.IsNullOrEmpty(ns)) ns += ".";
// Create assembly
var assembly = AppDomain.CurrentDomain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.RunAndSave);
// Create module
var module = assembly.DefineDynamicModule(moduleName, false);
// Create asynchronous interface type
TypeBuilder iWcfService = module.DefineType(
String.Format("{0}DynamicWcf", iService.FullName),
TypeAttributes.Public | TypeAttributes.Interface | TypeAttributes.Abstract
);
// Set ServiceContract attributes
iWcfService.SetCustomAttribute(ReflectionEmitHelper.BuildAttribute<ServiceContractAttribute>(null,
new Dictionary<string, object>() {
{ "Name", iService.Name },
}));
iWcfService.SetCustomAttribute(ReflectionEmitHelper.BuildAttribute<ServiceBehaviorAttribute>(null,
new Dictionary<string, object>() {
{ "InstanceContextMode" , InstanceContextMode.Single }
})
);
foreach (var method in iService.GetMethods())
{
BuildWcfMethod(iWcfService, method);
}
return iWcfService.CreateType();
}
private static MethodBuilder BuildWcfMethod(TypeBuilder target, MethodInfo template)
{
// Define method
var method = target.DefineMethod(
template.Name,
MethodAttributes.Abstract | MethodAttributes.Virtual
| MethodAttributes.FamANDAssem | MethodAttributes.Family | MethodAttributes.VtableLayoutMask | MethodAttributes.HideBySig,
CallingConventions.Standard,
template.ReturnType,
template.GetParameters().Select(p => p.ParameterType).ToArray()
);
// Define parameters
foreach (ParameterInfo param in template.GetParameters())
{
method.DefineParameter(param.Position, ParameterAttributes.None, param.Name);
}
// Set OperationContract attribute
method.SetCustomAttribute(ReflectionEmitHelper.BuildAttribute<OperationContractAttribute>(null, null));
return method;
}
감사합니다. 설명서를 읽으면서 시간을 절약 해주세요 :) –