private static CodeTypeMember CreatePickRandom()
        {
            var pickRandom = new CodeMemberMethod
            {
                Name           = "PickRandom",
                Attributes     = MemberAttributes.Public | MemberAttributes.Static,
                TypeParameters = { new CodeTypeParameter("T") },
                ReturnType     = new CodeTypeReference("T")
            };

            var optionParam = new CodeParameterDeclarationExpression(new CodeTypeReference("T[]"), "options");

            optionParam.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeTypeReference(typeof(System.ParamArrayAttribute))));
            pickRandom.Parameters.Add(optionParam);

            var randomiserCall = new CodeMethodInvokeExpression(
                new CodeTypeReferenceExpression("Randomiser"),
                "Next",
                new CodePrimitiveExpression(0),
                new CodeBinaryOperatorExpression(
                    new CodePropertyReferenceExpression(new CodeVariableReferenceExpression("options"), "Length"),
                    CodeBinaryOperatorType.Subtract,
                    new CodePrimitiveExpression(1)));

            var index = new CodeIndexerExpression(new CodeVariableReferenceExpression("options"), randomiserCall);

            pickRandom.Statements.Add(new CodeMethodReturnStatement(index));

            //public static string PickRandom(params string[] options)
            //{
            //    return options[Randomiser.Next(0, options.Length - 1)];
            //}

            return(pickRandom);
        }
 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);
 }
        public bool ValidateCodeIndexerExpression(CodeIndexerExpression exp)
        {
            bool result = true;

            PushLocation(exp);

            if (!IsSimpleTarget(exp.TargetObject))
            {
                result = false;
            }

            if (exp.Indices == null || exp.Indices.Count != 1)
            {
                PushError("There must be at least one index.");
                result = false;
            }

            if (exp.Indices.Count == 1 && !IsSimpleTarget(exp.Indices[0]))
            {
                PushError("Index must be a simple target.");
                result = false;
            }

            PopLocation();
            return(result);
        }
Esempio n. 4
0
 protected override void GenerateIndexerExpression(CodeIndexerExpression expression)
 {
     GenerateExpression(expression.TargetObject);
     Output.Write('(');
     OutputExpressionList(expression.Indices);
     Output.Write(')');
 }
        private bool HandleDynamic(CodeIndexerExpression obj, Context ctx)
        {
            CodeArrayIndexerExpression equivalent = new CodeArrayIndexerExpression(obj.TargetObject);

            equivalent.Indices.AddRange(obj.Indices);
            return(ctx.HandlerProvider.ExpressionHandler.Handle(equivalent, ctx));
        }
Esempio n. 6
0
        internal override void Decompile(CodeExpression expression, StringBuilder stringBuilder, CodeExpression parentExpression)
        {
            CodeIndexerExpression expression2  = (CodeIndexerExpression)expression;
            CodeExpression        targetObject = expression2.TargetObject;

            if (targetObject == null)
            {
                RuleEvaluationException exception = new RuleEvaluationException(string.Format(CultureInfo.CurrentCulture, Messages.NullIndexerTarget, new object[0]));
                exception.Data["ErrorObject"] = expression2;
                throw exception;
            }
            if ((expression2.Indices == null) || (expression2.Indices.Count == 0))
            {
                RuleEvaluationException exception2 = new RuleEvaluationException(string.Format(CultureInfo.CurrentCulture, Messages.MissingIndexExpressions, new object[0]));
                exception2.Data["ErrorObject"] = expression2;
                throw exception2;
            }
            RuleExpressionWalker.Decompile(stringBuilder, targetObject, expression2);
            stringBuilder.Append('[');
            RuleExpressionWalker.Decompile(stringBuilder, expression2.Indices[0], null);
            for (int i = 1; i < expression2.Indices.Count; i++)
            {
                stringBuilder.Append(", ");
                RuleExpressionWalker.Decompile(stringBuilder, expression2.Indices[i], null);
            }
            stringBuilder.Append(']');
        }
        private CodeStatement BuildControlSkinAssignmentStatement(ControlBuilder builder, string skinID)
        {
            Type            controlType = builder.ControlType;
            string          name        = base.GetMethodNameForBuilder(BaseTemplateCodeDomTreeGenerator.buildMethodPrefix, builder) + "_skinKey";
            CodeMemberField field       = new CodeMemberField(typeof(object), name)
            {
                Attributes = MemberAttributes.Private | MemberAttributes.Static
            };
            CodeMethodInvokeExpression expression = new CodeMethodInvokeExpression {
                Method = new CodeMethodReferenceExpression(new CodeTypeReferenceExpression(typeof(PageTheme)), "CreateSkinKey")
            };

            expression.Parameters.Add(new CodeTypeOfExpression(controlType));
            expression.Parameters.Add(new CodePrimitiveExpression(skinID));
            field.InitExpression = expression;
            base._sourceDataClass.Members.Add(field);
            CodeFieldReferenceExpression targetObject = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "__controlSkins");
            CodeIndexerExpression        left         = new CodeIndexerExpression(targetObject, new CodeExpression[] { new CodeVariableReferenceExpression(name) });
            CodeDelegateCreateExpression expression4  = new CodeDelegateCreateExpression(this._controlSkinDelegateType, new CodeThisReferenceExpression(), base.GetMethodNameForBuilder(BaseTemplateCodeDomTreeGenerator.buildMethodPrefix, builder));
            CodeObjectCreateExpression   right        = new CodeObjectCreateExpression(this._controlSkinType, new CodeExpression[0]);

            right.Parameters.Add(new CodeTypeOfExpression(controlType));
            right.Parameters.Add(expression4);
            return(new CodeAssignStatement(left, right));
        }
Esempio n. 8
0
        private static CodePropertyReferenceExpression DeserializeAppConfigExpression(string[] expressionParts)
        {
            int index = expressionParts.Length - 1;
            CodePropertyReferenceExpression expression = new CodePropertyReferenceExpression {
                PropertyName = expressionParts[index]
            };

            index--;
            CodeIndexerExpression expression2 = new CodeIndexerExpression();

            expression.TargetObject = expression2;
            expression2.Indices.Add(new CodePrimitiveExpression(expressionParts[index]));
            index--;
            CodePropertyReferenceExpression expression3 = new CodePropertyReferenceExpression();

            expression2.TargetObject = expression3;
            expression3.PropertyName = expressionParts[index];
            index--;
            CodeTypeReferenceExpression expression4 = new CodeTypeReferenceExpression();

            expression3.TargetObject = expression4;
            expression4.Type.Options = (CodeTypeReferenceOptions)Enum.Parse(typeof(CodeTypeReferenceOptions), expressionParts[index]);
            index--;
            expression4.Type.BaseType = expressionParts[index];
            index--;
            while (index > 0)
            {
                expression4.Type.BaseType = expressionParts[index] + "." + expression4.Type.BaseType;
                index--;
            }
            return(expression);
        }
Esempio n. 9
0
 protected override void GenerateIndexerExpression
     (CodeIndexerExpression e)
 {
     GenerateExpression(e.TargetObject);
     Output.Write("[");
     OutputExpressionList(e.Indices);
     Output.Write("]");
 }
        public void Constructor0_Deny_Unrestricted()
        {
            CodeIndexerExpression cie = new CodeIndexerExpression();

            Assert.AreEqual(0, cie.Indices.Count, "Indices");
            Assert.IsNull(cie.TargetObject, "TargetObject");
            cie.TargetObject = new CodeExpression();
        }
Esempio n. 11
0
 private void ValidateIndexerExpression(CodeIndexerExpression e)
 {
     this.ValidateExpression(e.TargetObject);
     foreach (CodeExpression expression in e.Indices)
     {
         this.ValidateExpression(expression);
     }
 }
Esempio n. 12
0
        protected override void GenerateIndexerExpression(CodeIndexerExpression expression)
        {
            TextWriter output = Output;

            GenerateExpression(expression.TargetObject);
            output.Write('[');
            OutputExpressionList(expression.Indices);
            output.Write(']');
        }
Esempio n. 13
0
 public static void ReplaceType(this CodeIndexerExpression expression, string oldType, string newType)
 {
     if (expression == null)
     {
         return;
     }
     expression.Indices.ReplaceType(oldType, newType);
     expression.TargetObject.ReplaceType(oldType, newType);
 }
Esempio n. 14
0
        public void EmitSimplePropertyMembers(CodeTypeDeclaration type, CodeSnippetExpression storage,
                                              CodeTypeReference interfaceType, bool changed, string name)
        {
            CodeIndexerExpression index = new CodeIndexerExpression(storage.Field("Values"),
                                                                    "this.OffsetStorage + {0}".Expr(Decorator.OffsetStorage));

            // getter method
            Action <CodeStatementCollection> getter = get =>
            {
                get.Add(
                    new CodeMethodReturnStatement(
                        new CodeFieldReferenceExpression(index, StorageField)
                        )
                    );
            };

            // setter method
            Action <CodeStatementCollection> setter = set =>
            {
                PropertyStateSettings s = Decorator.Definition.StateAssetSettings;
                if (s != null && VerifyModify)
                {
                    EmitAllowedCheck(set);
                }

                // allows emission of a validator snippet
                EmitSetPropertyValidator(set, type, storage, interfaceType, changed, name);

                if (changed)
                {
                    set.Add("{0} oldValue".Expr(Decorator.ClrType));
                    set.Add("oldValue".Expr().Assign(new CodeFieldReferenceExpression(index, StorageField)));
                }

                set.Add(new CodeAssignStatement(
                            new CodeFieldReferenceExpression(index, StorageField),
                            new CodeVariableReferenceExpression("value")
                            ));

                if (changed)
                {
                    string diff = Decorator.Definition.PropertyType.StrictCompare ? "Diff_Strict" : "Diff";
                    set.If("Ascension.Networking.NetworkValue.{0}(oldValue, value)".Expr(diff),
                           body => { EmitPropertyChanged(body, storage); });
                }
            };

            if (!AllowSetter)
            {
                setter = null;
            }

            CodeMemberProperty property = type.DeclareProperty(Decorator.ClrType, name, getter, setter);

            property.PrivateImplementationType = interfaceType;
            property.Attributes = Decorator.Attributes;
        }
Esempio n. 15
0
        internal override RuleExpressionResult Evaluate(CodeExpression expression, RuleExecution execution)
        {
            CodeIndexerExpression      expression2 = (CodeIndexerExpression)expression;
            RulePropertyExpressionInfo info        = execution.Validation.ExpressionInfo(expression2) as RulePropertyExpressionInfo;

            if (info == null)
            {
                InvalidOperationException exception = new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Messages.ExpressionNotValidated, new object[0]));
                exception.Data["ErrorObject"] = expression2;
                throw exception;
            }
            PropertyInfo propertyInfo = info.PropertyInfo;
            object       targetObject = RuleExpressionWalker.Evaluate(execution, expression2.TargetObject).Value;

            if (targetObject == null)
            {
                RuleEvaluationException exception2 = new RuleEvaluationException(string.Format(CultureInfo.CurrentCulture, Messages.TargetEvaluatedNullIndexer, new object[0]));
                exception2.Data["ErrorObject"] = expression2;
                throw exception2;
            }
            int count = expression2.Indices.Count;

            ParameterInfo[] indexParameters  = propertyInfo.GetIndexParameters();
            object[]        indexerArguments = new object[indexParameters.Length];
            int             length           = indexParameters.Length;

            if (info.NeedsParamsExpansion)
            {
                length--;
            }
            int index = 0;

            while (index < length)
            {
                Type expressionType         = execution.Validation.ExpressionInfo(expression2.Indices[index]).ExpressionType;
                RuleExpressionResult result = RuleExpressionWalker.Evaluate(execution, expression2.Indices[index]);
                indexerArguments[index] = Executor.AdjustType(expressionType, result.Value, indexParameters[index].ParameterType);
                index++;
            }
            if (length < count)
            {
                ParameterInfo info3         = indexParameters[length];
                Type          parameterType = info3.ParameterType;
                Type          elementType   = parameterType.GetElementType();
                Array         array         = (Array)parameterType.InvokeMember(parameterType.Name, BindingFlags.CreateInstance, null, null, new object[] { count - index }, CultureInfo.CurrentCulture);
                while (index < count)
                {
                    Type operandType             = execution.Validation.ExpressionInfo(expression2.Indices[index]).ExpressionType;
                    RuleExpressionResult result2 = RuleExpressionWalker.Evaluate(execution, expression2.Indices[index]);
                    array.SetValue(Executor.AdjustType(operandType, result2.Value, elementType), (int)(index - length));
                    index++;
                }
                indexerArguments[length] = array;
            }
            return(new RulePropertyResult(propertyInfo, targetObject, indexerArguments));
        }
Esempio n. 16
0
        private static bool IsWellKnownAppConfigExpression(CodePropertyReferenceExpression expression)
        {
            if ((expression.UserData != null) && (expression.UserData.Count > 0))
            {
                return(false);
            }
            if (!(expression.TargetObject is CodeIndexerExpression))
            {
                return(false);
            }
            CodeIndexerExpression targetObject = (CodeIndexerExpression)expression.TargetObject;

            if ((targetObject.UserData != null) && (targetObject.UserData.Count > 0))
            {
                return(false);
            }
            if (((targetObject.Indices == null) || (targetObject.Indices.Count != 1)) || !(targetObject.Indices[0] is CodePrimitiveExpression))
            {
                return(false);
            }
            if (!(((CodePrimitiveExpression)targetObject.Indices[0]).Value is string))
            {
                return(false);
            }
            if (!(targetObject.TargetObject is CodePropertyReferenceExpression))
            {
                return(false);
            }
            CodePropertyReferenceExpression expression3 = (CodePropertyReferenceExpression)targetObject.TargetObject;

            if ((expression3.UserData != null) && (expression3.UserData.Count > 0))
            {
                return(false);
            }
            if (!(expression3.TargetObject is CodeTypeReferenceExpression))
            {
                return(false);
            }
            CodeTypeReferenceExpression expression4 = (CodeTypeReferenceExpression)expression3.TargetObject;

            if ((expression4.UserData != null) && (expression4.UserData.Count > 0))
            {
                return(false);
            }
            CodeTypeReference type = expression4.Type;

            if ((type.UserData != null) && (type.UserData.Count > 0))
            {
                return(false);
            }
            if ((type.TypeArguments != null) && (type.TypeArguments.Count > 0))
            {
                return(false);
            }
            return((type.ArrayElementType == null) && (type.ArrayRank <= 0));
        }
Esempio n. 17
0
        public void CodeIndexerExample()
        {
            //<Snippet3>
            System.CodeDom.CodeIndexerExpression indexerExpression = new CodeIndexerExpression(new CodeThisReferenceExpression(), new CodePrimitiveExpression(1));

            // A C# code generator produces the following source code for the preceeding example code:

            //        this[1];
            //</Snippet3>
        }
 public TypescriptIndexerExpression(
     IExpressionFactory expressionFactory,
     CodeIndexerExpression codeExpression,
     CodeGeneratorOptions options)
 {
     _codeExpression    = codeExpression;
     _options           = options;
     _expressionFactory = expressionFactory;
     System.Diagnostics.Debug.WriteLine("TypescriptIndexerExpression Created");
 }
        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));
                    }
                }
            }
        }
Esempio n. 20
0
        private static void CreateConstructorFromTable(CodeTypeDeclaration classType, TableInfo tableInfo, CodeGenerationInfo generationInfo)
        {
            var cc = new CodeConstructor()
            {
                Attributes = MemberAttributes.Public
            };

            cc.Parameters.Add(generationInfo.ReaderNamespace, "ITable", "table");
            cc.BaseConstructorArgs.Add("table");

            // verify revision
            {
                var css = CreateCompareTypeStatement(classType, tableInfo, generationInfo);
                var tst = CremaDataClassCreator.CreateTryCatchStatement(classType, css, generationInfo);
                cc.Statements.Add(tst);
            }

            // initialize childs
            {
                var table   = new CodeVariableReferenceExpression("table");
                var dataSet = new CodePropertyReferenceExpression(table, "DataSet");
                var tables  = new CodePropertyReferenceExpression(dataSet, "Tables");

                foreach (var item in generationInfo.GetChilds(tableInfo))
                {
                    var tableName  = new CodePropertyReferenceExpression(table, "Name");
                    var childName  = new CodeBinaryOperatorExpression(tableName, CodeBinaryOperatorType.Add, new CodePrimitiveExpression("." + item.TableName));
                    var childTable = new CodeIndexerExpression(tables, childName);
                    var childField = item.GetFieldExpression();
                    var instance   = new CodeObjectCreateExpression(item.GetCodeType(), childTable);

                    cc.Statements.AddAssign(childField, instance);
                }
            }

            // SetRelations
            {
                var table = new CodeVariableReferenceExpression("table");
                foreach (var item in generationInfo.GetChilds(tableInfo))
                {
                    var setRelations   = new CodeMethodReferenceExpression(thisRef, "SetRelations");
                    var rows           = new CodePropertyReferenceExpression(item.GetFieldExpression(), "Rows");
                    var setChildAction = new CodePropertyReferenceExpression(tableInfo.GetRowCodeTypeExpression(), "Set" + item.TableName);
                    var tableName      = new CodePropertyReferenceExpression(table, "Name");
                    var childName      = new CodeBinaryOperatorExpression(tableName, CodeBinaryOperatorType.Add, new CodePrimitiveExpression("." + item.TableName));

                    var setRelationsInvoke = new CodeMethodInvokeExpression(setRelations, childName, rows, setChildAction);
                    cc.Statements.Add(setRelationsInvoke);
                }
            }

            classType.Members.Add(cc);
        }
Esempio n. 21
0
        internal override CodeExpression Clone(CodeExpression expression)
        {
            CodeIndexerExpression expression2  = (CodeIndexerExpression)expression;
            CodeExpression        targetObject = RuleExpressionWalker.Clone(expression2.TargetObject);

            CodeExpression[] indices = new CodeExpression[expression2.Indices.Count];
            for (int i = 0; i < indices.Length; i++)
            {
                indices[i] = RuleExpressionWalker.Clone(expression2.Indices[i]);
            }
            return(new CodeIndexerExpression(targetObject, indices));
        }
Esempio n. 22
0
        private static void CreateReadFromTableMethod(CodeTypeDeclaration classType, TableInfo tableInfo, CodeGenerationInfo generationInfo)
        {
            var cmm = new CodeMemberMethod();

            cmm.Attributes = MemberAttributes.Family;
            cmm.Name       = "readFromTable";
            cmm.Parameters.Add("reader", "ITable", "table");

            // invoke super.readFromFile
            {
                var table         = new CodeVariableReferenceExpression("table");
                var readFromTable = new CodeMethodReferenceExpression(new CodeBaseReferenceExpression(), "readFromTable");
                cmm.Statements.Add(new CodeMethodInvokeExpression(readFromTable, table));
            }

            // initialize childs
            {
                var table   = new CodeVariableReferenceExpression("table");
                var dataSet = new CodePropertyReferenceExpression(table, "dataSet");
                var tables  = new CodePropertyReferenceExpression(dataSet, "tables");

                foreach (var item in generationInfo.GetChilds(tableInfo))
                {
                    var tableName             = new CodePropertyReferenceExpression(table, "name");
                    var childName             = new CodeBinaryOperatorExpression(tableName, CodeBinaryOperatorType.Add, new CodePrimitiveExpression("." + item.TableName));
                    var childTable            = new CodeIndexerExpression(tables, childName);
                    var childField            = item.GetFieldExpression();
                    var createFromTable       = new CodeMethodReferenceExpression(item.GetCodeTypeExpression(), "createFromTable");
                    var createFromTableInvoke = new CodeMethodInvokeExpression(createFromTable, childTable);

                    cmm.Statements.AddAssign(childField, createFromTableInvoke);
                }
            }

            // setRelations
            {
                var table = new CodeVariableReferenceExpression("table");
                foreach (var item in generationInfo.GetChilds(tableInfo))
                {
                    var setRelations   = new CodeMethodReferenceExpression(thisRef, "SetRelations");
                    var rows           = new CodePropertyReferenceExpression(item.GetFieldExpression(), "rows");
                    var setChildAction = new CodePropertyReferenceExpression(tableInfo.GetRowCodeTypeExpression(), "set" + item.TableName);
                    var tableName      = new CodePropertyReferenceExpression(table, "name");
                    var childName      = new CodeBinaryOperatorExpression(tableName, CodeBinaryOperatorType.Add, new CodePrimitiveExpression("." + item.TableName));

                    var setRelationsInvoke = new CodeMethodInvokeExpression(setRelations, childName, rows, setChildAction);
                    cmm.Statements.Add(setRelationsInvoke);
                }
            }

            classType.Members.Add(cmm);
        }
        public void Constructor1_Deny_Unrestricted()
        {
            CodeExpression target = new CodeExpression();

            CodeExpression[] indices = new CodeExpression[1] {
                target
            };
            CodeIndexerExpression cie = new CodeIndexerExpression(target, indices);

            Assert.AreEqual(1, cie.Indices.Count, "Indices");
            Assert.AreSame(target, cie.TargetObject, "TargetObject");
            cie.TargetObject = new CodeExpression();
        }
        /// <summary>
        /// &lt;variable&gt; := Variables["&lt;parameterName&gt;"]
        /// </summary>
        private void GenerateWxeFunctionAndWxeTemplateControlPropertyAccessors(
            VariableDeclaration variableDeclaration, out CodeStatement getStatement, out CodeStatement setStatement)
        {
            CodeExpression variable = new CodeIndexerExpression(
                new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "Variables"),
                new CodePrimitiveExpression(variableDeclaration.Name));

            // <getStatement> := get { return (<type>) <variable>; }
            getStatement = new CodeMethodReturnStatement(new CodeCastExpression(new CodeTypeReference(variableDeclaration.TypeName), variable));

            // <setStatement> := set { <variable> = value; }
            setStatement = new CodeAssignStatement(variable, new CodePropertySetValueReferenceExpression());
        }
Esempio n. 25
0
        public static CodeIndexerExpression Clone(this CodeIndexerExpression expression)
        {
            if (expression == null)
            {
                return(null);
            }
            CodeIndexerExpression e = new CodeIndexerExpression();

            e.Indices.AddRange(expression.Indices.Clone());
            e.TargetObject = expression.TargetObject.Clone();
            e.UserData.AddRange(expression.UserData);
            return(e);
        }
        // Generates a codedom indexed identifier: one that is an identifier followed by an indexer: ex foo[1].
        public static CodeExpression Emit(IndexedIdentifier indexedIdentifier)
        {
            // Create the codedom indexer expression
            var codeIndex = new CodeIndexerExpression();

            // Set the object that is being indexed.
            codeIndex.TargetObject = new CodeVariableReferenceExpression(indexedIdentifier.Name);

            // Set the expression that is generating the index.
            codeIndex.Indices.Add(CodeDomEmitter.EmitCodeExpression(indexedIdentifier.ChildExpressions[0]));

            return(codeIndex);
        }
Esempio n. 27
0
        private static string SerializeAppConfigExpression(CodePropertyReferenceExpression expression)
        {
            string propertyName = expression.PropertyName;
            CodeIndexerExpression targetObject = (CodeIndexerExpression)expression.TargetObject;
            string str2 = ((CodePrimitiveExpression)targetObject.Indices[0]).Value as string;

            propertyName = str2 + "." + propertyName;
            CodePropertyReferenceExpression expression3 = (CodePropertyReferenceExpression)targetObject.TargetObject;

            propertyName = expression3.PropertyName + "." + propertyName;
            CodeTypeReferenceExpression expression4 = (CodeTypeReferenceExpression)expression3.TargetObject;

            propertyName = expression4.Type.Options.ToString() + "." + propertyName;
            propertyName = expression4.Type.BaseType + "." + propertyName;
            return("AppConfig." + propertyName);
        }
        public void ProcessRenderControlMethodFalseTest()
        {
            Assert.IsFalse(SectionControlBuilder.ProcessRenderControlMethod(null, null, null, Language.CSharp));
            Assert.IsFalse(SectionControlBuilder.ProcessRenderControlMethod(null, null, new CodeExpressionStatement(new CodeSnippetExpression("test")), Language.CSharp));

            var invoke = new CodeMethodInvokeExpression(null, "RenderControlX", new CodeExpression[] { new CodeArgumentReferenceExpression("__w") });
            var stmt   = new CodeExpressionStatement(invoke);

            Assert.IsFalse(SectionControlBuilder.ProcessRenderControlMethod(null, null, stmt, Language.CSharp));

            invoke = new CodeMethodInvokeExpression(new CodeSnippetExpression(""), "RenderControl", new CodeExpression[] { new CodeArgumentReferenceExpression("__w") });
            stmt   = new CodeExpressionStatement(invoke);
            Assert.IsFalse(SectionControlBuilder.ProcessRenderControlMethod(null, null, stmt, Language.CSharp));

            var indexer = new CodeIndexerExpression(new CodeSnippetExpression(""), new CodeExpression[] { new CodePrimitiveExpression(defaultIndex) });

            invoke = new CodeMethodInvokeExpression(indexer, "RenderControl", new CodeExpression[] { new CodeArgumentReferenceExpression("__w") });
            stmt   = new CodeExpressionStatement(invoke);
            Assert.IsFalse(SectionControlBuilder.ProcessRenderControlMethod(null, null, stmt, Language.CSharp));

            var container = new CodeArgumentReferenceExpression("parameterContainer");
            var controls  = new CodePropertyReferenceExpression(container, "Controls");

            indexer = new CodeIndexerExpression(controls, new CodeExpression[] { new CodeSnippetExpression("") });
            invoke  = new CodeMethodInvokeExpression(indexer, "RenderControl", new CodeExpression[] { new CodeArgumentReferenceExpression("__w") });
            stmt    = new CodeExpressionStatement(invoke);
            Assert.IsFalse(SectionControlBuilder.ProcessRenderControlMethod(null, null, stmt, Language.CSharp));

            controls = new CodePropertyReferenceExpression(container, "ControlsX");
            indexer  = new CodeIndexerExpression(controls, new CodeExpression[] { new CodePrimitiveExpression(defaultIndex) });
            invoke   = new CodeMethodInvokeExpression(indexer, "RenderControl", new CodeExpression[] { new CodeArgumentReferenceExpression("__w") });
            stmt     = new CodeExpressionStatement(invoke);
            Assert.IsFalse(SectionControlBuilder.ProcessRenderControlMethod(null, null, stmt, Language.CSharp));

            controls = new CodePropertyReferenceExpression(new CodeSnippetExpression("test"), "Controls");
            indexer  = new CodeIndexerExpression(controls, new CodeExpression[] { new CodePrimitiveExpression(defaultIndex) });
            invoke   = new CodeMethodInvokeExpression(indexer, "RenderControl", new CodeExpression[] { new CodeArgumentReferenceExpression("__w") });
            stmt     = new CodeExpressionStatement(invoke);
            Assert.IsFalse(SectionControlBuilder.ProcessRenderControlMethod(null, null, stmt, Language.CSharp));

            container = new CodeArgumentReferenceExpression("parameterContainerX");
            controls  = new CodePropertyReferenceExpression(container, "Controls");
            indexer   = new CodeIndexerExpression(controls, new CodeExpression[] { new CodePrimitiveExpression(defaultIndex) });
            invoke    = new CodeMethodInvokeExpression(indexer, "RenderControl", new CodeExpression[] { new CodeArgumentReferenceExpression("__w") });
            stmt      = new CodeExpressionStatement(invoke);
            Assert.IsFalse(SectionControlBuilder.ProcessRenderControlMethod(null, null, stmt, Language.CSharp));
        }
        static bool WriteCodeIndexerExpression(CodeIndexerExpression indexerExpression, TextWriter w, CodeGeneratorOptions o)
        {
            if (indexerExpression == null)
            {
                return(false);
            }

            GenerateCodeFromExpression(indexerExpression.TargetObject, w, o);
            for (int i = 0; i < indexerExpression.Indices.Count; i++)
            {
                w.Write("[");
                GenerateCodeFromExpression(indexerExpression.Indices[i], w, o);
                w.Write("]");
            }

            return(true);
        }
Esempio n. 30
0
        private CodeStatement BuildControlSkinAssignmentStatement(
            ControlBuilder builder, string skinID)
        {
            Type controlType = builder.ControlType;

            string keyVarName = GetMethodNameForBuilder(buildMethodPrefix, builder) + "_skinKey";

            // e.g.
            // private static object __BuildControl__control3_skinKey = PageTheme.CreateSkinKey(typeof({controlType}), {skinID});
            CodeMemberField field = new CodeMemberField(typeof(object), keyVarName);

            field.Attributes = MemberAttributes.Static | MemberAttributes.Private;
            CodeMethodInvokeExpression cmie = new CodeMethodInvokeExpression();

            cmie.Method = new CodeMethodReferenceExpression(new CodeTypeReferenceExpression(typeof(PageTheme)), "CreateSkinKey");
            cmie.Parameters.Add(new CodeTypeOfExpression(controlType));
            cmie.Parameters.Add(new CodePrimitiveExpression(skinID));
            field.InitExpression = cmie;
            _sourceDataClass.Members.Add(field);

            // e.g. this.__namedControlSkins[keyVarName] =
            //          new System.Web.UI.ControlSkin(typeof(System.Web.UI.WebControls.Label),
            //          new System.Web.UI.ControlSkinDelegate(this.__BuildControl__control3));
            CodeFieldReferenceExpression varExpr = new CodeFieldReferenceExpression(
                new CodeThisReferenceExpression(),
                _controlSkinsVarName);

            CodeIndexerExpression indexerExpr = new CodeIndexerExpression(
                varExpr,
                new CodeExpression[] {
                new CodeVariableReferenceExpression(keyVarName)
            }
                );

            CodeDelegateCreateExpression del = new CodeDelegateCreateExpression(
                _controlSkinDelegateType,
                new CodeThisReferenceExpression(),
                GetMethodNameForBuilder(buildMethodPrefix, builder));
            CodeObjectCreateExpression valueExpr = new CodeObjectCreateExpression(_controlSkinType);

            valueExpr.Parameters.Add(new CodeTypeOfExpression(controlType));
            valueExpr.Parameters.Add(del);

            return(new CodeAssignStatement(indexerExpr, valueExpr));
        }
Esempio n. 31
0
        private void CallSetter(Instruction il, MethodDefinition method, PropertyDefinition pi, bool isVirtual)
        {
            var args = method.Parameters;
            if (args.Count == 1) {
                var rhs = RefinePrimitiveExpression(Pop(), pi.PropertyType);
                var targetObject = GetTargetObject(method, isVirtual);
                CodePropertyReference lhs = new CodePropertyReference(CodePropertyReference.RefType.Set) {
                    Method = new CodeMethodReference(targetObject, method),
                    Property = pi
                };

                AddAssignment(lhs, rhs);
            }
            else {
                CodeIndexerExpression lhs = new CodeIndexerExpression(CodePropertyReference.RefType.Set);
                PopParametersInto(args, lhs.Indices);

                CodeExpression rhs = lhs.Indices[lhs.Indices.Count - 1];
                lhs.Indices.Remove(rhs);
                var targetObject = GetTargetObject(method, isVirtual);
                lhs.Method = new CodeMethodReference(targetObject, method);
                lhs.Property = pi;

                AddAssignment(lhs, rhs);
            }
        }
Esempio n. 32
0
 private void CallGetter(Instruction il, MethodDefinition method, PropertyDefinition pi, bool isVirtual)
 {
     var args = method.Parameters;
     if (args.Count == 0) {
         var targetObject = GetTargetObject(method, isVirtual);
         CodePropertyReference expr = new CodePropertyReference(CodePropertyReference.RefType.Get) {
             Method = new CodeMethodReference(targetObject, method),
             Property = pi
         };
         Push(expr);
     }
     else {
         CodeIndexerExpression expr = new CodeIndexerExpression(CodePropertyReference.RefType.Get);
         PopParametersInto(args, expr.Indices);
         var targetObject = GetTargetObject(method, isVirtual);
         expr.Method = new CodeMethodReference(targetObject, method);
         expr.Property = pi;
         Push(expr);
     }
 }
	protected override void GenerateIndexerExpression
				(CodeIndexerExpression e)
			{
				GenerateExpression(e.TargetObject);
				Output.Write("[");
				OutputExpressionList(e.Indices);
				Output.Write("]");
			}
Esempio n. 34
0
 protected abstract void GenerateIndexerExpression(CodeIndexerExpression e);
Esempio n. 35
0
			public void Visit(CodeIndexerExpression o)
			{
				g.GenerateIndexerExpression(o);
			}
Esempio n. 36
0
 private void ValidateIndexerExpression(CodeIndexerExpression e)
 {
     ValidateExpression(e.TargetObject);
     foreach (CodeExpression exp in e.Indices)
     {
         ValidateExpression(exp);
     }
 }