Exemplo n.º 1
0
 private static void ImplementConstructor(DynamicTypeInfo proxyTypeInfo, Type[] constructorArgs)
 {
     if (constructorArgs == null)
     {
         return;
     }
     if (!constructorArgs.Any())
     {
         proxyTypeInfo.WithConstructor(c => c.BodyDefinition()
                                       .Ldarg(0)
                                       .Newarr(typeof(object), 0)
                                       .Stfld(SERVICE_CLIENT_CONSTRUCTOR_PARAMETERS_FIELD_NAME)
                                       .Ret());
     }
     else
     {
         proxyTypeInfo.WithConstructor(c => c.BodyDefinition()
                                       .Ldarg(0)
                                       .Newarr(typeof(object), constructorArgs.Length)
                                       .Stfld(SERVICE_CLIENT_CONSTRUCTOR_PARAMETERS_FIELD_NAME)
                                       .Repeater(0, constructorArgs.Length - 1, 1, (i, m) =>
                                                 m.Ldarg(0)
                                                 .Ldfld(SERVICE_CLIENT_CONSTRUCTOR_PARAMETERS_FIELD_NAME)
                                                 .LdcI4(i)  //load array index to stack
                                                 .Ldarg((uint)i + 1)
                                                 .Box(constructorArgs[i])
                                                 .Stelem_Ref())
                                       .Ret(),
                                       constructorArgs);
     }
 }
 private static void ImplementConstructor(ConstructorInfo constructorInfo, DynamicTypeInfo clientChannelType)
 {
     clientChannelType.WithConstructor(c => c.BodyDefinition()
                                       .Ldarg(0)
                                       .Repeater(1, constructorInfo.Parameters().Count, 1, (i, m) => m.Ldarg((uint)i))
                                       .Call(constructorInfo)
                                       .Ret(),
                                       constructorInfo.Parameters()
                                       .Select(x => x.ParameterType)
                                       .ToArray());
 }