예제 #1
0
        private static void PrepareParametersForMethod(
            ProcessTemplate snippet,
            TypeReference AReturnType,
            List <ParameterDeclarationExpression> AParameters,
            string AMethodName,
            ref List <string> AMethodNames)
        {
            string ParameterDefinition = string.Empty;
            string ActualParameters    = string.Empty;

            snippet.SetCodelet("LOCALVARIABLES", string.Empty);
            string returnCodeJSClient = string.Empty;
            int    returnCounter      = 0;

            foreach (ParameterDeclarationExpression p in AParameters)
            {
                string parametertype  = p.TypeReference.ToString();
                bool   ArrayParameter = false;

                // check if the parametertype is not a generic type, eg. dictionary or list
                if (!parametertype.Contains("<"))
                {
                    if (parametertype.EndsWith("[]"))
                    {
                        ArrayParameter = true;
//Console.WriteLine("ArrayParameter found: " + parametertype);
                    }

                    parametertype = parametertype == "string" || parametertype == "String" ? "System.String" : parametertype;
                    parametertype = parametertype == "bool" || parametertype == "Boolean" ? "System.Boolean" : parametertype;

                    if (parametertype.Contains("UINT") || parametertype.Contains("unsigned"))
                    {
                        parametertype = parametertype.Contains("UInt32") || parametertype == "unsigned int" ? "System.UInt32" : parametertype;
                        parametertype = parametertype.Contains("UInt16") || parametertype == "unsigned short" ? "System.UInt16" : parametertype;
                        parametertype = parametertype.Contains("UInt64") || parametertype == "unsigned long" ? "System.UInt64" : parametertype;
                    }
                    else
                    {
                        parametertype = parametertype.Contains("Int32") || parametertype == "int" ? "System.Int32" : parametertype;
                        parametertype = parametertype.Contains("Int16") || parametertype == "short" ? "System.Int16" : parametertype;
                        parametertype = parametertype.Contains("Int64") || parametertype == "long" ? "System.Int64" : parametertype;
                    }

                    parametertype = parametertype.Contains("Decimal") || parametertype == "decimal" ? "System.Decimal" : parametertype;

                    if (ArrayParameter &&
                        !(parametertype.EndsWith("[]")))
                    {
                        // need to restore Array type!
                        parametertype += "[]";

//Console.WriteLine("ArrayParameter found - new parametertype = " + parametertype);
                    }
                }

                bool TypedDataSetParameter     = parametertype.EndsWith("TDS");
                bool DataTableParameter        = parametertype.EndsWith("DataTable");
                bool EnumParameter             = parametertype.EndsWith("Enum");
                bool DecimalParameter          = parametertype.StartsWith("System.Decimal") && !ArrayParameter;
                bool DateTimeParameter         = parametertype.EndsWith("DateTime");
                bool ListParameter             = parametertype.StartsWith("List<");
                bool NullableDateTimeParameter = parametertype.Contains("Nullable<DateTime>");
                bool BinaryParameter           =
                    p.ParameterName.EndsWith("Base64") ||
                    !((parametertype.StartsWith("System.Int64")) || (parametertype.StartsWith("System.Int32")) ||
                      (parametertype.StartsWith("System.Int16")) ||
                      (parametertype.StartsWith("System.String")) || (parametertype.StartsWith("System.Boolean")) ||
                      DecimalParameter ||
                      DateTimeParameter ||
                      NullableDateTimeParameter ||
                      EnumParameter ||
                      ListParameter);

                if (ActualParameters.Length > 0)
                {
                    ActualParameters += ", ";
                }

                // ignore out parameters in the web service method definition
                if ((ParameterModifiers.Out & p.ParamModifier) == 0)
                {
                    if (ParameterDefinition.Length > 0)
                    {
                        ParameterDefinition += ", ";
                    }

                    if ((!BinaryParameter) && (!ArrayParameter) && (!EnumParameter) && (!DateTimeParameter) && (!NullableDateTimeParameter) && (!DecimalParameter))
                    {
                        ParameterDefinition += parametertype + " " + p.ParameterName;
                    }
                    else
                    {
                        ParameterDefinition += "string " + p.ParameterName;
                    }
                }

                // for string parameters, check if they have been encoded binary due to special characters in the string;
                // this obviously does not apply to out parameters
                if ((parametertype == "System.String") && ((ParameterModifiers.Out & p.ParamModifier) == 0))
                {
                    snippet.AddToCodelet(
                        "LOCALVARIABLES",
                        p.ParameterName + " = (string) THttpBinarySerializer.DeserializeObject(" + p.ParameterName + ",\"System.String\");" +
                        Environment.NewLine);
                }
                else if (ListParameter && parametertype.Contains("System.String") && ((ParameterModifiers.Out & p.ParamModifier) == 0))
                {
                    if (!parametertype.Contains("[]"))
                    {
                        snippet.AddToCodelet(
                            "LOCALVARIABLES",
                            p.ParameterName + " = THttpBinarySerializer.DeserializeObject(" + p.ParameterName + ");" +
                            Environment.NewLine);
                    }
                }

                // EnumParameters are also binary encoded
                // this obviously does not apply to out parameters
                if (EnumParameter && ((ParameterModifiers.Out & p.ParamModifier) == 0))
                {
                    snippet.AddToCodelet(
                        "LOCALVARIABLES",
                        p.ParameterName + " = THttpBinarySerializer.DeserializeObject(" + p.ParameterName + ",\"System.String\").ToString();" +
                        Environment.NewLine);
                }

                if (DateTimeParameter && ((ParameterModifiers.Out & p.ParamModifier) == 0))
                {
                    snippet.AddToCodelet(
                        "LOCALVARIABLES",
                        parametertype + " Local" + p.ParameterName + " = DateTime.Parse(" + p.ParameterName + ", null, System.Globalization.DateTimeStyles.RoundtripKind);" +
                        Environment.NewLine);
                }

                if (NullableDateTimeParameter && ((ParameterModifiers.Out & p.ParamModifier) == 0))
                {
                    snippet.AddToCodelet(
                        "LOCALVARIABLES",
                        parametertype + " Local" + p.ParameterName + " = " + p.ParameterName + " == \"null\"?(DateTime?)null:DateTime.Parse(" + p.ParameterName + ", null, System.Globalization.DateTimeStyles.RoundtripKind);" +
                        Environment.NewLine);
                }

                if (DecimalParameter && ((ParameterModifiers.Out & p.ParamModifier) == 0))
                {
                    snippet.AddToCodelet(
                        "LOCALVARIABLES",
                        parametertype + " Local" + p.ParameterName + " = Decimal.Parse(" + p.ParameterName + ", System.Globalization.CultureInfo.InvariantCulture);" +
                        Environment.NewLine);
                }

                if (TypedDataSetParameter && (ParameterModifiers.Out & p.ParamModifier) == 0)
                {
                    snippet.AddToCodelet(
                        "LOCALVARIABLES",
                        parametertype + " Local" + p.ParameterName + " = new " + parametertype + "();" + Environment.NewLine +
                        "Local" + p.ParameterName + " = (" + parametertype + ") THttpBinarySerializer.DeserializeDataSet(" + p.ParameterName + ", Local" + p.ParameterName + ");" +
                        Environment.NewLine);
                }

                if ((ParameterModifiers.Out & p.ParamModifier) != 0)
                {
                    snippet.AddToCodelet("LOCALVARIABLES", parametertype + " " + p.ParameterName + ";" + Environment.NewLine);
                    ActualParameters += "out " + p.ParameterName;
                }
                else if ((ParameterModifiers.Ref & p.ParamModifier) != 0)
                {
                    if (TypedDataSetParameter || DateTimeParameter || NullableDateTimeParameter || DecimalParameter)
                    {
                        ActualParameters += "ref Local" + p.ParameterName;
                    }
                    else if (BinaryParameter)
                    {
                        snippet.AddToCodelet("LOCALVARIABLES", parametertype + " Local" + p.ParameterName + " = " +
                                             " (" + parametertype + ")THttpBinarySerializer.DeserializeObject(" + p.ParameterName + ",\"binary\");" +
                                             Environment.NewLine);
                        ActualParameters += "ref Local" + p.ParameterName;
                    }
                    else if (EnumParameter)
                    {
                        snippet.AddToCodelet("LOCALVARIABLES", parametertype + " Local" + p.ParameterName + " = " +
                                             " (" + parametertype + ") Enum.Parse(typeof(" + parametertype + "), " + p.ParameterName + ");" +
                                             Environment.NewLine);
                        ActualParameters += "ref Local" + p.ParameterName;
                    }
                    else
                    {
                        ActualParameters += "ref " + p.ParameterName;
                    }
                }
                else
                {
                    if (TypedDataSetParameter || DateTimeParameter || NullableDateTimeParameter || DecimalParameter)
                    {
                        ActualParameters += "Local" + p.ParameterName;
                    }
                    else if (DataTableParameter)
                    {
                        ActualParameters += "(" + parametertype + ")THttpBinarySerializer.DeserializeObject(" + p.ParameterName + ",\"System.Data.DataTable\")";
                    }
                    else if (BinaryParameter ||
                             ArrayParameter)
                    {
                        ActualParameters += "(" + parametertype + ")THttpBinarySerializer.DeserializeObject(" + p.ParameterName + ",\"binary\")";
                    }
                    else if (EnumParameter)
                    {
                        ActualParameters += " (" + parametertype + ") Enum.Parse(typeof(" + parametertype + "), " + p.ParameterName + ")";
                    }
                    else
                    {
                        ActualParameters += p.ParameterName;
                    }
                }

                if (((ParameterModifiers.Ref & p.ParamModifier) > 0) || ((ParameterModifiers.Out & p.ParamModifier) > 0))
                {
                    if (returnCounter == 0)
                    {
                        returnCodeJSClient = "\"{\" + ";
                    }
                    else
                    {
                        returnCodeJSClient += " + \",\" + ";
                    }

                    returnCodeJSClient += "\"\\\"" + p.ParameterName + "\\\": \" + ";
                    returnCodeJSClient +=
                        "THttpBinarySerializer.SerializeObject(" +
                        (((ParameterModifiers.Ref & p.ParamModifier) > 0 && BinaryParameter) ? "Local" : string.Empty) +
                        p.ParameterName + ")";

                    returnCounter++;
                }
            }

            if (AReturnType != null)
            {
                string returntype = AutoGenerationTools.TypeToString(AReturnType, "");

                if (!returntype.Contains("<"))
                {
                    returntype = returntype == "string" || returntype == "String" ? "System.String" : returntype;
                    returntype = returntype == "bool" || returntype == "Boolean" ? "System.Boolean" : returntype;

                    if (returntype.Contains("UINT") || returntype.Contains("unsigned"))
                    {
                        returntype = returntype.Contains("UInt32") || returntype == "unsigned int" ? "System.UInt32" : returntype;
                        returntype = returntype.Contains("UInt16") || returntype == "unsigned short" ? "System.UInt16" : returntype;
                        returntype = returntype.Contains("UInt64") || returntype == "unsigned long" ? "System.UInt64" : returntype;
                    }
                    else
                    {
                        returntype = returntype.Contains("Int32") || returntype == "int" ? "System.Int32" : returntype;
                        returntype = returntype.Contains("Int16") || returntype == "short" ? "System.Int16" : returntype;
                        returntype = returntype.Contains("Int64") || returntype == "long" ? "System.Int64" : returntype;
                    }

                    returntype = returntype.Contains("Decimal") || returntype == "decimal" ? "System.Decimal" : returntype;
                }

                if (returnCounter > 0)
                {
                    if (returntype != "void")
                    {
                        returnCodeJSClient += "+ \",\" + \"\\\"result\\\": \"+" +
                                              "THttpBinarySerializer.SerializeObject(Result)";

                        returnCounter++;
                    }

                    returntype = "string";
                }
                else if (returntype == "System.String")
                {
                    returntype         = "string";
                    returnCodeJSClient = "Result";
                }
                else if (!((returntype == "System.Int64") || (returntype == "System.Int32") || (returntype == "System.Int16") ||
                           (returntype == "System.UInt64") || (returntype == "System.UInt32") || (returntype == "System.UInt16") ||
                           (returntype == "System.Decimal") ||
                           (returntype == "System.Boolean")) && (returntype != "void"))
                {
                    returntype         = "string";
                    returnCodeJSClient = "\"{\\\"result\\\": \"+" +
                                         "THttpBinarySerializer.SerializeObject(Result)" + " + \"}\"";
                }

                string localreturn = AutoGenerationTools.TypeToString(AReturnType, "");

                if (localreturn == "void")
                {
                    localreturn = string.Empty;
                }
                else if (returnCodeJSClient.Length > 0)
                {
                    localreturn += " Result = ";
                }
                else
                {
                    localreturn = "return ";
                }

                if (returnCounter > 1)
                {
                    returnCodeJSClient += "+ \"}\"";
                }

                snippet.SetCodelet("RETURN", string.Empty);

                if (returnCodeJSClient.Length > 0)
                {
                    snippet.SetCodelet("RETURN",
                                       returntype != "void" ? "return " + returnCodeJSClient + ";" : string.Empty);
                }

                snippet.SetCodelet("RETURNTYPE", returntype);
                snippet.SetCodelet("LOCALRETURN", localreturn);
            }

//Console.WriteLine("Final ParameterDefinition = " + ParameterDefinition);
            snippet.SetCodelet("PARAMETERDEFINITION", ParameterDefinition);
            snippet.SetCodelet("ACTUALPARAMETERS", ActualParameters);

            // avoid duplicate names for webservice methods
            string methodname    = AMethodName;
            int    methodcounter = 1;

            while (AMethodNames.Contains(methodname))
            {
                methodcounter++;
                methodname = AMethodName + methodcounter.ToString();
            }

            AMethodNames.Add(methodname);

            snippet.SetCodelet("UNIQUEMETHODNAME", methodname);
        }
예제 #2
0
        /// <summary>
        /// write the interfaces for the methods that need to be reflected
        /// check connector files
        /// </summary>
        /// <param name="ATemplate"></param>
        /// <param name="AMethodsAlreadyWritten">write methods only once</param>
        /// <param name="AConnectorClasses">the classes that are implementing the methods</param>
        /// <param name="AInterfaceName">the interface that is written at the moment</param>
        /// <param name="AInterfaceNamespace">only needed to shorten the type names to improve readability</param>
        /// <param name="AServerNamespace">for the comment in the autogenerated code</param>
        /// <returns></returns>
        private bool WriteConnectorMethods(
            ProcessTemplate ATemplate,
            ref StringCollection AMethodsAlreadyWritten,
            List <TypeDeclaration> AConnectorClasses, String AInterfaceName, String AInterfaceNamespace, String AServerNamespace)
        {
            foreach (TypeDeclaration t in AConnectorClasses)
            {
                string ConnectorClassName = t.Name;

                foreach (PropertyDeclaration p in CSParser.GetProperties(t))
                {
                    if (TCollectConnectorInterfaces.IgnoreMethod(p.Attributes, p.Modifier))
                    {
                        continue;
                    }

                    // don't write namespace hierarchy here
                    if (p.TypeReference.Type.IndexOf("Namespace") == -1)
                    {
                        String returnType = AutoGenerationTools.TypeToString(p.TypeReference, AInterfaceNamespace);

                        // this interface got implemented somewhere on the server
                        ProcessTemplate snippet = ATemplate.GetSnippet("CONNECTORPROPERTY");
                        snippet.SetCodelet("CONNECTORCLASSNAME", ConnectorClassName);
                        snippet.SetCodelet("SERVERNAMESPACE", AServerNamespace);
                        snippet.SetCodelet("TYPE", returnType);
                        snippet.SetCodelet("NAME", p.Name);

                        if (p.HasGetRegion)
                        {
                            snippet.SetCodelet("GETTER", "true");
                        }

                        if (p.HasSetRegion)
                        {
                            snippet.SetCodelet("SETTER", "true");
                        }

                        ATemplate.InsertSnippet("CONTENT", snippet);
                    }
                }

                foreach (MethodDeclaration m in CSParser.GetMethods(t))
                {
                    string MethodName = m.Name;

                    if (TCollectConnectorInterfaces.IgnoreMethod(m.Attributes, m.Modifier))
                    {
                        continue;
                    }

                    String formattedMethod = "";
                    String returnType      = AutoGenerationTools.TypeToString(m.TypeReference, AInterfaceNamespace);

                    int align = (returnType + " " + m.Name).Length + 1;

                    // this interface got implemented somewhere on the server
                    formattedMethod = "/// <summary> auto generated from Connector method(" + AServerNamespace + "." + ConnectorClassName +
                                      ")</summary>" + Environment.NewLine;
                    formattedMethod += returnType + " " + m.Name + "(";

                    bool firstParameter = true;

                    foreach (ParameterDeclarationExpression p in m.Parameters)
                    {
                        if (!firstParameter)
                        {
                            ATemplate.AddToCodelet("CONTENT", formattedMethod + "," + Environment.NewLine);
                            formattedMethod = new String(' ', align);
                        }

                        firstParameter = false;
                        String parameterType = AutoGenerationTools.TypeToString(p.TypeReference, "");

                        if ((p.ParamModifier & ParameterModifiers.Ref) != 0)
                        {
                            formattedMethod += "ref ";
                        }
                        else if ((p.ParamModifier & ParameterModifiers.Out) != 0)
                        {
                            formattedMethod += "out ";
                        }

                        formattedMethod += parameterType + " " + p.ParameterName;
                    }

                    formattedMethod += ");";
                    AMethodsAlreadyWritten.Add(MethodName);
                    ATemplate.AddToCodelet("CONTENT", formattedMethod + Environment.NewLine);
                }
            }

            return(true);
        }
예제 #3
0
        private static void ImplementUIConnector(
            SortedList <string, TypeDeclaration> connectors,
            ProcessTemplate ATemplate, string AFullNamespace)
        {
            string ConnectorNamespace = AFullNamespace.
                                        Replace("Instantiator.", string.Empty);

            List <TypeDeclaration> ConnectorClasses = TCollectConnectorInterfaces.FindTypesInNamespace(connectors, ConnectorNamespace);

            ConnectorNamespace = ConnectorNamespace.
                                 Replace(".Shared.", ".Server.");

            foreach (TypeDeclaration connectorClass in ConnectorClasses)
            {
                foreach (ConstructorDeclaration m in CSParser.GetConstructors(connectorClass))
                {
                    if (TCollectConnectorInterfaces.IgnoreMethod(m.Attributes, m.Modifier))
                    {
                        continue;
                    }

                    ProcessTemplate snippet;

                    FModuleHasUIConnector = true;

                    if (FCompileForStandalone)
                    {
                        if (!FUsingNamespaces.ContainsKey(ConnectorNamespace))
                        {
                            FUsingNamespaces.Add(ConnectorNamespace, ConnectorNamespace);
                        }

                        snippet = ATemplate.GetSnippet("UICONNECTORMETHODSTANDALONE");
                    }
                    else
                    {
                        snippet = ATemplate.GetSnippet("UICONNECTORMETHODREMOTE");
                    }

                    string ParameterDefinition = string.Empty;
                    string ActualParameters    = string.Empty;

                    AutoGenerationTools.FormatParameters(m.Parameters, out ActualParameters, out ParameterDefinition);

                    string methodname = m.Name.Substring(1);

                    if (methodname.EndsWith("UIConnector"))
                    {
                        methodname = methodname.Substring(0, methodname.LastIndexOf("UIConnector"));
                    }

                    string interfacename = CSParser.GetImplementedInterface(connectorClass);
                    snippet.SetCodelet("METHODNAME", methodname);
                    snippet.SetCodelet("PARAMETERDEFINITION", ParameterDefinition);
                    snippet.SetCodelet("ACTUALPARAMETERS", ActualParameters);
                    snippet.SetCodelet("UICONNECTORINTERFACE", interfacename);
                    snippet.SetCodelet("UICONNECTORCLASSNAME", connectorClass.Name);

                    snippet.SetCodelet("UICONNECTORCLASS", string.Empty);

                    if (!FCompileForStandalone)
                    {
                        if (!FUIConnectorsAdded.Contains(connectorClass.Name))
                        {
                            FUIConnectorsAdded.Add(connectorClass.Name);

                            snippet.InsertSnippet("UICONNECTORCLASS",
                                                  GenerateUIConnector(ATemplate, connectorClass, interfacename));
                        }
                    }

                    ATemplate.InsertSnippet("CONNECTORMETHODS", snippet);
                }
            }
        }
예제 #4
0
        private static void InsertMethodsAndProperties(ProcessTemplate template, TypeDeclaration t)
        {
            List <string> MethodNames = new List <string>();

            // foreach public method create a method
            foreach (MethodDeclaration m in CSParser.GetMethods(t))
            {
                if (TCollectConnectorInterfaces.IgnoreMethod(m.Attributes, m.Modifier))
                {
                    continue;
                }

                ProcessTemplate methodSnippet = template.GetSnippet("UICONNECTORMETHOD");

                InsertMethodCall(methodSnippet, t, m, ref MethodNames);

                template.InsertSnippet("METHODSANDPROPERTIES", methodSnippet);
            }

            // foreach public property create a method
            foreach (PropertyDeclaration p in CSParser.GetProperties(t))
            {
                if (TCollectConnectorInterfaces.IgnoreMethod(p.Attributes, p.Modifier))
                {
                    continue;
                }

                ProcessTemplate propertySnippet = template.GetSnippet("UICONNECTORPROPERTY");

                string type = AutoGenerationTools.TypeToString(p.TypeReference, string.Empty);
                propertySnippet.SetCodelet("NAME", p.Name);
                propertySnippet.SetCodelet("TYPE", type);

                string expectedreturntype = GetExpectedReturnType(0, AutoGenerationTools.TypeToString(p.TypeReference, string.Empty));

                propertySnippet.SetCodelet("EXPECTEDRETURNTYPE", expectedreturntype);

                if (p.HasGetRegion)
                {
                    if (type.StartsWith("I"))
                    {
                        propertySnippet.SetCodelet(
                            "GETTER",
                            "return new T" + type.Substring(
                                1) +
                            "(\"M{#TOPLEVELMODULE}\", THttpConnector.ReadUIConnectorProperty(FObjectID, \"M{#TOPLEVELMODULE}\", \"{#UICONNECTORCLASSNAME}\", \"{#NAME}\", \"System.String\").ToString());");
                    }
                    else
                    {
                        propertySnippet.SetCodelet(
                            "GETTER",
                            "return ({#TYPE}) THttpConnector.ReadUIConnectorProperty(FObjectID, \"M{#TOPLEVELMODULE}\", \"{#UICONNECTORCLASSNAME}\", \"{#NAME}\", \"{#EXPECTEDRETURNTYPE}\");");
                    }
                }

                if (p.HasSetRegion)
                {
                    propertySnippet.SetCodelet("SETTER", "yes");
                }

                template.InsertSnippet("METHODSANDPROPERTIES", propertySnippet);
            }
        }
예제 #5
0
        /// <summary>
        /// insert a method call
        /// </summary>
        private static void InsertMethodCall(ProcessTemplate snippet, TypeDeclaration connectorClass, MethodDeclaration m,
                                             ref List <string> AMethodNames)
        {
            string ParameterDefinition = string.Empty;
            string ActualParameters    = string.Empty;

            AutoGenerationTools.FormatParameters(m.Parameters, out ActualParameters, out ParameterDefinition);

            // for standalone: add actual parameters directly
            snippet.AddToCodelet("ACTUALPARAMETERS", ActualParameters);

            string returntype = AutoGenerationTools.TypeToString(m.TypeReference, "");

            if (!returntype.Contains("<"))
            {
                returntype = returntype == "string" || returntype == "String" ? "System.String" : returntype;
                returntype = returntype == "bool" || returntype == "Boolean" ? "System.Boolean" : returntype;

                if (returntype.Contains("UINT") || returntype.Contains("unsigned"))
                {
                    returntype = returntype.Contains("UInt32") || returntype == "unsigned int" ? "System.UInt32" : returntype;
                    returntype = returntype.Contains("UInt16") || returntype == "unsigned short" ? "System.UInt16" : returntype;
                    returntype = returntype.Contains("UInt64") || returntype == "unsigned long" ? "System.UInt64" : returntype;
                }
                else
                {
                    returntype = returntype.Contains("Int32") || returntype == "int" ? "System.Int32" : returntype;
                    returntype = returntype.Contains("Int16") || returntype == "short" ? "System.Int16" : returntype;
                    returntype = returntype.Contains("Int64") || returntype == "long" ? "System.Int64" : returntype;
                }

                returntype = returntype.Contains("Decimal") || returntype == "decimal" ? "System.Decimal" : returntype;
            }

            snippet.SetCodelet("RETURN", returntype != "void" ? "return " : string.Empty);

            // avoid duplicate names for webservice methods
            string methodname    = m.Name;
            int    methodcounter = 1;

            while (AMethodNames.Contains(methodname))
            {
                methodcounter++;
                methodname = m.Name + methodcounter.ToString();
            }

            AMethodNames.Add(methodname);

            snippet.SetCodelet("UNIQUEMETHODNAME", methodname);
            snippet.SetCodelet("METHODNAME", m.Name);
            snippet.SetCodelet("PARAMETERDEFINITION", ParameterDefinition);
            snippet.SetCodelet("RETURNTYPE", returntype);
            snippet.SetCodelet("WEBCONNECTORCLASS", connectorClass.Name);
            snippet.SetCodelet("ASSIGNRESULTANDRETURN", string.Empty);
            snippet.SetCodelet("ADDACTUALPARAMETERS", string.Empty);

            int ResultCounter = 0;

            if (CheckServerAdminToken(m))
            {
                snippet.AddToCodelet("ADDACTUALPARAMETERS",
                                     "ActualParameters.Add(\"AServerAdminSecurityToken\", THttpConnector.ServerAdminSecurityToken" +
                                     ");" + Environment.NewLine);
            }

            foreach (ParameterDeclarationExpression p in m.Parameters)
            {
                if (((ParameterModifiers.Ref & p.ParamModifier) > 0) || ((ParameterModifiers.Out & p.ParamModifier) > 0))
                {
                    // need to assign the result to the ref and the out parameter
                    snippet.AddToCodelet("ASSIGNRESULTANDRETURN",
                                         p.ParameterName + " = (" + p.TypeReference.ToString() + ") Result[" + ResultCounter.ToString() + "];" +
                                         Environment.NewLine);
                    ResultCounter++;
                }

                if ((ParameterModifiers.Out & p.ParamModifier) == 0)
                {
                    snippet.AddToCodelet("ADDACTUALPARAMETERS",
                                         "ActualParameters.Add(\"" + p.ParameterName + "\", " +
                                         p.ParameterName + ");" + Environment.NewLine);
                }
            }

            string expectedreturntype = GetExpectedReturnType(ResultCounter, returntype);

            snippet.SetCodelet("EXPECTEDRETURNTYPE", expectedreturntype);
            snippet.SetCodelet("RESULT", string.Empty);

            if ((returntype != "void") || (ResultCounter > 0))
            {
                snippet.SetCodelet("RESULT", "List<object> Result = ");
            }

            if (returntype != "void")
            {
                snippet.AddToCodelet("ASSIGNRESULTANDRETURN",
                                     "return (" + returntype + ") Result[" + ResultCounter.ToString() + "];" + Environment.NewLine);
            }
        }
        private static void InsertMethodsAndProperties(ProcessTemplate template, TypeDeclaration t)
        {
            // foreach public method create a method
            foreach (MethodDeclaration m in CSParser.GetMethods(t))
            {
                if (TCollectConnectorInterfaces.IgnoreMethod(m.Attributes, m.Modifier))
                {
                    continue;
                }

                ProcessTemplate methodSnippet = ClientRemotingClassTemplate.GetSnippet("METHOD");

                string returntype = AutoGenerationTools.TypeToString(m.TypeReference, string.Empty);

                methodSnippet.SetCodelet("METHODNAME", m.Name);
                methodSnippet.SetCodelet("RETURNTYPE", returntype);

                string ParameterDefinition = string.Empty;
                string ActualParameters    = string.Empty;

                AutoGenerationTools.FormatParameters(m.Parameters, out ActualParameters, out ParameterDefinition);

                methodSnippet.SetCodelet("PARAMETERDEFINITION", ParameterDefinition);
                methodSnippet.SetCodelet("ACTUALPARAMETERS", ActualParameters);

                if (returntype != "void")
                {
                    methodSnippet.SetCodelet("RETURN", "return ");
                }
                else
                {
                    methodSnippet.SetCodelet("RETURN", string.Empty);
                }

                template.InsertSnippet("METHODSANDPROPERTIES", methodSnippet);
            }

            // foreach public method create a method
            foreach (PropertyDeclaration p in CSParser.GetProperties(t))
            {
                if (TCollectConnectorInterfaces.IgnoreMethod(p.Attributes, p.Modifier))
                {
                    continue;
                }

                ProcessTemplate propertySnippet = ClientRemotingClassTemplate.GetSnippet("PROPERTY");

                propertySnippet.SetCodelet("NAME", p.Name);
                propertySnippet.SetCodelet("TYPE", AutoGenerationTools.TypeToString(p.TypeReference, string.Empty));

                if (p.HasGetRegion)
                {
                    propertySnippet.SetCodelet("GETTER", "yes");
                }

                if (p.HasSetRegion)
                {
                    propertySnippet.SetCodelet("SETTER", "yes");
                }

                template.InsertSnippet("METHODSANDPROPERTIES", propertySnippet);
            }
        }