public void Constructor0 () { CodeGotoStatement cgs = new CodeGotoStatement (); Assert.IsNull (cgs.Label, "#1"); Assert.IsNotNull (cgs.StartDirectives, "#2"); Assert.AreEqual (0, cgs.StartDirectives.Count, "#3"); Assert.IsNotNull (cgs.EndDirectives, "#4"); Assert.AreEqual (0, cgs.EndDirectives.Count, "#5"); Assert.IsNotNull (cgs.UserData, "#6"); Assert.AreEqual (typeof(ListDictionary), cgs.UserData.GetType (), "#7"); Assert.AreEqual (0, cgs.UserData.Count, "#8"); Assert.IsNull (cgs.LinePragma, "#9"); CodeLinePragma clp = new CodeLinePragma ("mono", 10); cgs.LinePragma = clp; Assert.IsNotNull (cgs.LinePragma, "#10"); Assert.AreSame (clp, cgs.LinePragma, "#11"); cgs.LinePragma = null; Assert.IsNull (cgs.LinePragma, "#12"); string label = "mono"; cgs.Label = label; Assert.AreSame (label, cgs.Label, "#13"); }
internal static void BuildEvalExpression(string field, string formatString, string propertyName, Type propertyType, ControlBuilder controlBuilder, CodeStatementCollection methodStatements, CodeStatementCollection statements, CodeLinePragma linePragma, bool isEncoded, ref bool hasTempObject) { // Altogether, this function will create a statement that looks like this: // if (this.Page.GetDataItem() != null) { // target.{{propName}} = ({{propType}}) this.Eval(fieldName, formatString); // } // this.Eval(fieldName, formatString) CodeMethodInvokeExpression evalExpr = new CodeMethodInvokeExpression(); evalExpr.Method.TargetObject = new CodeThisReferenceExpression(); evalExpr.Method.MethodName = EvalMethodName; evalExpr.Parameters.Add(new CodePrimitiveExpression(field)); if (!String.IsNullOrEmpty(formatString)) { evalExpr.Parameters.Add(new CodePrimitiveExpression(formatString)); } CodeStatementCollection evalStatements = new CodeStatementCollection(); BuildPropertySetExpression(evalExpr, propertyName, propertyType, controlBuilder, methodStatements, evalStatements, linePragma, isEncoded, ref hasTempObject); // if (this.Page.GetDataItem() != null) CodeMethodInvokeExpression getDataItemExpr = new CodeMethodInvokeExpression(); getDataItemExpr.Method.TargetObject = new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "Page"); getDataItemExpr.Method.MethodName = GetDataItemMethodName; CodeConditionStatement ifStmt = new CodeConditionStatement(); ifStmt.Condition = new CodeBinaryOperatorExpression(getDataItemExpr, CodeBinaryOperatorType.IdentityInequality, new CodePrimitiveExpression(null)); ifStmt.TrueStatements.AddRange(evalStatements); statements.Add(ifStmt); }
public void Constructor0 () { CodeSnippetStatement css = new CodeSnippetStatement (); Assert.IsNull (css.LinePragma, "#1"); Assert.IsNotNull (css.Value, "#2"); Assert.AreEqual (string.Empty, css.Value, "#3"); Assert.IsNotNull (css.StartDirectives, "#4"); Assert.AreEqual (0, css.StartDirectives.Count, "#5"); Assert.IsNotNull (css.EndDirectives, "#6"); Assert.AreEqual (0, css.EndDirectives.Count, "#7"); Assert.IsNotNull (css.UserData, "#8"); Assert.AreEqual (typeof(ListDictionary), css.UserData.GetType (), "#9"); Assert.AreEqual (0, css.UserData.Count, "#10"); css.Value = null; Assert.IsNotNull (css.Value, "#11"); Assert.AreEqual (string.Empty, css.Value, "#12"); CodeLinePragma clp = new CodeLinePragma ("mono", 10); css.LinePragma = clp; Assert.IsNotNull (css.LinePragma, "#13"); Assert.AreSame (clp, css.LinePragma, "#14"); css.LinePragma = null; Assert.IsNull (css.LinePragma, "#15"); }
public StructureBuilder (NamespaceBuilder ns, CodeLinePragma loc, TypeAttributes attr) : base (BundleManagerBase.DefaultStructureClass, ns, loc, attr) { BaseClass = new UserType (typeof (StructureTemplate)); ns.SetUserParams (this); }
internal static void BuildExpressionSetup(ControlBuilder controlBuilder, CodeStatementCollection methodStatements, CodeStatementCollection statements, CodeLinePragma linePragma, bool isTwoWayBound, bool designerMode) { // {{controlType}} target; CodeVariableDeclarationStatement targetDecl = new CodeVariableDeclarationStatement(controlBuilder.ControlType, "dataBindingExpressionBuilderTarget"); methodStatements.Add(targetDecl); CodeVariableReferenceExpression targetExp = new CodeVariableReferenceExpression(targetDecl.Name); // target = ({{controlType}}) sender; CodeAssignStatement setTarget = new CodeAssignStatement(targetExp, new CodeCastExpression(controlBuilder.ControlType, new CodeArgumentReferenceExpression("sender"))); setTarget.LinePragma = linePragma; statements.Add(setTarget); Type bindingContainerType = controlBuilder.BindingContainerType; CodeVariableDeclarationStatement containerDecl = new CodeVariableDeclarationStatement(bindingContainerType, "Container"); methodStatements.Add(containerDecl); // {{containerType}} Container = ({{containerType}}) target.BindingContainer; CodeAssignStatement setContainer = new CodeAssignStatement(new CodeVariableReferenceExpression(containerDecl.Name), new CodeCastExpression(bindingContainerType, new CodePropertyReferenceExpression(targetExp, "BindingContainer"))); setContainer.LinePragma = linePragma; statements.Add(setContainer); string variableName = isTwoWayBound ? "BindItem" : "Item"; GenerateItemTypeExpressions(controlBuilder, methodStatements, statements, linePragma, variableName); //Generate code for other variable as well at design time in addition to runtime variable for intellisense to work. if (designerMode) { GenerateItemTypeExpressions(controlBuilder, methodStatements, statements, linePragma, isTwoWayBound ? "Item" : "BindItem"); } }
public FieldInfo (int idx, UserType type, string name, CodeLinePragma line) { Idx = idx; Type = type; Name = name; Line = line; }
public MetaRuleBuilder (string name, NamespaceBuilder ns, CodeLinePragma loc, TypeAttributes attr) { rb = new RuleBuilder (name, ns, loc, attr); tmpl = new RuleTemplateBuilder (name + "RTemplate", rb, ns, loc, attr); ns.AddMetaRule (this); BaseClass = RuleType; }
public TheResult (string name, NamespaceBuilder ns, string ename, CodeLinePragma loc, TypeAttributes attr) : base (name, ns, loc, attr) { etype = new UserType (ename); BaseClass = new UserType (typeof (EnumResult<>)); BaseClass.AddTypeArgument (etype); }
public EnumResultBuilder (string name, NamespaceBuilder ns, CodeLinePragma loc, TypeAttributes attr) { if (name == null) throw new ArgumentNullException (); enumer = new TheEnum (name, ns, loc, attr); result = new TheResult (name + "Result", ns, name, loc, attr); }
public void Constructor0_Deny_Unrestricted () { CodeLinePragma clp = new CodeLinePragma (); Assert.AreEqual (String.Empty, clp.FileName, "FileName"); clp.FileName = "filename"; Assert.AreEqual (0, clp.LineNumber, "LineNumber"); clp.LineNumber = Int32.MinValue; }
public void Constructor1_Deny_Unrestricted () { CodeLinePragma clp = new CodeLinePragma ("filename", Int32.MaxValue); Assert.AreEqual ("filename", clp.FileName, "FileName"); clp.FileName = String.Empty; Assert.AreEqual (Int32.MaxValue, clp.LineNumber, "LineNumber"); clp.LineNumber = 0; }
private void AddOutputWriteStatement(CodeStatementCollection methodStatements, CodeExpression expr, CodeLinePragma linePragma) { CodeStatement outputWriteStatement = this.GetOutputWriteStatement(expr, false); if (linePragma != null) { outputWriteStatement.LinePragma = linePragma; } methodStatements.Add(outputWriteStatement); }
public virtual void WriteLinePragma(CodeLinePragma pragma) { if (pragma == null) { WriteLinePragma(null, null); } else { WriteLinePragma(pragma.LineNumber, pragma.FileName); } }
internal virtual void BuildExpression(BoundPropertyEntry bpe, ControlBuilder controlBuilder, CodeExpression controlReference, CodeStatementCollection methodStatements, CodeStatementCollection statements, CodeLinePragma linePragma, ref bool hasTempObject) { CodeExpression codeExpression = GetCodeExpression(bpe, bpe.ParsedExpressionData, new ExpressionBuilderContext(controlBuilder.VirtualPath)); CodeDomUtility.CreatePropertySetStatements(methodStatements, statements, controlReference, bpe.Name, bpe.Type, codeExpression, linePragma); }
protected TypeExpressedItem (string namebase, NamespaceBuilder ns, CodeLinePragma loc, TypeAttributes attrs) { if (namebase == null) throw new ArgumentNullException (); this.namebase = namebase; location = loc; this.attrs = attrs; this.ns = ns; ns.AddItem (this); }
public void Constructor1 () { string fileName = "mono"; CodeLinePragma clp = new CodeLinePragma (fileName, 5); Assert.IsNotNull (clp.FileName, "#1"); Assert.AreSame (fileName, clp.FileName, "#2"); Assert.AreEqual (5, clp.LineNumber, "#3"); clp = new CodeLinePragma ((string) null, 10); Assert.IsNotNull (clp.FileName, "#4"); Assert.AreEqual (string.Empty, clp.FileName, "#5"); }
private static void BuildPropertySetExpression(CodeExpression expression, string propertyName, Type propertyType, ControlBuilder controlBuilder, CodeStatementCollection methodStatements, CodeStatementCollection statements, CodeLinePragma linePragma, bool isEncoded, ref bool hasTempObject) { if (isEncoded) { expression = new CodeMethodInvokeExpression( new CodeMethodReferenceExpression( new CodeTypeReferenceExpression(typeof(HttpUtility)), "HtmlEncode"), expression); } CodeDomUtility.CreatePropertySetStatements(methodStatements, statements, new CodeVariableReferenceExpression("dataBindingExpressionBuilderTarget"), propertyName, propertyType, expression, linePragma); }
public void Constructor0 () { CodeVariableDeclarationStatement cvds = new CodeVariableDeclarationStatement (); Assert.IsNull (cvds.InitExpression, "#1"); Assert.IsNotNull (cvds.Name, "#2"); Assert.AreEqual (string.Empty, cvds.Name, "#3"); Assert.IsNotNull (cvds.Type, "#4"); Assert.AreEqual (typeof (void).FullName, cvds.Type.BaseType, "#5"); string name = "mono"; cvds.Name = name; Assert.AreSame (name, cvds.Name, "#6"); cvds.Name = null; Assert.IsNotNull (cvds.Name, "#7"); Assert.AreEqual (string.Empty, cvds.Name, "#8"); CodeExpression expression = new CodeExpression (); cvds.InitExpression = expression; Assert.AreSame (expression, cvds.InitExpression, "#9"); CodeTypeReference type = new CodeTypeReference ("mono"); cvds.Type = type; Assert.AreSame (type, cvds.Type, "#10"); cvds.Type = null; Assert.IsNotNull (cvds.Type, "#11"); Assert.AreEqual (typeof (void).FullName, cvds.Type.BaseType, "#12"); #if NET_2_0 Assert.IsNotNull (cvds.StartDirectives, "#13"); Assert.AreEqual (0, cvds.StartDirectives.Count, "#14"); Assert.IsNotNull (cvds.EndDirectives, "#15"); Assert.AreEqual (0, cvds.EndDirectives.Count, "#16"); #endif Assert.IsNull (cvds.LinePragma, "#17"); CodeLinePragma clp = new CodeLinePragma ("mono", 10); cvds.LinePragma = clp; Assert.IsNotNull (cvds.LinePragma, "#18"); Assert.AreSame (clp, cvds.LinePragma, "#19"); cvds.LinePragma = null; Assert.IsNull (cvds.LinePragma, "#20"); }
public void Constructor0 () { CodeLabeledStatement cls = new CodeLabeledStatement (); Assert.IsNull (cls.LinePragma, "#1"); Assert.IsNotNull (cls.Label, "#2"); Assert.AreEqual (string.Empty, cls.Label, "#3"); #if NET_2_0 Assert.IsNotNull (cls.StartDirectives, "#4"); Assert.AreEqual (0, cls.StartDirectives.Count, "#5"); Assert.IsNotNull (cls.EndDirectives, "#6"); Assert.AreEqual (0, cls.EndDirectives.Count, "#7"); #endif Assert.IsNotNull (cls.UserData, "#8"); Assert.AreEqual (typeof(ListDictionary), cls.UserData.GetType (), "#9"); Assert.AreEqual (0, cls.UserData.Count, "#10"); string label = "mono"; cls.Label = label; Assert.IsNotNull (cls.Label, "#11"); Assert.AreSame (label, cls.Label, "#12"); cls.Label = null; Assert.IsNotNull (cls.Label, "#13"); Assert.AreEqual (string.Empty, cls.Label, "#14"); CodeLinePragma clp = new CodeLinePragma ("mono", 10); cls.LinePragma = clp; Assert.IsNotNull (cls.LinePragma, "#15"); Assert.AreSame (clp, cls.LinePragma, "#16"); cls.LinePragma = null; Assert.IsNull (cls.LinePragma, "#17"); Assert.IsNull (cls.Statement, "#18"); CodeStatement stmt = new CodeStatement (); cls.Statement = stmt; Assert.IsNotNull (cls.Statement, "#19"); Assert.AreSame (stmt, cls.Statement); }
internal static void CreatePropertySetStatements(CodeStatementCollection methodStatements, CodeStatementCollection statements, CodeExpression target, string targetPropertyName, Type destinationType, CodeExpression value, CodeLinePragma linePragma) { bool flag = false; if (destinationType == null) { flag = true; } if (flag) { CodeMethodInvokeExpression expression = new CodeMethodInvokeExpression(); CodeExpressionStatement statement = new CodeExpressionStatement(expression) { LinePragma = linePragma }; expression.Method.TargetObject = new CodeCastExpression(typeof(IAttributeAccessor), target); expression.Method.MethodName = "SetAttribute"; expression.Parameters.Add(new CodePrimitiveExpression(targetPropertyName)); expression.Parameters.Add(GenerateConvertToString(value)); statements.Add(statement); } else if (destinationType.IsValueType) { CodeAssignStatement statement2 = new CodeAssignStatement(BuildPropertyReferenceExpression(target, targetPropertyName), new CodeCastExpression(destinationType, value)) { LinePragma = linePragma }; statements.Add(statement2); } else { CodeExpression expression2; if (destinationType == typeof(string)) { expression2 = GenerateConvertToString(value); } else { expression2 = new CodeCastExpression(destinationType, value); } CodeAssignStatement statement3 = new CodeAssignStatement(BuildPropertyReferenceExpression(target, targetPropertyName), expression2) { LinePragma = linePragma }; statements.Add(statement3); } }
public void Constructor0 () { CodeLinePragma clp = new CodeLinePragma (); Assert.IsNotNull (clp.FileName, "#1"); Assert.AreEqual (string.Empty, clp.FileName, "#2"); Assert.AreEqual (0, clp.LineNumber, "#3"); clp.FileName = null; Assert.IsNotNull (clp.FileName, "#4"); Assert.AreEqual (string.Empty, clp.FileName, "#5"); string fileName = "mono"; clp.FileName = fileName; Assert.IsNotNull (clp.FileName, "#6"); Assert.AreSame (fileName, clp.FileName, "#7"); clp.LineNumber = 5; Assert.AreEqual (5, clp.LineNumber, "#8"); }
public void Constructor0 () { CodeSnippetTypeMember cstm = new CodeSnippetTypeMember (); Assert.AreEqual (MemberAttributes.Private | MemberAttributes.Final, cstm.Attributes, "#1"); Assert.IsNotNull (cstm.Comments, "#2"); Assert.AreEqual (0, cstm.Comments.Count, "#3"); Assert.IsNotNull (cstm.CustomAttributes, "#4"); Assert.AreEqual (0, cstm.CustomAttributes.Count, "#5"); #if NET_2_0 Assert.IsNotNull (cstm.StartDirectives, "#6"); Assert.AreEqual (0, cstm.StartDirectives.Count, "#7"); Assert.IsNotNull (cstm.EndDirectives, "#8"); Assert.AreEqual (0, cstm.EndDirectives.Count, "#9"); #endif Assert.IsNotNull (cstm.Text, "#10"); Assert.AreEqual (string.Empty, cstm.Text, "#11"); Assert.IsNull (cstm.LinePragma, "#12"); Assert.IsNotNull (cstm.Name, "#13"); Assert.AreEqual (string.Empty, cstm.Name, "#14"); Assert.IsNotNull (cstm.UserData, "#15"); Assert.AreEqual (typeof(ListDictionary), cstm.UserData.GetType (), "#16"); Assert.AreEqual (0, cstm.UserData.Count, "#17"); cstm.Name = null; Assert.IsNotNull (cstm.Name, "#18"); Assert.AreEqual (string.Empty, cstm.Name, "#19"); CodeLinePragma clp = new CodeLinePragma ("mono", 10); cstm.LinePragma = clp; Assert.IsNotNull (cstm.LinePragma, "#20"); Assert.AreSame (clp, cstm.LinePragma, "#21"); }
internal static void BuildEvalExpression(string field, string formatString, string propertyName, Type propertyType, ControlBuilder controlBuilder, CodeStatementCollection methodStatements, CodeStatementCollection statements, CodeLinePragma linePragma, ref bool hasTempObject) { CodeMethodInvokeExpression expression = new CodeMethodInvokeExpression { Method = { TargetObject = new CodeThisReferenceExpression(), MethodName = "Eval" } }; expression.Parameters.Add(new CodePrimitiveExpression(field)); if (!string.IsNullOrEmpty(formatString)) { expression.Parameters.Add(new CodePrimitiveExpression(formatString)); } CodeStatementCollection statements2 = new CodeStatementCollection(); BuildPropertySetExpression(expression, propertyName, propertyType, controlBuilder, methodStatements, statements2, linePragma, ref hasTempObject); CodeMethodInvokeExpression left = new CodeMethodInvokeExpression { Method = { TargetObject = new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "Page"), MethodName = "GetDataItem" } }; CodeConditionStatement statement = new CodeConditionStatement { Condition = new CodeBinaryOperatorExpression(left, CodeBinaryOperatorType.IdentityInequality, new CodePrimitiveExpression(null)) }; statement.TrueStatements.AddRange(statements2); statements.Add(statement); }
public void Constructor0 () { CodeNamespaceImport cni = new CodeNamespaceImport (); Assert.IsNull (cni.LinePragma, "#1"); Assert.IsNotNull (cni.Namespace, "#2"); Assert.AreEqual (string.Empty, cni.Namespace, "#3"); CodeLinePragma linePragma = new CodeLinePragma ("a", 5); cni.LinePragma = linePragma; Assert.IsNotNull (cni.LinePragma, "#4"); Assert.AreSame (linePragma, cni.LinePragma, "#5"); cni.LinePragma = null; Assert.IsNull (cni.LinePragma, "#6"); string ns = "mono"; cni.Namespace = ns; Assert.AreSame (ns, cni.Namespace, "#7"); cni.Namespace = null; Assert.IsNotNull (cni.Namespace, "#8"); Assert.AreEqual (string.Empty, cni.Namespace, "#9"); }
public void Constructor0 () { CodeSnippetCompileUnit cscu = new CodeSnippetCompileUnit (); Assert.IsNull (cscu.LinePragma, "#1"); Assert.IsNotNull (cscu.Value, "#2"); Assert.AreEqual (string.Empty, cscu.Value, "#3"); Assert.IsNotNull (cscu.AssemblyCustomAttributes, "#4"); Assert.AreEqual (0, cscu.AssemblyCustomAttributes.Count, "#5"); Assert.IsNotNull (cscu.EndDirectives, "#6"); Assert.AreEqual (0, cscu.EndDirectives.Count, "#7"); Assert.IsNotNull (cscu.Namespaces, "#8"); Assert.AreEqual (0, cscu.Namespaces.Count, "#9"); Assert.IsNotNull (cscu.ReferencedAssemblies, "#10"); Assert.AreEqual (0, cscu.ReferencedAssemblies.Count, "#11"); Assert.IsNotNull (cscu.StartDirectives, "#12"); Assert.AreEqual (0, cscu.StartDirectives.Count, "#13"); Assert.IsNotNull (cscu.UserData, "#14"); Assert.AreEqual (typeof(ListDictionary), cscu.UserData.GetType (), "#15"); Assert.AreEqual (0, cscu.UserData.Count, "#16"); cscu.Value = null; Assert.IsNotNull (cscu.Value, "#17"); Assert.AreEqual (string.Empty, cscu.Value, "#18"); CodeLinePragma clp = new CodeLinePragma ("mono", 10); cscu.LinePragma = clp; Assert.IsNotNull (cscu.LinePragma, "#19"); Assert.AreSame (clp, cscu.LinePragma, "#20"); }
protected override void GenerateLinePragmaStart(System.CodeDom.CodeLinePragma e) { throw new Exception("The method or operation is not implemented."); }
protected override void GenerateLinePragmaEnd(CodeLinePragma e) { Output.WriteLine("[CodeLinePragma: {0}]", e.ToString()); }
private void AddLinePragma(CodeStatement cs, int lineNumber) { CodeLinePragma clp = new CodeLinePragma(ParentFolderPrefix + SourceFileInfo.RelativeSourceFilePath + XAML, lineNumber); cs.LinePragma = clp; }
private void AddLinePragma(CodeTypeMember ctm, int lineNumber) { CodeLinePragma clp = new CodeLinePragma(ParentFolderPrefix + SourceFileInfo.RelativeSourceFilePath + XAML, lineNumber); ctm.LinePragma = clp; }
protected override void GenerateLinePragmaStart(CodeLinePragma e) { base.Output.WriteLine(""); base.Output.Write("#ExternalSource(\""); base.Output.Write(e.FileName); base.Output.Write("\","); base.Output.Write(e.LineNumber); base.Output.WriteLine(")"); }
protected override void GenerateLinePragmaEnd(CodeLinePragma e) { base.Output.WriteLine(""); base.Output.WriteLine("#End ExternalSource"); }