private static CodeMemberField CreateBeginOperationDelegate(ServiceContractGenerationContext context, CodeTypeDeclaration clientType, string syncMethodName)
 {
     CodeMemberField field = new CodeMemberField();
     field.Attributes = MemberAttributes.Private;
     field.Type = new CodeTypeReference(beginOperationDelegateTypeName);
     field.Name = NamingHelper.GetUniqueName(GetBeginOperationDelegateName(syncMethodName), new NamingHelper.DoesNameExist(ClientClassGenerator.DoesMethodNameExist), context.Operations);
     clientType.Members.Add(field);
     return field;
 }
 public OperationContractGenerationContext(ServiceContractGenerator serviceContractGenerator, ServiceContractGenerationContext contract, 
    OperationDescription operation, CodeTypeDeclaration declaringType, CodeMemberMethod method) : this(serviceContractGenerator, contract, operation, declaringType)
 {
     if (method == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("method"));
     }
     this.syncMethod = method;
     this.beginMethod = null;
     this.endMethod = null;
 }
 // Methods
 private OperationContractGenerationContext(ServiceContractGenerator serviceContractGenerator, 
    ServiceContractGenerationContext contract, OperationDescription operation, CodeTypeDeclaration declaringType)
 {
     if (serviceContractGenerator == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("serviceContractGenerator"));
     }
     if (contract == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("contract"));
     }
     if (declaringType == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("declaringType"));
     }
     this.serviceContractGenerator = serviceContractGenerator;
     this.contract = contract;
     this.operation = operation;
     this.declaringType = declaringType;
 }
 private static void GenerateEventAsyncMethods(ServiceContractGenerationContext context, CodeTypeDeclaration clientType, string syncMethodName, CodeMemberMethod beginMethod, CodeMemberMethod endMethod)
 {
     CodeTypeDeclaration operationCompletedEventArgsType = CreateOperationCompletedEventArgsType(context, syncMethodName, endMethod);
     CodeMemberEvent operationCompletedEvent = CreateOperationCompletedEvent(context, clientType, syncMethodName, operationCompletedEventArgsType);
     CodeMemberField beginOperationDelegate = CreateBeginOperationDelegate(context, clientType, syncMethodName);
     CodeMemberMethod beginOperationMethod = CreateBeginOperationMethod(context, clientType, syncMethodName, beginMethod);
     CodeMemberField endOperationDelegate = CreateEndOperationDelegate(context, clientType, syncMethodName);
     CodeMemberMethod endOperationMethod = CreateEndOperationMethod(context, clientType, syncMethodName, endMethod);
     CodeMemberField operationCompletedDelegate = CreateOperationCompletedDelegate(context, clientType, syncMethodName);
     CodeMemberMethod operationCompletedMethod = CreateOperationCompletedMethod(context, clientType, syncMethodName, operationCompletedEventArgsType, operationCompletedEvent);
     CodeMemberMethod eventAsyncMethod = CreateEventAsyncMethod(context, clientType, syncMethodName, beginMethod, beginOperationDelegate, beginOperationMethod, endOperationDelegate, endOperationMethod, operationCompletedDelegate, operationCompletedMethod);
     CreateEventAsyncMethodOverload(clientType, eventAsyncMethod);
     beginMethod.CustomAttributes.Add(CreateEditorBrowsableAttribute(EditorBrowsableState.Advanced));
     endMethod.CustomAttributes.Add(CreateEditorBrowsableAttribute(EditorBrowsableState.Advanced));
 }
 private static CodeMemberMethod CreateOperationCompletedMethod(ServiceContractGenerationContext context, CodeTypeDeclaration clientType, string syncMethodName, CodeTypeDeclaration operationCompletedEventArgsType, CodeMemberEvent operationCompletedEvent)
 {
     CodeObjectCreateExpression expression;
     CodeMemberMethod method = new CodeMemberMethod();
     method.Attributes = MemberAttributes.Private;
     method.Name = NamingHelper.GetUniqueName(GetOperationCompletedMethodName(syncMethodName), new NamingHelper.DoesNameExist(ClientClassGenerator.DoesMethodNameExist), context.Operations);
     method.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference(objectType), "state"));
     method.ReturnType = new CodeTypeReference(voidType);
     CodeVariableDeclarationStatement statement = new CodeVariableDeclarationStatement(invokeAsyncCompletedEventArgsTypeName, "e");
     statement.InitExpression = new CodeCastExpression(invokeAsyncCompletedEventArgsTypeName, new CodeArgumentReferenceExpression(method.Parameters[0].Name));
     CodeVariableReferenceExpression targetObject = new CodeVariableReferenceExpression(statement.Name);
     if (operationCompletedEventArgsType != null)
     {
         expression = new CodeObjectCreateExpression(operationCompletedEventArgsType.Name, new CodeExpression[] { new CodePropertyReferenceExpression(targetObject, EventArgsPropertyNames[0]), new CodePropertyReferenceExpression(targetObject, EventArgsPropertyNames[1]), new CodePropertyReferenceExpression(targetObject, EventArgsPropertyNames[2]), new CodePropertyReferenceExpression(targetObject, EventArgsPropertyNames[3]) });
     }
     else
     {
         expression = new CodeObjectCreateExpression(asyncCompletedEventArgsType, new CodeExpression[] { new CodePropertyReferenceExpression(targetObject, EventArgsPropertyNames[1]), new CodePropertyReferenceExpression(targetObject, EventArgsPropertyNames[2]), new CodePropertyReferenceExpression(targetObject, EventArgsPropertyNames[3]) });
     }
     CodeEventReferenceExpression expression3 = new CodeEventReferenceExpression(new CodeThisReferenceExpression(), operationCompletedEvent.Name);
     CodeDelegateInvokeExpression expression4 = new CodeDelegateInvokeExpression(expression3, new CodeExpression[] { new CodeThisReferenceExpression(), expression });
     CodeConditionStatement statement2 = new CodeConditionStatement(new CodeBinaryOperatorExpression(expression3, CodeBinaryOperatorType.IdentityInequality, new CodePrimitiveExpression(null)), new CodeStatement[] { statement, new CodeExpressionStatement(expression4) });
     method.Statements.Add(statement2);
     clientType.Members.Add(method);
     return method;
 }
 private static CodeTypeDeclaration CreateOperationCompletedEventArgsType(ServiceContractGenerationContext context, string syncMethodName, CodeMemberMethod endMethod)
 {
     if ((endMethod.Parameters.Count == 1) && (endMethod.ReturnType.BaseType == voidTypeRef.BaseType))
     {
         return null;
     }
     CodeTypeDeclaration ownerTypeDecl = context.TypeFactory.CreateClassType();
     ownerTypeDecl.BaseTypes.Add(new CodeTypeReference(asyncCompletedEventArgsType));
     CodeMemberField field = new CodeMemberField();
     field.Type = new CodeTypeReference(objectArrayType);
     CodeFieldReferenceExpression left = new CodeFieldReferenceExpression();
     left.TargetObject = new CodeThisReferenceExpression();
     CodeConstructor constructor = new CodeConstructor();
     constructor.Attributes = MemberAttributes.Public;
     for (int i = 0; i < EventArgsCtorParamTypes.Length; i++)
     {
         constructor.Parameters.Add(new CodeParameterDeclarationExpression(EventArgsCtorParamTypes[i], EventArgsCtorParamNames[i]));
         if (i > 0)
         {
             constructor.BaseConstructorArgs.Add(new CodeVariableReferenceExpression(EventArgsCtorParamNames[i]));
         }
     }
     ownerTypeDecl.Members.Add(constructor);
     constructor.Statements.Add(new CodeAssignStatement(left, new CodeVariableReferenceExpression(EventArgsCtorParamNames[0])));
     int asyncResultParamIndex = GetAsyncResultParamIndex(endMethod);
     int num3 = 0;
     for (int j = 0; j < endMethod.Parameters.Count; j++)
     {
         if (j != asyncResultParamIndex)
         {
             CreateEventAsyncCompletedArgsTypeProperty(ownerTypeDecl, endMethod.Parameters[j].Type, endMethod.Parameters[j].Name, new CodeArrayIndexerExpression(left, new CodeExpression[] { new CodePrimitiveExpression(num3++) }));
         }
     }
     if (endMethod.ReturnType.BaseType != voidTypeRef.BaseType)
     {
         CreateEventAsyncCompletedArgsTypeProperty(ownerTypeDecl, endMethod.ReturnType, NamingHelper.GetUniqueName("Result", new NamingHelper.DoesNameExist(ClientClassGenerator.DoesMemberNameExist), ownerTypeDecl), new CodeArrayIndexerExpression(left, new CodeExpression[] { new CodePrimitiveExpression(num3) }));
     }
     field.Name = NamingHelper.GetUniqueName("results", new NamingHelper.DoesNameExist(ClientClassGenerator.DoesMemberNameExist), ownerTypeDecl);
     left.FieldName = field.Name;
     ownerTypeDecl.Members.Add(field);
     ownerTypeDecl.Name = NamingHelper.GetUniqueName(GetOperationCompletedEventArgsTypeName(syncMethodName), new NamingHelper.DoesNameExist(ClientClassGenerator.DoesTypeAndMemberNameExist), new object[] { context.Namespace.Types, ownerTypeDecl });
     context.Namespace.Types.Add(ownerTypeDecl);
     return ownerTypeDecl;
 }
 private static CodeMemberEvent CreateOperationCompletedEvent(ServiceContractGenerationContext context, CodeTypeDeclaration clientType, string syncMethodName, CodeTypeDeclaration operationCompletedEventArgsType)
 {
     CodeMemberEvent event2 = new CodeMemberEvent();
     event2.Attributes = MemberAttributes.Public;
     event2.Type = new CodeTypeReference(eventHandlerType);
     if (operationCompletedEventArgsType == null)
     {
         event2.Type.TypeArguments.Add(asyncCompletedEventArgsType);
     }
     else
     {
         event2.Type.TypeArguments.Add(operationCompletedEventArgsType.Name);
     }
     event2.Name = NamingHelper.GetUniqueName(GetOperationCompletedEventName(syncMethodName), new NamingHelper.DoesNameExist(ClientClassGenerator.DoesMethodNameExist), context.Operations);
     clientType.Members.Add(event2);
     return event2;
 }
 private static CodeMemberMethod CreateEventAsyncMethod(ServiceContractGenerationContext context, CodeTypeDeclaration clientType, string syncMethodName, CodeMemberMethod beginMethod, CodeMemberField beginOperationDelegate, CodeMemberMethod beginOperationMethod, CodeMemberField endOperationDelegate, CodeMemberMethod endOperationMethod, CodeMemberField operationCompletedDelegate, CodeMemberMethod operationCompletedMethod)
 {
     CodeMemberMethod nameCollection = new CodeMemberMethod();
     nameCollection.Name = NamingHelper.GetUniqueName(GetEventAsyncMethodName(syncMethodName), new NamingHelper.DoesNameExist(ClientClassGenerator.DoesMethodNameExist), context.Operations);
     nameCollection.Attributes = MemberAttributes.Public | MemberAttributes.Final;
     nameCollection.ReturnType = new CodeTypeReference(voidType);
     CodeArrayCreateExpression expression = new CodeArrayCreateExpression(new CodeTypeReference(objectArrayType), new CodeExpression[0]);
     for (int i = 0; i < (beginMethod.Parameters.Count - 2); i++)
     {
         CodeParameterDeclarationExpression expression2 = beginMethod.Parameters[i];
         CodeParameterDeclarationExpression expression3 = new CodeParameterDeclarationExpression(expression2.Type, expression2.Name);
         expression3.Direction = FieldDirection.In;
         nameCollection.Parameters.Add(expression3);
         expression.Initializers.Add(new CodeVariableReferenceExpression(expression3.Name));
     }
     string name = NamingHelper.GetUniqueName("userState", new NamingHelper.DoesNameExist(ClientClassGenerator.DoesParameterNameExist), nameCollection);
     nameCollection.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference(objectType), name));
     nameCollection.Statements.Add(CreateDelegateIfNotNull(beginOperationDelegate, beginOperationMethod));
     nameCollection.Statements.Add(CreateDelegateIfNotNull(endOperationDelegate, endOperationMethod));
     nameCollection.Statements.Add(CreateDelegateIfNotNull(operationCompletedDelegate, operationCompletedMethod));
     CodeMethodInvokeExpression expression4 = new CodeMethodInvokeExpression(new CodeBaseReferenceExpression(), invokeAsyncMethodName, new CodeExpression[0]);
     expression4.Parameters.Add(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), beginOperationDelegate.Name));
     if (expression.Initializers.Count > 0)
     {
         expression4.Parameters.Add(expression);
     }
     else
     {
         expression4.Parameters.Add(new CodePrimitiveExpression(null));
     }
     expression4.Parameters.Add(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), endOperationDelegate.Name));
     expression4.Parameters.Add(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), operationCompletedDelegate.Name));
     expression4.Parameters.Add(new CodeVariableReferenceExpression(name));
     nameCollection.Statements.Add(new CodeExpressionStatement(expression4));
     clientType.Members.Add(nameCollection);
     return nameCollection;
 }
 private void AddServiceContractAttribute(ServiceContractGenerationContext context)
 {
     CodeAttributeDeclaration declaration = new CodeAttributeDeclaration(context.ServiceContractGenerator.GetCodeTypeReference(typeof(ServiceContractAttribute)));
     if (context.ContractType.Name != context.Contract.CodeName)
     {
         string str = (NamingHelper.XmlName(context.Contract.CodeName) == context.Contract.Name)  context.Contract.CodeName  context.Contract.Name;
         declaration.Arguments.Add(new CodeAttributeArgument(Name, new CodePrimitiveExpression(str)));
     }
     if (httptempuri.org != context.Contract.Namespace)
     {
         declaration.Arguments.Add(new CodeAttributeArgument(Namespace, new CodePrimitiveExpression(context.Contract.Namespace)));
     }
     declaration.Arguments.Add(new CodeAttributeArgument(ConfigurationName, new CodePrimitiveExpression(ServiceContractGenerator.NamespaceHelper.GetCodeTypeReference(context.Namespace, context.ContractType).BaseType)));
     if (context.Contract.HasProtectionLevel)
     {
         declaration.Arguments.Add(new CodeAttributeArgument(ProtectionLevel, new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(typeof(ProtectionLevel)), context.Contract.ProtectionLevel.ToString())));
     }
     if (context.DuplexCallbackType != null)
     {
         declaration.Arguments.Add(new CodeAttributeArgument(CallbackContract, new CodeTypeOfExpression(context.DuplexCallbackTypeReference)));
     }
     if (context.Contract.SessionMode != SessionMode.Allowed)
     {
         declaration.Arguments.Add(new CodeAttributeArgument(SessionMode, new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(typeof(SessionMode)), context.Contract.SessionMode.ToString())));
     }
     context.ContractType.CustomAttributes.Add(declaration);
 }
Beispiel #10
0
 public void GenerateContract(ServiceContractGenerationContext context)
 {
     Debug.WriteLine("In generate contract.");
     context.ContractType.Comments.AddRange(FormatComments(text));
 }
 private static CodeMemberMethod CreateBeginOperationMethod(ServiceContractGenerationContext context, CodeTypeDeclaration clientType, string syncMethodName, CodeMemberMethod beginMethod)
 {
     CodeMemberMethod method = new CodeMemberMethod();
     method.Attributes = MemberAttributes.Private;
     method.ReturnType = new CodeTypeReference(asyncResultType);
     method.Name = NamingHelper.GetUniqueName(GetBeginOperationMethodName(syncMethodName), new NamingHelper.DoesNameExist(ClientClassGenerator.DoesMethodNameExist), context.Operations);
     CodeParameterDeclarationExpression expression = new CodeParameterDeclarationExpression();
     expression.Type = new CodeTypeReference(objectArrayType);
     expression.Name = NamingHelper.GetUniqueName("inValues", new NamingHelper.DoesNameExist(ClientClassGenerator.DoesParameterNameExist), beginMethod);
     method.Parameters.Add(expression);
     CodeMethodInvokeExpression expression2 = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), beginMethod.Name, new CodeExpression[0]);
     CodeExpression targetObject = new CodeVariableReferenceExpression(expression.Name);
     for (int i = 0; i < (beginMethod.Parameters.Count - 2); i++)
     {
         CodeVariableDeclarationStatement statement = new CodeVariableDeclarationStatement();
         statement.Type = beginMethod.Parameters[i].Type;
         statement.Name = beginMethod.Parameters[i].Name;
         statement.InitExpression = new CodeCastExpression(statement.Type, new CodeArrayIndexerExpression(targetObject, new CodeExpression[] { new CodePrimitiveExpression(i) }));
         method.Statements.Add(statement);
         expression2.Parameters.Add(new CodeDirectionExpression(beginMethod.Parameters[i].Direction, new CodeVariableReferenceExpression(statement.Name)));
     }
     for (int j = beginMethod.Parameters.Count - 2; j < beginMethod.Parameters.Count; j++)
     {
         method.Parameters.Add(new CodeParameterDeclarationExpression(beginMethod.Parameters[j].Type, beginMethod.Parameters[j].Name));
         expression2.Parameters.Add(new CodeVariableReferenceExpression(beginMethod.Parameters[j].Name));
     }
     method.Statements.Add(new CodeMethodReturnStatement(expression2));
     clientType.Members.Add(method);
     return method;
 }
 void IServiceContractGenerationExtension.GenerateContract(ServiceContractGenerationContext context)
 {
     CodeTypeDeclaration clientType = context.TypeFactory.CreateClassType();
     clientType.Name = NamingHelper.GetUniqueName(GetClientClassName(context.ContractType.Name), new NamingHelper.DoesNameExist(ClientClassGenerator.DoesMethodNameExist), context.Operations);
     CodeTypeReference contractTypeReference = context.ContractTypeReference;
     if (context.DuplexCallbackType == null)
     {
         clientType.BaseTypes.Add(new CodeTypeReference(context.ServiceContractGenerator.GetCodeTypeReference(typeof(ClientBase<>)).BaseType, new CodeTypeReference[] { context.ContractTypeReference }));
     }
     else
     {
         clientType.BaseTypes.Add(new CodeTypeReference(context.ServiceContractGenerator.GetCodeTypeReference(typeof(DuplexClientBase<>)).BaseType, new CodeTypeReference[] { context.ContractTypeReference }));
     }
     clientType.BaseTypes.Add(context.ContractTypeReference);
     if (ClientCtorParamNames.Length != ClientCtorParamTypes.Length)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Invalid client generation constructor table initialization", new object[0])));
     }
     for (int i = 0; i < ClientCtorParamNames.Length; i++)
     {
         if (ClientCtorParamNames[i].Length != ClientCtorParamTypes[i].Length)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Invalid client generation constructor table initialization", new object[0])));
         }
         CodeConstructor constructor = new CodeConstructor();
         constructor.Attributes = MemberAttributes.Public;
         if (context.DuplexCallbackType != null)
         {
             constructor.Parameters.Add(new CodeParameterDeclarationExpression(typeof(InstanceContext), inputInstanceName));
             constructor.BaseConstructorArgs.Add(new CodeVariableReferenceExpression(inputInstanceName));
         }
         for (int j = 0; j < ClientCtorParamNames[i].Length; j++)
         {
             constructor.Parameters.Add(new CodeParameterDeclarationExpression(ClientCtorParamTypes[i][j], ClientCtorParamNames[i][j]));
             constructor.BaseConstructorArgs.Add(new CodeVariableReferenceExpression(ClientCtorParamNames[i][j]));
         }
         clientType.Members.Add(constructor);
     }
     foreach (OperationContractGenerationContext context2 in context.Operations)
     {
         if (!context2.Operation.IsServerInitiated())
         {
             CodeTypeReference declaringTypeReference = context2.DeclaringTypeReference;
             GenerateClientClassMethod(clientType, contractTypeReference, context2.SyncMethod, this.tryAddHelperMethod, declaringTypeReference);
             if (context2.IsAsync)
             {
                 CodeMemberMethod beginMethod = GenerateClientClassMethod(clientType, contractTypeReference, context2.BeginMethod, this.tryAddHelperMethod, declaringTypeReference);
                 CodeMemberMethod endMethod = GenerateClientClassMethod(clientType, contractTypeReference, context2.EndMethod, this.tryAddHelperMethod, declaringTypeReference);
                 if (this.generateEventAsyncMethods)
                 {
                     GenerateEventAsyncMethods(context, clientType, context2.SyncMethod.Name, beginMethod, endMethod);
                 }
             }
         }
     }
     context.Namespace.Types.Add(clientType);
     context.ClientType = clientType;
     context.ClientTypeReference = ServiceContractGenerator.NamespaceHelper.GetCodeTypeReference(context.Namespace, clientType);
 }
 internal static void CallOperationExtensions(IEnumerableIOperationContractGenerationExtension extensions, ServiceContractGenerationContext context)
 {
     foreach (OperationContractGenerationContext context2 in context.Operations)
     {
         CallOperationExtensions(extensions, context2);
     }
 }
 internal static void CallContractExtensions(IEnumerableIServiceContractGenerationExtension extensions, ServiceContractGenerationContext context)
 {
     foreach (IServiceContractGenerationExtension extension in extensions)
     {
         extension.GenerateContract(context);
     }
 }
 internal static void CallBehaviorExtensions(ServiceContractGenerationContext context)
 {
     CallContractExtensions(EnumerateBehaviorExtensions(context.Contract), context);
     foreach (OperationContractGenerationContext context2 in context.Operations)
     {
         CallOperationExtensions(EnumerateBehaviorExtensions(context2.Operation), context2);
     }
 }
 private void Visit(OperationDescription operationDescription)
 {
     OperationContractGenerationContext context;
     bool flag = operationDescription.IsServerInitiated();
     CodeTypeDeclaration declaringType = flag  this.context.DuplexCallbackType  this.context.ContractType;
     string str = (flag  this.callbackMemberScope  this.contractMemberScope).AddUnique(operationDescription.CodeName, Method);
     CodeMemberMethod method = new CodeMemberMethod();
     method.Name = str;
     declaringType.Members.Add(method);
     if (this.asyncMethods)
     {
         CodeMemberMethod method2 = new CodeMemberMethod();
         method2.Name = Begin + str;
         method2.Parameters.Add(new CodeParameterDeclarationExpression(this.context.ServiceContractGenerator.GetCodeTypeReference(typeof(AsyncCallback)), callback));
         method2.Parameters.Add(new CodeParameterDeclarationExpression(this.context.ServiceContractGenerator.GetCodeTypeReference(typeof(object)), asyncState));
         method2.ReturnType = this.context.ServiceContractGenerator.GetCodeTypeReference(typeof(IAsyncResult));
         declaringType.Members.Add(method2);
         CodeMemberMethod method3 = new CodeMemberMethod();
         method3.Name = End + str;
         method3.Parameters.Add(new CodeParameterDeclarationExpression(this.context.ServiceContractGenerator.GetCodeTypeReference(typeof(IAsyncResult)), result));
         declaringType.Members.Add(method3);
         context = new OperationContractGenerationContext(this.parent, this.context, operationDescription, declaringType, method, method2, method3);
     }
     else
     {
         context = new OperationContractGenerationContext(this.parent, this.context, operationDescription, declaringType, method);
     }
     context.DeclaringTypeReference = operationDescription.IsServerInitiated()  this.context.DuplexCallbackTypeReference  this.context.ContractTypeReference;
     this.context.Operations.Add(context);
     this.AddOperationContractAttributes(context);
 }
 private void Visit(ContractDescription contractDescription)
 {
     bool flag = IsDuplex(contractDescription);
     this.contractMemberScope = new UniqueCodeIdentifierScope();
     this.callbackMemberScope = flag  new UniqueCodeIdentifierScope()  null;
     UniqueCodeNamespaceScope scope = new UniqueCodeNamespaceScope(this.parent.NamespaceManager.EnsureNamespace(contractDescription.Namespace));
     CodeTypeDeclaration codeType = this.typeFactory.CreateInterfaceType();
     CodeTypeReference reference = scope.AddUnique(codeType, contractDescription.CodeName, IContract);
     CodeTypeDeclaration declaration2 = null;
     CodeTypeReference reference2 = null;
     if (flag)
     {
         declaration2 = this.typeFactory.CreateInterfaceType();
         reference2 = scope.AddUnique(declaration2, contractDescription.CodeName + Callback, IContract);
     }
     this.context = new ServiceContractGenerationContext(this.parent, contractDescription, codeType, declaration2);
     this.context.Namespace = scope.CodeNamespace;
     this.context.TypeFactory = this.typeFactory;
     this.context.ContractTypeReference = reference;
     this.context.DuplexCallbackTypeReference = reference2;
     this.AddServiceContractAttribute(this.context);
 }
        public void GenerateContract(ServiceContractGenerationContext context)
        {
            var compileUnit = context.ServiceContractGenerator.TargetCompileUnit;

            GenerateContract(compileUnit);
        }
 void IServiceContractGenerationExtension.GenerateContract(ServiceContractGenerationContext context)
 {
     context.ContractType.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeTypeReference(typeof(SoapHeadersAttribute))));
 }
        // IServiceContractGenerationExtensions

        public void GenerateContract(
            ServiceContractGenerationContext context)
        {
            this.context        = context;
            ml_context.Contract = this;
        }
 private static CodeMemberMethod CreateEndOperationMethod(ServiceContractGenerationContext context, CodeTypeDeclaration clientType, string syncMethodName, CodeMemberMethod endMethod)
 {
     CodeMemberMethod method = new CodeMemberMethod();
     method.Attributes = MemberAttributes.Private;
     method.ReturnType = new CodeTypeReference(objectArrayType);
     method.Name = NamingHelper.GetUniqueName(GetEndOperationMethodName(syncMethodName), new NamingHelper.DoesNameExist(ClientClassGenerator.DoesMethodNameExist), context.Operations);
     int asyncResultParamIndex = GetAsyncResultParamIndex(endMethod);
     CodeMethodInvokeExpression expression = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), endMethod.Name, new CodeExpression[0]);
     CodeArrayCreateExpression expression2 = new CodeArrayCreateExpression();
     expression2.CreateType = new CodeTypeReference(objectArrayType);
     for (int i = 0; i < endMethod.Parameters.Count; i++)
     {
         if (i == asyncResultParamIndex)
         {
             method.Parameters.Add(new CodeParameterDeclarationExpression(endMethod.Parameters[i].Type, endMethod.Parameters[i].Name));
             expression.Parameters.Add(new CodeVariableReferenceExpression(endMethod.Parameters[i].Name));
         }
         else
         {
             CodeVariableDeclarationStatement statement = new CodeVariableDeclarationStatement(endMethod.Parameters[i].Type, endMethod.Parameters[i].Name);
             CodeMethodReferenceExpression expression3 = new CodeMethodReferenceExpression(new CodeThisReferenceExpression(), getDefaultValueForInitializationMethodName, new CodeTypeReference[] { endMethod.Parameters[i].Type });
             statement.InitExpression = new CodeMethodInvokeExpression(expression3, new CodeExpression[0]);
             method.Statements.Add(statement);
             expression.Parameters.Add(new CodeDirectionExpression(endMethod.Parameters[i].Direction, new CodeVariableReferenceExpression(statement.Name)));
             expression2.Initializers.Add(new CodeVariableReferenceExpression(statement.Name));
         }
     }
     if (endMethod.ReturnType.BaseType != voidTypeRef.BaseType)
     {
         CodeVariableDeclarationStatement statement2 = new CodeVariableDeclarationStatement();
         statement2.Type = endMethod.ReturnType;
         statement2.Name = NamingHelper.GetUniqueName("retVal", new NamingHelper.DoesNameExist(ClientClassGenerator.DoesParameterNameExist), endMethod);
         statement2.InitExpression = expression;
         expression2.Initializers.Add(new CodeVariableReferenceExpression(statement2.Name));
         method.Statements.Add(statement2);
     }
     else
     {
         method.Statements.Add(expression);
     }
     if (expression2.Initializers.Count > 0)
     {
         method.Statements.Add(new CodeMethodReturnStatement(expression2));
     }
     else
     {
         method.Statements.Add(new CodeMethodReturnStatement(new CodePrimitiveExpression(null)));
     }
     clientType.Members.Add(method);
     return method;
 }
 // <snippet12>
 public void GenerateContract(ServiceContractGenerationContext context)
 {
     Console.WriteLine("In generate contract.");
     context.ContractType.Comments.AddRange(Formatter.FormatComments(commentText));
 }
 void IServiceContractGenerationExtension.GenerateContract(ServiceContractGenerationContext context)
 {
     CodeTypeDeclaration codeType = context.TypeFactory.CreateInterfaceType();
     codeType.BaseTypes.Add(context.ContractTypeReference);
     codeType.BaseTypes.Add(context.ServiceContractGenerator.GetCodeTypeReference(typeof(IClientChannel)));
     new UniqueCodeNamespaceScope(context.Namespace).AddUnique(codeType, context.ContractType.Name + Channel, Channel);
 }