Add() public method

public Add ( CodeParameterDeclarationExpression value ) : int
value CodeParameterDeclarationExpression
return int
 public CodeParameterDeclarationExpressionCollection GenerateMethodsParameters()
 {
     var sqlQuery = new CodeParameterDeclarationExpression ("System.String", "query");
     var sqlQueryParameter = new CodeParameterDeclarationExpression () {
         Type = new CodeTypeReference ("System.Object"),
         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;
 }
 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;
 }
示例#3
0
        public CodeParameterDeclarationExpressionCollection ToCodeParameterDeclarationExpressionCollection()
        {
            CodeParameterDeclarationExpressionCollection collection = new CodeParameterDeclarationExpressionCollection();

            for (Node n = normal; n != null; n = n.nd_next)
                collection.Add(new CodeParameterDeclarationExpression(typeof(object), ((StaticLocalVar)n).vid));

            // Fixme: add other parameters here

            return collection;
        }
		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);
		}
 public 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 = this.ConvertSQLTypeToObjectType(queryParam.Value)
         });
     }
     return methodInputParameters;
 }
 private CodeParameterDeclarationExpressionCollection GetParametersList(XSharpParser.ParameterListContext paramList)
 {
     CodeParameterDeclarationExpressionCollection pList = new CodeParameterDeclarationExpressionCollection();
     //
     foreach (var param in paramList._Params)
     {
         CodeParameterDeclarationExpression pm = new CodeParameterDeclarationExpression();
         pm.Name = param.Id.GetText();
         pm.Type = BuildDataType(param.Type); // new CodeTypeReference(param.Type.GetText());
         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;
 }
        /// <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);
        }
        private static void PopulateMethodParameters(IMethodSignature member,
            CodeParameterDeclarationExpressionCollection parameters, 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("{0} = {1}", parameter.Name, FormatParameterConstant(parameter))
                    : parameter.Name;
                var expression = new CodeParameterDeclarationExpression(type, name)
                {
                    Direction = direction,
                    CustomAttributes = CreateCustomAttributes(parameter)
                };
                parameters.Add(expression);
            }
        }
        public virtual CodeParameterDeclarationExpression AddParameter(CodeParameterDeclarationExpressionCollection parameters
            , string idlArgName, string idlArgDirection, CodeTypeReference typerefParam)
        {
            CodeParameterDeclarationExpression param = new CodeParameterDeclarationExpression(typerefParam, idlArgName);

            if (idlArgDirection == "out") // If output parameter
            {
                param.Direction = FieldDirection.Out;

            } // Ends if output parameter

            parameters.Add(param);
            return param;
        }
示例#10
0
	public CodeParameterDeclarationExpressionCollection  parameter_dcls() //throws RecognitionException, TokenStreamException
{
		CodeParameterDeclarationExpressionCollection paramColl;

		returnAST = null;
		ASTPair currentAST = new ASTPair();
		AST parameter_dcls_AST = null;

				paramColl = new CodeParameterDeclarationExpressionCollection();
				CodeParameterDeclarationExpression param;


		try {      // for error handling
			match(LPAREN);
			{
				switch ( LA(1) )
				{
				case INT3264:
				case INT64:
				case LBRACKET:
				case SCOPEOP:
				case LITERAL_const:
				case LITERAL_signed:
				case LITERAL_unsigned:
				case LITERAL_octet:
				case LITERAL_any:
				case LITERAL_void:
				case LITERAL_byte:
				case LITERAL_wchar_t:
				case LITERAL_handle_t:
				case LITERAL_small:
				case LITERAL_short:
				case LITERAL_long:
				case LITERAL_int:
				case LITERAL_hyper:
				case LITERAL_char:
				case LITERAL_float:
				case LITERAL_double:
				case LITERAL_boolean:
				case LITERAL_string:
				case LITERAL_SAFEARRAY:
				case IDENT:
				{
					param=param_dcl();
					if (0 == inputState.guessing)
					{
						astFactory.addASTChild(ref currentAST, returnAST);
					}
					if (0==inputState.guessing)
					{
						paramColl.Add(param);
					}
					{    // ( ... )*
						for (;;)
						{
							if ((LA(1)==COMMA))
							{
								match(COMMA);
								param=param_dcl();
								if (0 == inputState.guessing)
								{
									astFactory.addASTChild(ref currentAST, returnAST);
								}
								if (0==inputState.guessing)
								{
									paramColl.Add(param);
								}
							}
							else
							{
								goto _loop208_breakloop;
							}

						}
_loop208_breakloop:						;
					}    // ( ... )*
					break;
				}
				case RPAREN:
				{
					break;
				}
				default:
				{
					throw new NoViableAltException(LT(1), getFilename());
				}
				 }
			}
			match(RPAREN);
			parameter_dcls_AST = currentAST.root;
		}
		catch (RecognitionException ex)
		{
			if (0 == inputState.guessing)
			{
				reportError(ex);
				recover(ex,tokenSet_51_);
			}
			else
			{
				throw ex;
			}
		}
		returnAST = parameter_dcls_AST;
		return paramColl;
	}
		public void Insert ()
		{
			CodeParameterDeclarationExpression param1 = new CodeParameterDeclarationExpression ();
			CodeParameterDeclarationExpression param2 = new CodeParameterDeclarationExpression ();

			CodeParameterDeclarationExpressionCollection coll = new CodeParameterDeclarationExpressionCollection ();
			coll.Add (param1);
			Assert.AreEqual (1, coll.Count, "#1");
			Assert.AreEqual (0, coll.IndexOf (param1), "#2");
			coll.Insert (0, param2);
			Assert.AreEqual (2, coll.Count, "#3");
			Assert.AreEqual (1, coll.IndexOf (param1), "#4");
			Assert.AreEqual (0, coll.IndexOf (param2), "#5");
		}
示例#12
0
        public static CodeMemberMethod GenerateMethod(MethodInfo member)
        {
            var method = new CodeMemberMethod
            {
                Name = member.Name,
                Attributes = MemberAttributes.Public | MemberAttributes.Final
                // ReSharper restore BitwiseOperatorOnEnumWithoutFlags
            };
            var methodTypeRef = new CodeTypeReference(member.ReturnType);
            method.ReturnType = methodTypeRef;

            var methodParameters = member.GetParameters().ToList();
            var parameterCollection = new CodeParameterDeclarationExpressionCollection();
            foreach (ParameterInfo info in methodParameters)
            {
                var expresion = new CodeParameterDeclarationExpression(info.ParameterType, info.Name);
                parameterCollection.Add(expresion);
            }
            method.Parameters.AddRange(parameterCollection);
            return method;
        }
示例#13
0
 protected void Rewrite(CodeParameterDeclarationExpressionCollection target, CodeParameterDeclarationExpressionCollection source, ref bool didRewrite)
 {
     foreach (CodeParameterDeclarationExpression item in source)
     {
         target.Add(this.Rewrite(item, ref didRewrite));
     }
 }
        private CodeMemberMethod CreateFetch(AliasBase aliasBase, out CodeTypeReference anonType)
        {
            var statementDomArg = VisitChild(aliasBase.Statement);
            if (Scope.Current.IsTableRegistered(statementDomArg.Scope.CodeDomReference.TypeArguments[0].BaseType))
            {
                var scope = Scope.Current.GetTableDescriptor(statementDomArg.Scope.CodeDomReference.TypeArguments[0].BaseType);
                if (aliasBase.Alias == null)
                    aliasBase.Children.Add(new TableAlias { Id = statementDomArg.Scope.CodeDomReference.TypeArguments[0].BaseType });

                Scope.Current.Register(aliasBase.Alias.Id, new ScopeData<TableDescriptor> { Type = scope.Type, CodeDomReference = scope.CodeDomReference.TypeArguments[0] });
            }

            CodeMemberMethod method = new CodeMemberMethod();
            method.Name = "Fetch_" + Guid.NewGuid().ToString("N");
            _mainType.Type.Members.Add(method);

            var anon = "anon_" + Guid.NewGuid().ToString("N");
            var bufferTable = new CodeTypeDeclaration(anon) { TypeAttributes = TypeAttributes.NestedPrivate };
            bufferTable.BaseTypes.Add(new CodeTypeReference("IRow"));
            _mainType.Type.Members.Add(bufferTable);

            var field = new CodeMemberField();
            field.Name = aliasBase.Alias == null ? string.Empty : aliasBase.Alias.Id;
            field.Attributes = MemberAttributes.Public | MemberAttributes.Final;
            field.Type = statementDomArg.Scope.CodeDomReference.TypeArguments[0];
            _joinMembers.Add(field);
            bufferTable.Members.Add(field);

            method.Statements.Add(new CodeVariableDeclarationStatement(statementDomArg.Scope.CodeDomReference, "table", statementDomArg.CodeExpression));

            anonType = new CodeTypeReference(anon);

            var copyStatments = new CodeStatementCollection();
            copyStatments.Add(new CodeVariableDeclarationStatement(anonType, "t",
               new CodeObjectCreateExpression(anonType)));

            copyStatments.Add(new CodeAssignStatement(new CodePropertyReferenceExpression(new CodeVariableReferenceExpression("t"), field.Name),
                new CodeVariableReferenceExpression("o")));

            copyStatments.Add(new CodeMethodReturnStatement(new CodeVariableReferenceExpression("t")));

            var codeParams = new CodeParameterDeclarationExpressionCollection();
            codeParams.Add(new CodeParameterDeclarationExpression(statementDomArg.Scope.CodeDomReference.TypeArguments[0], "o"));
            var copyMethod = CreateCopyMethod(codeParams, copyStatments);

            var anonExpression = new CodeSnippetExpression("o => {" + GenerateCodeFromStatement(
                new CodeMethodReturnStatement(
                    new CodeMethodInvokeExpression(new CodeMethodReferenceExpression(null, copyMethod.Name),
                        new CodeVariableReferenceExpression("o")))) + "}");

            method.Statements.Add(new CodeMethodReturnStatement(new CodeMethodInvokeExpression(new CodeMethodReferenceExpression(
                       new CodeTypeReferenceExpression("table"), "Select"), anonExpression)));

            method.ReturnType = new CodeTypeReference("IEnumerable", anonType);
            copyMethod.ReturnType = anonType;

            return method;
        }
		public void Add_Null () {
			CodeParameterDeclarationExpressionCollection coll = new CodeParameterDeclarationExpressionCollection ();
			coll.Add ((CodeParameterDeclarationExpression) null);
		}
		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");
		}
        /// <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 == "" || paramDeclsArgs != "null")
            {
                parameters = new CodeParameterDeclarationExpressionCollection();

                if (paramDeclsArgs != "null")
                {
                    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;
        }
		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");
		}
示例#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;
        }
		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");
		}
		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");
		}