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; }
public CodeDefaultProperty(CodeMemberProperty property, CodeParameterDeclarationExpressionCollection parameters, bool isDefault) { Parameters = parameters; IsDefault = isDefault; _property = property; }
public void Constructor1_NullItem () { CodeParameterDeclarationExpression[] parameters = new CodeParameterDeclarationExpression[] { new CodeParameterDeclarationExpression (), null }; CodeParameterDeclarationExpressionCollection coll = new CodeParameterDeclarationExpressionCollection ( parameters); }
public CodeTypeDelegate() { this.parameters = new CodeParameterDeclarationExpressionCollection(); base.TypeAttributes &= ~TypeAttributes.ClassSemanticsMask; base.TypeAttributes = base.TypeAttributes; base.BaseTypes.Clear(); base.BaseTypes.Add(new CodeTypeReference("System.Delegate")); }
public void Constructor0 () { CodeParameterDeclarationExpressionCollection coll = new CodeParameterDeclarationExpressionCollection (); Assert.IsFalse (((IList) coll).IsFixedSize, "#1"); Assert.IsFalse (((IList) coll).IsReadOnly, "#2"); Assert.AreEqual (0, coll.Count, "#3"); Assert.IsFalse (((ICollection) coll).IsSynchronized, "#4"); }
public CodeMemberMethod GenerateQueryMethodWithReturnType(CodeParameterDeclarationExpressionCollection parameters) { var methodQueryList = new CodeMemberMethod { Name = "Query<TPoco>", ReturnType = new CodeTypeReference ("IEnumerable<TPoco>") }; methodQueryList.Parameters.AddRange (parameters); return methodQueryList; }
private CodeMemberMethod CreateCopyMethod(CodeParameterDeclarationExpressionCollection methodParams, CodeStatementCollection statements) { CodeMemberMethod method = new CodeMemberMethod(); method.Name = "Copy_" + Guid.NewGuid().ToString("N"); method.Parameters.AddRange(methodParams); _mainType.Type.Members.Add(method); method.Statements.AddRange(statements); return method; }
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 AddRange(CodeParameterDeclarationExpressionCollection value) { if (value == null) { throw new ArgumentNullException("value"); } int count = value.Count; for (int i = 0; i < count; i++) { this.Add(value[i]); } }
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 void Constructor1 () { CodeParameterDeclarationExpression param1 = new CodeParameterDeclarationExpression (); CodeParameterDeclarationExpression param2 = new CodeParameterDeclarationExpression (); CodeParameterDeclarationExpression[] parameters = new CodeParameterDeclarationExpression[] { param1, param2 }; CodeParameterDeclarationExpressionCollection coll = new CodeParameterDeclarationExpressionCollection ( parameters); Assert.AreEqual (2, coll.Count, "#1"); Assert.AreEqual (0, coll.IndexOf (param1), "#2"); Assert.AreEqual (1, coll.IndexOf (param2), "#3"); }
Type[] GetParameterTypes(CodeParameterDeclarationExpressionCollection param) { var types = new Type[param.Count]; for (int i = 0; i < types.Length; i++) { if (param[i].UserData.Contains(Parser.RawData)) types[i] = param[i].UserData[Parser.RawData] as Type; else types[i] = Type.GetType(param[i].Type.BaseType); } return types; }
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 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; }
protected virtual void OutputParameters (CodeParameterDeclarationExpressionCollection parameters) { bool first = true; foreach (CodeParameterDeclarationExpression expr in parameters) { if (first) first = false; else output.Write (", "); GenerateExpression (expr); } }
void OutputMethodSignature(MemberAttributes attributes, CodeTypeReference returnType, string name, CodeParameterDeclarationExpressionCollection parameters, bool isSpecialName, bool isDelegateMethod) { OutputIdentifier(name); // generate parameters if (parameters != null) OutputParametersDeclarations(parameters); // return type //OutputType(returnType); Output.WriteLine(";"); }
protected virtual void OutputParametersDeclarations(CodeParameterDeclarationExpressionCollection parameters) { int count = parameters.Count; if (count == 0) return; Output.Write("("); GenerateParameterDeclarationExpression(parameters[0]); for (int i = 1; i < count; ++i) { Output.Write("; "); GenerateParameterDeclarationExpression(parameters[i]); } Output.Write(")"); }
public CodeParameterDeclarationExpressionCollection(CodeParameterDeclarationExpressionCollection value) { return(default(CodeParameterDeclarationExpressionCollection)); }
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; }
public CodeParameterDeclarationExpressionCollection(CodeParameterDeclarationExpressionCollection value) { AddRange(value); }
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); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Gets the return type. /// </summary> /// <param name="parameters">The parameters.</param> /// <returns></returns> /// ------------------------------------------------------------------------------------ private CodeParameterDeclarationExpression GetReturnType( CodeParameterDeclarationExpressionCollection parameters) { CodeParameterDeclarationExpression retType = new CodeParameterDeclarationExpression(typeof(void), "return"); foreach (CodeParameterDeclarationExpression exp in parameters) { if (exp.UserData["retval"] != null && (bool)exp.UserData["retval"] && exp.Type.ArrayRank <=0) { /// Marshalling arrays as return value doesn't work! retType = exp; parameters.Remove(exp); break; } } return retType; }
private void ValidateParameters(CodeParameterDeclarationExpressionCollection parameters) { IEnumerator en = parameters.GetEnumerator(); while (en.MoveNext()) { CodeParameterDeclarationExpression current = (CodeParameterDeclarationExpression)en.Current; ValidateParameterDeclarationExpression(current); } }
/// <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="parameters">if provided, the parameters for the method to be generated</param> /// <param name="comments">the comments for the partial property definition</param> public void AddMethodFor(string baseMethodName, CodeParameterDeclarationExpressionCollection parameters, string comments) { Debug.Assert(!string.IsNullOrEmpty(baseMethodName), "Unexpected null or empty base method name!"); if (!string.IsNullOrEmpty(baseMethodName)) { if (!this.methodInvokeExpressions.ContainsKey(baseMethodName)) { string methodName = string.Concat("On", baseMethodName); List<CodeArgumentReferenceExpression> args = new List<CodeArgumentReferenceExpression>(); if (parameters != null && parameters.Count > 0) { foreach (CodeParameterDeclarationExpression paramDeclaration in parameters) { args.Add(new CodeArgumentReferenceExpression(paramDeclaration.Name)); } } // Create method call. // OnMethod(arg1, arg2); this.methodInvokeExpressions.Add(baseMethodName, new CodeMethodInvokeExpression( new CodeThisReferenceExpression(), methodName, args.ToArray())); // Create method declaration. // partial void OnMethod(Type1 param1, Type2 param2); CodeSnippetTypeMember codeSnippet = this.CreateNotificationPartialMethod(baseMethodName, parameters); if (!string.IsNullOrEmpty(comments)) { // Add comment on method declaration. codeSnippet.Comments.AddRange(CodeGenUtilities.GetDocComments(comments, this.isCSharp)); } this.partialMethodSnippets.Add(baseMethodName, codeSnippet); } } }
/// <summary> /// Generates a notification partial method for the specified method, this is of the form /// OnCreated(args...) for the Created(args...) method. /// </summary> /// <param name="methodName">The name of the method to create a notification method for.</param> /// <param name="parameters">the method parameters, if any.</param> /// <returns>Code snippet for the notification partial method.</returns> private CodeSnippetTypeMember CreateNotificationPartialMethod(string methodName, CodeParameterDeclarationExpressionCollection parameters) { CodeMemberMethod method = new CodeMemberMethod(); method.Attributes = MemberAttributes.Public | MemberAttributes.Final; method.Name = "On" + methodName; method.Parameters.AddRange(parameters); if (this.proxyGenerator.ClientProxyCodeGenerationOptions.UseFullTypeNames) { foreach (CodeParameterDeclarationExpression paramExp in parameters.Cast<CodeParameterDeclarationExpression>()) { SetGlobalTypeReference(paramExp.Type); } } StringBuilder snippet = null; using (CodeDomProvider provider = CodeDomProvider.CreateProvider(this.isCSharp ? "CSharp" : "VisualBasic")) { using (StringWriter snippetWriter = new StringWriter(System.Globalization.CultureInfo.CurrentCulture)) { provider.GenerateCodeFromMember(method, snippetWriter, new CodeGeneratorOptions()); snippet = snippetWriter.GetStringBuilder(); } } // replace 'public' with 'partial' - partial methods cannot be public. // observe we replace 'ublic' only to get the proper language keyword capitalization. snippet.Replace("\r\n", string.Empty); snippet.Replace("ublic", "artial", 1, "ublic".Length); if (this.isCSharp) { int idx = snippet.ToString().LastIndexOf(')'); snippet.Remove(idx + 1, snippet.Length - idx - 1); snippet.Append(";"); } else // VB.net { snippet.Insert(0, "Private "); int idx = snippet.ToString().IndexOf("End Sub", StringComparison.Ordinal); snippet.Insert(idx, string.Concat("\r\n", this.indent)); } snippet.Insert(0, this.indent); return new CodeSnippetTypeMember(snippet.ToString()); }
/// <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); }
/// <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="comments">the comments for the partial property definition</param> public void AddMethodFor(string baseMethodName, string comments) { CodeParameterDeclarationExpressionCollection parameters = new CodeParameterDeclarationExpressionCollection(); this.AddMethodFor(baseMethodName, parameters, comments); }
public void AddRange(CodeParameterDeclarationExpressionCollection value) { throw new NotImplementedException(); }
public void AddRange(CodeParameterDeclarationExpressionCollection value) { Contract.Requires(value != null); }
/// <devdoc> /// <para> /// Generates code for the specified parameters. /// </para> /// </devdoc> private void OutputParameters(CodeParameterDeclarationExpressionCollection parameters) { bool first = true; bool multiline = parameters.Count > ParameterMultilineThreshold; if (multiline) { Indent += 3; } IEnumerator en = parameters.GetEnumerator(); while (en.MoveNext()) { CodeParameterDeclarationExpression current = (CodeParameterDeclarationExpression)en.Current; if (first) { first = false; } else { Output.Write(", "); } if (multiline) { ContinueOnNewLine(""); } GenerateExpression(current); } if (multiline) { Indent -= 3; } }
private void OutputParameters(CodeParameterDeclarationExpressionCollection parameters) { bool flag1 = true; bool flag2 = parameters.Count > 15; if (flag2) { this.Indent += 3; } foreach (CodeParameterDeclarationExpression expression1 in parameters) { if (flag1) { flag1 = false; } else { this.Output.Write(", "); } if (flag2) { this.ContinueOnNewLine(""); } this.GenerateExpression(expression1); } if (flag2) { this.Indent -= 3; } }
// Generates code for the specified CodeDom based parameter declaration expression representation. // 'parameters' indicates the parameter declaration expressions to generate code for. protected override void OutputParameters(CodeParameterDeclarationExpressionCollection parameters) { bool first = true; IEnumerator en = parameters.GetEnumerator(); while (en.MoveNext()) { CodeParameterDeclarationExpression current = (CodeParameterDeclarationExpression)en.Current; if (first) { first = false; } else { Output.Write(", "); } GenerateExpression(current); } }
/// <devdoc> /// <para> /// Initializes a new instance of <see cref='System.CodeDom.CodeParameterDeclarationExpressionCollection'/> based on another <see cref='System.CodeDom.CodeParameterDeclarationExpressionCollection'/>. /// </para> /// </devdoc> public CodeParameterDeclarationExpressionCollection(CodeParameterDeclarationExpressionCollection value) { this.AddRange(value); }
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; }