2010-02-02 1 views
1

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; 
    } 

답변

9

알았습니다.
대답은 DefineParameter 함수를 사용하는 방식입니다.
GetParameters 함수는 제공된 메서드의 매개 변수에 대한 정보를 반환합니다. DefineParameter, 위치 0 참조 반환 매개 변수를 사용하고, 호출 매개 변수 1.

수정 프로그램을 참조받은 위치에서 시작 :
그러나 (반환 매개 변수를 포함하여) 모든 매개 변수에 대한 DefineParameter 기능 설정 파라미터 정보는 postions은 이동 있도록

MethodBuilder.DefineParameter Method @ MSDN

건배 :)

:
method.DefineParameter(param.Position+1, ParameterAttributes.None, param.Name); 

STFM (... 수동 푸 참조)

+0

감사합니다. 설명서를 읽으면서 시간을 절약 해주세요 :) –