示例#1
0
        public void AddRange()
        {
            CodeParameterDeclarationExpression param1 = new CodeParameterDeclarationExpression();
            CodeParameterDeclarationExpression param2 = new CodeParameterDeclarationExpression();
            CodeParameterDeclarationExpression param3 = new CodeParameterDeclarationExpression();

            CodeParameterDeclarationExpressionCollection coll1 = new CodeParameterDeclarationExpressionCollection();

            coll1.Add(param1);
            coll1.Add(param2);

            CodeParameterDeclarationExpressionCollection coll2 = new CodeParameterDeclarationExpressionCollection();

            coll2.Add(param3);
            coll2.AddRange(coll1);
            Assert.AreEqual(3, coll2.Count, "#1");
            Assert.AreEqual(1, coll2.IndexOf(param1), "#2");
            Assert.AreEqual(2, coll2.IndexOf(param2), "#3");
            Assert.AreEqual(0, coll2.IndexOf(param3), "#4");

            CodeParameterDeclarationExpressionCollection coll3 = new CodeParameterDeclarationExpressionCollection();

            coll3.Add(param3);
            coll3.AddRange(new CodeParameterDeclarationExpression[] { param1, param2 });
            Assert.AreEqual(3, coll2.Count, "#5");
            Assert.AreEqual(1, coll2.IndexOf(param1), "#6");
            Assert.AreEqual(2, coll2.IndexOf(param2), "#7");
            Assert.AreEqual(0, coll2.IndexOf(param3), "#8");
        }
 public DynaArgumentCollection(DynaArgument[] args)
     : this()
 {
     foreach (DynaArgument arg in args)
     {
         codeArgs.Add(arg.CodeArgument);
     }
 }
        public CodeParameterDeclarationExpressionCollection GenerateOnEventMethodInputParameters(TibcoBWProcess tibcoBwProcessToGenerate)
        {
            var parameters = new CodeParameterDeclarationExpressionCollection();

            parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference(CSharpTypeConstant.SystemObject), "sender"));
            parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference("System.EventArgs"), "args"));

            return(parameters);
        }
示例#4
0
        private CodeParameterDeclarationExpressionCollection GenerateParametters(List <GameDataVariable> variables)
        {
            CodeParameterDeclarationExpressionCollection retVal = new CodeParameterDeclarationExpressionCollection();

            retVal.Add(new CodeParameterDeclarationExpression(typeof(string), "I18nFile"));
            foreach (var v in variables)
            {
                retVal.Add(GetParametter(v));
            }
            return(retVal);
        }
示例#5
0
        public void Add()
        {
            CodeParameterDeclarationExpression param1 = new CodeParameterDeclarationExpression();
            CodeParameterDeclarationExpression param2 = new CodeParameterDeclarationExpression();

            CodeParameterDeclarationExpressionCollection coll = new CodeParameterDeclarationExpressionCollection();

            Assert.AreEqual(0, coll.Add(param1), "#1");
            Assert.AreEqual(1, coll.Count, "#2");
            Assert.AreEqual(0, coll.IndexOf(param1), "#3");

            Assert.AreEqual(1, coll.Add(param2), "#4");
            Assert.AreEqual(2, coll.Count, "#5");
            Assert.AreEqual(1, coll.IndexOf(param2), "#6");
        }
        /// <summary>
        /// Generates a CodeParameterDeclarationExpresseionCollection from a semicolon separated string of
        /// comma delimited type-name value pair argument strings.
        /// </summary>
        /// <param name="paramDeclArgs"></param>
        /// <returns></returns>
        private static CodeParameterDeclarationExpressionCollection GetCodeParameterDeclaraionExpressions(string paramDeclsArgs)
        {
            CodeParameterDeclarationExpressionCollection parameters = null;

            if (paramDeclsArgs != "null")
            {
                parameters = new CodeParameterDeclarationExpressionCollection();

                string[] paramDecls = paramDeclsArgs.Split(new char[] { ';' });
                foreach (string paramDecl in paramDecls)
                {
                    if (paramDecl != "")
                    {
                        string[] args = paramDecl.Split(new char[] { ',' });
                        Assert.AreEqual(args.Length, 2, "Params definition file not in the correct format!");
                        CodeParameterDeclarationExpression codeParam = new CodeParameterDeclarationExpression(args[0], args[1]);
                        parameters.Add(codeParam);
                    }
                    // else  Note: setting an empty CodeParamDeclExp creates a 'void' param (we don't do this for code gen)
                    // codeParam = new CodeParameterDeclarationExpression();
                }
            }

            return(parameters);
        }
示例#7
0
        public CodeParameterDeclarationExpressionCollection AddParameters(CodeParameterDeclarationExpressionCollection collection, params object[] paramNameValue)
        {
            int j = paramNameValue.GetLength(0);

            if (j % 2 == 1)
            {
                j--;
            }
            CodeTypeReference name;
            string            val;

            for (int i = 0; i < j; i += 2)
            {
                name = NewType(paramNameValue[i]);
                if (paramNameValue[i + 1].GetType() == typeof(ArgRef))
                {
                    //val = ((ArgRef)paramNameValue[i+1]).ParameterName;
                    val = ((ArgRef)paramNameValue[i + 1]);
                }
                else
                {
                    val = paramNameValue[i + 1].ToString();
                }
                collection.Add(new CodeParameterDeclarationExpression(name, val));
            }
            return(collection);
        }
示例#8
0
 public static void Add(this CodeParameterDeclarationExpressionCollection collection, IEnumerable <ColumnInfo> columns)
 {
     foreach (var item in columns)
     {
         collection.Add(new CodeParameterDeclarationExpression(item.GetCodeType(), item.Name));
     }
 }
示例#9
0
        public void Constructor2()
        {
            CodeParameterDeclarationExpression param1 = new CodeParameterDeclarationExpression();
            CodeParameterDeclarationExpression param2 = new CodeParameterDeclarationExpression();

            CodeParameterDeclarationExpressionCollection c = new CodeParameterDeclarationExpressionCollection();

            c.Add(param1);
            c.Add(param2);

            CodeParameterDeclarationExpressionCollection coll = new CodeParameterDeclarationExpressionCollection(c);

            Assert.AreEqual(2, coll.Count, "#1");
            Assert.AreEqual(0, coll.IndexOf(param1), "#2");
            Assert.AreEqual(1, coll.IndexOf(param2), "#3");
        }
示例#10
0
        private CodeParameterDeclarationExpressionCollection GenerateParameters(NativeSignature ntSig, ref string comments)
        {
            ThrowIfNull(ntSig);
            if (comments == null)
            {
                comments = string.Empty;
            }

            CodeParameterDeclarationExpressionCollection col = new CodeParameterDeclarationExpressionCollection();
            Int32 count = 0;

            foreach (NativeParameter ntParam in ntSig.Parameters)
            {
                string comment = null;
                CodeParameterDeclarationExpression param = new CodeParameterDeclarationExpression();
                param.Name = ntParam.Name;
                param.Type = GenerateTypeReferenceImpl(ntParam.NativeType, ref comment);
                param.UserData[TransformConstants.Param] = ntParam;
                col.Add(param);

                if (string.IsNullOrEmpty(param.Name))
                {
                    param.Name = "param" + count;
                }

                // Add the type comment to the procedure
                comments += Environment.NewLine;
                comments += param.Name + ": " + comment;
                count    += 1;
            }

            return(col);
        }
示例#11
0
文件: driver.cs 项目: surak8/cdtest
 static void populateParmList(CodeParameterDeclarationExpressionCollection parms, CodeTypeDelegate ctdDel)
 {
     foreach (CodeParameterDeclarationExpression cpde in ctdDel.Parameters)
     {
         parms.Add(cpde);
     }
 }
 internal override void AddToConstructor(CodeConstructor functionalConstructor)
 {
     if (!this.IsList)
     {
         functionalConstructor.Parameters.Add(new CodeParameterDeclarationExpression(this.ReturnType, this.propertyName));
         if (!this.FromBaseType)
         {
             functionalConstructor.Statements.Add(new CodeAssignStatement(CodeDomHelper.CreateFieldReference("this", this.propertyName), new CodeVariableReferenceExpression(this.propertyName)));
         }
         else
         {
             functionalConstructor.BaseConstructorArgs.Add(new CodeVariableReferenceExpression(this.propertyName));
         }
     }
     else
     {
         CodeParameterDeclarationExpressionCollection parameters = functionalConstructor.Parameters;
         CodeTypeReference[] codeTypeReference = new CodeTypeReference[] { new CodeTypeReference(this.clrTypeName) };
         parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference("IEnumerable", codeTypeReference), this.propertyName));
         if (!this.FromBaseType)
         {
             CodeTypeReference listType = this.GetListType();
             functionalConstructor.Statements.Add(new CodeAssignStatement(CodeDomHelper.CreateFieldReference("this", NameGenerator.ChangeClrName(this.propertyName, NameOptions.MakeField)), new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(listType), "Initialize", this.GetListParameters(true, true))));
         }
         else
         {
             functionalConstructor.BaseConstructorArgs.Add(new CodeVariableReferenceExpression(this.propertyName));
         }
     }
 }
        protected CodeParameterDeclarationExpressionCollection GetParametersList(XSharpParser.ParameterListContext paramList)
        {
            CodeParameterDeclarationExpressionCollection pList = new CodeParameterDeclarationExpressionCollection();

            //
            if (paramList != null)
            {
                foreach (var param in paramList._Params)
                {
                    CodeParameterDeclarationExpression pm = new CodeParameterDeclarationExpression();
                    pm.Name      = param.Id.GetText();
                    pm.Type      = BuildDataType(param.Type);
                    pm.Direction = FieldDirection.In;
                    if (param.Modifiers != null)
                    {
                        if (param.Modifiers.REF() != null)
                        {
                            pm.Direction = FieldDirection.Ref;
                        }
                        else if (param.Modifiers.OUT() != null)
                        {
                            pm.Direction = FieldDirection.Out;
                        }
                    }
                    //
                    pList.Add(pm);
                }
            }
            //
            return(pList);
        }
示例#14
0
        public void Remove()
        {
            CodeParameterDeclarationExpression cpde1 = new CodeParameterDeclarationExpression();
            CodeParameterDeclarationExpression cpde2 = new CodeParameterDeclarationExpression();

            CodeParameterDeclarationExpressionCollection coll = new CodeParameterDeclarationExpressionCollection();

            coll.Add(cpde1);
            coll.Add(cpde2);
            Assert.AreEqual(2, coll.Count, "#1");
            Assert.AreEqual(0, coll.IndexOf(cpde1), "#2");
            Assert.AreEqual(1, coll.IndexOf(cpde2), "#3");
            coll.Remove(cpde1);
            Assert.AreEqual(1, coll.Count, "#4");
            Assert.AreEqual(-1, coll.IndexOf(cpde1), "#5");
            Assert.AreEqual(0, coll.IndexOf(cpde2), "#6");
        }
示例#15
0
 public void CloneParameters(CodeParameterDeclarationExpressionCollection source, CodeParameterDeclarationExpressionCollection dest)
 {
     dest.Clear();
     foreach (CodeParam param in source)
     {
         dest.Add(CloneParam(param));
     }
 }
示例#16
0
        public void AddRange_Self()
        {
            CodeParameterDeclarationExpressionCollection coll = new CodeParameterDeclarationExpressionCollection();

            coll.Add(new CodeParameterDeclarationExpression());
            Assert.AreEqual(1, coll.Count, "#1");
            coll.AddRange(coll);
            Assert.AreEqual(2, coll.Count, "#2");
        }
        public CodeParameterDeclarationExpressionCollection GenerateMethodsParameters()
        {
            var sqlQuery          = new CodeParameterDeclarationExpression(CSharpTypeConstant.SystemString, "query");
            var sqlQueryParameter = new CodeParameterDeclarationExpression()
            {
                Type = new CodeTypeReference(CSharpTypeConstant.SystemObject),
                Name = "paramater = null",
                // TODO : find a way to do it properly
                //				CustomAttributes = new CodeAttributeDeclarationCollection {
                //					new CodeAttributeDeclaration ("Optional")
                //				}
            };
            var parameters = new CodeParameterDeclarationExpressionCollection();

            parameters.Add(sqlQuery);
            parameters.Add(sqlQueryParameter);
            return(parameters);
        }
示例#18
0
        private void addParamToDeclaration(EventType evt, ParameterType param, CodeParameterDeclarationExpressionCollection targetCollection)
        {
            //todo add param to the collection
            setParamName(evt, param);

            CodeParameterDeclarationExpression _type = new CodeParameterDeclarationExpression(GetTypeReference(param.type), param.name);

            targetCollection.Add(_type);
        }
示例#19
0
        // CodeParameterDeclarationExpressionCollection helpers
        // -- this one is possibly dangerous?
        public static CodeParameterDeclarationExpressionCollection CreateParameterList(params object[] parameters)
        {
            // must have an even number of arguments for
            // a list of pairs to be valid
            if (parameters.Length % 2 != 0)
            {
                throw new ArgumentException("Must supply an even number of arguments.");
            }

            CodeParameterDeclarationExpressionCollection exps =
                new CodeParameterDeclarationExpressionCollection();

            for (Int32 i = 0; i < parameters.Length; i += 2)
            {
                if (!typeof(string).IsInstanceOfType(parameters[i + 1]))
                {
                    throw new ArgumentException(String.Format(CultureInfo.InvariantCulture,
                                                              "Argument {0} should be of type string.", i + 1));
                }

                if (typeof(Type).IsInstanceOfType(parameters[i]))
                {
                    exps.Add(new CodeParameterDeclarationExpression(
                                 (Type)parameters[i], (string)parameters[i + 1]));
                }
                else if (typeof(string).IsInstanceOfType(parameters[i]))
                {
                    exps.Add(new CodeParameterDeclarationExpression(
                                 (string)parameters[i], (string)parameters[i + 1]));
                }
                else if (typeof(CodeTypeReference).IsInstanceOfType(parameters[i]))
                {
                    exps.Add(new CodeParameterDeclarationExpression(
                                 (CodeTypeReference)parameters[i], (string)parameters[i + 1]));
                }
                else
                {
                    throw new ArgumentException(String.Format(CultureInfo.InvariantCulture,
                                                              "Argument {0} should be of Type, string, or CodeTypeReference.", i));
                }
            }

            return(exps);
        }
示例#20
0
        static void PopulateMethodParameters(IMethodSignature member,
                                             CodeParameterDeclarationExpressionCollection parameters,
                                             HashSet <string> excludeAttributes,
                                             bool isExtension = false)
        {
            foreach (var parameter in member.Parameters)
            {
                FieldDirection direction = 0;
                if (parameter.IsOut)
                {
                    direction |= FieldDirection.Out;
                }
                else if (parameter.ParameterType.IsByReference)
                {
                    direction |= FieldDirection.Ref;
                }

                var parameterType = parameter.ParameterType;
                if (parameterType is RequiredModifierType requiredModifierType)
                {
                    parameterType = requiredModifierType.ElementType;
                }
                // order is crucial because a RequiredModifierType can be a ByReferenceType
                if (parameterType is ByReferenceType byReferenceType)
                {
                    parameterType = byReferenceType.ElementType;
                }

                var type = CreateCodeTypeReference(parameterType);

                if (isExtension)
                {
                    type        = ModifyCodeTypeReference(type, "this");
                    isExtension = false;
                }

                // special case of ref is in
                // TODO: Move CustomAttributes.Any(a => a.AttributeType.FullName == "System.Runtime.CompilerServices.IsReadOnlyAttribute") to extension method once other PR is merged
                if (parameter.CustomAttributes.Any(a =>
                                                   a.AttributeType.FullName == "System.Runtime.CompilerServices.IsReadOnlyAttribute"))
                {
                    type      = ModifyCodeTypeReference(type, "in");
                    direction = FieldDirection.In;
                }

                var name = parameter.HasConstant
                    ? string.Format(CultureInfo.InvariantCulture, "{0} = {1}", parameter.Name, FormatParameterConstant(parameter))
                    : parameter.Name;
                var expression = new CodeParameterDeclarationExpression(type, name)
                {
                    Direction        = direction,
                    CustomAttributes = CreateCustomAttributes(parameter, excludeAttributes)
                };
                parameters.Add(expression);
            }
        }
示例#21
0
        /// <summary>
        /// Adds a method invoke expression and a partial method definition based on the specified base method name
        /// to the internal method collection.
        /// </summary>
        /// <param name="baseMethodName">base method name w/o the On prefix (like Created for OnCreated)</param>
        /// <param name="parameterDeclaration">parameter declaration for the only param of the method to be generated</param>
        /// <param name="comments">the comments for the partial property definition</param>
        public void AddMethodFor(string baseMethodName, CodeParameterDeclarationExpression parameterDeclaration, string comments)
        {
            CodeParameterDeclarationExpressionCollection parameters = new CodeParameterDeclarationExpressionCollection();

            if (parameterDeclaration != null)
            {
                parameters.Add(parameterDeclaration);
            }

            this.AddMethodFor(baseMethodName, parameters, comments);
        }
示例#22
0
        public CodeNamespace Build()
        {
            var namespaceResult = new CodeNamespace(TargetAppNameSpaceService.loggerNameSpace());

            namespaceResult.Imports.Add(new CodeNamespaceImport("System"));
            var dataAccessInterface = new CodeTypeDeclaration();

            dataAccessInterface.Name        = "ILogger";
            dataAccessInterface.IsInterface = true;

            var message = new CodeParameterDeclarationExpression("System.String", "message");

            var parameters = new CodeParameterDeclarationExpressionCollection();

            parameters.Add(message);

            var voidReturnType = new CodeTypeReference(CSharpTypeConstant.SystemVoid);

            var debugMethod = new CodeMemberMethod {
                Name = "Debug", ReturnType = voidReturnType
            };

            debugMethod.Parameters.AddRange(parameters);
            dataAccessInterface.Members.Add(debugMethod);

            var infoMethod = new CodeMemberMethod {
                Name = "Info", ReturnType = voidReturnType
            };

            infoMethod.Parameters.AddRange(parameters);
            dataAccessInterface.Members.Add(infoMethod);

            var errorMethod = new CodeMemberMethod {
                Name = "Error", ReturnType = voidReturnType
            };

            errorMethod.Parameters.AddRange(parameters);
            dataAccessInterface.Members.Add(errorMethod);

            var warnMethod = new CodeMemberMethod {
                Name = "Warning", ReturnType = voidReturnType
            };

            warnMethod.Parameters.AddRange(parameters);
            dataAccessInterface.Members.Add(warnMethod);

            namespaceResult.Types.Add(dataAccessInterface);

            return(namespaceResult);
        }
示例#23
0
        public void Constructor1_Deny_Unrestricted()
        {
            CodeParameterDeclarationExpressionCollection coll = new CodeParameterDeclarationExpressionCollection(array);

            coll.CopyTo(array, 0);
            Assert.AreEqual(1, coll.Add(cpde), "Add");
            Assert.AreSame(cpde, coll[0], "this[int]");
            coll.AddRange(array);
            coll.AddRange(coll);
            Assert.IsTrue(coll.Contains(cpde), "Contains");
            Assert.AreEqual(0, coll.IndexOf(cpde), "IndexOf");
            coll.Insert(0, cpde);
            coll.Remove(cpde);
        }
示例#24
0
        public static CodeParameterDeclarationExpressionCollection Clone(this CodeParameterDeclarationExpressionCollection collection)
        {
            if (collection == null)
            {
                return(null);
            }
            CodeParameterDeclarationExpressionCollection c = new CodeParameterDeclarationExpressionCollection();

            foreach (CodeParameterDeclarationExpression expression in collection)
            {
                c.Add(expression.Clone());
            }
            return(c);
        }
        /// <summary>
        /// Generate the method and add to code compile unit
        /// </summary>
        /// <param name="component"></param>
        /// <param name="e"></param>
        /// <param name="methodName"></param>
        /// <param name="addMethod"></param>
        private void Generate(IComponent component, EventDescriptor e, string methodName, bool addMethod)
        {
            TypeProvider    typeProvider = (TypeProvider)this.serviceProvider.GetService(typeof(ITypeProvider));
            CodeCompileUnit ccu          = this.loader.CodeBesideCCU;

            Type       delegateType = e.EventType;
            MethodInfo invokeInfo   = delegateType.GetMethod("Invoke");

            Type returnType = invokeInfo.ReturnType;

            MemberAttributes   modifiers     = MemberAttributes.Private;
            PropertyDescriptor modifiersProp = TypeDescriptor.GetProperties(component)["DefaultEventModifiers"];

            if (modifiersProp != null && modifiersProp.PropertyType == typeof(MemberAttributes))
            {
                modifiers = (MemberAttributes)modifiersProp.GetValue(component);
            }

            CodeParameterDeclarationExpressionCollection paramCollection = new CodeParameterDeclarationExpressionCollection();

            foreach (ParameterInfo paramInfo in invokeInfo.GetParameters())
            {
                CodeParameterDeclarationExpression codeParamExpression = new CodeParameterDeclarationExpression();
                codeParamExpression.Name = paramInfo.Name;
                codeParamExpression.Type = new CodeTypeReference(paramInfo.ParameterType);

                paramCollection.Add(codeParamExpression);
            }

            // create code member method
            CodeMemberMethod method = new CodeMemberMethod();

            method.Name = methodName;
            method.Parameters.AddRange(paramCollection);
            method.ReturnType = new CodeTypeReference(returnType);
            method.Attributes = modifiers;

            if (addMethod)
            {
                // The assumption here is that we have only one namespace and type being designed
                ccu.Namespaces[0].Types[0].Members.Add(method);
            }
            else
            {
                ccu.Namespaces[0].Types[0].Members.Remove(method);
            }

            typeProvider.RefreshCodeCompileUnit(this.loader.CodeBesideCCU, new EventHandler(RefreshCCU));
        }
        private void RemoveDuplicateParameters(CodeParameterDeclarationExpressionCollection parameters)
        {
            var toKeep = parameters
                         .Cast <CodeParameterDeclarationExpression>()
                         .GroupBy(x => new { x.Name })
                         .SelectMany(x => x.Take(1))
                         .ToArray();

            parameters.Clear();

            foreach (var objToKeep in toKeep)
            {
                parameters.Add(objToKeep);
            }
        }
示例#27
0
        //public static T ParamRef<T>(string name)
        //{
        //    return default(T);
        //}

        internal static T GetMethodName <T>(LambdaExpression exp, CodeParameterDeclarationExpressionCollection pars)
        {
            foreach (var p in exp.Parameters)
            {
                var par = new CodeParameterDeclarationExpression(p.Type, p.Name);

                if (typeof(IRefParam).IsAssignableFrom(p.Type))
                {
                    par.Direction = FieldDirection.Ref;
                }

                if (typeof(IOutParam).IsAssignableFrom(p.Type))
                {
                    par.Direction = FieldDirection.Out;
                }

                if (typeof(IParamArray).IsAssignableFrom(p.Type))
                {
                    par.CustomAttributes.Add(Define.Attribute(typeof(ParamArrayAttribute)));
                }

                if (p.Type.IsGenericType && (
                        p.Type.GetGenericTypeDefinition() == typeof(RefParam <>) ||
                        p.Type.GetGenericTypeDefinition() == typeof(OutParam <>) ||
                        p.Type.GetGenericTypeDefinition() == typeof(ParamArray <>))
                    )
                {
                    Type rt = p.Type.GetGenericArguments()[0];

                    if (p.Type.GetGenericTypeDefinition() == typeof(ParamArray <>) &&
                        !rt.IsArray)
                    {
                        par.Type = new CodeTypeReference(rt.ToString() + "[]");
                    }
                    else
                    {
                        par.Type = new CodeTypeReference(rt);
                    }
                }

                //if (typeof(IParamArray).IsAssignableFrom(p.Type))
                //    pars.Add()
                //else
                //    pars.Add(par);
                pars.Add(par);
            }
            return(Eval <T>(exp, pars));
        }
        public CodeParameterDeclarationExpressionCollection GenerateStartMethodInputParameters(TibcoBWProcess tibcoBwProcessToGenerate)
        {
            var parameters = new CodeParameterDeclarationExpressionCollection();

            if (tibcoBwProcessToGenerate.StartActivity != null && tibcoBwProcessToGenerate.StartActivity.Parameters != null)
            {
                foreach (var parameter in tibcoBwProcessToGenerate.StartActivity.Parameters)
                {
                    parameters.Add(new CodeParameterDeclarationExpression
                    {
                        Name = "start_" + parameter.Name,
                        Type = new CodeTypeReference(parameter.Type)
                    });
                }
            }

            return(parameters);
        }
示例#29
0
        public static CodeParameterDeclarationExpressionCollection ConvertQueryStatementParameter(Dictionary <string, string> queryStatementParameters)
        {
            var methodInputParameters = new CodeParameterDeclarationExpressionCollection();

            if (queryStatementParameters == null)
            {
                return(methodInputParameters);
            }
            foreach (var queryParam in queryStatementParameters)
            {
                methodInputParameters.Add(new CodeParameterDeclarationExpression
                {
                    Name = VariableHelper.ToVariableName(queryParam.Key),
                    Type = ConvertSQLTypeToObjectType(queryParam.Value)
                });
            }

            return(methodInputParameters);
        }
示例#30
0
        static void PopulateMethodParameters(IMethodSignature member,
                                             CodeParameterDeclarationExpressionCollection parameters,
                                             HashSet <string> excludeAttributes,
                                             bool isExtension = false)
        {
            foreach (var parameter in member.Parameters)
            {
                FieldDirection direction = 0;
                if (parameter.IsOut)
                {
                    direction |= FieldDirection.Out;
                }
                else if (parameter.ParameterType.IsByReference)
                {
                    direction |= FieldDirection.Ref;
                }

                var parameterType = parameter.ParameterType.IsByReference
                    ? parameter.ParameterType.GetElementType()
                    : parameter.ParameterType;

                var type = CreateCodeTypeReference(parameterType);

                if (isExtension)
                {
                    type        = ModifyCodeTypeReference(type, "this");
                    isExtension = false;
                }

                var name = parameter.HasConstant
                    ? string.Format(CultureInfo.InvariantCulture, "{0} = {1}", parameter.Name, FormatParameterConstant(parameter))
                    : parameter.Name;
                var expression = new CodeParameterDeclarationExpression(type, name)
                {
                    Direction        = direction,
                    CustomAttributes = CreateCustomAttributes(parameter, excludeAttributes)
                };
                parameters.Add(expression);
            }
        }
示例#31
0
    public CodeMemberMethod GenerateBasicMethodDefinition(Smoke* smoke, Smoke.Method* method, string cppSignature,
	                                                      CodeTypeReference iface)
    {
        // do we actually want that method?
        string className = ByteArrayManager.GetString(smokeClass->className);
        string completeSignature = className + "::" + cppSignature;
        if (translator.ExcludedMethods.Any(regex => regex.IsMatch(completeSignature)))
        {
            return null;
        }

        CodeParameterDeclarationExpressionCollection args = new CodeParameterDeclarationExpressionCollection();
        int count = 1;
        bool isRef;

        // make instance operators static and bring the arguments in the correct order
        string methName = ByteArrayManager.GetString(smoke->methodNames[method->name]);
        bool isOperator = false;
        string explicitConversionType = null;
        if (methName.StartsWith("operator"))
        {
            string op = methName.Substring(8);
            if (unsupportedOperators.Contains(op))
            {
                // not supported
                Debug.Print("  |--Won't wrap method {0}::{1}", className, cppSignature);
                return null;
            }

            if (op == "<<")
            {
                methName = "Write";
            }
            else if (op == ">>")
            {
                methName = "Read";
            }

            // binary/unary operator
            if (binaryOperators.Contains(op) || unaryOperators.Contains(op))
            {
                // instance operator
                if (smoke->classes[method->classId].size > 0)
                {
                    if (op == "*" && method->numArgs == 0 || (op == "++" || op == "--") && method->numArgs == 1)
                    {
                        // dereference operator and postfix in-/decrement operator are not supported
                        Debug.Print("  |--Won't wrap method {0}::{1}", className, cppSignature);
                        return null;
                    }

                    try
                    {
                        CodeParameterDeclarationExpression exp =
                            new CodeParameterDeclarationExpression(translator.CppToCSharp(className, type, out isRef), "one");
                        args.Add(exp);
                    }
                    catch (NotSupportedException)
                    {
                        Debug.Print("  |--Won't wrap method {0}::{1}", className, cppSignature);
                        return null;
                    }
                }
                else
                {
                    // global operator
                    if (op == "*" && method->numArgs == 0 || (op == "++" || op == "--") && method->numArgs == 2)
                    {
                        // dereference operator and postfix in-/decrement operator are not supported
                        Debug.Print("  |--Won't wrap method {0}::{1}", className, cppSignature);
                        return null;
                    }
                }
                isOperator = true;
            }
            else if (op[0] == ' ')
            {
                // conversion operator
                explicitConversionType = op.Substring(1);
                if (explicitConversionType.Contains("QVariant"))
                {
                    return null;
                }
                try
                {
                    explicitConversionType = translator.CppToCSharp(explicitConversionType, type, out isRef).GetStringRepresentation();
                    if (smoke->classes[method->classId].size > 0)
                    {
                        CodeParameterDeclarationExpression exp =
                            new CodeParameterDeclarationExpression(translator.CppToCSharp(className, type, out isRef), "value");
                        args.Add(exp);
                    }
                }
                catch (NotSupportedException)
                {
                    Debug.Print("  |--Won't wrap method {0}::{1}", className, cppSignature);
                    return null;
                }
                isOperator = true;
            }
        }

        // translate return type
        CodeTypeReference returnType;
        try
        {
            returnType = translator.CppToCSharp(smoke->types + method->ret, type, out isRef);
        }
        catch (NotSupportedException)
        {
            Debug.Print("  |--Won't wrap method {0}::{1}", className, cppSignature);
            return null;
        }

        CodeMemberMethod cmm;
        if ((method->flags & (uint) Smoke.MethodFlags.mf_ctor) > 0)
        {
            cmm = new CodeConstructor();
            cmm.Attributes = 0; // initialize to 0 so we can do |=
            ((CodeConstructor) cmm).ChainedConstructorArgs.Add(new CodeSnippetExpression("(System.Type) null"));
        }
        else
        {
            cmm = new CodeMemberMethod();
            cmm.Attributes = 0; // initialize to 0 so we can do |=

            string csName = methName;
            if (!isOperator && methName != "finalize")
            {
                // capitalize the first letter
                StringBuilder builder = new StringBuilder(csName);
                builder[0] = char.ToUpper(builder[0]);
                string tmp = builder.ToString();

                // If the new name clashes with a name of a type declaration, keep the lower-case name.
                var typesWithSameName = from member in data.GetAccessibleMembers(smokeClass)
                                        where member.Type == MemberTypes.NestedType && member.Name == tmp
                                        select member;

                var propertiesWithSameName = (from member in data.GetAccessibleMembers(smokeClass)
                                              where member.Type == MemberTypes.Property && member.Name == tmp
                                              select member).ToList();

                if (iface != null && propertiesWithSameName.Count() == 1 &&
                    (method->flags & (uint) Smoke.MethodFlags.mf_protected) == 0 &&
                    (method->flags & (uint) Smoke.MethodFlags.mf_virtual) == 0)
                {
                    cmm.PrivateImplementationType = iface;
                    csName = tmp;
                }
                else
                {
                    if (propertiesWithSameName.Any())
                    {
                        if ((method->flags & (uint) Smoke.MethodFlags.mf_virtual) == 0)
                        {
                            Debug.Print(
                                "  |--Conflicting names: method/(type or property): {0} in class {1} - keeping original method name", tmp,
                                className);
                        }
                        else
                        {
                            csName = tmp;
                        }
                    }
                    else if (typesWithSameName.Any())
                    {
                        Debug.Print("  |--Conflicting names: method/classname: {0} in class {1} - keeping original method name", tmp,
                                    className);
                    }
                    else
                    {
                        csName = tmp;
                    }
                }
            }

            if (explicitConversionType != null)
            {
                cmm.Name = "explicit operator " + explicitConversionType;
                cmm.ReturnType = new CodeTypeReference(" ");
            }
            else
            {
                cmm.Name = csName;
                cmm.ReturnType = returnType;
            }
        }

        // translate arguments
        string[] methodArgs = this.GetMethodArgs(smoke, method);
        for (short* typeIndex = smoke->argumentList + method->args; *typeIndex > 0; typeIndex++)
        {
            try
            {
                args.Add(this.GetArgument(smoke, typeIndex, methodArgs, args, ref count));
            }
            catch (NotSupportedException)
            {
                Debug.Print("  |--Won't wrap method {0}::{1}", className, cppSignature);
                return null;
            }
        }
        this.RemovePreviousOverload(args, cmm.Name);

        // for destructors we already have this stuff set
        if ((method->flags & (uint) Smoke.MethodFlags.mf_dtor) == 0)
        {
            // set access
            if ((method->flags & (uint) Smoke.MethodFlags.mf_protected) > 0)
            {
                cmm.Attributes |= MemberAttributes.Family;
            }
            else
            {
                cmm.Attributes |= MemberAttributes.Public;
            }

            if (isOperator)
            {
                cmm.Attributes |= MemberAttributes.Final | MemberAttributes.Static;
            }
            else if (cmm.Name == "ToString" && args.Count == 0 && cmm.ReturnType.BaseType == "System.String")
            {
                cmm.Attributes = MemberAttributes.Public | MemberAttributes.Override;
            }
            else
            {
                if ((method->flags & (uint) Smoke.MethodFlags.mf_static) > 0)
                {
                    cmm.Attributes |= MemberAttributes.Static;
                }
                else
                {
                    // virtual/final
                    MemberAttributes access;
                    bool foundInInterface;
                    bool isOverride = MethodOverrides(smoke, method, out access, out foundInInterface);

                    // methods that have to be implemented from interfaces can't override anything
                    if (iface == null && isOverride)
                    {
                        cmm.Attributes = access | MemberAttributes.Override;
                    }
                    else if (foundInInterface)
                    {
                        cmm.Attributes = access;
                    }

                    if ((method->flags & (uint) Smoke.MethodFlags.mf_purevirtual) > 0)
                    {
                        if (!m_internalImplementation)
                        {
                            cmm.Attributes = (cmm.Attributes & ~MemberAttributes.ScopeMask) | MemberAttributes.Abstract;

                            // The code generator doesn't like MemberAttributes.Abstract | MemberAttributes.Override being set.
                            if (isOverride && !type.IsInterface)
                            {
                                cmm.ReturnType.BaseType = "override " + cmm.ReturnType.BaseType == "System.Void"
                                                          	? "void"
                                                          	: cmm.ReturnType.BaseType;
                            }
                        }
                        else
                        {
                            cmm.Attributes |= MemberAttributes.Override;
                        }
                    }

                    if ((method->flags & (uint) Smoke.MethodFlags.mf_virtual) == 0 &&
                        (method->flags & (uint) Smoke.MethodFlags.mf_purevirtual) == 0 &&
                        !isOverride)
                    {
                        cmm.Attributes |= MemberAttributes.Final | MemberAttributes.New;
                    }
                }
            }
        }
        else
        {
            // hack, so we don't have to use CodeSnippetTypeMember to generator the destructor
            cmm.ReturnType = new CodeTypeReference(" ");
        }

        // add the parameters
        foreach (CodeParameterDeclarationExpression exp in args)
        {
            cmm.Parameters.Add(exp);
        }
        this.DocumentMemberFromInterface(iface, cmm);
        this.DistributeMethod(cmm);
        if (PostMethodDefinitionHooks != null)
        {
            PostMethodDefinitionHooks(smoke, method, cmm, this.type);
        }
        this.CorrectParameterNames(cmm);
        return cmm;
    }