示例#1
0
        public override object Serialize(IDesignerSerializationManager manager, object value)
        {
            CodeDomSerializer serializer1 = (CodeDomSerializer)manager.GetSerializer(this.GetPropType().BaseType, typeof(CodeDomSerializer));
            object            obj1        = serializer1.Serialize(manager, value);

            if (this.ShouldSerialize(value) && (obj1 is CodeStatementCollection))
            {
                string text1 = manager.GetName(value);
                if ((text1 != null) && (text1 != string.Empty))
                {
                    CodeStatementCollection collection1 = (CodeStatementCollection)obj1;
                    CodeExpression          expression1 = base.SerializeToExpression(manager, value);
                    IDesignerHost           host1       = ((Component)value).Container as IDesignerHost;
                    if (host1.RootComponent != null)
                    {
                        string text2 = manager.GetName(host1.RootComponent);
                        if ((text2 != null) && (text2 != string.Empty))
                        {
                            CodePropertyReferenceExpression expression2 = new CodePropertyReferenceExpression(expression1, this.GetPropName());
                            CodeExpression[] expressionArray1           = new CodeExpression[1] {
                                new CodeTypeOfExpression(text2)
                            };
                            expressionArray1 = new CodeExpression[1] {
                                new CodePrimitiveExpression(text1 + ".XmlScheme")
                            };
                            CodeMethodInvokeExpression expression3 = new CodeMethodInvokeExpression(new CodeObjectCreateExpression(typeof(ResourceManager), expressionArray1), "GetObject", expressionArray1);
                            CodeCastExpression         expression4 = new CodeCastExpression("System.String", expression3);
                            CodeAssignStatement        statement1  = new CodeAssignStatement(expression2, expression4);
                            collection1.Add(statement1);
                        }
                    }
                }
            }
            return(obj1);
        }
示例#2
0
 public void ExportCode(ActionBranch currentAction, ActionBranch nextAction, ILimnorCodeCompiler compiler, IMethodCompile methodToCompile, CodeMemberMethod method, CodeStatementCollection statements, bool debug)
 {
     if (IsValid)
     {
         CodeExpression ceCondition = null;
         if (_condition != null)
         {
             ceCondition = _condition.ExportCode(methodToCompile);
             if (ceCondition != null)
             {
                 ceCondition = CompilerUtil.ConvertToBool(_condition.DataType, ceCondition);
             }
         }
         CodeStatementCollection sts = statements;
         if (ceCondition != null)
         {
             CodeConditionStatement cs = new CodeConditionStatement();
             cs.Condition = ceCondition;
             statements.Add(cs);
             sts = cs.TrueStatements;
         }
         CodeExpression right;
         if (_valType.ValueType == EnumValueType.ConstantValue)
         {
             right = _val.GetReferenceCode(methodToCompile, sts, true);
         }
         else
         {
             List <CodeExpression> ps = new List <CodeExpression>();
             ps.Add(_valType.GetReferenceCode(methodToCompile, sts, true));
             if (_val.ConstantValue != null)
             {
                 CodeExpression[] pp = _val.ConstantValue.GetConstructorParameters(methodToCompile, sts);
                 if (pp != null)
                 {
                     ps.AddRange(pp);
                 }
             }
             right = new CodeCastExpression(_var.BaseClassType,
                                            new CodeMethodInvokeExpression(
                                                new CodeTypeReferenceExpression(typeof(Activator)),
                                                "CreateInstance",
                                                ps.ToArray())
                                            );
         }
         CodeExpression left = _var.GetReferenceCode(methodToCompile, sts, false);
         CodeVariableReferenceExpression cvre = left as CodeVariableReferenceExpression;
         CodeSnippetExpression           cse  = right as CodeSnippetExpression;
         if (cvre != null && cse != null && string.CompareOrdinal(cse.Value, string.Format(CultureInfo.InvariantCulture, "{0}++", cvre.VariableName)) == 0)
         {
             CodeExpressionStatement ces = new CodeExpressionStatement(right);
             sts.Add(ces);
         }
         else
         {
             CodeAssignStatement cas = new CodeAssignStatement(left, right);
             sts.Add(cas);
         }
     }
 }
        private void AddEnumGet(EnumPropertyInfo info, CodeMemberProperty property)
        {
            CodeExpression returnExpression;

            if (info.IsMultSelect)
            {
                MultiSelectEnumCreated = true;
                // return EntityOptionSetEnum.GetMultiEnum<info.OptionSetType>(this, info.LogicalName);
                returnExpression =
                    new CodeMethodInvokeExpression(
                        new CodeMethodReferenceExpression(
                            CreateBaseClasses
                                ? new CodeTypeReferenceExpression(EntityBaseClassGenerator.BaseEntityName)
                                : new CodeTypeReferenceExpression("EntityOptionSetEnum"),
                            "GetMultiEnum",
                            new CodeTypeReference(info.OptionSetType)),
                        new CodeThisReferenceExpression(),
                        new CodePrimitiveExpression(info.LogicalName));
            }
            else
            {
                returnExpression =
                    new CodeCastExpression(
                        info.EnumType,
                        new CodeMethodInvokeExpression(
                            CreateBaseClasses
                                ? new CodeTypeReferenceExpression(EntityBaseClassGenerator.BaseEntityName)
                                : new CodeTypeReferenceExpression("EntityOptionSetEnum"),
                            "GetEnum",
                            new CodeThisReferenceExpression(),
                            new CodePrimitiveExpression(info.LogicalName)));
            }

            property.GetStatements.Add(new CodeMethodReturnStatement(returnExpression));
        }
示例#4
0
        public IEnumerable <CodeStatement> GenerateForMethod()
        {
            var methodInfo = this.memberInfo as MethodInfo;

            if (methodInfo == null)
            {
                throw new InvalidOperationException();
            }

            yield return(GenerateMethodStartStatement());

            var returnsValue = methodInfo.ReturnType != typeof(void);
            var aspectInvocationExpression = this.GenerateAspectInvocationForMethod(returnsValue);

            CodeStatement returnValueStatement;

            if (returnsValue)
            {
                var returnValueExpression = new CodeCastExpression(
                    methodInfo.ReturnType, Constructs.BoxedReturnValueExpression);

                returnValueStatement = new CodeMethodReturnStatement(returnValueExpression);
            }
            else
            {
                returnValueStatement = new CodeMethodReturnStatement();
            }

            yield return(new CodeConditionStatement(aspectInvocationExpression,
                                                    new CodeStatement[0],
                                                    returnValueStatement.AsArray()));
        }
示例#5
0
        private void GenerateObjectCollection(CodeTypeDeclaration rootClass,
                                              JsonObjectCollection jsonObject)
        {
            // find default constructor
            CodeConstructor ctor = null;

            foreach (CodeTypeMember m in rootClass.Members)
            {
                CodeConstructor c = m as CodeConstructor;

                if (c != null)
                {
                    if (c.Parameters.Count == 0)
                    {
                        ctor = c;
                        break;
                    }
                }
            }

            if (ctor == null)
            {
                throw new Exception("Cannot find default constructor");
            }

            // enumerate nested data fields
            foreach (JsonObject obj in jsonObject)
            {
                // generate property
                CodeMemberProperty prop = new CodeMemberProperty();
                prop.Name       = obj.Name;
                prop.Attributes = MemberAttributes.Public;
                PropertyInfo valueInfo = obj.GetType().GetProperty("Value");
                if (valueInfo == null)
                {
                    throw new GeneratorException("Cannot generate nested arrays or objects. Wait for release :)");
                }

                prop.Type = new CodeTypeReference(valueInfo.PropertyType);
                CodeExpression rootItem       = new CodeArrayIndexerExpression(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "RootObject"), new CodePrimitiveExpression(obj.Name));
                CodeExpression castedRootItem = new CodeCastExpression(obj.GetType(), rootItem);
                CodeExpression rootItemValue  = new CodeFieldReferenceExpression(castedRootItem, "Value");
                prop.GetStatements.Add(new CodeMethodReturnStatement(rootItemValue));
                prop.SetStatements.Add(new CodeAssignStatement(rootItemValue, new CodePropertySetValueReferenceExpression()));
                rootClass.Members.Add(prop);


                // generate constructor's part
                CodeVariableDeclarationStatement createVar = new CodeVariableDeclarationStatement(obj.GetType(), obj.Name.ToLower(),
                                                                                                  new CodeObjectCreateExpression(obj.GetType(), new CodePrimitiveExpression(obj.Name)));
                //CodeAssignStatement assignVar = new CodeAssignStatement(codevariable
                ctor.Statements.Add(createVar);

                CodeMethodInvokeExpression invokeAdd = new CodeMethodInvokeExpression(new CodeMethodReferenceExpression(new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "RootObject"), "Add"),
                                                                                      new CodeVariableReferenceExpression(obj.Name.ToLower()));
                ctor.Statements.Add(invokeAdd);
                //JsonStringValue name = new JsonStringValue("Name");
                //RootObject.Add(name);
            }
        }
示例#6
0
        void AddProfileClassGroupProperty(string groupName, string memberName, CodeTypeDeclaration profileClass)
        {
            CodeMemberProperty property = new CodeMemberProperty();

            property.Name       = memberName;
            property.Type       = new CodeTypeReference(groupName);
            property.Attributes = MemberAttributes.Public;

            CodeMethodReturnStatement ret  = new CodeMethodReturnStatement();
            CodeCastExpression        cast = new CodeCastExpression();

            ret.Expression = cast;

            CodeMethodReferenceExpression mref = new CodeMethodReferenceExpression(
                new CodeThisReferenceExpression(),
                "GetProfileGroup");
            CodeMethodInvokeExpression minvoke = new CodeMethodInvokeExpression(
                mref,
                new CodeExpression[] { new CodePrimitiveExpression(memberName) }
                );

            cast.TargetType = new CodeTypeReference(groupName);
            cast.Expression = minvoke;
            property.GetStatements.Add(ret);

            profileClass.Members.Add(property);
        }
示例#7
0
        CodeMemberMethod CreateMethod()
        {
            CodeMemberMethod method = new CodeMemberMethod();

            // BeginInit method call.
            CodeExpressionStatement    statement    = new CodeExpressionStatement();
            CodeMethodInvokeExpression methodInvoke = new CodeMethodInvokeExpression();

            statement.Expression = methodInvoke;

            CodeMethodReferenceExpression methodRef = new CodeMethodReferenceExpression();

            methodRef.MethodName = "BeginInit";

            CodeCastExpression cast = new CodeCastExpression();

            cast.TargetType          = new CodeTypeReference();
            cast.TargetType.BaseType = "System.ComponentModel.ISupportInitialize";

            CodeFieldReferenceExpression fieldRef = new CodeFieldReferenceExpression();

            fieldRef.FieldName    = "pictureBox1";
            fieldRef.TargetObject = new CodeThisReferenceExpression();
            cast.Expression       = fieldRef;

            methodRef.TargetObject = cast;
            methodInvoke.Method    = methodRef;

            method.Statements.Add(statement);
            return(method);
        }
        private static void AddWriteXml(CodeTypeDeclaration classToGen)
        {
            CodeMemberMethod writeXml = new CodeMemberMethod();

            writeXml.Name       = "WriteXml";
            writeXml.Attributes = MemberAttributes.Public;
            writeXml.ImplementationTypes.Add(classToGen.BaseTypes[1]);

            writeXml.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference(typeof(Microsoft.Xml.XmlWriter)), "writer"));
            CodeVariableDeclarationStatement enumeratorDec =
                new CodeVariableDeclarationStatement(
                    CreateTypeReference("System.Collections.Generic.IEnumerator`1", xelementType), "e",
                    new CodeMethodInvokeExpression(new CodeVariableReferenceExpression("nodesList"), "GetEnumerator"));

            writeXml.Statements.Add(enumeratorDec);

            CodeVariableReferenceExpression eRef     = new CodeVariableReferenceExpression("e");
            CodePropertyReferenceExpression eCurrent = new CodePropertyReferenceExpression(eRef, "Current");
            CodeCastExpression         iXmlSerCast   = new CodeCastExpression(new CodeTypeReference(typeof(Microsoft.Xml.Serialization.IXmlSerializable)), eCurrent);
            CodeMethodInvokeExpression codeWrite     = new CodeMethodInvokeExpression(iXmlSerCast, "WriteXml", new CodeVariableReferenceExpression("writer"));

            CodeIterationStatement codeFor = new CodeIterationStatement();

            codeFor.TestExpression = new CodeMethodInvokeExpression(new CodeMethodReferenceExpression(new CodeVariableReferenceExpression("e"), "MoveNext"));
            codeFor.Statements.Add(codeWrite);
            codeFor.IncrementStatement = new CodeSnippetStatement("");
            codeFor.InitStatement      = new CodeSnippetStatement("");

            writeXml.Statements.Add(codeFor);

            classToGen.Members.Add(writeXml);
        }
示例#9
0
        public override void AddConstructor(IShaderDom shader, Action <CodeStatement> add)
        {
            //setup the default values for the masks and samplers

            if (psSamplers.Count > 0)
            {
                //set the PS mask to a big number
                CodeStatement assign = new CodeAssignStatement(new CodeFieldReferenceExpression(shader.Instance, "psm"), new CodePrimitiveExpression(int.MaxValue));
                add(assign);
            }

            if (vsSamplers.Count > 0)
            {
                //set the PS mask to a big number
                CodeStatement assign = new CodeAssignStatement(new CodeFieldReferenceExpression(shader.Instance, "vsm"), new CodePrimitiveExpression(int.MaxValue));
                add(assign);
            }

            //set the samplers to their defaults

            foreach (SharedSampler ss in allSamplers.Values)
            {
                //get the default as an int,
                //then cast it to a sampler state using explicit cast construction
                CodeExpression value = new CodeCastExpression(typeof(Xen.Graphics.State.TextureSamplerState), new CodePrimitiveExpression((int)ss.DefaultState));

                //assign the value
                CodeStatement assign = new CodeAssignStatement(new CodeFieldReferenceExpression(shader.Instance, "ts" + ss.Index), value);
                add(assign);
            }
        }
 public static CodeExpression GetDrawItemExpression(DrawingControl dc)
 {
     if (dc != null)
     {
         DrawingItem di = dc.Item as DrawingItem;
         if (di != null)
         {
             DrawDataRepeater ddp = di.Container as DrawDataRepeater;
             if (ddp != null)
             {
                 //((item type)<repeater name>[<drawing item name>])
                 TypeMappingAttribute tma = null;
                 object[]             vs  = dc.GetType().GetCustomAttributes(typeof(TypeMappingAttribute), true);
                 if (vs != null && vs.Length > 0)
                 {
                     tma = vs[0] as TypeMappingAttribute;
                 }
                 if (tma != null)
                 {
                     CodeFieldReferenceExpression repeater = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), ddp.Name);
                     CodeIndexerExpression        cie      = new CodeIndexerExpression(repeater, new CodePrimitiveExpression(dc.Name));
                     CodeCastExpression           cce      = new CodeCastExpression(tma.MappedType, cie);
                     return(cce);
                 }
             }
         }
     }
     return(null);
 }
        /// <summary>
        /// Constructs a single property in the template.
        /// </summary>
        private void CreateProperty(CodeTypeDeclaration ctd,
                                    string propertyName, string contextName, string typeName)
        {
            // Create the property
            CodeMemberProperty property = new CodeMemberProperty();

            property.Name       = propertyName;
            property.Type       = new CodeTypeReference(typeName);
            property.Attributes = MemberAttributes.Public;
            ctd.Members.Add(property);

            // Context variables
            CodeVariableReferenceExpression context =
                new CodeVariableReferenceExpression("Context");
            CodePrimitiveExpression contextEx =
                new CodePrimitiveExpression(contextName);
            CodeArrayIndexerExpression atContext =
                new CodeArrayIndexerExpression(context, contextEx);

            // Create the getter
            CodeCastExpression getCast =
                new CodeCastExpression(typeName, atContext);
            CodeMethodReturnStatement getReturn =
                new CodeMethodReturnStatement(getCast);

            property.GetStatements.Add(getReturn);

            // Create the setter
            CodeVariableReferenceExpression valueExpression =
                new CodeVariableReferenceExpression("value");
            CodeAssignStatement set =
                new CodeAssignStatement(atContext, valueExpression);

            property.SetStatements.Add(set);
        }
示例#12
0
            // pops: reference to the object being ended
            // pops: the type of the object being ended
            //
            // destType is the type of the property to which the object will be stored
            public override void EndPropertyObject(Type destType)
            {
                debug();
                CodeExpression varRef     = (CodeExpression)pop();
                Type           sourceType = (Type)pop();

                Debug.WriteLine("ParserToCode: " + destType + "->" + sourceType);


                CodeExpression expr;

                if (sourceType == destType || sourceType.IsSubclassOf(destType))
                {
                    expr = varRef;
                }
                else
                {
                    expr = new CodeCastExpression(
                        new CodeTypeReference(destType),
                        new CodeMethodInvokeExpression(
                            fetchConverter(sourceType),
                            "ConvertTo",
                            varRef,
                            new CodeTypeOfExpression(destType)));
                }
                CodeAssignStatement assignment = new CodeAssignStatement(
                    (CodeExpression)peek(),
                    expr);

                constructor.Statements.Add(assignment);
            }
示例#13
0
 private void RefactorMethodNamesInStatement(CodeStatement statement, string newName)
 {
     if (typeof(CodeVariableDeclarationStatement) == statement.GetType())
     {
         CodeVariableDeclarationStatement vdeclStatement = (CodeVariableDeclarationStatement)statement;
         if (vdeclStatement.InitExpression != null)
         {
             if (typeof(CodeCastExpression) == vdeclStatement.InitExpression.GetType())
             {
                 CodeCastExpression castExp = (CodeCastExpression)vdeclStatement.InitExpression;
                 if (typeof(CodeMethodInvokeExpression) == castExp.Expression.GetType())
                 {
                     CodeMethodInvokeExpression miExp = (CodeMethodInvokeExpression)castExp.Expression;
                     miExp.Method.MethodName = PascalCaseConverterHelper.GetPascalCaseMethodName(miExp.Method.MethodName);
                 }
             }
             else if (typeof(CodeMethodInvokeExpression) == vdeclStatement.InitExpression.GetType())
             {
                 CodeMethodInvokeExpression miExp = (CodeMethodInvokeExpression)vdeclStatement.InitExpression;
                 miExp.Method.MethodName = PascalCaseConverterHelper.GetPascalCaseMethodName(miExp.Method.MethodName);
             }
         }
     }
     else if (typeof(CodeExpressionStatement) == statement.GetType())
     {
         CodeExpressionStatement ceStatement = (CodeExpressionStatement)statement;
         if (typeof(CodeMethodInvokeExpression) == ceStatement.Expression.GetType())
         {
             CodeMethodInvokeExpression miExp = (CodeMethodInvokeExpression)ceStatement.Expression;
             miExp.Method.MethodName = PascalCaseConverterHelper.GetPascalCaseMethodName(miExp.Method.MethodName);
         }
     }
     else if (typeof(CodeAssignStatement) == statement.GetType())
     {
         CodeAssignStatement asnStatement = (CodeAssignStatement)statement;
         if (typeof(CodeCastExpression) == asnStatement.Right.GetType())
         {
             CodeCastExpression castExp = (CodeCastExpression)asnStatement.Right;
             if (typeof(CodeMethodInvokeExpression) == castExp.Expression.GetType())
             {
                 CodeMethodInvokeExpression miExp = (CodeMethodInvokeExpression)castExp.Expression;
                 miExp.Method.MethodName = PascalCaseConverterHelper.GetPascalCaseMethodName(miExp.Method.MethodName);
             }
         }
         else if (typeof(CodeMethodInvokeExpression) == asnStatement.Right.GetType())
         {
             CodeMethodInvokeExpression miExp = (CodeMethodInvokeExpression)asnStatement.Right;
             miExp.Method.MethodName = PascalCaseConverterHelper.GetPascalCaseMethodName(miExp.Method.MethodName);
         }
     }
     else if (typeof(CodeMethodReturnStatement) == statement.GetType())
     {
         CodeMethodReturnStatement retStatement = (CodeMethodReturnStatement)statement;
         if (typeof(CodeMethodInvokeExpression) == retStatement.Expression.GetType())
         {
             CodeMethodInvokeExpression miExp = (CodeMethodInvokeExpression)retStatement.Expression;
             miExp.Method.MethodName = PascalCaseConverterHelper.GetPascalCaseMethodName(miExp.Method.MethodName);
         }
     }
 }
示例#14
0
        private static void MakeReturnStatement(CodeMemberMethod method, Type returnType)
        {
            if (returnType != typeof(void))
            {
                // create a cast statement
                CodeCastExpression cce = new CodeCastExpression(
                    returnType,
                    new CodeVariableReferenceExpression(DEFAULT_TEMP)
                    );

                CodeAssignStatement casCast = new CodeAssignStatement();
                casCast.Left  = new CodeVariableReferenceExpression(DEFAULT_RET);
                casCast.Right = cce;

                method.Statements.Add(casCast);

                // return retVal
                CodeMethodReturnStatement cmrsCast = new CodeMethodReturnStatement();
                cmrsCast.Expression = new CodeVariableReferenceExpression(DEFAULT_RET);

                method.Statements.Add(cmrsCast);
            }
            else
            {
                // construct an undecorated return statement
                method.Statements.Add(new CodeMethodReturnStatement());
            }
        }
        public void Constructor0()
        {
            CodeCastExpression cce = new CodeCastExpression();

            Assert.IsNull(cce.Expression, "#1");
            Assert.IsNotNull(cce.TargetType, "#2");
            Assert.AreEqual(typeof(void).FullName, cce.TargetType.BaseType, "#3");

            CodeExpression expression = new CodeExpression();

            cce.Expression = expression;
            Assert.IsNotNull(cce.Expression, "#4");
            Assert.AreSame(expression, cce.Expression, "#5");

            cce.Expression = null;
            Assert.IsNull(cce.Expression, "#6");

            CodeTypeReference type = new CodeTypeReference("mono");

            cce.TargetType = type;
            Assert.IsNotNull(cce.TargetType, "#7");
            Assert.AreSame(type, cce.TargetType, "#8");

            cce.TargetType = null;
            Assert.IsNotNull(cce.TargetType, "#9");
            Assert.AreEqual(typeof(void).FullName, cce.TargetType.BaseType, "#10");
        }
        private static Rule Rule_with_Cast_object_expression_in_then_action()
        {
            // define first predicate: this.State == "VA"
            CodeBinaryOperatorExpression ruleStateTest = new CodeBinaryOperatorExpression
            {
                Left     = new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "State"),
                Operator = CodeBinaryOperatorType.ValueEquality,
                Right    = new CodePrimitiveExpression("VA")
            };

            //(SampleFlow.ChildEntity)this.DClass
            CodeCastExpression castExpression = new CodeCastExpression
                                                (
                "SampleFlow.ChildEntity",
                //this.DClass
                new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "DClass")
                                                );

            //((SampleFlow.ChildEntity)this.DClass).Description = "This Description"
            CodeAssignStatement assignmentAction = new CodeAssignStatement
                                                   (
                new CodePropertyReferenceExpression(castExpression, "Description"),
                new CodePrimitiveExpression("This Description")
                                                   );

            Rule rule7 = new Rule("Rule7")
            {
                Condition = new RuleExpressionCondition(ruleStateTest)
            };

            rule7.ThenActions.Add(new RuleStatementAction(assignmentAction));

            return(rule7);
        }
示例#17
0
        public CodeMemberMethod Generate()
        {
            this.returnsValue = this.contractMethod.ReturnType != typeof(void);

            this.methodDeclaration = new CodeMemberMethod
            {
                Name       = this.contractMethod.Name,
                ReturnType = new CodeTypeReference(this.contractMethod.ReturnType),
                Attributes = MemberAttributes.Public
            };

            this.methodInvocation = new CodeMethodInvokeExpression(
                Constructs.TargetFieldExpression,
                this.contractMethod.Name);

            this.AssignParameters();
            this.AssignTypeParameters();
            this.AssignReturnValueDeclaration();
            this.AssignBodyWithAspectCode();

            if (this.returnsValue)
            {
                var castExpression = new CodeCastExpression(
                    this.contractMethod.ReturnType, Constructs.BoxedReturnValueExpression);
                var returnValueStatement = new CodeMethodReturnStatement(castExpression);
                this.methodDeclaration.Statements.Add(returnValueStatement);
            }

            this.AssignAspectAttributes();

            return(this.methodDeclaration);
        }
示例#18
0
        /// <summary>
        ///  This emits a method invoke to ISupportInitialize.
        /// </summary>
        private void SerializeSupportInitialize(IDesignerSerializationManager manager, CodeStatementCollection statements, CodeExpression valueExpression, object value, string methodName)
        {
            Trace("Emitting {0}", methodName);

            CodeTypeReference             type         = new CodeTypeReference(typeof(ISupportInitialize));
            CodeCastExpression            castExp      = new CodeCastExpression(type, valueExpression);
            CodeMethodReferenceExpression method       = new CodeMethodReferenceExpression(castExp, methodName);
            CodeMethodInvokeExpression    methodInvoke = new CodeMethodInvokeExpression
            {
                Method = method
            };

            CodeExpressionStatement statement = new CodeExpressionStatement(methodInvoke);

            if (methodName == "BeginInit")
            {
                statement.UserData["statement-ordering"] = "begin";
            }
            else
            {
                statement.UserData["statement-ordering"] = "end";
            }

            statements.Add(statement);
        }
示例#19
0
        void CreateStronglyTypedProperty(Type type, string name)
        {
            if (type == null)
            {
                return;
            }

            CodeMemberProperty mprop = new CodeMemberProperty();

            mprop.Name       = name;
            mprop.Type       = new CodeTypeReference(type);
            mprop.Attributes = MemberAttributes.Public | MemberAttributes.New;
            CodeExpression prop = new CodePropertyReferenceExpression(new CodeBaseReferenceExpression(), name);

            prop = new CodeCastExpression(type, prop);
            mprop.GetStatements.Add(new CodeMethodReturnStatement(prop));
            if (partialClass != null)
            {
                partialClass.Members.Add(mprop);
            }
            else
            {
                mainClass.Members.Add(mprop);
            }

            AddReferencedAssembly(type.Assembly);
        }
示例#20
0
        private static void CreateParentProperty(CodeTypeDeclaration classType, TableInfo tableInfo)
        {
            if (string.IsNullOrEmpty(tableInfo.ParentName) == true)
            {
                return;
            }

            var cmp = new CodeMemberProperty()
            {
                Attributes = MemberAttributes.Public | MemberAttributes.Final,
                Name       = "Parent",
                Type       = tableInfo.GetParentRowCodeType(),
                HasGet     = true,
                HasSet     = false
            };

            // statement
            {
                var parentExp = new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "ParentInternal");
                var castExp   = new CodeCastExpression(tableInfo.GetParentRowCodeType(), parentExp);
                cmp.GetStatements.AddMethodReturn(castExp);
            }

            classType.Members.Add(cmp);
        }
示例#21
0
        private CodeStatement GenerateCallStatementC2J(GMethod method, CodeExpression invokeExpression, bool fieldSetter)
        {
            CodeStatement call;

            if (method.IsConstructor || method.IsVoid || fieldSetter)
            {
                call = new CodeExpressionStatement(invokeExpression);
            }
            else
            {
                if (method.ReturnType.IsPrimitive)
                {
                    if (method.ReturnType.JVMSubst != null)
                    {
                        invokeExpression = new CodeCastExpression(method.ReturnType.CLRReference, invokeExpression);
                    }
                    call = new CodeMethodReturnStatement(invokeExpression);
                }
                else
                {
                    CodeMethodInvokeExpression conversionExpression = CreateConversionExpressionJ2CParam(method.ReturnType,
                                                                                                         invokeExpression);
                    call = new CodeMethodReturnStatement(conversionExpression);
                }
            }
            return(call);
        }
示例#22
0
        internal override void Decompile(CodeExpression expression, StringBuilder stringBuilder, CodeExpression parentExpression)
        {
            CodeCastExpression childExpr   = (CodeCastExpression)expression;
            CodeExpression     expression3 = childExpr.Expression;

            if (expression3 == null)
            {
                RuleEvaluationException exception = new RuleEvaluationException(Messages.NullCastExpr);
                exception.Data["ErrorObject"] = childExpr;
                throw exception;
            }
            if (childExpr.TargetType == null)
            {
                RuleEvaluationException exception2 = new RuleEvaluationException(Messages.NullCastType);
                exception2.Data["ErrorObject"] = childExpr;
                throw exception2;
            }
            bool flag = RuleDecompiler.MustParenthesize(childExpr, parentExpression);

            if (flag)
            {
                stringBuilder.Append("(");
            }
            stringBuilder.Append("(");
            RuleDecompiler.DecompileType(stringBuilder, childExpr.TargetType);
            stringBuilder.Append(")");
            RuleExpressionWalker.Decompile(stringBuilder, expression3, childExpr);
            if (flag)
            {
                stringBuilder.Append(")");
            }
        }
示例#23
0
        internal override RuleExpressionResult Evaluate(CodeExpression expression, RuleExecution execution)
        {
            CodeCastExpression expression2  = (CodeCastExpression)expression;
            object             operandValue = RuleExpressionWalker.Evaluate(execution, expression2.Expression).Value;
            RuleExpressionInfo info         = execution.Validation.ExpressionInfo(expression2);

            if (info == null)
            {
                InvalidOperationException exception = new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Messages.ExpressionNotValidated, new object[0]));
                exception.Data["ErrorObject"] = expression2;
                throw exception;
            }
            Type expressionType = info.ExpressionType;

            if (operandValue == null)
            {
                if (ConditionHelper.IsNonNullableValueType(expressionType))
                {
                    RuleEvaluationException exception2 = new RuleEvaluationException(string.Format(CultureInfo.CurrentCulture, Messages.CastIncompatibleTypes, new object[] { Messages.NullValue, RuleDecompiler.DecompileType(expressionType) }));
                    exception2.Data["ErrorObject"] = expression2;
                    throw exception2;
                }
            }
            else
            {
                operandValue = Executor.AdjustTypeWithCast(execution.Validation.ExpressionInfo(expression2.Expression).ExpressionType, operandValue, expressionType);
            }
            return(new RuleLiteralResult(operandValue));
        }
示例#24
0
        internal static CodeCastExpression BuildJSharpCastExpression(Type castType, CodeExpression expression)
        {
            CodeCastExpression expression2 = new CodeCastExpression(castType, expression);

            expression2.UserData.Add("CastIsBoxing", true);
            return(expression2);
        }
示例#25
0
        internal override bool Match(CodeExpression expression, CodeExpression comperand)
        {
            CodeCastExpression expression2 = (CodeCastExpression)expression;
            CodeCastExpression expression3 = (CodeCastExpression)comperand;

            return(TypeReferenceExpression.MatchType(expression2.TargetType, expression3.TargetType) && RuleExpressionWalker.Match(expression2.Expression, expression3.Expression));
        }
        /// <summary>
        /// Generates a derived <see cref="TransformationContext"/> with a strongly-typed
        /// <see cref="TransformationContext.Transformation"/> property.
        /// </summary>
        private void GenerateTransformationContext()
        {
            //// public abstract class TransformationContext : T4Toolbox.TransformationContext {
            CodeTypeDeclaration transformationContext = new CodeTypeDeclaration("TransformationContext");

            transformationContext.TypeAttributes = TypeAttributes.Abstract | TypeAttributes.Public;
            transformationContext.BaseTypes.Add(new CodeTypeReference(typeof(TransformationContext)));

            ////     public new static GeneratedTextTransformation Transformation {
            CodeMemberProperty transformation = new CodeMemberProperty();

            transformation.Attributes = MemberAttributes.Public | MemberAttributes.New | MemberAttributes.Static;
            transformation.Type       = new CodeTypeReference("GeneratedTextTransformation");
            transformation.Name       = "Transformation";
            transformationContext.Members.Add(transformation);

            ////         get { return (GeneratedTextTransformation)T4Toolbox.TransformationContext.Transformation; }
            ////     }
            CodePropertyReferenceExpression propertyReference = new CodePropertyReferenceExpression(
                new CodeTypeReferenceExpression(typeof(TransformationContext)),
                "Transformation");
            CodeCastExpression castExpression = new CodeCastExpression("GeneratedTextTransformation", propertyReference);

            transformation.GetStatements.Add(new CodeMethodReturnStatement(castExpression));

            //// }
            this.LanguageProvider.GenerateCodeFromType(transformationContext, this.ClassCode, null);
        }
示例#27
0
        void InternalCreatePageProperty(string retType, string name, string contextProperty)
        {
            CodeMemberProperty property = new CodeMemberProperty();

            property.Name       = name;
            property.Type       = new CodeTypeReference(retType);
            property.Attributes = MemberAttributes.Family | MemberAttributes.Final;

            CodeMethodReturnStatement ret  = new CodeMethodReturnStatement();
            CodeCastExpression        cast = new CodeCastExpression();

            ret.Expression = cast;

            CodePropertyReferenceExpression refexp = new CodePropertyReferenceExpression();

            refexp.TargetObject = new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "Context");
            refexp.PropertyName = contextProperty;

            cast.TargetType = new CodeTypeReference(retType);
            cast.Expression = refexp;

            property.GetStatements.Add(ret);
            if (partialClass == null)
            {
                mainClass.Members.Add(property);
            }
            else
            {
                partialClass.Members.Add(property);
            }
        }
示例#28
0
 protected override void GenerateCastExpression(CodeCastExpression expression)
 {
     OutputType(expression.TargetType);
     Output.Write('(');
     GenerateExpression(expression.Expression);
     Output.Write(')');
 }
        /// <summary>
        ///  Serializes the given object into a CodeDom object.
        /// </summary>
        public override object Serialize(IDesignerSerializationManager manager, object value)
        {
            using (TraceScope("PrimitiveCodeDomSerializer::" + nameof(Serialize)))
            {
                Trace("Value: {0}", (value is null ? "(null)" : value.ToString()));
            }

            CodeExpression expression = new CodePrimitiveExpression(value);

            if (value is null)
            {
                return(expression);
            }

            if (value is string stringValue)
            {
                if (stringValue.Length > 200)
                {
                    expression = SerializeToResourceExpression(manager, stringValue);
                }

                return(expression);
            }

            if (!(value is bool || value is char || value is int || value is float || value is double))
            {
                // Generate a cast for all other types because we won't parse them properly otherwise
                // because we won't know to convert them to the narrow form.
                expression = new CodeCastExpression(new CodeTypeReference(value.GetType()), expression);
            }

            return(expression);
        }
示例#30
0
        void AddProfileClassGetProfileMethod(CodeTypeDeclaration profileClass)
        {
            CodeMethodReferenceExpression mref = new CodeMethodReferenceExpression(
                new CodeTypeReferenceExpression(typeof(System.Web.Profile.ProfileBase)),
                "Create");
            CodeMethodInvokeExpression minvoke = new CodeMethodInvokeExpression(
                mref,
                new CodeExpression[] { new CodeVariableReferenceExpression("username") }
                );
            CodeCastExpression cast = new CodeCastExpression();

            cast.TargetType = new CodeTypeReference("ProfileCommon");
            cast.Expression = minvoke;

            CodeMethodReturnStatement ret = new CodeMethodReturnStatement();

            ret.Expression = cast;

            CodeMemberMethod method = new CodeMemberMethod();

            method.Name       = "GetProfile";
            method.ReturnType = new CodeTypeReference("ProfileCommon");
            method.Parameters.Add(new CodeParameterDeclarationExpression("System.String", "username"));
            method.Statements.Add(ret);
            method.Attributes = MemberAttributes.Public;

            profileClass.Members.Add(method);
        }
示例#31
0
 protected abstract void GenerateCastExpression(CodeCastExpression e);
	protected override void GenerateCastExpression
				(CodeCastExpression e)
			{
				Output.Write("CType(");
				GenerateExpression(e.Expression);
				Output.Write(", ");
				OutputType(e.TargetType);
				Output.Write(")");
			}
示例#33
0
 private void GenerateCastExpression(CodeCastExpression e)
 {
     OutputType(e.TargetType);
     Output.Write("(");
     GenerateExpression(e.Expression);
     Output.Write(")");
 }
示例#34
0
			public void Visit(CodeCastExpression o)
			{
				g.GenerateCastExpression(o);
			}
	protected override void GenerateCastExpression
				(CodeCastExpression e)
			{
				// Heavily bracket the cast to prevent the possibility
				// of ambiguity issues within the compiler.  See the
				// Portable.NET "cs_grammar.y" file for a description of
				// the possible conflicts that may arise without brackets.
				Output.Write("((");
				OutputType(e.TargetType);
				Output.Write(")(");
				GenerateExpression(e.Expression);
				Output.Write("))");
			}
示例#36
0
 private void ValidateCastExpression(CodeCastExpression e)
 {
     ValidateTypeReference(e.TargetType);
     ValidateExpression(e.Expression);
 }