protected override CodeTypeDeclaration BeginClass()
        {
            methodNames.Clear();
            CodeAttributeDeclarationCollection metadata = new CodeAttributeDeclarationCollection();

            if (Style == ServiceDescriptionImportStyle.Client)
            {
                WebCodeGenerator.AddCustomAttribute(metadata, typeof(DebuggerStepThroughAttribute), new CodeExpression[0]);
                WebCodeGenerator.AddCustomAttribute(metadata, typeof(DesignerCategoryAttribute), new CodeExpression[] { new CodePrimitiveExpression("code") });
            }

            Type[] requiredTypes = new Type[] { typeof(SoapDocumentMethodAttribute), typeof(XmlAttributeAttribute), typeof(WebService), typeof(Object), typeof(DebuggerStepThroughAttribute), typeof(DesignerCategoryAttribute) };
            WebCodeGenerator.AddImports(this.CodeNamespace, WebCodeGenerator.GetNamespacesForTypes(requiredTypes));
            CodeTypeDeclaration codeClass = WebCodeGenerator.CreateClass(this.ClassName, BaseClass.FullName,
                                                                         new string[0], metadata, CodeFlags.IsPublic | (Style == ServiceDescriptionImportStyle.Client ? 0 : CodeFlags.IsAbstract));

            codeClass.Comments.Add(new CodeCommentStatement("<remarks/>", true));

            CodeConstructor ctor = WebCodeGenerator.AddConstructor(codeClass, new string[0], new string[0], null, CodeFlags.IsPublic);

            ctor.Comments.Add(new CodeCommentStatement("<remarks/>", true));

            HttpAddressBinding httpAddressBinding = Port == null ? null : (HttpAddressBinding)Port.Extensions.Find(typeof(HttpAddressBinding));
            string             url = (httpAddressBinding != null) ? httpAddressBinding.Location : null;
            ServiceDescription serviceDescription = Binding.ServiceDescription;

            ProtocolImporterUtil.GenerateConstructorStatements(ctor, url, serviceDescription.AppSettingUrlKey, serviceDescription.AppSettingBaseUrl);

            codeClasses.Add(codeClass);
            return(codeClass);
        }
        protected override CodeTypeDeclaration BeginClass()
        {
            base.MethodNames.Clear();
            base.ExtraCodeClasses.Clear();
            CodeAttributeDeclarationCollection metadata = new CodeAttributeDeclarationCollection();

            if (base.Style == ServiceDescriptionImportStyle.Client)
            {
                WebCodeGenerator.AddCustomAttribute(metadata, typeof(DebuggerStepThroughAttribute), new CodeExpression[0]);
                WebCodeGenerator.AddCustomAttribute(metadata, typeof(DesignerCategoryAttribute), new CodeExpression[] { new CodePrimitiveExpression("code") });
            }
            Type[] types = new Type[] { typeof(SoapDocumentMethodAttribute), typeof(XmlAttributeAttribute), typeof(WebService), typeof(object), typeof(DebuggerStepThroughAttribute), typeof(DesignerCategoryAttribute), typeof(TransactionOption) };
            WebCodeGenerator.AddImports(base.CodeNamespace, WebCodeGenerator.GetNamespacesForTypes(types));
            CodeFlags isAbstract = (CodeFlags)0;

            if (base.Style == ServiceDescriptionImportStyle.Server)
            {
                isAbstract = CodeFlags.IsAbstract;
            }
            else if (base.Style == ServiceDescriptionImportStyle.ServerInterface)
            {
                isAbstract = CodeFlags.IsInterface;
            }
            CodeTypeDeclaration codeClass = WebCodeGenerator.CreateClass(base.ClassName, this.BaseClass.FullName, new string[0], metadata, CodeFlags.IsPublic | isAbstract, base.ServiceImporter.CodeGenerator.Supports(GeneratorSupport.PartialTypes));

            codeClass.Comments.Add(new CodeCommentStatement(System.Web.Services.Res.GetString("CodeRemarks"), true));
            CodeConstructor ctor = WebCodeGenerator.AddConstructor(codeClass, new string[0], new string[0], null, CodeFlags.IsPublic);

            ctor.Comments.Add(new CodeCommentStatement(System.Web.Services.Res.GetString("CodeRemarks"), true));
            HttpAddressBinding binding            = (base.Port == null) ? null : ((HttpAddressBinding)base.Port.Extensions.Find(typeof(HttpAddressBinding)));
            string             url                = (binding != null) ? binding.Location : null;
            ServiceDescription serviceDescription = base.Binding.ServiceDescription;

            ProtocolImporterUtil.GenerateConstructorStatements(ctor, url, serviceDescription.AppSettingUrlKey, serviceDescription.AppSettingBaseUrl, false);
            this.codeClasses.Add(codeClass);
            return(codeClass);
        }
Ejemplo n.º 3
0
        CodeMemberMethod GenerateMethod(HttpMethodInfo method)
        {
            MimeParameterCollection parameters = method.MimeParameters != null ? method.MimeParameters : method.UrlParameters;

            string[] parameterTypeNames = new string[parameters.Count];
            string[] parameterNames     = new string[parameters.Count];

            for (int i = 0; i < parameters.Count; i++)
            {
                MimeParameter param = parameters[i];
                parameterNames[i]     = param.Name;
                parameterTypeNames[i] = param.TypeName;
            }

            CodeAttributeDeclarationCollection metadata = new CodeAttributeDeclarationCollection();

            CodeExpression[] formatterTypes = new CodeExpression[2];

            if (method.MimeReturn.ReaderType == null)
            {
                formatterTypes[0] = new CodeTypeOfExpression(typeof(NopReturnReader).FullName);
            }
            else
            {
                formatterTypes[0] = new CodeTypeOfExpression(method.MimeReturn.ReaderType.FullName);
            }

            if (method.MimeParameters != null)
            {
                formatterTypes[1] = new CodeTypeOfExpression(method.MimeParameters.WriterType.FullName);
            }
            else
            {
                formatterTypes[1] = new CodeTypeOfExpression(typeof(UrlParameterWriter).FullName);
            }

            WebCodeGenerator.AddCustomAttribute(metadata, typeof(HttpMethodAttribute), formatterTypes, new string[0], new CodeExpression[0]);


            CodeMemberMethod mainCodeMethod = WebCodeGenerator.AddMethod(this.CodeTypeDeclaration, method.Name, new CodeFlags[parameterTypeNames.Length], parameterTypeNames, parameterNames,
                                                                         method.MimeReturn.TypeName, metadata,
                                                                         CodeFlags.IsPublic | (Style == ServiceDescriptionImportStyle.Client ? 0 : CodeFlags.IsAbstract));

            AppendMetadata(method.MimeReturn.Attributes, mainCodeMethod.ReturnTypeCustomAttributes);

            mainCodeMethod.Comments.Add(new CodeCommentStatement(Res.GetString(Res.CodeRemarks), true));

            for (int i = 0; i < parameters.Count; i++)
            {
                AppendMetadata(parameters[i].Attributes, mainCodeMethod.Parameters[i].CustomAttributes);
            }

            if (Style == ServiceDescriptionImportStyle.Client)
            {
                bool oldAsync = (ServiceImporter.CodeGenerationOptions & CodeGenerationOptions.GenerateOldAsync) != 0;
                bool newAsync = (ServiceImporter.CodeGenerationOptions & CodeGenerationOptions.GenerateNewAsync) != 0 &&
                                ServiceImporter.CodeGenerator.Supports(GeneratorSupport.DeclareEvents) &&
                                ServiceImporter.CodeGenerator.Supports(GeneratorSupport.DeclareDelegates);

                CodeExpression[] invokeParams = new CodeExpression[3];
                CreateInvokeParams(invokeParams, method, parameterNames);
                CodeMethodInvokeExpression invoke = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), "Invoke", invokeParams);
                if (method.MimeReturn.ReaderType != null)
                {
                    mainCodeMethod.Statements.Add(new CodeMethodReturnStatement(new CodeCastExpression(method.MimeReturn.TypeName, invoke)));
                }
                else
                {
                    mainCodeMethod.Statements.Add(new CodeExpressionStatement(invoke));
                }

                metadata = new CodeAttributeDeclarationCollection();

                string[] asyncParameterTypeNames = new string[parameterTypeNames.Length + 2];
                parameterTypeNames.CopyTo(asyncParameterTypeNames, 0);
                asyncParameterTypeNames[parameterTypeNames.Length]     = typeof(AsyncCallback).FullName;
                asyncParameterTypeNames[parameterTypeNames.Length + 1] = typeof(object).FullName;

                string[] asyncParameterNames = new string[parameterNames.Length + 2];
                parameterNames.CopyTo(asyncParameterNames, 0);
                asyncParameterNames[parameterNames.Length]     = "callback";
                asyncParameterNames[parameterNames.Length + 1] = "asyncState";

                if (oldAsync)
                {
                    CodeMemberMethod beginCodeMethod = WebCodeGenerator.AddMethod(this.CodeTypeDeclaration, "Begin" + method.Name, new CodeFlags[asyncParameterTypeNames.Length],
                                                                                  asyncParameterTypeNames, asyncParameterNames,
                                                                                  typeof(IAsyncResult).FullName, metadata, CodeFlags.IsPublic);
                    beginCodeMethod.Comments.Add(new CodeCommentStatement(Res.GetString(Res.CodeRemarks), true));

                    invokeParams = new CodeExpression[5];
                    CreateInvokeParams(invokeParams, method, parameterNames);

                    invokeParams[3] = new CodeArgumentReferenceExpression("callback");
                    invokeParams[4] = new CodeArgumentReferenceExpression("asyncState");

                    invoke = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), "BeginInvoke", invokeParams);
                    beginCodeMethod.Statements.Add(new CodeMethodReturnStatement(invoke));

                    CodeMemberMethod endCodeMethod = WebCodeGenerator.AddMethod(this.CodeTypeDeclaration, "End" + method.Name, new CodeFlags[1],
                                                                                new string[] { typeof(IAsyncResult).FullName },
                                                                                new string[] { "asyncResult" },
                                                                                method.MimeReturn.TypeName, metadata, CodeFlags.IsPublic);
                    endCodeMethod.Comments.Add(new CodeCommentStatement(Res.GetString(Res.CodeRemarks), true));

                    CodeExpression expr = new CodeArgumentReferenceExpression("asyncResult");
                    invoke = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), "EndInvoke", new CodeExpression[] { expr });
                    if (method.MimeReturn.ReaderType != null)
                    {
                        endCodeMethod.Statements.Add(new CodeMethodReturnStatement(new CodeCastExpression(method.MimeReturn.TypeName, invoke)));
                    }
                    else
                    {
                        endCodeMethod.Statements.Add(new CodeExpressionStatement(invoke));
                    }
                }
                if (newAsync)
                {
                    metadata = new CodeAttributeDeclarationCollection();
                    string       uniqueMethodName = method.Name;
                    string       methodKey        = MethodSignature(uniqueMethodName, method.MimeReturn.TypeName, new CodeFlags[parameterTypeNames.Length], parameterTypeNames);
                    DelegateInfo delegateInfo     = (DelegateInfo)ExportContext[methodKey];
                    if (delegateInfo == null)
                    {
                        string handlerType = ClassNames.AddUnique(uniqueMethodName + "CompletedEventHandler", uniqueMethodName);
                        string handlerArgs = ClassNames.AddUnique(uniqueMethodName + "CompletedEventArgs", uniqueMethodName);
                        delegateInfo = new DelegateInfo(handlerType, handlerArgs);
                    }
                    string handlerName    = MethodNames.AddUnique(uniqueMethodName + "Completed", uniqueMethodName);
                    string asyncName      = MethodNames.AddUnique(uniqueMethodName + "Async", uniqueMethodName);
                    string callbackMember = MethodNames.AddUnique(uniqueMethodName + "OperationCompleted", uniqueMethodName);
                    string callbackName   = MethodNames.AddUnique("On" + uniqueMethodName + "OperationCompleted", uniqueMethodName);

                    // public event xxxCompletedEventHandler xxxCompleted;
                    WebCodeGenerator.AddEvent(this.CodeTypeDeclaration.Members, delegateInfo.handlerType, handlerName);

                    // private SendOrPostCallback xxxOperationCompleted;
                    WebCodeGenerator.AddCallbackDeclaration(this.CodeTypeDeclaration.Members, callbackMember);

                    // create the pair of xxxAsync methods
                    string           userState       = UniqueName("userState", parameterNames);
                    CodeMemberMethod asyncCodeMethod = WebCodeGenerator.AddAsyncMethod(this.CodeTypeDeclaration, asyncName,
                                                                                       parameterTypeNames, parameterNames, callbackMember, callbackName, userState);

                    // Generate InvokeAsync call
                    invokeParams = new CodeExpression[5];
                    CreateInvokeParams(invokeParams, method, parameterNames);
                    invokeParams[3] = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), callbackMember);
                    invokeParams[4] = new CodeArgumentReferenceExpression(userState);

                    invoke = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), "InvokeAsync", invokeParams);
                    asyncCodeMethod.Statements.Add(invoke);

                    //  private void On_xxx_OperationCompleted(object arg) {..}
                    bool methodHasReturn = method.MimeReturn.ReaderType != null;
                    WebCodeGenerator.AddCallbackImplementation(this.CodeTypeDeclaration, callbackName, handlerName, delegateInfo.handlerArgs, methodHasReturn);
                    if (ExportContext[methodKey] == null)
                    {
                        // public delegate void xxxCompletedEventHandler(object sender, System.ComponentModel.AsyncCompletedEventArgs args);
                        WebCodeGenerator.AddDelegate(ExtraCodeClasses, delegateInfo.handlerType, methodHasReturn ? delegateInfo.handlerArgs : typeof(AsyncCompletedEventArgs).FullName);

                        if (methodHasReturn)
                        {
                            ExtraCodeClasses.Add(WebCodeGenerator.CreateArgsClass(delegateInfo.handlerArgs, new string[] { method.MimeReturn.TypeName }, new string[] { "Result" },
                                                                                  ServiceImporter.CodeGenerator.Supports(GeneratorSupport.PartialTypes)));
                        }
                        ExportContext[methodKey] = delegateInfo;
                    }
                }
            }
            return(mainCodeMethod);
        }
        CodeMemberMethod GenerateMethod(HttpMethodInfo method)
        {
            MimeParameterCollection parameters = method.MimeParameters != null ? method.MimeParameters : method.UrlParameters;

            string[] parameterTypeNames = new string[parameters.Count];
            string[] parameterNames     = new string[parameters.Count];

            for (int i = 0; i < parameters.Count; i++)
            {
                MimeParameter param = parameters[i];
                parameterNames[i]     = param.Name;
                parameterTypeNames[i] = param.TypeName;
            }

            CodeAttributeDeclarationCollection metadata = new CodeAttributeDeclarationCollection();

            CodeExpression[] formatterTypes = new CodeExpression[2];

            if (method.MimeReturn.ReaderType == null)
            {
                formatterTypes[0] = new CodeTypeOfExpression(typeof(NopReturnReader).FullName);
            }
            else
            {
                formatterTypes[0] = new CodeTypeOfExpression(method.MimeReturn.ReaderType.FullName);
            }

            if (method.MimeParameters != null)
            {
                formatterTypes[1] = new CodeTypeOfExpression(method.MimeParameters.WriterType.FullName);
            }
            else
            {
                formatterTypes[1] = new CodeTypeOfExpression(typeof(UrlParameterWriter).FullName);
            }

            WebCodeGenerator.AddCustomAttribute(metadata, typeof(HttpMethodAttribute), formatterTypes, new string[0], new CodeExpression[0]);


            CodeMemberMethod mainCodeMethod = WebCodeGenerator.AddMethod(this.CodeTypeDeclaration, method.Name, new CodeFlags[parameterTypeNames.Length], parameterTypeNames, parameterNames,
                                                                         method.MimeReturn.TypeName, metadata,
                                                                         CodeFlags.IsPublic | (Style == ServiceDescriptionImportStyle.Client ? 0 : CodeFlags.IsAbstract));

            AppendMetadata(method.MimeReturn.Attributes, mainCodeMethod.ReturnTypeCustomAttributes);

            mainCodeMethod.Comments.Add(new CodeCommentStatement("<remarks/>", true));

            for (int i = 0; i < parameters.Count; i++)
            {
                AppendMetadata(parameters[i].Attributes, mainCodeMethod.Parameters[i].CustomAttributes);
            }

            if (Style == ServiceDescriptionImportStyle.Client)
            {
                CodeExpression[] invokeParams = new CodeExpression[3];
                CreateInvokeParams(invokeParams, method, parameterNames);
                CodeExpression invoke = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), "Invoke", invokeParams);
                if (method.MimeReturn.ReaderType != null)
                {
                    invoke = new CodeCastExpression(method.MimeReturn.TypeName, invoke);
                }
                if (method.MimeReturn.ReaderType != null)
                {
                    mainCodeMethod.Statements.Add(new CodeMethodReturnStatement(invoke));
                }
                else
                {
                    mainCodeMethod.Statements.Add(new CodeExpressionStatement(invoke));
                }

                metadata = new CodeAttributeDeclarationCollection();

                string[] asyncParameterTypeNames = new string[parameterTypeNames.Length + 2];
                parameterTypeNames.CopyTo(asyncParameterTypeNames, 0);
                asyncParameterTypeNames[parameterTypeNames.Length]     = typeof(AsyncCallback).FullName;
                asyncParameterTypeNames[parameterTypeNames.Length + 1] = typeof(object).FullName;

                string[] asyncParameterNames = new string[parameterNames.Length + 2];
                parameterNames.CopyTo(asyncParameterNames, 0);
                asyncParameterNames[parameterNames.Length]     = "callback";
                asyncParameterNames[parameterNames.Length + 1] = "asyncState";

                CodeMemberMethod beginCodeMethod = WebCodeGenerator.AddMethod(this.CodeTypeDeclaration, "Begin" + method.Name, new CodeFlags[asyncParameterTypeNames.Length],
                                                                              asyncParameterTypeNames, asyncParameterNames,
                                                                              typeof(IAsyncResult).FullName, metadata, CodeFlags.IsPublic);
                beginCodeMethod.Comments.Add(new CodeCommentStatement("<remarks/>", true));

                invokeParams = new CodeExpression[5];
                CreateInvokeParams(invokeParams, method, parameterNames);

                invokeParams[3] = new CodeArgumentReferenceExpression("callback");
                invokeParams[4] = new CodeArgumentReferenceExpression("asyncState");

                invoke = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), "BeginInvoke", invokeParams);
                beginCodeMethod.Statements.Add(new CodeMethodReturnStatement(invoke));

                CodeMemberMethod endCodeMethod = WebCodeGenerator.AddMethod(this.CodeTypeDeclaration, "End" + method.Name, new CodeFlags[1],
                                                                            new string[] { typeof(IAsyncResult).FullName },
                                                                            new string[] { "asyncResult" },
                                                                            method.MimeReturn.TypeName, metadata, CodeFlags.IsPublic);
                endCodeMethod.Comments.Add(new CodeCommentStatement("<remarks/>", true));

                CodeExpression expr = new CodeArgumentReferenceExpression("asyncResult");
                invoke = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), "EndInvoke", new CodeExpression[] { expr });
                if (method.MimeReturn.ReaderType != null)
                {
                    invoke = new CodeCastExpression(method.MimeReturn.TypeName, invoke);
                }
                if (method.MimeReturn.ReaderType != null)
                {
                    endCodeMethod.Statements.Add(new CodeMethodReturnStatement(invoke));
                }
                else
                {
                    endCodeMethod.Statements.Add(new CodeExpressionStatement(invoke));
                }
            }

            return(mainCodeMethod);
        }
Ejemplo n.º 5
0
        void GenerateCode(string typeName, MimeTextMatchCollection matches, CodeGenerationOptions options)
        {
            CodeIdentifiers     members   = new CodeIdentifiers();
            CodeTypeDeclaration codeClass = WebCodeGenerator.AddClass(ImportContext.CodeNamespace, typeName, string.Empty, new string[0], null, CodeFlags.IsPublic,
                                                                      ImportContext.ServiceImporter.CodeGenerator.Supports(GeneratorSupport.PartialTypes));

            string[] fieldTypeNames = new string[matches.Count];
            for (int i = 0; i < matches.Count; i++)
            {
                MimeTextMatch match = matches[i];
                string        name  = members.AddUnique(CodeIdentifier.MakeValid(match.Name.Length == 0 ? methodName + "Match" : match.Name), match);
                CodeAttributeDeclarationCollection metadata = new CodeAttributeDeclarationCollection();
                if (match.Pattern.Length == 0)
                {
                    throw new ArgumentException(Res.GetString(Res.WebTextMatchMissingPattern));
                }

                CodeExpression pattern       = new CodePrimitiveExpression(match.Pattern);
                int            numPropValues = 0;
                if (match.Group != 1)
                {
                    numPropValues++;
                }
                if (match.Capture != 0)
                {
                    numPropValues++;
                }
                if (match.IgnoreCase)
                {
                    numPropValues++;
                }
                if (match.Repeats != 1 && match.Repeats != int.MaxValue)
                {
                    numPropValues++;
                }
                CodeExpression[] propertyValues = new CodeExpression[numPropValues];
                string[]         propertyNames  = new string[propertyValues.Length];
                numPropValues = 0;
                if (match.Group != 1)
                {
                    propertyValues[numPropValues] = new CodePrimitiveExpression(match.Group);
                    propertyNames[numPropValues]  = "Group";
                    numPropValues++;
                }
                if (match.Capture != 0)
                {
                    propertyValues[numPropValues] = new CodePrimitiveExpression(match.Capture);
                    propertyNames[numPropValues]  = "Capture";
                    numPropValues++;
                }
                if (match.IgnoreCase)
                {
                    propertyValues[numPropValues] = new CodePrimitiveExpression(match.IgnoreCase);
                    propertyNames[numPropValues]  = "IgnoreCase";
                    numPropValues++;
                }
                if (match.Repeats != 1 && match.Repeats != int.MaxValue)
                {
                    propertyValues[numPropValues] = new CodePrimitiveExpression(match.Repeats);
                    propertyNames[numPropValues]  = "MaxRepeats";
                    numPropValues++;
                }
                WebCodeGenerator.AddCustomAttribute(metadata, typeof(MatchAttribute), new CodeExpression[] { pattern }, propertyNames, propertyValues);

                string fieldTypeName;
                if (match.Matches.Count > 0)
                {
                    fieldTypeName     = ImportContext.ClassNames.AddUnique(CodeIdentifier.MakeValid(match.Type.Length == 0 ? name : match.Type), match);
                    fieldTypeNames[i] = fieldTypeName;
                }
                else
                {
                    fieldTypeName = typeof(string).FullName;
                }
                if (match.Repeats != 1)
                {
                    fieldTypeName += "[]";
                }

                CodeTypeMember member = WebCodeGenerator.AddMember(codeClass, fieldTypeName, name, null, metadata, CodeFlags.IsPublic, options);

                if (match.Matches.Count == 0 && match.Type.Length > 0)
                {
                    ImportContext.Warnings |= ServiceDescriptionImportWarnings.OptionalExtensionsIgnored;
                    ProtocolImporter.AddWarningComment(member.Comments, Res.GetString(Res.WebTextMatchIgnoredTypeWarning));
                }
            }

            for (int i = 0; i < fieldTypeNames.Length; i++)
            {
                string fieldTypeName = fieldTypeNames[i];
                if (fieldTypeName != null)
                {
                    GenerateCode(fieldTypeName, matches[i].Matches, options);
                }
            }
        }
Ejemplo n.º 6
0
        private void GenerateCode(string typeName, MimeTextMatchCollection matches, CodeGenerationOptions options)
        {
            CodeIdentifiers     identifiers = new CodeIdentifiers();
            CodeTypeDeclaration codeClass   = WebCodeGenerator.AddClass(base.ImportContext.CodeNamespace, typeName, string.Empty, new string[0], null, CodeFlags.IsPublic, base.ImportContext.ServiceImporter.CodeGenerator.Supports(GeneratorSupport.PartialTypes));

            string[] strArray = new string[matches.Count];
            for (int i = 0; i < matches.Count; i++)
            {
                string        fullName;
                MimeTextMatch match      = matches[i];
                string        memberName = identifiers.AddUnique(CodeIdentifier.MakeValid((match.Name.Length == 0) ? (this.methodName + "Match") : match.Name), match);
                CodeAttributeDeclarationCollection metadata = new CodeAttributeDeclarationCollection();
                if (match.Pattern.Length == 0)
                {
                    throw new ArgumentException(Res.GetString("WebTextMatchMissingPattern"));
                }
                CodeExpression expression = new CodePrimitiveExpression(match.Pattern);
                int            index      = 0;
                if (match.Group != 1)
                {
                    index++;
                }
                if (match.Capture != 0)
                {
                    index++;
                }
                if (match.IgnoreCase)
                {
                    index++;
                }
                if ((match.Repeats != 1) && (match.Repeats != 0x7fffffff))
                {
                    index++;
                }
                CodeExpression[] propValues = new CodeExpression[index];
                string[]         propNames  = new string[propValues.Length];
                index = 0;
                if (match.Group != 1)
                {
                    propValues[index] = new CodePrimitiveExpression(match.Group);
                    propNames[index]  = "Group";
                    index++;
                }
                if (match.Capture != 0)
                {
                    propValues[index] = new CodePrimitiveExpression(match.Capture);
                    propNames[index]  = "Capture";
                    index++;
                }
                if (match.IgnoreCase)
                {
                    propValues[index] = new CodePrimitiveExpression(match.IgnoreCase);
                    propNames[index]  = "IgnoreCase";
                    index++;
                }
                if ((match.Repeats != 1) && (match.Repeats != 0x7fffffff))
                {
                    propValues[index] = new CodePrimitiveExpression(match.Repeats);
                    propNames[index]  = "MaxRepeats";
                    index++;
                }
                WebCodeGenerator.AddCustomAttribute(metadata, typeof(MatchAttribute), new CodeExpression[] { expression }, propNames, propValues);
                if (match.Matches.Count > 0)
                {
                    fullName    = base.ImportContext.ClassNames.AddUnique(CodeIdentifier.MakeValid((match.Type.Length == 0) ? memberName : match.Type), match);
                    strArray[i] = fullName;
                }
                else
                {
                    fullName = typeof(string).FullName;
                }
                if (match.Repeats != 1)
                {
                    fullName = fullName + "[]";
                }
                CodeTypeMember member = WebCodeGenerator.AddMember(codeClass, fullName, memberName, null, metadata, CodeFlags.IsPublic, options);
                if ((match.Matches.Count == 0) && (match.Type.Length > 0))
                {
                    HttpProtocolImporter importContext = base.ImportContext;
                    importContext.Warnings |= ServiceDescriptionImportWarnings.OptionalExtensionsIgnored;
                    ProtocolImporter.AddWarningComment(member.Comments, Res.GetString("WebTextMatchIgnoredTypeWarning"));
                }
            }
            for (int j = 0; j < strArray.Length; j++)
            {
                string str3 = strArray[j];
                if (str3 != null)
                {
                    this.GenerateCode(str3, matches[j].Matches, options);
                }
            }
        }
        private CodeMemberMethod GenerateMethod(HttpMethodInfo method)
        {
            MimeParameterCollection parameters = (method.MimeParameters != null) ? method.MimeParameters : method.UrlParameters;

            string[] parameterTypeNames = new string[parameters.Count];
            string[] parameterNames     = new string[parameters.Count];
            for (int i = 0; i < parameters.Count; i++)
            {
                MimeParameter parameter = parameters[i];
                parameterNames[i]     = parameter.Name;
                parameterTypeNames[i] = parameter.TypeName;
            }
            CodeAttributeDeclarationCollection metadata = new CodeAttributeDeclarationCollection();

            CodeExpression[] expressionArray = new CodeExpression[2];
            if (method.MimeReturn.ReaderType == null)
            {
                expressionArray[0] = new CodeTypeOfExpression(typeof(NopReturnReader).FullName);
            }
            else
            {
                expressionArray[0] = new CodeTypeOfExpression(method.MimeReturn.ReaderType.FullName);
            }
            if (method.MimeParameters != null)
            {
                expressionArray[1] = new CodeTypeOfExpression(method.MimeParameters.WriterType.FullName);
            }
            else
            {
                expressionArray[1] = new CodeTypeOfExpression(typeof(UrlParameterWriter).FullName);
            }
            WebCodeGenerator.AddCustomAttribute(metadata, typeof(HttpMethodAttribute), expressionArray, new string[0], new CodeExpression[0]);
            CodeMemberMethod method2 = WebCodeGenerator.AddMethod(base.CodeTypeDeclaration, method.Name, new CodeFlags[parameterTypeNames.Length], parameterTypeNames, parameterNames, method.MimeReturn.TypeName, metadata, CodeFlags.IsPublic | ((base.Style == ServiceDescriptionImportStyle.Client) ? ((CodeFlags)0) : CodeFlags.IsAbstract));

            AppendMetadata(method.MimeReturn.Attributes, method2.ReturnTypeCustomAttributes);
            method2.Comments.Add(new CodeCommentStatement(System.Web.Services.Res.GetString("CodeRemarks"), true));
            for (int j = 0; j < parameters.Count; j++)
            {
                AppendMetadata(parameters[j].Attributes, method2.Parameters[j].CustomAttributes);
            }
            if (base.Style == ServiceDescriptionImportStyle.Client)
            {
                bool             flag         = (base.ServiceImporter.CodeGenerationOptions & CodeGenerationOptions.GenerateOldAsync) != CodeGenerationOptions.None;
                bool             flag2        = (((base.ServiceImporter.CodeGenerationOptions & CodeGenerationOptions.GenerateNewAsync) != CodeGenerationOptions.None) && base.ServiceImporter.CodeGenerator.Supports(GeneratorSupport.DeclareEvents)) && base.ServiceImporter.CodeGenerator.Supports(GeneratorSupport.DeclareDelegates);
                CodeExpression[] invokeParams = new CodeExpression[3];
                this.CreateInvokeParams(invokeParams, method, parameterNames);
                CodeMethodInvokeExpression expression = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), "Invoke", invokeParams);
                if (method.MimeReturn.ReaderType != null)
                {
                    method2.Statements.Add(new CodeMethodReturnStatement(new CodeCastExpression(method.MimeReturn.TypeName, expression)));
                }
                else
                {
                    method2.Statements.Add(new CodeExpressionStatement(expression));
                }
                metadata = new CodeAttributeDeclarationCollection();
                string[] array = new string[parameterTypeNames.Length + 2];
                parameterTypeNames.CopyTo(array, 0);
                array[parameterTypeNames.Length]     = typeof(AsyncCallback).FullName;
                array[parameterTypeNames.Length + 1] = typeof(object).FullName;
                string[] strArray4 = new string[parameterNames.Length + 2];
                parameterNames.CopyTo(strArray4, 0);
                strArray4[parameterNames.Length]     = "callback";
                strArray4[parameterNames.Length + 1] = "asyncState";
                if (flag)
                {
                    CodeMemberMethod method3 = WebCodeGenerator.AddMethod(base.CodeTypeDeclaration, "Begin" + method.Name, new CodeFlags[array.Length], array, strArray4, typeof(IAsyncResult).FullName, metadata, CodeFlags.IsPublic);
                    method3.Comments.Add(new CodeCommentStatement(System.Web.Services.Res.GetString("CodeRemarks"), true));
                    invokeParams = new CodeExpression[5];
                    this.CreateInvokeParams(invokeParams, method, parameterNames);
                    invokeParams[3] = new CodeArgumentReferenceExpression("callback");
                    invokeParams[4] = new CodeArgumentReferenceExpression("asyncState");
                    expression      = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), "BeginInvoke", invokeParams);
                    method3.Statements.Add(new CodeMethodReturnStatement(expression));
                    CodeMemberMethod method4 = WebCodeGenerator.AddMethod(base.CodeTypeDeclaration, "End" + method.Name, new CodeFlags[1], new string[] { typeof(IAsyncResult).FullName }, new string[] { "asyncResult" }, method.MimeReturn.TypeName, metadata, CodeFlags.IsPublic);
                    method4.Comments.Add(new CodeCommentStatement(System.Web.Services.Res.GetString("CodeRemarks"), true));
                    CodeExpression expression2 = new CodeArgumentReferenceExpression("asyncResult");
                    expression = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), "EndInvoke", new CodeExpression[] { expression2 });
                    if (method.MimeReturn.ReaderType != null)
                    {
                        method4.Statements.Add(new CodeMethodReturnStatement(new CodeCastExpression(method.MimeReturn.TypeName, expression)));
                    }
                    else
                    {
                        method4.Statements.Add(new CodeExpressionStatement(expression));
                    }
                }
                if (!flag2)
                {
                    return(method2);
                }
                metadata = new CodeAttributeDeclarationCollection();
                string       name = method.Name;
                string       str2 = ProtocolImporter.MethodSignature(name, method.MimeReturn.TypeName, new CodeFlags[parameterTypeNames.Length], parameterTypeNames);
                DelegateInfo info = (DelegateInfo)base.ExportContext[str2];
                if (info == null)
                {
                    string handlerType = base.ClassNames.AddUnique(name + "CompletedEventHandler", name);
                    string handlerArgs = base.ClassNames.AddUnique(name + "CompletedEventArgs", name);
                    info = new DelegateInfo(handlerType, handlerArgs);
                }
                string handlerName    = base.MethodNames.AddUnique(name + "Completed", name);
                string methodName     = base.MethodNames.AddUnique(name + "Async", name);
                string callbackMember = base.MethodNames.AddUnique(name + "OperationCompleted", name);
                string callbackName   = base.MethodNames.AddUnique("On" + name + "OperationCompleted", name);
                WebCodeGenerator.AddEvent(base.CodeTypeDeclaration.Members, info.handlerType, handlerName);
                WebCodeGenerator.AddCallbackDeclaration(base.CodeTypeDeclaration.Members, callbackMember);
                string           userState = ProtocolImporter.UniqueName("userState", parameterNames);
                CodeMemberMethod method5   = WebCodeGenerator.AddAsyncMethod(base.CodeTypeDeclaration, methodName, parameterTypeNames, parameterNames, callbackMember, callbackName, userState);
                invokeParams = new CodeExpression[5];
                this.CreateInvokeParams(invokeParams, method, parameterNames);
                invokeParams[3] = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), callbackMember);
                invokeParams[4] = new CodeArgumentReferenceExpression(userState);
                expression      = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), "InvokeAsync", invokeParams);
                method5.Statements.Add(expression);
                bool methodHasOutParameters = method.MimeReturn.ReaderType != null;
                WebCodeGenerator.AddCallbackImplementation(base.CodeTypeDeclaration, callbackName, handlerName, info.handlerArgs, methodHasOutParameters);
                if (base.ExportContext[str2] != null)
                {
                    return(method2);
                }
                WebCodeGenerator.AddDelegate(base.ExtraCodeClasses, info.handlerType, methodHasOutParameters ? info.handlerArgs : typeof(AsyncCompletedEventArgs).FullName);
                if (methodHasOutParameters)
                {
                    base.ExtraCodeClasses.Add(WebCodeGenerator.CreateArgsClass(info.handlerArgs, new string[] { method.MimeReturn.TypeName }, new string[] { "Result" }, base.ServiceImporter.CodeGenerator.Supports(GeneratorSupport.PartialTypes)));
                }
                base.ExportContext[str2] = info;
            }
            return(method2);
        }