public void Constructor1_Deny_Unrestricted ()
		{
			CodeExpression to_throw = new CodeExpression ();
			CodeThrowExceptionStatement ctes = new CodeThrowExceptionStatement (to_throw);
			Assert.AreSame (to_throw, ctes.ToThrow, "ToThrow");
			ctes.ToThrow = new CodeExpression ();
		}
        /// <summary>
        /// Inspects the specified code unit.
        /// </summary>
        /// <param name="unit">The code unit.</param>
        /// <param name="ns">The code namespace declaration.</param>
        /// <param name="type">The code type declaration.</param>
        /// <param name="executeMethod">The code method declaration for the Execute method.</param>
        public void Inspect(CodeCompileUnit unit, CodeNamespace ns, CodeTypeDeclaration type, CodeMemberMethod executeMethod)
        {
            var statement = new CodeThrowExceptionStatement(
                new CodeObjectCreateExpression(
                    new CodeTypeReference(typeof(System.InvalidOperationException)), new CodeExpression[] {}));

            executeMethod.Statements.Insert(0, statement);
        }
Пример #3
0
        // Generate a codedom throw statement
        public static CodeStatement Emit(Throw th)
        {
            var codeThrow = new CodeThrowExceptionStatement();

            codeThrow.ToThrow = CodeDomEmitter.EmitCodeExpression(th.ChildExpressions[0]);

            return codeThrow;
        }
 public TypescriptThrowExceptionStatement(
     IExpressionFactory expressionFactory,
     CodeThrowExceptionStatement statement,
     CodeGeneratorOptions options)
 {
     _expressionFactory = expressionFactory;
     _statement = statement;
     _options = options;
 }
 public static CodeThrowExceptionStatement Clone(this CodeThrowExceptionStatement statement)
 {
     if (statement == null) return null;
     CodeThrowExceptionStatement s = new CodeThrowExceptionStatement();
     s.EndDirectives.AddRange(statement.EndDirectives);
     s.LinePragma = statement.LinePragma;
     s.StartDirectives.AddRange(statement.StartDirectives);
     s.ToThrow = statement.ToThrow.Clone();
     s.UserData.AddRange(statement.UserData);
     return s;
 }
        private CodeThrowExceptionStatement GenerateExceptionStatement(GenerateErrorActivity activity)
        {
            var parameters = DefaultActivityBuilder.GenerateParameters(new List<string> {
                @"""Message : {0}\nMessage code : {1} """
            }, activity);

            CodeMethodInvokeExpression stringFormatCall = new CodeMethodInvokeExpression();
            stringFormatCall.Parameters.AddRange(parameters);

            CodeMethodReferenceExpression formatMethod = new CodeMethodReferenceExpression();
            formatMethod.MethodName = "Format";
            CodeVariableReferenceExpression stringObject = new CodeVariableReferenceExpression();
            stringObject.VariableName = "String";
            formatMethod.TargetObject = stringObject;
            stringFormatCall.Method = formatMethod;
            CodeThrowExceptionStatement throwException = new CodeThrowExceptionStatement(new CodeObjectCreateExpression(new CodeTypeReference(typeof(System.Exception)), stringFormatCall));
            return throwException;
        }
Пример #7
0
			public void Visit (CodeThrowExceptionStatement o)
			{
				g.GenerateThrowExceptionStatement (o);
			}
Пример #8
0
 private static void PrintThrowExceptionStatement(TextWriter output, CodeThrowExceptionStatement statement)
 {
     output.Write("throw ");
     if (statement.ToThrow != null)
     {
         PrintExpression(output, statement.ToThrow);
     }
 }
Пример #9
0
        internal static void EmitCodeToAddIntoCustomStdBinding(Type standardBindingType, string generatedElementClassName, string generatedCollectionElementClassName, string srcFile)
        {
            CodeMemberMethod applyCfgMethodForStdBinding = new CodeMemberMethod();
            applyCfgMethodForStdBinding.Name = MethodNameConstants.ApplyConfigurationMethod;

            string paramConfigName = "configurationName";
            CodeVariableReferenceExpression paramVarRef = new CodeVariableReferenceExpression(paramConfigName);

            applyCfgMethodForStdBinding.Parameters.Add(new CodeParameterDeclarationExpression(
                                                          CodeDomHelperObjects.stringTypeRef,
                                                          paramConfigName));

            string bindingsString = "bindings";
            CodeVariableReferenceExpression bindingsVarRef = new CodeVariableReferenceExpression(bindingsString);

            string sectionString = "section";
            CodeVariableReferenceExpression sectionVarRef = new CodeVariableReferenceExpression(sectionString);

            string elementString = "element";
            CodeVariableReferenceExpression elementVarRef = new CodeVariableReferenceExpression(elementString);

            string topLevelSectionNameInConfig = "system.serviceModel/bindings/";
            string subSectionNameInConfig = Helpers.TurnFirstCharLower(standardBindingType.Name);

            CodeVariableDeclarationStatement bindingsInit = new CodeVariableDeclarationStatement(
                                                            new CodeTypeReference(TypeNameConstants.BindingsSection),
                                                            bindingsString,
                                                            new CodeCastExpression(TypeNameConstants.BindingsSection,
                                                                new CodeMethodInvokeExpression(
                                                                    new CodeTypeReferenceExpression(TypeNameConstants.ConfigurationManager),
                                                                    MethodNameConstants.GetSectionMethod,
                                                                    new CodePrimitiveExpression(topLevelSectionNameInConfig))));
            applyCfgMethodForStdBinding.Statements.Add(bindingsInit);

            CodeVariableDeclarationStatement sectionInit = new CodeVariableDeclarationStatement(
                                                            new CodeTypeReference(generatedCollectionElementClassName),
                                                            sectionString,
                                                            new CodeCastExpression(generatedCollectionElementClassName,
                                                                new CodeArrayIndexerExpression(
                                                                    bindingsVarRef,
                                                                    new CodePrimitiveExpression(subSectionNameInConfig))));
            applyCfgMethodForStdBinding.Statements.Add(sectionInit);

            CodeVariableDeclarationStatement elementInit = new CodeVariableDeclarationStatement(
                                                new CodeTypeReference(generatedElementClassName),
                                                elementString,
                                                new CodeArrayIndexerExpression(
                                                    new CodeFieldReferenceExpression(
                                                        sectionVarRef,
                                                        PropertyNameConstants.BindingsProperty),
                                                    paramVarRef));
            applyCfgMethodForStdBinding.Statements.Add(elementInit);

            CodeBinaryOperatorExpression cboe = new CodeBinaryOperatorExpression(
                                                    elementVarRef,
                                                    CodeBinaryOperatorType.IdentityEquality,
                                                    CodeDomHelperObjects.NullRef);

            CodeThrowExceptionStatement ctes = new CodeThrowExceptionStatement(
                        new CodeObjectCreateExpression(
                            new CodeTypeReference(typeof(ConfigurationErrorsException)),
                            new CodeMethodInvokeExpression(
                                new CodeTypeReferenceExpression(CodeDomHelperObjects.stringTypeRef),
                                MethodNameConstants.FormatMethod,
                                CodeDomHelperObjects.cultureInfoCurrent,
                                new CodePrimitiveExpression("There is no binding named {0} at {1}."),
                                paramVarRef,
                                new CodePropertyReferenceExpression(
                                    sectionVarRef, PropertyNameConstants.BindingNameProperty))));
            CodeMethodInvokeExpression cmie = new CodeMethodInvokeExpression(
                                                            elementVarRef,
                                                            MethodNameConstants.ApplyConfigurationMethod,
                                                            CodeDomHelperObjects.ThisRef);
            CodeStatement[] trueStatements = { ctes };
            CodeStatement[] falseStatements = { new CodeExpressionStatement(cmie) };
            CodeConditionStatement ccs = new CodeConditionStatement(cboe, trueStatements, falseStatements);
            applyCfgMethodForStdBinding.Statements.Add(ccs);

            string indent = "    ";
            CodeDomProvider provider = new Microsoft.CSharp.CSharpCodeProvider();

            using (System.IO.StreamWriter sbSW = new System.IO.StreamWriter(srcFile, false))
            {
                using (IndentedTextWriter sbTW = new IndentedTextWriter(sbSW, indent))
                {
                    provider.GenerateCodeFromMember(
                                    applyCfgMethodForStdBinding,
                                    sbTW,
                                    new CodeGeneratorOptions());
                }
            }
        }
Пример #10
0
        public CodeStatement ParseStatement()
        {
            if (IsKeyword("var"))
            {
                GetNextToken();
                CodeTypeReference type = ParseType();
                string name = EatKeyword();
                if (TokenType == CDILToken.Assign)
                {
                    Expect(CDILToken.Assign);
                    CodeExpression expr = ParseExpression();
                    return new CodeVariableDeclarationStatement(type, name, expr);
                }
                else
                {
                    return new CodeVariableDeclarationStatement(type, name);
                }
            }
            if (IsKeyword("call"))
            {
                GetNextToken();
                return new CodeExpressionStatement(ParseExpression());
            }

            if (IsKeyword("return"))
            {
                CodeMethodReturnStatement retVal;

                GetNextToken();
                retVal = new CodeMethodReturnStatement();
                if (TokenType != CDILToken.Semicolon && TokenType != CDILToken.EOF)
                    retVal.Expression = ParseExpression();
                return retVal;
            }
            if (IsKeyword("throw"))
            {
                CodeThrowExceptionStatement retVal;

                GetNextToken();
                retVal = new CodeThrowExceptionStatement();
                if (TokenType != CDILToken.Semicolon && TokenType != CDILToken.EOF)
                    retVal.ToThrow = ParseExpression();
                return retVal;
            }
            if (IsKeyword("if"))
            {
                CodeConditionStatement retVal = new CodeConditionStatement();
                GetNextToken();
                retVal.Condition = ParseExpression();
                ExpectKeyword("then");
                while (TokenType != CDILToken.EOF && !IsKeyword("else") && !IsKeyword("endif"))
                {
                    retVal.TrueStatements.Add(ParseStatement());
                    if (TokenType == CDILToken.Semicolon)
                        GetNextToken();
                }
                if (IsKeyword("else"))
                {
                    ExpectKeyword("else");
                    while (TokenType != CDILToken.EOF && !IsKeyword("endif"))
                    {
                        retVal.FalseStatements.Add(ParseStatement());
                        if (TokenType == CDILToken.Semicolon)
                            GetNextToken();
                    }
                }
                ExpectKeyword("endif");
                return retVal;
            }
            if (IsKeyword("let"))
            {
                CodeAssignStatement retVal = new CodeAssignStatement();
                GetNextToken();
                retVal.Left = ParseExpression();
                Expect(CDILToken.Assign);
                retVal.Right = ParseExpression();
                return retVal;
            }
            if (IsKeyword("comment"))
            {
                GetNextToken();
                string s = TokenValue.ToString();
                GetNextToken();
                return new CodeCommentStatement(s);
            }
            throw BuildException("Invalid token: '" + TokenType + "': " + TokenValue);
        }
Пример #11
0
 internal static new CodeThrowExceptionStatement ThrowArgOutExceptionImpl(string idlMethodName, int nOutArgCounter, string idlMethodArgName, CodeTypeReference typerefParam,
     CodeTypeReferenceExpression typerefexprArgumentOut)
 {
     CodeThrowExceptionStatement throwargOutPrev = new CodeThrowExceptionStatement( // * throw Udbus.Core.Exceptions.UdbusMessageSignalArgumentException.Create(
         new CodeMethodInvokeExpression(typerefexprArgumentOut, "Create",
             new CodePrimitiveExpression(nOutArgCounter), // * <nOutArg>,
             new CodePrimitiveExpression(idlMethodArgName), // * "<signal_arg>",
             new CodeTypeOfExpression(typerefParam), // * typeof(<signal_type>),
             fieldrefResult, // * this.result,
             new CodePrimitiveExpression(idlMethodName), // * "<signal>",
             new CodeObjectCreateExpression( new CodeTypeReference(typeof(Udbus.Core.DbusSignalParams)),
                                             new CodePropertyReferenceExpression(fieldrefConnectionParameters, "Interface"),
                                             new CodePropertyReferenceExpression(fieldrefConnectionParameters, "Path")), // * new Udbus.DbusSignalParams(this.connectionParameters.Path, this.connectionParameters.Interface),
             proprefResponseData // * messageData.Data);
         )
     );
     return throwargOutPrev;
 }
Пример #12
0
 private void CheckOccurrence(CodeStatementCollection getStatements)
 {
     Debug.Assert(!this.IsList);
     CodeStatement returnStatement = null;
     if (IsNullable && DefaultValue == null)
     {
         if (typeRef.IsValueType)
         {
             // Need to return T?, since parseValue handles only T,
             // checking for null
             returnStatement = new CodeMethodReturnStatement(
                 new CodePrimitiveExpression(null));
         }
     }
     else if (VerifyRequired)
     {
         Debug.Assert(this.occursInSchema == Occurs.One);
         string origin =
             this.propertyOrigin == SchemaOrigin.Element ?
                 "Element" :
             this.propertyOrigin == SchemaOrigin.Attribute ?
                 "Attribute":
             // otherwise
                 null;
         returnStatement = new CodeThrowExceptionStatement(new CodeObjectCreateExpression(Constants.LinqToXsdException, new CodePrimitiveExpression("Missing required " + origin)));
     }
     if (returnStatement != null) {
         getStatements.Add(
             new CodeConditionStatement(
                 new CodeBinaryOperatorExpression(
                     new CodeVariableReferenceExpression("x"),
                     CodeBinaryOperatorType.IdentityEquality,
                     new CodePrimitiveExpression(null)),
                 returnStatement));
     }
 }
Пример #13
0
        private static void GenerateConstructors(Type t, CodeTypeDeclaration codeType)
        {
            CodeFieldReferenceExpression omObjectFieldReference = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), OmObject);

            ConstructorInfo[] constructors = t.GetConstructors();
            ConstructorInfo publicParameterless = null;
            ConstructorInfo publicSystemParams = null;
            ConstructorInfo publicEnumParams = null;
            List<ConstructorInfo> publicGeneralParams = new List<ConstructorInfo>();
            foreach (ConstructorInfo con in constructors.Where(c => c.IsPublic || c.IsStatic))
            {
                ParameterInfo[] parameters = con.GetParameters();
                if (parameters == null || parameters.Length == 0)
                {
                    publicParameterless = con;
                }
                else if (con.IsStatic)
                {
                }
                else
                {
                    publicGeneralParams.Add(con);
                }
            }

            if (publicParameterless != null)
            {
                CodeConstructor constructor = new CodeConstructor();
                constructor.Attributes = MemberAttributes.Public;
                CodeObjectCreateExpression createExpression = new CodeObjectCreateExpression(t);
                constructor.Statements.Add(new CodeAssignStatement(omObjectFieldReference, createExpression));
                codeType.Members.Add(constructor);
            }

            foreach (ConstructorInfo c in publicGeneralParams)
            {
                AddConstructorWithCopiedParameters(codeType, t, omObjectFieldReference, c);
            }

            // Default internal constructor that accepts the OM object to wrap
            CodeConstructor defaultConstructor = new CodeConstructor();
            defaultConstructor.Attributes = MemberAttributes.Assembly;
            CodeParameterDeclarationExpression omObjectParameter = new CodeParameterDeclarationExpression(t, OmObject);
            defaultConstructor.Parameters.Add(omObjectParameter);
            CodeArgumentReferenceExpression omObjectArgumentReference = new CodeArgumentReferenceExpression(OmObject);
            CodeObjectCreateExpression createException = new CodeObjectCreateExpression(typeof(ArgumentNullException), new CodePrimitiveExpression(OmObject));
            CodeThrowExceptionStatement throwException = new CodeThrowExceptionStatement(createException);
            CodeBinaryOperatorExpression nullCheck = new CodeBinaryOperatorExpression(omObjectArgumentReference, CodeBinaryOperatorType.IdentityEquality, new CodePrimitiveExpression(null));

            // if the parameter is null, throw an exception
            defaultConstructor.Statements.Add(new CodeConditionStatement(nullCheck, throwException));

            defaultConstructor.Statements.Add(new CodeAssignStatement(omObjectFieldReference, omObjectArgumentReference));
            codeType.Members.Add(defaultConstructor);
        }
Пример #14
0
 protected override void GenerateThrowExceptionStatement(CodeThrowExceptionStatement e)
 {
     base.Output.Write("Throw");
     if (e.ToThrow != null)
     {
         base.Output.Write(" ");
         base.GenerateExpression(e.ToThrow);
     }
     base.Output.WriteLine("");
 }
Пример #15
0
		protected override void GenerateThrowExceptionStatement (CodeThrowExceptionStatement statement)
		{
			Output.Write ("Throw");
			if (statement.ToThrow != null) {
				Output.Write (' ');
				GenerateExpression (statement.ToThrow);
			}
			Output.WriteLine ();
		}
Пример #16
0
		protected abstract void GenerateThrowExceptionStatement (CodeThrowExceptionStatement s);
Пример #17
0
		public void CodeThrowExceptionStatementTest ()
		{
			CodeThrowExceptionStatement ctes = new CodeThrowExceptionStatement ();
			statement = ctes;

			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
				"throw;{0}", NewLine), Generate (), "#1");

			ctes.ToThrow = new CodeSnippetExpression ("whatever");
			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
				"throw whatever;{0}", NewLine), Generate (), "#2");
		}
Пример #18
0
        /// <summary>
        /// Generates code for the specified throw exception statement.
        /// </summary>
        /// <remarks><c>throw TOTHROW;</c></remarks>
        protected override void GenerateThrowExceptionStatement(CodeThrowExceptionStatement e)
        {
            Output.Write(Keywords.Throw + WhiteSpace.Space);
            GenerateExpression(e.ToThrow);

            Output.WriteLine(Tokens.Semicolon);
        }
        void EmitOnApplyConfigurationMethod(ref CodeTypeDeclaration customSBConfigSectionClass)
        {
            CodeMemberMethod onApplyCfgMethod = new CodeMemberMethod();
            onApplyCfgMethod.Name = MethodNameConstants.OnApplyConfigurationMethod; ;
            onApplyCfgMethod.Parameters.Add(bindingMethodParamRef);
            onApplyCfgMethod.Attributes = CodeDomHelperObjects.ProtectedOverride;
            CodeBinaryOperatorExpression cboe = new CodeBinaryOperatorExpression(
                                                    CodeDomHelperObjects.bindingVarRef,
                                                    CodeBinaryOperatorType.IdentityEquality,
                                                    CodeDomHelperObjects.NullRef);
            CodeThrowExceptionStatement ctes = new CodeThrowExceptionStatement(
                                                    new CodeObjectCreateExpression(
                                                        new CodeTypeReference(typeof(System.ArgumentNullException)),
                                                        new CodePrimitiveExpression(Constants.bindingParamName)));
            CodeConditionStatement ccs = new CodeConditionStatement(cboe, ctes);
            onApplyCfgMethod.Statements.Add(ccs);
            CodeMethodInvokeExpression cmie = new CodeMethodInvokeExpression(
                                                CodeDomHelperObjects.bindingVarRef, 
                                                MethodNameConstants.GetTypeMethod);
            cboe = new CodeBinaryOperatorExpression(
                        cmie,
                        CodeBinaryOperatorType.IdentityInequality,
                        customSBTypeOfRef);
            ctes = new CodeThrowExceptionStatement(
                new CodeObjectCreateExpression(
                    new CodeTypeReference(typeof(System.ArgumentException)),
                    new CodeMethodInvokeExpression(
                        new CodeTypeReferenceExpression(CodeDomHelperObjects.stringTypeRef),
                        MethodNameConstants.FormatMethod,
                        CodeDomHelperObjects.cultureInfoCurrent,
                        new CodePrimitiveExpression("Invalid type for binding. Expected type: {0}. Type passed in: {1}."),
                        new CodeMethodReferenceExpression(
                            customSBTypeOfRef,
                            PropertyNameConstants.AssemblyQualifiedNameProperty),
                        new CodeMethodReferenceExpression(
                            cmie,
                            PropertyNameConstants.AssemblyQualifiedNameProperty))));
            ccs = new CodeConditionStatement(cboe, ctes);
            onApplyCfgMethod.Statements.Add(ccs);

            string varInstanceName = Helpers.TurnFirstCharLower(standardBindingType.Name);
            CodeVariableDeclarationStatement cvds = new CodeVariableDeclarationStatement(
                                                        customSBTypeRef,
                                                        varInstanceName,
                                                        new CodeCastExpression(
                                                            standardBindingType.Name,
                                                            CodeDomHelperObjects.bindingVarRef));
            onApplyCfgMethod.Statements.Add(cvds);

            foreach (PropertyNameType nameType in propertiesGenerated)
            {
                CodeAssignStatement assignment = new CodeAssignStatement(
                                                    new CodeFieldReferenceExpression(
                                                        new CodeVariableReferenceExpression(varInstanceName),
                                                        nameType.propertyName),
                                                    new CodeFieldReferenceExpression(
                                                        CodeDomHelperObjects.ThisRef,
                                                        nameType.propertyName));
                onApplyCfgMethod.Statements.Add(assignment);
            }
            customSBConfigSectionClass.Members.Add(onApplyCfgMethod);
        }
 public void Generate(CodeThrowExceptionStatement statement)
 {
     Write("raise ");
     Generate(statement.ToThrow);
     WriteLine();
 }
Пример #21
0
		private CodeTypeDeclaration CreateSoapExtensionEx()
		{
			CodeTypeReference ctrSoapMessage = new CodeTypeReference(typeof(System.Web.Services.Protocols.SoapMessage));
			CodeTypeReference ctrStream = new CodeTypeReference(typeof(System.IO.Stream));
			CodeTypeReference ctrMemoryStream = new CodeTypeReference(typeof(System.IO.MemoryStream));
			CodeTypeReference ctrByteArray = new CodeTypeReference(typeof(System.Byte[]));
			CodeTypeReference ctrEncoder = new CodeTypeReference(typeof(System.Text.UTF8Encoding));

			CodeVariableReferenceExpression cvreMessage = new CodeVariableReferenceExpression();
			cvreMessage.VariableName = "Message";

			CodeVariableReferenceExpression cvreStrFrom = new CodeVariableReferenceExpression();
			cvreStrFrom.VariableName = "StrFrom";

			CodeVariableReferenceExpression cvreStrTo = new CodeVariableReferenceExpression();
			cvreStrTo.VariableName = "StrTo";

			CodeVariableReferenceExpression cvreByteBuf = new CodeVariableReferenceExpression();
			cvreByteBuf.VariableName = "ByteBuf";

			CodeVariableReferenceExpression cvreEncoder = new CodeVariableReferenceExpression();
			cvreEncoder.VariableName = "Encoder";

			// SoapMessage Message
			CodeParameterDeclarationExpression cpdeMessage = new CodeParameterDeclarationExpression();
			cpdeMessage.Name = cvreMessage.VariableName;
			cpdeMessage.Type = ctrSoapMessage;
			cpdeMessage.Direction = FieldDirection.In;
			
			// Stream StrFrom
			CodeParameterDeclarationExpression cpdeStrFrom = new CodeParameterDeclarationExpression();
			cpdeStrFrom.Name = cvreStrFrom.VariableName;
			cpdeStrFrom.Type = ctrStream;
			cpdeStrFrom.Direction = FieldDirection.In;
	
			// Stream StrFrom
			CodeParameterDeclarationExpression cpdeStrTo = new CodeParameterDeclarationExpression();
			cpdeStrTo.Name = cvreStrTo.VariableName;
			cpdeStrTo.Type = ctrStream;
			cpdeStrTo.Direction = FieldDirection.In;
	
			// Class Declaration
			CodeTypeDeclaration ctd = new CodeTypeDeclaration();
			ctd.Name = "SoapExtensionEx";
			ctd.Comments.AddRange(GetSummaryStatements());
			ctd.BaseTypes.Add(typeof(System.Web.Services.Protocols.SoapExtension));

			// Field mStrOld
			CodeMemberField cmfStrOld = new CodeMemberField();
			cmfStrOld.Attributes = MemberAttributes.Private | MemberAttributes.Final;
			cmfStrOld.Name = "mStrOld";
			cmfStrOld.Type = new CodeTypeReference(typeof(System.IO.Stream));
			ctd.Members.Add(cmfStrOld);

			// Field mStrNew
			CodeMemberField cmfStrNew = new CodeMemberField();
			cmfStrNew.Attributes = MemberAttributes.Private | MemberAttributes.Final;
			cmfStrNew.Name = "mStrNew";
			cmfStrNew.Type = new CodeTypeReference(typeof(System.IO.Stream));
			ctd.Members.Add(cmfStrNew);

			// Reference to the created field
			CodeFieldReferenceExpression cfreStrOld = new CodeFieldReferenceExpression(null, cmfStrOld.Name);
			
			// Reference to the created field
			CodeFieldReferenceExpression cfreStrNew = new CodeFieldReferenceExpression(null, cmfStrNew.Name);

			// Methods GetInitializer(MethodInfo, Attribute)
			CodeMemberMethod cmmGetInitializerLM = new CodeMemberMethod();    
			cmmGetInitializerLM.Attributes = MemberAttributes.Public | MemberAttributes.Override;
			cmmGetInitializerLM.Comments.AddRange(GetSummaryStatements());
			cmmGetInitializerLM.Comments.Add(new CodeCommentStatement("<param name=\"MethodInfo\"></param>", true));
			cmmGetInitializerLM.Comments.Add(new CodeCommentStatement("<param name=\"Attribute\"></param>", true));
			cmmGetInitializerLM.Comments.Add(new CodeCommentStatement("<returns></returns>", true));
			cmmGetInitializerLM.Name = "GetInitializer";
			cmmGetInitializerLM.ReturnType = new CodeTypeReference(typeof(System.Object));
			CodeParameterDeclarationExpression cpdeMethodInfo = new CodeParameterDeclarationExpression();
			cpdeMethodInfo.Type = new CodeTypeReference(typeof(System.Web.Services.Protocols.LogicalMethodInfo));
			cpdeMethodInfo.Name = "MethodInfo";
			cpdeMethodInfo.Direction = FieldDirection.In;
			CodeParameterDeclarationExpression cpdeAttribute = new CodeParameterDeclarationExpression();
			cpdeAttribute.Type = new CodeTypeReference(typeof(System.Web.Services.Protocols.SoapExtensionAttribute));
			cpdeAttribute.Name = "Attribute";
			cpdeAttribute.Direction = FieldDirection.In;
			cmmGetInitializerLM.Parameters.Add(cpdeMethodInfo);
			cmmGetInitializerLM.Parameters.Add(cpdeAttribute);
			cmmGetInitializerLM.Statements.Add( new CodeMethodReturnStatement( new CodePrimitiveExpression(null) ) );
			ctd.Members.Add(cmmGetInitializerLM);

			// Methods GetInitializer(ServiceType)
			CodeMemberMethod cmmGetInitializerST = new CodeMemberMethod();    
			cmmGetInitializerST.Attributes = MemberAttributes.Public | MemberAttributes.Override;
			cmmGetInitializerST.Comments.AddRange(GetSummaryStatements());
			cmmGetInitializerST.Comments.Add(new CodeCommentStatement("<param name=\"ServiceType\"></param>", true));
			cmmGetInitializerST.Comments.Add(new CodeCommentStatement("<returns></returns>", true));
			cmmGetInitializerST.Name = "GetInitializer";
			cmmGetInitializerST.ReturnType = new CodeTypeReference(typeof(System.Object));
			CodeParameterDeclarationExpression cpdeServiceType = new CodeParameterDeclarationExpression();
			cpdeServiceType.Type = new CodeTypeReference(typeof(System.Type));
			cpdeServiceType.Name = "ServiceType";
			cpdeServiceType.Direction = FieldDirection.In;
			cmmGetInitializerST.Parameters.Add(cpdeServiceType);
			cmmGetInitializerST.Statements.Add( new CodeMethodReturnStatement(new CodeTypeOfExpression(new CodeTypeReference("SoapExtensionEx"))));
			ctd.Members.Add(cmmGetInitializerST);

			// Methods Initialize
			CodeMemberMethod cmmInitialize = new CodeMemberMethod();    
			cmmInitialize.Attributes = MemberAttributes.Public | MemberAttributes.Override;
			cmmInitialize.Comments.AddRange(GetSummaryStatements());
			cmmInitialize.Comments.Add(new CodeCommentStatement("<param name=\"Initializer\"></param>", true));
			cmmInitialize.Name = "Initialize";
			CodeParameterDeclarationExpression cpdeInitializer = new CodeParameterDeclarationExpression();
			cpdeInitializer.Type = new CodeTypeReference(typeof(System.Object));
			cpdeInitializer.Name = "Initializer";
			cpdeInitializer.Direction = FieldDirection.In;
			cmmInitialize.Parameters.Add(cpdeInitializer);
			ctd.Members.Add(cmmInitialize);

			// Methods ProcessMessage
			CodeMemberMethod cmmProcessMessage = new CodeMemberMethod();    
			cmmProcessMessage.Attributes = MemberAttributes.Public | MemberAttributes.Override;
			cmmProcessMessage.Comments.AddRange(GetSummaryStatements());
			cmmProcessMessage.Comments.Add(new CodeCommentStatement("<param name=\"Message\"></param>", true));
			cmmProcessMessage.Name = "ProcessMessage";
			cmmProcessMessage.Parameters.Add(cpdeMessage);
			CodePropertyReferenceExpression cpreMessageStage = new CodePropertyReferenceExpression(cvreMessage, "Stage");
			CodeVariableReferenceExpression cvreSoapMessageStage = new CodeVariableReferenceExpression("System.Web.Services.Protocols.SoapMessageStage");
			CodeConditionStatement cdsBeforeSerialize = new CodeConditionStatement();
			cdsBeforeSerialize.Condition = new CodeBinaryOperatorExpression(cpreMessageStage, CodeBinaryOperatorType.ValueEquality, new CodePropertyReferenceExpression(cvreSoapMessageStage, "BeforeSerialize"));
			CodeConditionStatement cdsAfterSerialize = new CodeConditionStatement();
			cdsAfterSerialize.Condition = new CodeBinaryOperatorExpression(cpreMessageStage, CodeBinaryOperatorType.ValueEquality, new CodePropertyReferenceExpression(cvreSoapMessageStage, "AfterSerialize"));
			CodeMethodInvokeExpression cmieSaveRequest = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), "SaveRequestMessage", cvreMessage);
			CodeMethodInvokeExpression cmieCopy = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), "Copy", new CodeExpression[] {cfreStrNew, cfreStrOld});
			cdsAfterSerialize.TrueStatements.Add(cmieSaveRequest);
			cdsAfterSerialize.TrueStatements.Add(cmieCopy);
			CodeConditionStatement cdsBeforeDeserialize = new CodeConditionStatement();
			cdsBeforeDeserialize.Condition = new CodeBinaryOperatorExpression(cpreMessageStage, CodeBinaryOperatorType.ValueEquality, new CodePropertyReferenceExpression(cvreSoapMessageStage, "BeforeDeserialize"));
			CodeMethodInvokeExpression cmieSaveResponse = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), "SaveResponseMessage", cvreMessage);
			cdsBeforeDeserialize.TrueStatements.Add(cmieSaveResponse);
			CodeConditionStatement cdsAfterDeserialize = new CodeConditionStatement();
			cdsAfterDeserialize.Condition = new CodeBinaryOperatorExpression(cpreMessageStage, CodeBinaryOperatorType.ValueEquality, new CodePropertyReferenceExpression(cvreSoapMessageStage, "AfterDeserialize"));
			CodeMethodInvokeExpression cmieStringFormat = new CodeMethodInvokeExpression(null, "System.String.Format", new CodeExpression[]{new CodePropertyReferenceExpression(new CodeVariableReferenceExpression("System.Globalization.CultureInfo"), "InvariantCulture"), new CodePrimitiveExpression("Invalid Soap Message stage [{0}]"), cpreMessageStage});
			CodeThrowExceptionStatement ctesException = new CodeThrowExceptionStatement(new CodeObjectCreateExpression(typeof(System.ArgumentException), new CodeExpression[] {cmieStringFormat, new CodePrimitiveExpression("Message")}));
			cdsBeforeSerialize.FalseStatements.Add(cdsAfterSerialize);
			cdsAfterSerialize.FalseStatements.Add(cdsBeforeDeserialize);
			cdsBeforeDeserialize.FalseStatements.Add(cdsAfterDeserialize);
			cdsAfterDeserialize.FalseStatements.Add(ctesException);
			cmmProcessMessage.Statements.Add(cdsBeforeSerialize);
			ctd.Members.Add(cmmProcessMessage);

			// Methods ChainStream
			CodeMemberMethod cmmChainStream = new CodeMemberMethod();    
			cmmChainStream.Attributes = MemberAttributes.Public | MemberAttributes.Override;
			cmmChainStream.Comments.AddRange(GetSummaryStatements());
			cmmChainStream.Comments.Add(new CodeCommentStatement("<param name=\"StrFrom\"></param>", true));
			cmmChainStream.Name = "ChainStream";
			cmmChainStream.ReturnType = ctrStream;
			cmmChainStream.Parameters.Add(cpdeStrFrom);
			cmmChainStream.Statements.Add( new CodeAssignStatement( cfreStrOld, cvreStrFrom));
			cmmChainStream.Statements.Add( new CodeAssignStatement( cfreStrNew, new CodeObjectCreateExpression(ctrMemoryStream, new CodeExpression[] {})));
			cmmChainStream.Statements.Add( new CodeMethodReturnStatement(cfreStrNew));
			ctd.Members.Add(cmmChainStream);

			// Methods SaveRequestMessage
			CodeMemberMethod cmmSaveRequestMessage = new CodeMemberMethod();    
			cmmSaveRequestMessage.Attributes = MemberAttributes.Private | MemberAttributes.Final;
			cmmSaveRequestMessage.Comments.AddRange(GetSummaryStatements());
			cmmSaveRequestMessage.Comments.Add(new CodeCommentStatement("<param name=\"Message\"></param>", true));
			cmmSaveRequestMessage.Name = "SaveRequestMessage";
			cmmSaveRequestMessage.Parameters.Add(cpdeMessage);
			CodeVariableDeclarationStatement cvdsEncoder = new CodeVariableDeclarationStatement();
			cvdsEncoder.Name = cvreEncoder.VariableName;
			cvdsEncoder.Type = ctrEncoder;
			cvdsEncoder.InitExpression = new CodeObjectCreateExpression(ctrEncoder, new CodeExpression[] {});
			CodeVariableDeclarationStatement cvdsByteBuf = new CodeVariableDeclarationStatement();
			cvdsByteBuf.Name = cvreByteBuf.VariableName;
			cvdsByteBuf.Type = ctrByteArray;
			cvdsByteBuf.InitExpression = new CodeArrayCreateExpression(ctrByteArray, new CodePropertyReferenceExpression(cfreStrNew, "Length"));
			CodeMethodInvokeExpression cmieStrNewRead = new CodeMethodInvokeExpression(cfreStrNew, "Read", new CodeExpression[] {cvreByteBuf, new CodePrimitiveExpression(0), new CodePropertyReferenceExpression(cvreByteBuf, "Length") });
			CodeMethodInvokeExpression cmieEncoderGetString = new CodeMethodInvokeExpression(cvreEncoder, "GetString", new CodeCastExpression(typeof(byte[]), cvreByteBuf));
			CodeAssignStatement casSoapRequest = new CodeAssignStatement(new CodePropertyReferenceExpression(new CodeCastExpression("SoapHttpClientProtocolEx", new CodePropertyReferenceExpression(new CodeCastExpression(typeof(System.Web.Services.Protocols.SoapClientMessage), cvreMessage), "Client")),"SoapRequest"), cmieEncoderGetString);
			cmmSaveRequestMessage.Statements.Add(cvdsEncoder);
			cmmSaveRequestMessage.Statements.Add( new CodeAssignStatement( new CodePropertyReferenceExpression(cfreStrNew, "Position"), new CodePrimitiveExpression(0)));
			cmmSaveRequestMessage.Statements.Add(cvdsByteBuf);
			cmmSaveRequestMessage.Statements.Add(cmieStrNewRead);
			cmmSaveRequestMessage.Statements.Add(casSoapRequest);
			ctd.Members.Add(cmmSaveRequestMessage);

			// Methods SaveResponseMessage
			CodeMemberMethod cmmSaveResponseMessage = new CodeMemberMethod();    
			cmmSaveResponseMessage.Attributes = MemberAttributes.Private | MemberAttributes.Final;
			cmmSaveResponseMessage.Comments.AddRange(GetSummaryStatements());
			cmmSaveResponseMessage.Comments.Add(new CodeCommentStatement("<param name=\"Message\"></param>", true));
			cmmSaveResponseMessage.Name = "SaveResponseMessage";
			cmmSaveResponseMessage.Parameters.Add(cpdeMessage);
			CodeVariableReferenceExpression cvreStrTemp = new CodeVariableReferenceExpression();
			cvreStrTemp.VariableName = "StrTemp";
			CodeVariableDeclarationStatement cvdsStrTemp = new CodeVariableDeclarationStatement();
			cvdsStrTemp.Name = cvreStrTemp.VariableName;
			cvdsStrTemp.Type = ctrStream;
			cvdsStrTemp.InitExpression = new CodeObjectCreateExpression(ctrMemoryStream,  new CodeExpression[] {});
			CodeMethodInvokeExpression cmieCopyToTemp = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), "Copy", new CodeExpression[] {cfreStrOld, cvreStrTemp});
			CodeVariableDeclarationStatement cvdsByteBuf2 = new CodeVariableDeclarationStatement();
			cvdsByteBuf2.Name = cvreByteBuf.VariableName;
			cvdsByteBuf2.Type = ctrByteArray;
			cvdsByteBuf2.InitExpression = new CodeArrayCreateExpression(ctrByteArray, new CodePropertyReferenceExpression(cvreStrTemp, "Length"));
			CodeMethodInvokeExpression cmieStrTempRead = new CodeMethodInvokeExpression(cvreStrTemp, "Read", new CodeExpression[] {cvreByteBuf, new CodePrimitiveExpression(0), new CodePropertyReferenceExpression(cvreByteBuf, "Length")});
			CodeAssignStatement casSoapResponse = new CodeAssignStatement(new CodePropertyReferenceExpression(new CodeCastExpression("SoapHttpClientProtocolEx", new CodePropertyReferenceExpression(new CodeCastExpression(typeof(System.Web.Services.Protocols.SoapClientMessage), cvreMessage), "Client")),"SoapResponse"), cmieEncoderGetString);
			CodeMethodInvokeExpression cmieCopyToNew = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), "Copy", new CodeExpression[] {cvreStrTemp, cfreStrNew });
			cmmSaveResponseMessage.Statements.Add(cvdsEncoder);
			cmmSaveResponseMessage.Statements.Add(cvdsStrTemp);
			cmmSaveResponseMessage.Statements.Add(cmieCopyToTemp);
			cmmSaveResponseMessage.Statements.Add(cvdsByteBuf2);
			cmmSaveResponseMessage.Statements.Add(cmieStrTempRead);
			cmmSaveResponseMessage.Statements.Add(casSoapResponse);
			cmmSaveResponseMessage.Statements.Add(cmieCopyToNew);
			ctd.Members.Add(cmmSaveResponseMessage);

			// Methods Copy
			CodeMemberMethod cmmCopy = new CodeMemberMethod();    
			cmmCopy.Attributes = MemberAttributes.Private | MemberAttributes.Final;
			cmmCopy.Comments.AddRange(GetSummaryStatements());
			cmmCopy.Comments.Add(new CodeCommentStatement("<param name=\"StrFrom\"></param>", true));
			cmmCopy.Comments.Add(new CodeCommentStatement("<param name=\"StrTo\"></param>", true));
			cmmCopy.Name = "Copy";
			cmmCopy.Parameters.Add(cpdeStrFrom);
			cmmCopy.Parameters.Add(cpdeStrTo);
	
			CodeAssignStatement casStrFromPosition = new CodeAssignStatement(new CodePropertyReferenceExpression(cvreStrFrom, "Position"), new CodePrimitiveExpression(0) );
			CodeConditionStatement ccsStrFromCanSeek = new CodeConditionStatement(new CodePropertyReferenceExpression(cvreStrFrom, "CanSeek"), new CodeStatement[] {casStrFromPosition});
			
			CodeVariableReferenceExpression cvreTxtReader = new CodeVariableReferenceExpression("TxtReader");
			CodeVariableDeclarationStatement cvdsTxtReader = new CodeVariableDeclarationStatement();
			cvdsTxtReader.Name = cvreTxtReader.VariableName;
			cvdsTxtReader.Type = new CodeTypeReference(typeof(System.IO.TextReader));
			cvdsTxtReader.InitExpression = new CodeObjectCreateExpression(typeof(System.IO.StreamReader), new CodeExpression[] {cvreStrFrom});

			CodeVariableReferenceExpression cvreTxtWriter = new CodeVariableReferenceExpression("TxtWriter");
			CodeVariableDeclarationStatement cvdsTxtWriter = new CodeVariableDeclarationStatement();
			cvdsTxtWriter.Name = cvreTxtWriter.VariableName;
			cvdsTxtWriter.Type = new CodeTypeReference(typeof(System.IO.TextWriter));
			cvdsTxtWriter.InitExpression = new CodeObjectCreateExpression(typeof(System.IO.StreamWriter), new CodeExpression[] {cvreStrTo });
			
			CodeMethodInvokeExpression cmieTxtWriterWriteLine = new CodeMethodInvokeExpression(cvreTxtWriter, "WriteLine", new CodeExpression[] {new CodeMethodInvokeExpression(cvreTxtReader, "ReadToEnd", new CodeExpression[] {})});
			CodeMethodInvokeExpression cmiTxtWriterFlush = new CodeMethodInvokeExpression(cvreTxtWriter, "Flush", new CodeExpression[] {});
			CodeConditionStatement ccsStrToCanSeek = new CodeConditionStatement(new CodePropertyReferenceExpression(cvreStrTo, "CanSeek"), new CodeStatement[] {new CodeAssignStatement(new CodePropertyReferenceExpression(cvreStrTo, "Position"), new CodePrimitiveExpression(0) )});

			cmmCopy.Statements.Add(ccsStrFromCanSeek);
			cmmCopy.Statements.Add(cvdsTxtReader);
			cmmCopy.Statements.Add(cvdsTxtWriter);
			cmmCopy.Statements.Add(cmieTxtWriterWriteLine);
			cmmCopy.Statements.Add(cmiTxtWriterFlush);
			cmmCopy.Statements.Add(ccsStrToCanSeek);

			ctd.Members.Add(cmmCopy);

			return ctd;
		}
        private void CreateServiceType()
        {
            // We can create the service type(s) only if we have one or more service
            // contract.
            if (code.ServiceContracts.Count > 0)
            {
                // Take a reference to the first ServiceContract available.
                // IMPORTANT!:(Currently we only support single service type)
                // May be want to support multiple service contracts in the next version.
                CodeTypeExtension srvContract = code.ServiceContracts[0];
                // Notify if srvContract is null. This would mean that we have constructed a bad 
                // GeneratedCode instance from our CodeFactory.
                Debug.Assert(srvContract != null, "Generated service contract could not be null.");

                // Construct the service type name by removing the leading "I" character from 
				// the service contract name that was added for generation of the interface.
            	string srvTypeName = srvContract.ExtendedObject.Name.Substring(1);

                // Create a new instance of CodeTypeDeclaration type representing the service type.
                CodeTypeDeclaration srvType = new CodeTypeDeclaration(srvTypeName);

                // Also wrap the CodeTypeDeclaration in an extension.
                CodeTypeExtension typeExt = new CodeTypeExtension(srvType);

                // This class.
                srvType.IsClass = true;

				switch (options.MethodImplementation)
				{
					case MethodImplementation.PartialClassMethodCalls:
						// The service type is partial so that the implementation methods can be written in separate file.
						srvType.IsPartial = true;
						break;
					case MethodImplementation.AbstractMethods:
						// The service type is abstract so that the operation methods can be made abstract.
						srvType.TypeAttributes |= TypeAttributes.Abstract;
						break;
				}

                // And this implements the service contract interface.
				if (code.CodeLanguauge == CodeLanguage.VisualBasic)
				{
					srvType.Members.Add(new CodeSnippetTypeMember("Implements " + srvContract.ExtendedObject.Name));
				}
				else
				{
					srvType.BaseTypes.Add(new CodeTypeReference(srvContract.ExtendedObject.Name));					
				}

                // Now itterate the srvContractObject.Members and add each and every method in 
                // the service contract type to the new type being created.
                foreach (CodeTypeMemberExtension methodExtension in srvContract.Methods)
                {
                    // Get a referece to the actual CodeMemberMethod object extended
                    // by ext.
                    CodeMemberMethod method = methodExtension.ExtendedObject as CodeMemberMethod;

                    // Create a new CodeMemeberMethod and copy the attributes.
                    CodeMemberMethod newMethod = new CodeMemberMethod();
                    newMethod.Name = method.Name;

                    // Implemented method has to be public.
                    newMethod.Attributes = MemberAttributes.Public;

                    // Notify that this member is implementing a method in the service contract.
					if (code.CodeLanguauge == CodeLanguage.VisualBasic)
					{
						newMethod.ImplementationTypes.Add(new CodeTypeReference(srvContract.ExtendedObject.Name));
					}
					else
					{
						newMethod.ImplementationTypes.Add(srvType.BaseTypes[0]);						
					}

                    // Add all parametes to the newly created method.
                    foreach (CodeParameterDeclarationExpression cpde in method.Parameters)
                    {
                        newMethod.Parameters.Add(cpde);
                    }

                    // Set the return type.
                    newMethod.ReturnType = method.ReturnType;

					switch (options.MethodImplementation)
					{
						case MethodImplementation.PartialClassMethodCalls:
							{
								// Gather the parameters from the operation to pass into the implementation method.
								IEnumerable<CodeArgumentReferenceExpression> parameters = newMethod.Parameters
									.OfType<CodeParameterDeclarationExpression>()
									.Select(p => new CodeArgumentReferenceExpression(p.Name));

								// Create an expression to invoke the implementation method.
								CodeMethodInvokeExpression methodInvocation = new CodeMethodInvokeExpression(null, newMethod.Name + "Implementation", parameters.ToArray());

								// Check if the method has a return type.
								if (newMethod.ReturnType.BaseType != "System.Void")
								{
									// Make sure the call to the implementation method is returned.
									CodeMethodReturnStatement returnStatement = new CodeMethodReturnStatement(methodInvocation);
									newMethod.Statements.Add(returnStatement);
								}
								else
								{
									// Add the call to the implementation method without a return.
									newMethod.Statements.Add(methodInvocation);
								}
							}
							break;
						case MethodImplementation.NotImplementedException:
							{
								// Create a new code statement to throw NotImplementedExcption.
								CodeThrowExceptionStatement niex = new CodeThrowExceptionStatement(
									new CodeObjectCreateExpression(
										new CodeTypeReference(typeof(NotImplementedException)), new CodeExpression[] { })
									);

								// Add it to the statements collection in the new method.
								newMethod.Statements.Add(niex);
							}
							break;
						case MethodImplementation.AbstractMethods:
							{
								// No statement is required for the abstract methods.
								newMethod.Attributes |= MemberAttributes.Abstract;
								break;
							}
					}

					// Wrap the CodeMemberMethod in an extension. This could be useful for other extensions.
					CodeTypeMemberExtension newMethodExt = new CodeTypeMemberExtension(newMethod, typeExt);
					srvType.Members.Add(newMethodExt);
                }

                // Add the ServiceBehaviorAttribute attribute.
            	CodeAttributeDeclaration serviceBehaviorAttribute = new CodeAttributeDeclaration(
            		new CodeTypeReference(typeof(ServiceBehaviorAttribute)));

				if (!string.IsNullOrEmpty(options.InstanceContextMode))
				{
					CodeTypeReferenceExpression instanceContextModeEnum = new CodeTypeReferenceExpression(typeof(InstanceContextMode));
					CodeFieldReferenceExpression instanceContextModeValue = new CodeFieldReferenceExpression(instanceContextModeEnum, options.InstanceContextMode);
					CodeAttributeArgument instanceContextModeArgument = new CodeAttributeArgument("InstanceContextMode", instanceContextModeValue);
					serviceBehaviorAttribute.Arguments.Add(instanceContextModeArgument);					
				}

				if (!string.IsNullOrEmpty(options.ConcurrencyMode))
				{
					CodeTypeReferenceExpression concurrencyModeEnum = new CodeTypeReferenceExpression(typeof(ConcurrencyMode));
					CodeFieldReferenceExpression concurrencyModeValue = new CodeFieldReferenceExpression(concurrencyModeEnum, options.ConcurrencyMode);
					CodeAttributeArgument concurrencyModeArgument = new CodeAttributeArgument("ConcurrencyMode", concurrencyModeValue);
					serviceBehaviorAttribute.Arguments.Add(concurrencyModeArgument);	
				}

				if (!options.UseSynchronizationContext)
				{
					CodeAttributeArgument useSynchronizationContextAttribute = new CodeAttributeArgument("UseSynchronizationContext", new CodePrimitiveExpression(false));
					serviceBehaviorAttribute.Arguments.Add(useSynchronizationContextAttribute);					
				}

            	typeExt.AddAttribute(serviceBehaviorAttribute);

                this.serviceTypeName = srvType.Name;
                // Finally add the newly created type to the code being generated.
                code.ServiceTypes.Add(typeExt);
            }
        }        
Пример #23
0
 public CodeThrowExceptionStatement Throw(CodeExpression expr)
 {
     CodeThrowExceptionStatement st = new CodeThrowExceptionStatement(expr);
     csc.Add(st);
     return st;
 }
Пример #24
0
		protected override void GenerateThrowExceptionStatement (CodeThrowExceptionStatement e)
		{
		}
 public bool ValidateCodeThrowExceptionStatement (CodeThrowExceptionStatement exp) {
     PushError ("CodeThrowExceptionStatement is not in the subset.");
     return false;
 }
Пример #26
0
 private void ValidateThrowExceptionStatement(CodeThrowExceptionStatement e) {
     if (e.ToThrow != null) {
         ValidateExpression(e.ToThrow);
     }
 }
Пример #27
0
 protected override void GenerateThrowExceptionStatement(System.CodeDom.CodeThrowExceptionStatement e)
 {
     throw new Exception("The method or operation is not implemented.");
 }
		protected override void GenerateThrowExceptionStatement(CodeThrowExceptionStatement e)
		{
			Output.WriteLine("[CodeThrowExceptionStatement: {0}]", e.ToString());
		}
 /// <devdoc>
 ///    <para>
 ///       Generates code for the specified CodeDom based throw exception statement
 ///       representation.
 ///    </para>
 /// </devdoc>
 private  void GenerateThrowExceptionStatement(CodeThrowExceptionStatement e) {
     Output.Write("throw");
     if (e.ToThrow != null) {
         Output.Write(" ");
         GenerateExpression(e.ToThrow);
     }
     Output.WriteLine(";");
 }
        public override object Visit(ThrowStatement throwStatement, object data)
        {
            ProcessSpecials(throwStatement.Specials);

            CodeThrowExceptionStatement throwStmt = new CodeThrowExceptionStatement((CodeExpression)throwStatement.ThrowExpression.AcceptVisitor(this, data));

            // Add Statement to Current Statement Collection
            AddStmt(throwStmt);

            return throwStmt;
        }
Пример #31
0
        public override void PrefixOutParams(ref CodeConditionStatement condOut, ref CodeConditionStatement condOutIter, string idlMethodName, ref int nOutArgCounter, ref CodeThrowExceptionStatement throwargOutPrev)
        {
            CodeVariableReferenceExpression varrefVariantSignature = new CodeVariableReferenceExpression("variantSignature");
            CodeConditionStatement condVariantSignature = new CodeConditionStatement(
                // * if (this.result == 0)
                exprResultOk,
                new CodeStatement[] // True statements
                    {
                        // * dbus_sig variantSignature;
                        new CodeVariableDeclarationStatement(typerefSig, "variantSignature")
                        // * this.result = Udbus.Core.UdbusMessageReader.MarshalSignature(reader, out variantSignature);
                        , new CodeAssignStatement(fieldrefResult,
                            new CodeMethodInvokeExpression(CodeBuilderCommon.typerefexprMessageReader, "ReadSignature", varrefReader,
                                new CodeDirectionExpression(FieldDirection.Out, varrefVariantSignature)))
                    }
                , new CodeStatement[] // False statements
                {
                    throwargOutPrev
                }
            );
            throwargOutPrev = ThrowArgOutException(idlMethodName, nOutArgCounter, "variantSignature", typerefSig);

            this.StoreCondIterator(ref condOut, ref condOutIter, condVariantSignature);
            ++nOutArgCounter;
        }