protected object DeserializeStatementToInstance(IDesignerSerializationManager manager, CodeStatement statement) { object obj2 = null; CodeVariableDeclarationStatement statement3; CodeAssignStatement statement2 = statement as CodeAssignStatement; if (statement2 != null) { CodeFieldReferenceExpression left = statement2.Left as CodeFieldReferenceExpression; if (left != null) { return base.DeserializeExpression(manager, left.FieldName, statement2.Right); } CodeVariableReferenceExpression expression2 = statement2.Left as CodeVariableReferenceExpression; if (expression2 != null) { return base.DeserializeExpression(manager, expression2.VariableName, statement2.Right); } base.DeserializeStatement(manager, statement2); return obj2; } if (((statement3 = statement as CodeVariableDeclarationStatement) != null) && (statement3.InitExpression != null)) { return base.DeserializeExpression(manager, statement3.Name, statement3.InitExpression); } base.DeserializeStatement(manager, statement); return obj2; }
public void CodeAssignStatementTest () { CodeSnippetExpression cse1 = new CodeSnippetExpression("A"); CodeSnippetExpression cse2 = new CodeSnippetExpression("B"); CodeAssignStatement assignStatement = new CodeAssignStatement (cse1, cse2); statement = assignStatement; Assert.AreEqual (string.Format (CultureInfo.InvariantCulture, "A = B;{0}", NewLine), Generate (), "#1"); assignStatement.Left = null; try { Generate (); Assert.Fail ("#2"); } catch (ArgumentNullException) { } assignStatement.Left = cse1; Generate (); assignStatement.Right = null; try { Generate (); Assert.Fail ("#3"); } catch (ArgumentNullException) { } assignStatement.Right = cse2; Generate (); }
private void NotifyChanged(CollectionChangeAction action, CodeStatement option, int index) { if (_changed != null) { _changed(action, option, index); } }
/// <summary> /// Creation method. /// </summary> /// <param name="className">Class name</param> /// <param name="isGet">isGet flag</param> /// <param name="member">Member</param> /// <param name="statement">Statement</param> /// <returns></returns> /// <remarks>For properties.</remarks> public static MethodInfo CreateProperty(string className, bool isGet, CodeTypeMember member, CodeStatement statement) { return new MethodInfo(member, className, true, isGet, statement); }
private static void EmitPragma(bool emitPragmas, CodeStatement statement, string fileName, int line) { if (emitPragmas) { statement.LinePragma = new CodeLinePragma(fileName, line); } }
internal static void AddCallbackImplementation(CodeTypeDeclaration codeClass, string callbackName, string handlerName, string handlerArgs, bool methodHasOutParameters) { CodeFlags[] parameterFlags = new CodeFlags[1]; CodeMemberMethod method = AddMethod(codeClass, callbackName, parameterFlags, new string[] { typeof(object).FullName }, new string[] { "arg" }, typeof(void).FullName, null, (CodeFlags) 0); CodeEventReferenceExpression left = new CodeEventReferenceExpression(new CodeThisReferenceExpression(), handlerName); CodeBinaryOperatorExpression condition = new CodeBinaryOperatorExpression(left, CodeBinaryOperatorType.IdentityInequality, new CodePrimitiveExpression(null)); CodeStatement[] trueStatements = new CodeStatement[2]; trueStatements[0] = new CodeVariableDeclarationStatement(typeof(InvokeCompletedEventArgs), "invokeArgs", new CodeCastExpression(typeof(InvokeCompletedEventArgs), new CodeArgumentReferenceExpression("arg"))); CodeVariableReferenceExpression targetObject = new CodeVariableReferenceExpression("invokeArgs"); CodeObjectCreateExpression expression4 = new CodeObjectCreateExpression(); if (methodHasOutParameters) { expression4.CreateType = new CodeTypeReference(handlerArgs); expression4.Parameters.Add(new CodePropertyReferenceExpression(targetObject, "Results")); } else { expression4.CreateType = new CodeTypeReference(typeof(AsyncCompletedEventArgs)); } expression4.Parameters.Add(new CodePropertyReferenceExpression(targetObject, "Error")); expression4.Parameters.Add(new CodePropertyReferenceExpression(targetObject, "Cancelled")); expression4.Parameters.Add(new CodePropertyReferenceExpression(targetObject, "UserState")); trueStatements[1] = new CodeExpressionStatement(new CodeDelegateInvokeExpression(new CodeEventReferenceExpression(new CodeThisReferenceExpression(), handlerName), new CodeExpression[] { new CodeThisReferenceExpression(), expression4 })); method.Statements.Add(new CodeConditionStatement(condition, trueStatements, new CodeStatement[0])); }
public override void GenerateCodeFromStatement(CodeStatement statement, TextWriter writer, CodeGeneratorOptions options) { var codeExpressionStatement = statement as CodeExpressionStatement; if (codeExpressionStatement != null) { var methodInvokeExpression = codeExpressionStatement.Expression as CodeMethodInvokeExpression; if (methodInvokeExpression != null) { if (methodInvokeExpression.Method.MethodName == "Write" && methodInvokeExpression.Parameters.Count == 1) { var parameter = methodInvokeExpression.Parameters[0] as CodeSnippetExpression; if ((parameter != null) && (!string.IsNullOrEmpty(parameter.Value))) { // Appears to be a candidate for rewriting string originalValue = parameter.Value; var processor = SnippetModifiers.OfType<ICodeSnippetTextModifier>() .FirstOrDefault(m => m.CanProcessString(originalValue)); if (processor != null) originalValue = processor.ProcessString(originalValue); parameter.Value = "global::" + GetType().FullName + ".PreProcessObject(this, " + originalValue + ")"; } } } } base.GenerateCodeFromStatement(statement, writer, options); }
public void AddRange(CodeStatement[] value) { foreach(CodeStatement e in value) { List.Add(e); } }
internal static CodeMemberMethod AddAsyncMethod(CodeTypeDeclaration codeClass, string methodName, string[] parameterTypeNames, string[] parameterNames, string callbackMember, string callbackName, string userState) { CodeMemberMethod method = AddMethod(codeClass, methodName, new CodeFlags[parameterNames.Length], parameterTypeNames, parameterNames, typeof(void).FullName, null, CodeFlags.IsPublic); method.Comments.Add(new CodeCommentStatement(Res.GetString("CodeRemarks"), true)); CodeMethodInvokeExpression expression = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), methodName, new CodeExpression[0]); for (int i = 0; i < parameterNames.Length; i++) { expression.Parameters.Add(new CodeArgumentReferenceExpression(parameterNames[i])); } expression.Parameters.Add(new CodePrimitiveExpression(null)); method.Statements.Add(expression); method = AddMethod(codeClass, methodName, new CodeFlags[parameterNames.Length], parameterTypeNames, parameterNames, typeof(void).FullName, null, CodeFlags.IsPublic); method.Comments.Add(new CodeCommentStatement(Res.GetString("CodeRemarks"), true)); method.Parameters.Add(new CodeParameterDeclarationExpression(typeof(object), userState)); CodeFieldReferenceExpression left = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), callbackMember); CodeBinaryOperatorExpression condition = new CodeBinaryOperatorExpression(left, CodeBinaryOperatorType.IdentityEquality, new CodePrimitiveExpression(null)); CodeDelegateCreateExpression right = new CodeDelegateCreateExpression { DelegateType = new CodeTypeReference(typeof(SendOrPostCallback)), TargetObject = new CodeThisReferenceExpression(), MethodName = callbackName }; CodeStatement[] trueStatements = new CodeStatement[] { new CodeAssignStatement(left, right) }; method.Statements.Add(new CodeConditionStatement(condition, trueStatements, new CodeStatement[0])); return method; }
public void Constructor1_NullItem () { CodeStatement[] statements = new CodeStatement[] { new CodeStatement (), null }; CodeStatementCollection coll = new CodeStatementCollection ( statements); }
public CodeTryCatchFinallyStatement (CodeStatement [] tryStatements, CodeCatchClause [] catchClauses, CodeStatement [] finallyStatements) { TryStatements.AddRange( tryStatements ); CatchClauses.AddRange( catchClauses ); FinallyStatements.AddRange( finallyStatements ); }
public CodeConditionStatement(CodeExpression condition, CodeStatement[] trueStatements, CodeStatement[] falseStatements) { this.condition = condition; TrueStatements.AddRange(trueStatements); FalseStatements.AddRange(falseStatements); }
public CodeTryCatchFinallyStatement(CodeStatement[] tryStatements, CodeCatchClause[] catchClauses) { this.tryStatments = new CodeStatementCollection(); this.finallyStatments = new CodeStatementCollection(); this.catchClauses = new CodeCatchClauseCollection(); this.TryStatements.AddRange(tryStatements); this.CatchClauses.AddRange(catchClauses); }
public void Constructor0_Deny_Unrestricted () { CodeStatement cs = new CodeStatement (); Assert.IsNull (cs.LinePragma, "LinePragma"); cs.LinePragma = new CodeLinePragma (String.Empty, Int16.MinValue); Assert.AreEqual (0, cs.StartDirectives.Count, "StartDirectives"); Assert.AreEqual (0, cs.EndDirectives.Count, "EndDirectives"); }
internal static CodeStatement Clone(CodeStatement statement) { if (statement == null) { return null; } return GetStatement(statement).Clone(); }
/// <devdoc> /// <para>Copies the elements of an array to the end of the <see cref='System.CodeDom.CodeStatementCollection'/>.</para> /// </devdoc> public void AddRange(CodeStatement[] value) { if (value == null) { throw new ArgumentNullException("value"); } for (int i = 0; ((i) < (value.Length)); i = ((i) + (1))) { this.Add(value[i]); } }
public CodeIterationStatement(CodeStatement initStatement, CodeExpression testExpression, CodeStatement incrementStatement, params CodeStatement[] statements) { this.statements = new CodeStatementCollection(); this.InitStatement = initStatement; this.TestExpression = testExpression; this.IncrementStatement = incrementStatement; this.Statements.AddRange(statements); }
void AddStmt(CodeStatement stmt) { if (codeStack.Count == 0) return; CodeStatementCollection stmtCollection = codeStack.Peek(); if (stmtCollection != null) { stmtCollection.Add(stmt); } }
private static CodeCatchClause Catch(System.Type type, string name, CodeStatement catchStmnt) { CodeCatchClause clause = new CodeCatchClause { CatchExceptionType = Type(type), LocalName = name }; clause.Statements.Add(catchStmnt); return clause; }
public void Constructor1_Deny_Unrestricted () { CodeStatement[] try_statements = new CodeStatement[1] { new CodeStatement () }; CodeCatchClause[] catch_clauses = new CodeCatchClause[1] { new CodeCatchClause () }; CodeTryCatchFinallyStatement ctcfs = new CodeTryCatchFinallyStatement (try_statements, catch_clauses); Assert.AreEqual (1, ctcfs.CatchClauses.Count, "CatchClauses"); Assert.AreEqual (0, ctcfs.FinallyStatements.Count, "FinallyStatements"); Assert.AreEqual (1, ctcfs.TryStatements.Count, "TryStatements"); }
public void Constructor1_Deny_Unrestricted () { CodeExpression condition = new CodeExpression (); CodeStatement[] cs = new CodeStatement[1] { new CodeStatement () }; CodeConditionStatement css = new CodeConditionStatement (condition, cs); Assert.AreSame (condition, css.Condition, "Condition"); css.Condition = new CodeExpression (); Assert.AreEqual (0, css.FalseStatements.Count, "FalseStatements"); Assert.AreEqual (1, css.TrueStatements.Count, "TrueStatements"); }
public CodeIterationStatement( CodeStatement initStatement, CodeExpression testExpression, CodeStatement incrementStatement, params CodeStatement[] statements ) { this.initStatement = initStatement; this.testExpression = testExpression; this.incrementStatement = incrementStatement; this.Statements.AddRange( statements ); }
public void AddRange (CodeStatement [] value) { if (value == null) { throw new ArgumentNullException ("value"); } for (int i = 0; i < value.Length; i++) { Add (value[i]); } }
public void Add (CodeStatement statement) { if (statement.UserData["statement-order"] == null) _default.Add (statement); else if ((string)statement.UserData["statement-order"] == "initializer") _initializers.Add (statement); else if ((string)statement.UserData["statement-order"] == "begin") _begin.Add (statement); else if ((string)statement.UserData["statement-order"] == "end") _end.Add (statement); }
public void DefaultCodeCommentStatementTest () { CodeCommentStatement commentStatement = new CodeCommentStatement (); CodeComment comment = new CodeComment (); commentStatement.Comment = comment; statement = commentStatement; Generate (); Assertion.AssertEquals ("// \n", Code); }
public void MultiLineCodeCommentStatementTest () { CodeCommentStatement commentStatement = new CodeCommentStatement (); CodeComment comment = new CodeComment (); comment.Text = "a\nb"; commentStatement.Comment = comment; statement = commentStatement; Generate (); Assertion.AssertEquals ("// a\n//b\n", Code); }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily")] // TODO: fix protected void WriteStatement(CodeStatement s) { // Save statement source location if (s.LinePragma != null) { _writer.MapLocation(s.LinePragma); } if (s is CodeExpressionStatement) { WriteExpressionStatement((CodeExpressionStatement)s); } else if (s is CodeSnippetStatement) { WriteSnippetStatement((CodeSnippetStatement)s); } }
internal static CodeCatchClause Catch(CodeTypeReference type, string name, CodeStatement catchStmnt) { CodeCatchClause clause = new CodeCatchClause { CatchExceptionType = type, LocalName = name }; if (catchStmnt != null) { clause.Statements.Add(catchStmnt); } return clause; }
internal static void GenerateConstructorStatements(CodeConstructor ctor, string url, string appSettingUrlKey, string appSettingBaseUrl, bool soap11) { bool flag = (url != null) && (url.Length > 0); bool flag2 = (appSettingUrlKey != null) && (appSettingUrlKey.Length > 0); CodeAssignStatement statement = null; if (flag || flag2) { CodeExpression expression; CodePropertyReferenceExpression left = new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "Url"); if (flag) { expression = new CodePrimitiveExpression(url); statement = new CodeAssignStatement(left, expression); } if (flag && !flag2) { ctor.Statements.Add(statement); } else if (flag2) { CodeVariableReferenceExpression expression3 = new CodeVariableReferenceExpression("urlSetting"); CodeTypeReferenceExpression targetObject = new CodeTypeReferenceExpression(typeof(ConfigurationManager)); CodePropertyReferenceExpression expression5 = new CodePropertyReferenceExpression(targetObject, "AppSettings"); expression = new CodeIndexerExpression(expression5, new CodeExpression[] { new CodePrimitiveExpression(appSettingUrlKey) }); ctor.Statements.Add(new CodeVariableDeclarationStatement(typeof(string), "urlSetting", expression)); if ((appSettingBaseUrl == null) || (appSettingBaseUrl.Length == 0)) { expression = expression3; } else { if ((url == null) || (url.Length == 0)) { throw new ArgumentException(Res.GetString("IfAppSettingBaseUrlArgumentIsSpecifiedThen0")); } string str = new Uri(appSettingBaseUrl).MakeRelative(new Uri(url)); CodeExpression[] parameters = new CodeExpression[] { expression3, new CodePrimitiveExpression(str) }; expression = new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(typeof(string)), "Concat", parameters); } CodeStatement[] trueStatements = new CodeStatement[] { new CodeAssignStatement(left, expression) }; CodeBinaryOperatorExpression condition = new CodeBinaryOperatorExpression(expression3, CodeBinaryOperatorType.IdentityInequality, new CodePrimitiveExpression(null)); if (flag) { ctor.Statements.Add(new CodeConditionStatement(condition, trueStatements, new CodeStatement[] { statement })); } else { ctor.Statements.Add(new CodeConditionStatement(condition, trueStatements)); } } } }
public void Constructor1 () { CodeStatement cs1 = new CodeStatement (); CodeStatement cs2 = new CodeStatement (); CodeStatement[] statements = new CodeStatement[] { cs1, cs2 }; CodeStatementCollection coll = new CodeStatementCollection ( statements); Assert.AreEqual (2, coll.Count, "#1"); Assert.AreEqual (0, coll.IndexOf (cs1), "#2"); Assert.AreEqual (1, coll.IndexOf (cs2), "#3"); }
public bool Contains(CodeStatement value) => List.Contains(value);
//System.CodeDom.CodeVariableDeclarationStatement mVecVariableDeclaration = new System.CodeDom.CodeVariableDeclarationStatement(); public override async System.Threading.Tasks.Task GCode_CodeDom_GenerateCode(CodeTypeDeclaration codeClass, CodeStatementCollection codeStatementCollection, CodeGenerateSystem.Base.LinkPinControl element, CodeGenerateSystem.Base.GenerateCodeContext_Method context) { var strValueName = GCode_GetValueName(null, context); if (!context.Method.Statements.Contains(mVarDec)) { mVarDec = new CodeAssignStatement(new CodeSnippetExpression(mValueType.FullName + " " + strValueName), CodeGenerateSystem.Program.GetDefaultValueExpressionFromType(mValueType));//, paramCodeName, CodeGenerateSystem.Program.GetDefaultValueExpressionFromType(ParamType)); context.Method.Statements.Insert(0, mVarDec); } if (mCtrlvalue_VectorIn.HasLink) { if (!mCtrlvalue_VectorIn.GetLinkedObject(0, true).IsOnlyReturnValue) { await mCtrlvalue_VectorIn.GetLinkedObject(0, true).GCode_CodeDom_GenerateCode(codeClass, codeStatementCollection, mCtrlvalue_VectorIn.GetLinkedPinControl(0, true), context); } if (!codeStatementCollection.Contains(mAssignCode)) { mAssignCode = new CodeAssignStatement(new System.CodeDom.CodeVariableReferenceExpression(strValueName), mCtrlvalue_VectorIn.GetLinkedObject(0, true).GCode_CodeDom_GetValue(mCtrlvalue_VectorIn.GetLinkedPinControl(0, true), context)); codeStatementCollection.Add(mAssignCode); } } else { if (!codeStatementCollection.Contains(mAssignCode)) { mAssignCode = new CodeAssignStatement(); mAssignCode.Left = new System.CodeDom.CodeVariableReferenceExpression(strValueName); var paramExp = new System.CodeDom.CodeExpression[mLinkInDic.Count]; var param = CSParam as AixConstructionParams; if (param != null) { for (int i = 0; i < mLinkInDic.Count; i++) { paramExp[i] = new System.CodeDom.CodePrimitiveExpression(param.Value[i]); } } mAssignCode.Right = new CodeObjectCreateExpression(mValueType, paramExp); codeStatementCollection.Add(mAssignCode); } } foreach (var data in mLinkInDic) { var linkOI = data.Element; if (linkOI.HasLink) { if (!linkOI.GetLinkedObject(0, true).IsOnlyReturnValue) { await linkOI.GetLinkedObject(0, true).GCode_CodeDom_GenerateCode(codeClass, codeStatementCollection, linkOI.GetLinkedPinControl(0, true), context); } var fieldRef = new System.CodeDom.CodeFieldReferenceExpression(); fieldRef.TargetObject = new CodeVariableReferenceExpression(strValueName); fieldRef.FieldName = data.KeyName; var statValAss = new System.CodeDom.CodeAssignStatement(); statValAss.Left = fieldRef; statValAss.Right = new CodeGenerateSystem.CodeDom.CodeCastExpression(typeof(float), linkOI.GetLinkedObject(0, true).GCode_CodeDom_GetValue(linkOI.GetLinkedPinControl(0, true), context)); codeStatementCollection.Add(statValAss); } } }
/// <include file='doc\CodeStatementCollection.uex' path='docs/doc[@for="CodeStatementCollection.Contains"]/*' /> /// <devdoc> /// <para>Gets a value indicating whether the /// <see cref='System.CodeDom.CodeStatementCollection'/> contains the specified <see cref='System.CodeDom.CodeStatement'/>.</para> /// </devdoc> public bool Contains(CodeStatement value) { return(List.Contains(value)); }
public void Remove(CodeStatement value) { }
public void Insert(int index, CodeStatement value) { }
public int Add(CodeStatement value) { return(default(int)); }
public int IndexOf(CodeStatement value) { return(default(int)); }
public bool Contains(CodeStatement value) { return(default(bool)); }
public int IndexOf(CodeStatement value) { throw new NotImplementedException(); }
/// <include file='doc\CodeStatementCollection.uex' path='docs/doc[@for="CodeStatementCollection.Add"]/*' /> /// <devdoc> /// <para>Adds a <see cref='System.CodeDom.CodeStatement'/> with the specified value to the /// <see cref='System.CodeDom.CodeStatementCollection'/> .</para> /// </devdoc> public int Add(CodeStatement value) { return(List.Add(value)); }
public void Insert(int index, CodeStatement value) { throw new NotImplementedException(); }
public CodeLabeledStatement(string label, CodeStatement statement) { }
public int Add(CodeStatement value) => List.Add(value);
public void Remove(CodeStatement value) { throw new NotImplementedException(); }
public CodeLabeledStatement(string label, CodeStatement statement) { this.label = label; this.statement = statement; }
/// <devdoc> /// <para> /// Initializes a new instance of <see cref='System.CodeDom.CodeIterationStatement'/>. /// </para> /// </devdoc> public CodeIterationStatement(CodeStatement initStatement, CodeExpression testExpression, CodeStatement incrementStatement, params CodeStatement[] statements) { InitStatement = initStatement; TestExpression = testExpression; IncrementStatement = incrementStatement; Statements.AddRange(statements); }
public int IndexOf(CodeStatement value) => List.IndexOf(value);
public void Insert(int index, CodeStatement value) => List.Insert(index, value);
public void Remove(CodeStatement value) => List.Remove(value);
public bool Contains(CodeStatement value) { throw new NotImplementedException(); }
/// <include file='doc\CodeStatementCollection.uex' path='docs/doc[@for="CodeStatementCollection.IndexOf"]/*' /> /// <devdoc> /// <para>Returns the index of a <see cref='System.CodeDom.CodeStatement'/> in /// the <see cref='System.CodeDom.CodeStatementCollection'/> .</para> /// </devdoc> public int IndexOf(CodeStatement value) { return(List.IndexOf(value)); }