private void AddCommitTransactionMethod( ServiceBase service, DCBuilderType userProfileDCBuilderType, TypeBuilder typeBuilder, DCBuilderType requestDCBuilderType, DCBuilderType resultDCBuilderType) { DCBuilderType dcBuilderType = this.dCTypeStore.GetDCBuilderType(service.Name + "Method"); Type[] typeArray = new Type[4] { userProfileDCBuilderType.Type, dcBuilderType.Type.MakeArrayType(), requestDCBuilderType.Type, resultDCBuilderType.Type.MakeByRefType() }; MethodBuilder methodBuilder = this.DefineMethod("CommitTransaction", new Type[4] { userProfileDCBuilderType.Type, dcBuilderType.Type.MakeArrayType(), requestDCBuilderType.Type, resultDCBuilderType.Type.MakeByRefType() }, typeBuilder); methodBuilder.DefineParameter(1, ParameterAttributes.None, "userProfile"); methodBuilder.DefineParameter(2, ParameterAttributes.None, "methods"); methodBuilder.DefineParameter(3, ParameterAttributes.None, "request"); methodBuilder.DefineParameter(4, ParameterAttributes.Out, "result"); }
private void AddParameterType(DCBuilderType dCBuilderType) { DCBuilderType dcBuilderType = this.dCTypeStore.GetDCBuilderType("Parameters"); TypeBuilder typeBuilder = this.DefineType(this.nameSpacePrefix + dCBuilderType.Name + "_Parameters", dcBuilderType.Type); this.dCTypeStore.Add(dCBuilderType.Name + "_Parameters", typeBuilder.CreateType(), typeBuilder); }
protected void DefineLiteral( EnumBuilder enumBuilder, string name, int number, string defaultValue, DCField field) { var fieldBuilder = enumBuilder.DefineLiteral(name, number); var customBuilder1 = new CustomAttributeBuilder(typeof(EnumMemberAttribute).GetConstructor(Type.EmptyTypes), new object[0]); fieldBuilder.SetCustomAttribute(customBuilder1); DCBuilderType dcBuilderType = dCTypeStore.GetDCBuilderType("EnumerationAttribute"); if (dcBuilderType != null) { var customBuilder2 = new CustomAttributeBuilder(dcBuilderType.Type.GetConstructor( new Type[1] { typeof(string) }), new object[1] { defaultValue }); fieldBuilder.SetCustomAttribute(customBuilder2); } if (field == null) { return; } AddMetadataAttribute(fieldBuilder, field); }
public override void AddDC(DCType dCType) { if (dCType.IsEnum) { AddEnumeration(dCType); } else { DCBuilderType dcBuilderType = dCTypeStore.GetDCBuilderType(dCType.ParentName); if (dcBuilderType == null) { dcBuilderType = dCTypeStore.GetDCBuilderType("CDOObject"); dCType.ParentName = "CDOObject"; } var typeBuilder1 = DefineType(nameSpacePrefix + dCType.Name, dcBuilderType.Type); dCTypeStore.Add(dCType.Name, typeBuilder1.UnderlyingSystemType, typeBuilder1); AddKnownTypeAttribute(dCType, typeBuilder1, dcBuilderType); DCBuilderType dCBuilderType1 = dCTypeStore.GetDCBuilderType(dCType.ParentName + "_Info") ?? dCTypeStore.GetDCBuilderType("Info"); var typeBuilder2 = DefineType(nameSpacePrefix + dCType.Name + "_Info", dCBuilderType1.Type); dCTypeStore.Add(dCType.Name + "_Info", typeBuilder2.UnderlyingSystemType, typeBuilder2); AddKnownTypeAttribute(dCType, typeBuilder2, dCBuilderType1); DCBuilderType dCBuilderType2 = dCTypeStore.GetDCBuilderType(dCType.ParentName + "_Environment") ?? dCTypeStore.GetDCBuilderType("Environment"); var typeBuilder3 = DefineType(nameSpacePrefix + dCType.Name + "_Environment", dCBuilderType2.Type); dCTypeStore.Add(dCType.Name + "_Environment", typeBuilder3.UnderlyingSystemType, typeBuilder3); AddKnownTypeAttribute(dCType, typeBuilder3, dCBuilderType2); } }
public DCBuilderType GetDCBuilderType(string name) { DCBuilderType dcBuilderType = (DCBuilderType) null; if (this._Types.ContainsKey((object) name)) dcBuilderType = this._Types[(object) name] as DCBuilderType; return dcBuilderType; }
private Type GetEnvironmentType(DCBuilderType dCBuilderType) { Type type = this.dCTypeStore.GetDCBuilderType("Environment").Type; if (!dCBuilderType.IsSimpleType) { type = this.dCTypeStore.GetDCBuilderType(dCBuilderType.Name + "_Environment").Type; } return(type); }
private Type GetInfoType(DCBuilderType dCBuilderType) { Type type = this.dCTypeStore.GetDCBuilderType("Info").Type; if (!dCBuilderType.IsSimpleType) { type = this.dCTypeStore.GetDCBuilderType(dCBuilderType.Name + "_Info").Type; } return(type); }
public void Add( string name, Type type, TypeBuilder typeBuilder, bool isSimpleType, bool isEmptyEnum) { if (!(type != (Type) null)) return; DCBuilderType dcBuilderType = new DCBuilderType(name, type, typeBuilder, isSimpleType, isEmptyEnum); this._Types.Add((object) name, (object) dcBuilderType); }
protected MethodBuilder DefineMethod( string name, Type[] parameterTypes, TypeBuilder typeBuilder) { DCBuilderType dcBuilderType = this.dCTypeStore.GetDCBuilderType("ResultStatus"); MethodBuilder methodBuilder = typeBuilder.DefineMethod(name, MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.Abstract, CallingConventions.Standard, dcBuilderType.Type, parameterTypes); CustomAttributeBuilder customBuilder = new CustomAttributeBuilder(typeof(OperationContractAttribute).GetConstructor(Type.EmptyTypes), new object[0]); methodBuilder.SetCustomAttribute(customBuilder); return(methodBuilder); }
private void AddRequestType(DCBuilderType dCBuilderType, bool isForClient) { DCBuilderType dcBuilderType1 = this.dCTypeStore.GetDCBuilderType("Request"); DCBuilderType dcBuilderType2 = this.dCTypeStore.GetDCBuilderType(dCBuilderType.Name + "_Info"); TypeBuilder typeBuilder = this.DefineType(this.nameSpacePrefix + dCBuilderType.Name + "_Request", dcBuilderType1.Type); this.DefineUniqueField(typeBuilder, "Info", dcBuilderType2.Type, isForClient); if (isForClient) { this.DefineProperty(typeBuilder, "Info", dcBuilderType2.Type); } this.dCTypeStore.Add(dCBuilderType.Name + "_Request", typeBuilder.CreateType(), typeBuilder); }
private void AddMethodParametersType(string serviceName, Method method, bool isForClient) { DCBuilderType dcBuilderType = this.dCTypeStore.GetDCBuilderType(serviceName + "_Parameters"); TypeBuilder typeBuilder = this.DefineType(this.nameSpacePrefix + serviceName + "_" + method.Name + "_Parameters", dcBuilderType.Type); foreach (Parameter parameter in method.Parameters) { this.DefineUniqueField(typeBuilder, parameter.Name, typeof(string), isForClient); if (isForClient) { this.DefineProperty(typeBuilder, parameter.Name, typeof(string)); } } this.dCTypeStore.Add(serviceName + "_" + method.Name + "_Parameters", typeBuilder.CreateType(), typeBuilder); }
private void AddGetEnvironmentMethod( ServiceBase service, TypeBuilder typeBuilder, Type baseType) { DCBuilderType dcBuilderType1 = this.dCTypeStore.GetDCBuilderType(service.Name); DCBuilderType dcBuilderType2 = this.dCTypeStore.GetDCBuilderType(service.Name + "_Request"); DCBuilderType dcBuilderType3 = this.dCTypeStore.GetDCBuilderType(service.Name + "_Result"); DCBuilderType dcBuilderType4 = this.dCTypeStore.GetDCBuilderType("ResultStatus"); Type[] parameterTypes = new Type[4] { this.dCTypeStore.GetDCBuilderType("UserProfile").Type, dcBuilderType1.Type, dcBuilderType2.Type, dcBuilderType3.Type.MakeByRefType() }; MethodBuilder methodBuilder = typeBuilder.DefineMethod("GetEnvironment", MethodAttributes.Public | MethodAttributes.Final | MethodAttributes.Virtual | MethodAttributes.VtableLayoutMask, dcBuilderType4.Type, parameterTypes); methodBuilder.DefineParameter(1, ParameterAttributes.None, "userProfile"); methodBuilder.DefineParameter(2, ParameterAttributes.None, service.Name.Substring(0, 1).ToLower() + service.Name.Substring(1)); methodBuilder.DefineParameter(3, ParameterAttributes.None, "request"); methodBuilder.DefineParameter(4, ParameterAttributes.Out, "result"); ILGenerator ilGenerator = methodBuilder.GetILGenerator(); ilGenerator.DeclareLocal(dcBuilderType4.Type); ilGenerator.DeclareLocal(dcBuilderType4.Type); ilGenerator.Emit(OpCodes.Ldarg_S, 4); ilGenerator.Emit(OpCodes.Newobj, dcBuilderType3.Type.GetConstructor(Type.EmptyTypes)); ilGenerator.Emit(OpCodes.Stind_Ref); ilGenerator.Emit(OpCodes.Ldarg_0); ilGenerator.Emit(OpCodes.Ldstr, "GetEnvironment"); ilGenerator.Emit(OpCodes.Ldarg_1); ilGenerator.Emit(OpCodes.Ldarg_2); ilGenerator.Emit(OpCodes.Ldnull); ilGenerator.Emit(OpCodes.Ldarg_3); ilGenerator.Emit(OpCodes.Ldarg_S, 4); ilGenerator.Emit(OpCodes.Ldind_Ref); ilGenerator.Emit(OpCodes.Call, baseType.GetMethod("CallMethod", BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.NonPublic)); ilGenerator.Emit(OpCodes.Stloc_0); Label label = ilGenerator.DefineLabel(); ilGenerator.Emit(OpCodes.Br_S, label); ilGenerator.MarkLabel(label); ilGenerator.Emit(OpCodes.Ldloc_0); ilGenerator.Emit(OpCodes.Ret); }
private void AddKnownTypeAttribute( DCType dCType, TypeBuilder typeBuilder, DCBuilderType dCBuilderType) { if (!dCType.IsSubentity || !(dCType.ParentName != "Subentity")) { return; } var customBuilder = new CustomAttributeBuilder(typeof(KnownTypeAttribute).GetConstructor(new Type[1] { typeof(Type) }), new object[1] { typeBuilder.UnderlyingSystemType }); dCBuilderType.TypeBuilder.SetCustomAttribute(customBuilder); }
private void AddGetEnvironmentMethod( ServiceBase service, DCBuilderType userProfileDCBuilderType, TypeBuilder typeBuilder, DCBuilderType dCBuilderType, DCBuilderType requestDCBuilderType, DCBuilderType resultDCBuilderType) { MethodBuilder methodBuilder = this.DefineMethod("GetEnvironment", new Type[4] { userProfileDCBuilderType.Type, dCBuilderType.Type, requestDCBuilderType.Type, resultDCBuilderType.Type.MakeByRefType() }, typeBuilder); methodBuilder.DefineParameter(1, ParameterAttributes.None, "userProfile"); methodBuilder.DefineParameter(2, ParameterAttributes.None, service.Name.Substring(0, 1).ToLower() + service.Name.Substring(1)); methodBuilder.DefineParameter(3, ParameterAttributes.None, "request"); methodBuilder.DefineParameter(4, ParameterAttributes.Out, "result"); }
private void AddMetadataAttribute(FieldBuilder fieldBuilder, DCField field) { DCBuilderType dcBuilderType = dCTypeStore.GetDCBuilderType("MetadataAttribute"); if (dcBuilderType == null || field == null) { return; } var customBuilder = new CustomAttributeBuilder(dcBuilderType.Type.GetConstructor( new Type[11] { typeof(string), typeof(string), typeof(bool), typeof(bool), typeof(bool), typeof(string), typeof(int), typeof(bool), typeof(bool), typeof(bool), typeof(string) }), new object[11] { field.Description, field.FieldTypeName, field.IsUserDefinedField, field.IsRequired, field.IsReadOnly, field.IsEnum ? field.EnumFieldTypeName : (object)field.TypeName, field.Label, field.CreateOnInitialize, field.IsList, field.HasSelVal, string.IsNullOrEmpty(field.DefaultValue) ? null : (object)field.DefaultValue }); fieldBuilder.SetCustomAttribute(customBuilder); }
private void AddMethodType( string serviceName, DCBuilderType enumDCBuilderType, DCBuilderType parametersDCBuilderType) { DCBuilderType dcBuilderType1 = this.dCTypeStore.GetDCBuilderType(serviceName); DCBuilderType dcBuilderType2 = this.dCTypeStore.GetDCBuilderType("Method"); TypeBuilder typeBuilder = this.DefineType(this.nameSpacePrefix + serviceName + "Method", dcBuilderType2.Type); FieldBuilder fieldBuilder1 = this.DefineUniqueField(typeBuilder, "Cdo", dcBuilderType1.Type, false); FieldBuilder fieldBuilder2 = this.DefineUniqueField(typeBuilder, "ServiceMethod", enumDCBuilderType.Type, false); FieldBuilder fieldBuilder3 = this.DefineUniqueField(typeBuilder, "Parameters", parametersDCBuilderType.Type, false); Type[] parameterTypes = new Type[3] { dcBuilderType1.Type, enumDCBuilderType.Type, parametersDCBuilderType.Type }; ConstructorBuilder constructorBuilder = typeBuilder.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, parameterTypes); constructorBuilder.DefineParameter(1, ParameterAttributes.None, "Cdo"); constructorBuilder.DefineParameter(2, ParameterAttributes.None, "Method"); constructorBuilder.DefineParameter(3, ParameterAttributes.None, "Parameters"); ILGenerator ilGenerator = constructorBuilder.GetILGenerator(); ilGenerator.Emit(OpCodes.Ldarg_0); ilGenerator.Emit(OpCodes.Call, dcBuilderType2.Type.GetConstructor(Type.EmptyTypes)); ilGenerator.Emit(OpCodes.Ldarg_0); ilGenerator.Emit(OpCodes.Ldarg_1); ilGenerator.Emit(OpCodes.Stfld, (FieldInfo)fieldBuilder1); ilGenerator.Emit(OpCodes.Ldarg_0); ilGenerator.Emit(OpCodes.Ldarg_2); ilGenerator.Emit(OpCodes.Stfld, (FieldInfo)fieldBuilder2); ilGenerator.Emit(OpCodes.Ldarg_0); ilGenerator.Emit(OpCodes.Ldarg_3); ilGenerator.Emit(OpCodes.Stfld, (FieldInfo)fieldBuilder3); ilGenerator.Emit(OpCodes.Ret); this.dCTypeStore.Add(serviceName + "Method", typeBuilder.CreateType(), typeBuilder); }
protected void AddServiceInterface(ServiceBase service) { bool isForClient = this is ClientGenerator; if (service.ExposedState != ExposedServiceStateType.Exposed && !this._IsSilverlight) { DCBuilderType dcBuilderType1 = (DCBuilderType)null; if (service.ParentWCFServiceBaseType != null) { dcBuilderType1 = this.dCTypeStore.GetDCBuilderType("I" + service.ParentWCFServiceBaseType.Name + "Base"); } if (dcBuilderType1 == null) { dcBuilderType1 = this.dCTypeStore.GetDCBuilderType("IWCFService"); } if (dcBuilderType1 != null) { TypeBuilder typeBuilder = this.moduleBuilder.DefineType(this.nameSpacePrefix + "I" + service.Name + "Base", TypeAttributes.Public | TypeAttributes.ClassSemanticsMask | TypeAttributes.Abstract, (Type)null, new Type[1] { dcBuilderType1.Type }); DCBuilderType dcBuilderType2 = this.dCTypeStore.GetDCBuilderType("DCObject"); DCBuilderType dcBuilderType3 = this.dCTypeStore.GetDCBuilderType("Request"); DCBuilderType dcBuilderType4 = this.dCTypeStore.GetDCBuilderType("Result"); DCBuilderType dcBuilderType5 = this.dCTypeStore.GetDCBuilderType("Parameters"); List <MethodInfo> methodInfoList = new List <MethodInfo>(); methodInfoList.AddRange((IEnumerable <MethodInfo>)dcBuilderType1.Type.GetMethods(BindingFlags.Instance | BindingFlags.Public)); foreach (Type type in dcBuilderType1.Type.GetInterfaces()) { methodInfoList.AddRange((IEnumerable <MethodInfo>)type.GetMethods(BindingFlags.Instance | BindingFlags.Public)); } foreach (IMethod method1 in service.GetMethods()) { if (method1.ExposedState == ExposedMethodStateType.Base || method1.ExposedState == ExposedMethodStateType.BaseAndExposed) { if (method1.IsInherited) { bool flag = false; foreach (MethodInfo methodInfo in methodInfoList) { if (method1.Name == methodInfo.Name) { flag = true; } } if (flag) { continue; } } Method method2 = method1 as Method; Type[] parameterTypes1 = new Type[4] { dcBuilderType2.Type, dcBuilderType5.Type, dcBuilderType3.Type, dcBuilderType4.Type.MakeByRefType() }; MethodBuilder methodBuilder1 = this.DefineMethod(method2.Name, parameterTypes1, typeBuilder); methodBuilder1.DefineParameter(1, ParameterAttributes.None, service.Name.Substring(0, 1).ToLower() + service.Name.Substring(1)); methodBuilder1.DefineParameter(2, ParameterAttributes.None, "parameters"); methodBuilder1.DefineParameter(3, ParameterAttributes.None, "request"); methodBuilder1.DefineParameter(4, ParameterAttributes.Out, "result"); Type[] parameterTypes2 = new Type[3] { dcBuilderType2.Type, dcBuilderType3.Type, dcBuilderType4.Type.MakeByRefType() }; MethodBuilder methodBuilder2 = this.DefineMethod(method2.Name, parameterTypes2, typeBuilder); methodBuilder2.DefineParameter(1, ParameterAttributes.None, service.Name.Substring(0, 1).ToLower() + service.Name.Substring(1)); methodBuilder2.DefineParameter(2, ParameterAttributes.None, "request"); methodBuilder2.DefineParameter(3, ParameterAttributes.Out, "result"); Type[] parameterTypes3 = new Type[1] { dcBuilderType2.Type }; this.DefineMethod(method2.Name, parameterTypes3, typeBuilder).DefineParameter(1, ParameterAttributes.None, service.Name.Substring(0, 1).ToLower() + service.Name.Substring(1)); this.DefineMethod(method2.Name, Type.EmptyTypes, typeBuilder); } } this.dCTypeStore.Add("I" + service.Name + "Base", typeBuilder.CreateType(), typeBuilder); } } if (service.ExposedState == ExposedServiceStateType.Base) { return; } TypeBuilder typeBuilder1 = (TypeBuilder)null; if (!this._IsSilverlight) { typeBuilder1 = this.moduleBuilder.DefineType(this.nameSpacePrefix + "I" + service.Name + "Service", TypeAttributes.Public | TypeAttributes.ClassSemanticsMask | TypeAttributes.Abstract); CustomAttributeBuilder customBuilder = new CustomAttributeBuilder(typeof(ServiceContractAttribute).GetConstructor(Type.EmptyTypes), new object[0]); typeBuilder1.SetCustomAttribute(customBuilder); } DCBuilderType dcBuilderType6 = this.dCTypeStore.GetDCBuilderType(service.Name); this.AddResultType(dcBuilderType6, isForClient); this.AddRequestType(dcBuilderType6, isForClient); this.AddParameterType(dcBuilderType6); DCBuilderType dcBuilderType7 = this.dCTypeStore.GetDCBuilderType(service.Name + "_Request"); DCBuilderType dcBuilderType8 = this.dCTypeStore.GetDCBuilderType(service.Name + "_Result"); DCBuilderType dcBuilderType9 = this.dCTypeStore.GetDCBuilderType(service.Name + "_Parameters"); DCBuilderType dcBuilderType10 = this.dCTypeStore.GetDCBuilderType("UserProfile"); EnumBuilder enumBuilder1 = this.DefineEnum(this.nameSpacePrefix + service.Name + "Methods"); int num = 0; foreach (IMethod method1 in service.GetMethods()) { if (method1.ExposedState == ExposedMethodStateType.Exposed || method1.ExposedState == ExposedMethodStateType.BaseAndExposed) { Method method2 = method1 as Method; Type[] parameterTypes = new Type[5] { dcBuilderType10.Type, dcBuilderType6.Type, dcBuilderType9.Type, dcBuilderType7.Type, dcBuilderType8.Type.MakeByRefType() }; if (method2.HasParameters) { this.AddMethodParametersType(service.Name, method2, isForClient); parameterTypes[2] = this.dCTypeStore.GetDCBuilderType(service.Name + "_" + method2.Name + "_Parameters").Type; } if (!this._IsSilverlight) { MethodBuilder methodBuilder = this.DefineMethod(method2.Name, parameterTypes, typeBuilder1); methodBuilder.DefineParameter(1, ParameterAttributes.None, "userProfile"); methodBuilder.DefineParameter(2, ParameterAttributes.None, service.Name.Substring(0, 1).ToLower() + service.Name.Substring(1)); methodBuilder.DefineParameter(3, ParameterAttributes.None, "parameters"); methodBuilder.DefineParameter(4, ParameterAttributes.None, "request"); methodBuilder.DefineParameter(5, ParameterAttributes.Out, "result"); } this.DefineLiteral(enumBuilder1, method1.Name, num++, (string)null, (DCField)null); } } EnumBuilder enumBuilder2 = enumBuilder1; int number1 = num; int number2 = number1 + 1; this.DefineLiteral(enumBuilder2, "ExecuteTransaction", number1, (string)null, (DCField)null); this.DefineLiteral(enumBuilder1, "AddDataTransaction", number2, (string)null, (DCField)null); this.dCTypeStore.Add(service.Name + "Methods", enumBuilder1.CreateType(), (TypeBuilder)null); DCBuilderType dcBuilderType11 = this.dCTypeStore.GetDCBuilderType(service.Name + "Methods"); this.AddMethodType(service.Name, dcBuilderType11, dcBuilderType9); if (this._IsSilverlight) { return; } this.AddCommitTransactionMethod(service, dcBuilderType10, typeBuilder1, dcBuilderType7, dcBuilderType8); this.AddExecuteTransactionMethod(service, dcBuilderType10, typeBuilder1, dcBuilderType6, dcBuilderType7, dcBuilderType8); this.AddGetEnvironmentMethod(service, dcBuilderType10, typeBuilder1, dcBuilderType6, dcBuilderType7, dcBuilderType8); this.dCTypeStore.Add("I" + service.Name + "Service", typeBuilder1.CreateType(), typeBuilder1); }
public override void AddService(ServiceBase service) { if (service.ExposedState == ExposedServiceStateType.Base) { return; } this.AddServiceInterface(service); Type type = this.dCTypeStore.GetDCBuilderType("ServiceBase").Type; DCBuilderType dcBuilderType1 = this.dCTypeStore.GetDCBuilderType("I" + service.Name + "Service"); DCBuilderType dcBuilderType2 = this.dCTypeStore.GetDCBuilderType(service.Name); TypeBuilder typeBuilder = this.moduleBuilder.DefineType(this.nameSpacePrefix + service.Name + "Service", TypeAttributes.Public, type, new Type[1] { dcBuilderType1.Type }); DCBuilderType dcBuilderType3 = this.dCTypeStore.GetDCBuilderType(service.Name + "_Request"); DCBuilderType dcBuilderType4 = this.dCTypeStore.GetDCBuilderType(service.Name + "_Result"); DCBuilderType dcBuilderType5 = this.dCTypeStore.GetDCBuilderType("ResultStatus"); DCBuilderType dcBuilderType6 = this.dCTypeStore.GetDCBuilderType(service.Name + "_Parameters"); DCBuilderType dcBuilderType7 = this.dCTypeStore.GetDCBuilderType("UserProfile"); foreach (IMethod method1 in service.GetMethods()) { if (method1.ExposedState == ExposedMethodStateType.Exposed || method1.ExposedState == ExposedMethodStateType.BaseAndExposed) { Method method2 = method1 as Method; Type[] parameterTypes = new Type[5] { dcBuilderType7.Type, dcBuilderType2.Type, dcBuilderType6.Type, dcBuilderType3.Type, dcBuilderType4.Type.MakeByRefType() }; if (method2.HasParameters) { parameterTypes[2] = this.dCTypeStore.GetDCBuilderType(service.Name + "_" + method2.Name + "_Parameters").Type; } MethodBuilder methodBuilder = typeBuilder.DefineMethod(method2.Name, MethodAttributes.Public | MethodAttributes.Final | MethodAttributes.Virtual | MethodAttributes.VtableLayoutMask, dcBuilderType5.Type, parameterTypes); methodBuilder.DefineParameter(1, ParameterAttributes.None, "userProfile"); methodBuilder.DefineParameter(2, ParameterAttributes.None, service.Name.Substring(0, 1).ToLower() + service.Name.Substring(1)); methodBuilder.DefineParameter(3, ParameterAttributes.None, "parameters"); methodBuilder.DefineParameter(4, ParameterAttributes.None, "request"); methodBuilder.DefineParameter(5, ParameterAttributes.Out, "result"); ILGenerator ilGenerator = methodBuilder.GetILGenerator(); ilGenerator.DeclareLocal(dcBuilderType5.Type); ilGenerator.Emit(OpCodes.Ldarg_S, 5); ilGenerator.Emit(OpCodes.Newobj, dcBuilderType4.Type.GetConstructor(Type.EmptyTypes)); ilGenerator.Emit(OpCodes.Stind_Ref); ilGenerator.Emit(OpCodes.Ldarg_0); ilGenerator.Emit(OpCodes.Ldstr, method2.Name); ilGenerator.Emit(OpCodes.Ldarg_1); ilGenerator.Emit(OpCodes.Ldarg_2); ilGenerator.Emit(OpCodes.Ldarg_3); ilGenerator.Emit(OpCodes.Ldarg_S, 4); ilGenerator.Emit(OpCodes.Ldarg_S, 5); ilGenerator.Emit(OpCodes.Ldind_Ref); ilGenerator.Emit(OpCodes.Call, type.GetMethod("CallMethod", BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.NonPublic)); ilGenerator.Emit(OpCodes.Stloc_0); Label label = ilGenerator.DefineLabel(); ilGenerator.Emit(OpCodes.Br_S, label); ilGenerator.MarkLabel(label); ilGenerator.Emit(OpCodes.Ldloc_0); ilGenerator.Emit(OpCodes.Ret); } } this.AddCommitTransactionMethod(service, typeBuilder, type); this.AddExecuteTransactionMethod(service, typeBuilder, type); this.AddGetEnvironmentMethod(service, typeBuilder, type); typeBuilder.CreateType(); }
public override void AddDC(DCType dCType) { bool isPrivate = this is ClientGenerator; if (dCType.IsEnum) { return; } DCBuilderType dcBuilderType1 = this.dCTypeStore.GetDCBuilderType(dCType.ParentName); DCBuilderType dcBuilderType2 = this.dCTypeStore.GetDCBuilderType(dCType.Name); DCBuilderType dcBuilderType3 = this.dCTypeStore.GetDCBuilderType(dCType.Name + "_Environment"); DCBuilderType dcBuilderType4 = this.dCTypeStore.GetDCBuilderType(dCType.Name + "_Info"); if (isPrivate) { this.BeginOverrideMethods(dcBuilderType2.TypeBuilder); } foreach (DCField field in dCType.GetFields()) { DCBuilderType dcBuilderType5 = this.dCTypeStore.GetDCBuilderType(field.TypeName); Type type = dcBuilderType5.Type; if (field.IsList) { type = dcBuilderType5.Type.MakeArrayType(); } FieldInfo fieldInfo = dcBuilderType1.Type.GetField((isPrivate ? "_" : "") + field.Name, (BindingFlags)(4 | (!isPrivate || this._IsSilverlight ? 16 : 32))); if (!field.IsSimpleType) { if (fieldInfo != (FieldInfo)null) { try { Type fieldType = fieldInfo.FieldType; } catch (TypeLoadException ex) { fieldInfo = (FieldInfo)null; } } } if (field.IsActual(fieldInfo == (FieldInfo)null ? string.Empty : (fieldInfo.FieldType.IsArray ? fieldInfo.FieldType.GetElementType().Name : fieldInfo.FieldType.Name))) { FieldBuilder fieldBuilder = this.DefineField(dcBuilderType2.TypeBuilder, field.Name, type, isPrivate); if (isPrivate) { this.AddFieldOverrideMethods(dcBuilderType2.TypeBuilder, fieldBuilder); } this.DefineField(dcBuilderType3.TypeBuilder, field.Name, this.GetEnvironmentType(dcBuilderType5), field, isPrivate); this.DefineField(dcBuilderType4.TypeBuilder, field.Name, this.GetInfoType(dcBuilderType5), isPrivate); if (isPrivate) { this.DefineProperty(dcBuilderType2.TypeBuilder, field.Name, type); this.DefineProperty(dcBuilderType3.TypeBuilder, field.Name, this.GetEnvironmentType(dcBuilderType5), field); this.DefineProperty(dcBuilderType4.TypeBuilder, field.Name, this.GetInfoType(dcBuilderType5)); } } } if (isPrivate) { this.EndOverrideMethods(dcBuilderType1.Type); } this.DefineTypeConstructor(dcBuilderType2.TypeBuilder, dcBuilderType1.Type); dcBuilderType2.TypeBuilder.CreateType(); dcBuilderType3.TypeBuilder.CreateType(); dcBuilderType4.TypeBuilder.CreateType(); }