private static CodeMemberMethod CreateOperationCompletedMethod(ServiceContractGenerationContext context, CodeTypeDeclaration clientType, string syncMethodName, CodeTypeDeclaration operationCompletedEventArgsType, CodeMemberEvent operationCompletedEvent)
        {
            CodeObjectCreateExpression expression;
            CodeMemberMethod           method = new CodeMemberMethod {
                Attributes = MemberAttributes.Private,
                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")
            {
                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 CodeMemberMethod CreateEndOperationMethod(ServiceContractGenerationContext context, CodeTypeDeclaration clientType, string syncMethodName, CodeMemberMethod endMethod)
        {
            CodeMemberMethod method = new CodeMemberMethod {
                Attributes = MemberAttributes.Private,
                ReturnType = new CodeTypeReference(objectArrayType),
                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 {
                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 {
                    Type           = endMethod.ReturnType,
                    Name           = NamingHelper.GetUniqueName("retVal", new NamingHelper.DoesNameExist(ClientClassGenerator.DoesParameterNameExist), endMethod),
                    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);
        }
        private static CodeMemberField CreateBeginOperationDelegate(ServiceContractGenerationContext context, CodeTypeDeclaration clientType, string syncMethodName)
        {
            CodeMemberField field = new CodeMemberField {
                Attributes = MemberAttributes.Private,
                Type       = new CodeTypeReference(beginOperationDelegateTypeName),
                Name       = NamingHelper.GetUniqueName(GetBeginOperationDelegateName(syncMethodName), new NamingHelper.DoesNameExist(ClientClassGenerator.DoesMethodNameExist), context.Operations)
            };

            clientType.Members.Add(field);
            return(field);
        }
        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 {
                Type = new CodeTypeReference(objectArrayType)
            };
            CodeFieldReferenceExpression left = new CodeFieldReferenceExpression {
                TargetObject = new CodeThisReferenceExpression()
            };
            CodeConstructor constructor = new CodeConstructor {
                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);
        }
        internal ChannelEndpointElement WriteChannelDescription(ServiceEndpoint endpoint, string typeName)
        {
            ChannelEndpointElement element = null;
            BindingDictionaryValue value2  = this.CreateBindingConfig(endpoint.Binding);

            element = new ChannelEndpointElement(endpoint.Address, typeName)
            {
                Name = NamingHelper.GetUniqueName(NamingHelper.CodeName(endpoint.Name), new NamingHelper.DoesNameExist(this.CheckIfChannelNameInUse), null),
                BindingConfiguration = value2.BindingName,
                Binding = value2.BindingSectionName
            };
            this.channels.Add(element);
            return(element);
        }
        private BindingDictionaryValue CreateBindingConfig(Binding binding)
        {
            BindingDictionaryValue value2;

            if (!this.bindingTable.TryGetValue(binding, out value2))
            {
                string str2;
                string name = NamingHelper.GetUniqueName(NamingHelper.CodeName(binding.Name), new NamingHelper.DoesNameExist(this.CheckIfBindingNameInUse), null);
                if (!BindingsSection.TryAdd(name, binding, this.config, out str2))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(System.ServiceModel.SR.GetString("ConfigBindingCannotBeConfigured"), "endpoint.Binding"));
                }
                value2 = new BindingDictionaryValue(name, str2);
                this.bindingTable.Add(binding, value2);
            }
            return(value2);
        }
        private static CodeMemberEvent CreateOperationCompletedEvent(ServiceContractGenerationContext context, CodeTypeDeclaration clientType, string syncMethodName, CodeTypeDeclaration operationCompletedEventArgsType)
        {
            CodeMemberEvent event2 = new CodeMemberEvent {
                Attributes = MemberAttributes.Public,
                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 {
                Name       = NamingHelper.GetUniqueName(GetEventAsyncMethodName(syncMethodName), new NamingHelper.DoesNameExist(ClientClassGenerator.DoesMethodNameExist), context.Operations),
                Attributes = MemberAttributes.Public | MemberAttributes.Final,
                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)
                {
                    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);
        }
Example #9
0
        private static void MergeWsdl(WsdlNS.ServiceDescription singleWsdl, WsdlNS.ServiceDescription wsdl, Dictionary <XmlQualifiedName, XmlQualifiedName> bindingReferenceChanges)
        {
            if (wsdl.Services.Count > 0)
            {
                singleWsdl.Name = wsdl.Name;
            }

            foreach (WsdlNS.Binding binding in wsdl.Bindings)
            {
                string uniqueBindingName = NamingHelper.GetUniqueName(binding.Name, WsdlHelper.IsBindingNameUsed, singleWsdl.Bindings);
                if (binding.Name != uniqueBindingName)
                {
                    bindingReferenceChanges.Add(
                        new XmlQualifiedName(binding.Name, binding.ServiceDescription.TargetNamespace),
                        new XmlQualifiedName(uniqueBindingName, singleWsdl.TargetNamespace));
                    UpdatePolicyKeys(binding, uniqueBindingName, wsdl);
                    binding.Name = uniqueBindingName;
                }

                singleWsdl.Bindings.Add(binding);
            }

            foreach (object extension in wsdl.Extensions)
            {
                singleWsdl.Extensions.Add(extension);
            }

            foreach (WsdlNS.Message message in wsdl.Messages)
            {
                singleWsdl.Messages.Add(message);
            }

            foreach (WsdlNS.Service service in wsdl.Services)
            {
                singleWsdl.Services.Add(service);
            }

            foreach (string warning in wsdl.ValidationWarnings)
            {
                singleWsdl.ValidationWarnings.Add(warning);
            }
        }
Example #10
0
        internal ChannelEndpointElement WriteChannelDescription(ServiceEndpoint endpoint, string typeName)
        {
            ChannelEndpointElement channelElement = null;

            // Create Binding
            BindingDictionaryValue bindingDV = CreateBindingConfig(endpoint.Binding);


            channelElement = new ChannelEndpointElement(endpoint.Address, typeName);

            // [....]: review: Use decoded form to preserve the user-given friendly name, however, beacuse our Encoding algorithm
            // does not touch ASCII names, a name that looks like encoded name will not roundtrip(Example: "_x002C_" will turned into ",")
            channelElement.Name = NamingHelper.GetUniqueName(NamingHelper.CodeName(endpoint.Name), this.CheckIfChannelNameInUse, null);

            channelElement.BindingConfiguration = bindingDV.BindingName;
            channelElement.Binding = bindingDV.BindingSectionName;
            channels.Add(channelElement);

            return(channelElement);
        }
Example #11
0
        BindingDictionaryValue CreateBindingConfig(Binding binding)
        {
            BindingDictionaryValue bindingDV;

            if (!bindingTable.TryGetValue(binding, out bindingDV))
            {
                // [....]: review: Use decoded form to preserve the user-given friendly name, however, beacuse our Encoding algorithm
                // does not touch ASCII names, a name that looks like encoded name will not roundtrip(Example: "_x002C_" will turned into ",")
                string bindingName = NamingHelper.GetUniqueName(NamingHelper.CodeName(binding.Name), this.CheckIfBindingNameInUse, null);
                string bindingSectionName;

                if (!BindingsSection.TryAdd(bindingName, binding, config, out bindingSectionName))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.GetString(SR.ConfigBindingCannotBeConfigured), "endpoint.Binding"));
                }

                bindingDV = new BindingDictionaryValue(bindingName, bindingSectionName);
                bindingTable.Add(binding, bindingDV);
            }
            return(bindingDV);
        }
        private static CodeMemberMethod CreateBeginOperationMethod(ServiceContractGenerationContext context, CodeTypeDeclaration clientType, string syncMethodName, CodeMemberMethod beginMethod)
        {
            CodeMemberMethod method = new CodeMemberMethod {
                Attributes = MemberAttributes.Private,
                ReturnType = new CodeTypeReference(asyncResultType),
                Name       = NamingHelper.GetUniqueName(GetBeginOperationMethodName(syncMethodName), new NamingHelper.DoesNameExist(ClientClassGenerator.DoesMethodNameExist), context.Operations)
            };
            CodeParameterDeclarationExpression expression = new CodeParameterDeclarationExpression {
                Type = new CodeTypeReference(objectArrayType),
                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;
                statement = new CodeVariableDeclarationStatement {
                    Type           = beginMethod.Parameters[i].Type,
                    Name           = beginMethod.Parameters[i].Name,
                    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 {
                    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);
        }
        private static CodeMethodReturnStatement GenerateParameters(CodeMemberMethod helperMethod, CodeTypeDeclaration codeTypeDeclaration, CodeExpression target, FieldDirection dir)
        {
            CodeMethodReturnStatement statement = null;

            foreach (CodeTypeMember member in codeTypeDeclaration.Members)
            {
                CodeMemberField field = member as CodeMemberField;
                if (field != null)
                {
                    CodeFieldReferenceExpression left     = new CodeFieldReferenceExpression(target, field.Name);
                    CodeTypeDeclaration          codeType = ServiceContractGenerator.NamespaceHelper.GetCodeType(field.Type);
                    if (codeType != null)
                    {
                        if (dir == FieldDirection.In)
                        {
                            helperMethod.Statements.Add(new CodeAssignStatement(left, new CodeObjectCreateExpression(field.Type, new CodeExpression[0])));
                        }
                        statement = GenerateParameters(helperMethod, codeType, left, dir);
                    }
                    else
                    {
                        CodeParameterDeclarationExpression expression2 = GetRefParameter(helperMethod.Parameters, dir, field);
                        if (((expression2 == null) && (dir == FieldDirection.Out)) && (helperMethod.ReturnType.BaseType == voidTypeRef.BaseType))
                        {
                            helperMethod.ReturnType = field.Type;
                            statement = new CodeMethodReturnStatement(left);
                        }
                        else
                        {
                            if (expression2 == null)
                            {
                                expression2 = new CodeParameterDeclarationExpression(field.Type, NamingHelper.GetUniqueName(field.Name, new NamingHelper.DoesNameExist(ClientClassGenerator.DoesParameterNameExist), helperMethod))
                                {
                                    Direction = dir
                                };
                                helperMethod.Parameters.Add(expression2);
                            }
                            if (dir == FieldDirection.Out)
                            {
                                helperMethod.Statements.Add(new CodeAssignStatement(new CodeArgumentReferenceExpression(expression2.Name), left));
                            }
                            else
                            {
                                helperMethod.Statements.Add(new CodeAssignStatement(left, new CodeArgumentReferenceExpression(expression2.Name)));
                            }
                        }
                    }
                }
            }
            return(statement);
        }
Example #15
0
 private string GetUniqueMessageName(System.Web.Services.Description.ServiceDescription wsdl, string messageNameBase)
 {
     return(NamingHelper.GetUniqueName(messageNameBase, new NamingHelper.DoesNameExist(MessageContractExporter.DoesMessageNameExist), wsdl));
 }