internal CodeStatement GetCodeStatement(BaseTemplateCodeDomTreeGenerator generator, CodeExpression ctrlRefExpr)
 {
     CodeExpression expression2;
     if (this.UseSetAttribute)
     {
         CodeMethodInvokeExpression expression = new CodeMethodInvokeExpression(new CodeCastExpression(typeof(IAttributeAccessor), ctrlRefExpr), "SetAttribute", new CodeExpression[0]);
         expression.Parameters.Add(new CodePrimitiveExpression(base.Name));
         expression.Parameters.Add(new CodePrimitiveExpression(this.Value));
         return new CodeExpressionStatement(expression);
     }
     CodeExpression right = null;
     if (base.PropertyInfo != null)
     {
         expression2 = CodeDomUtility.BuildPropertyReferenceExpression(ctrlRefExpr, base.Name);
     }
     else
     {
         expression2 = new CodeFieldReferenceExpression(ctrlRefExpr, base.Name);
     }
     if (base.Type == typeof(string))
     {
         right = generator.BuildStringPropertyExpression(this);
     }
     else
     {
         right = CodeDomUtility.GenerateExpressionForValue(base.PropertyInfo, this.Value, base.Type);
     }
     return new CodeAssignStatement(expression2, right);
 }
コード例 #2
0
        // Build the statement that assigns this property
        internal CodeStatement GetCodeStatement(BaseTemplateCodeDomTreeGenerator generator,
            CodeExpression ctrlRefExpr) {

            // If we don't have a type, use IAttributeAccessor.SetAttribute
            if (UseSetAttribute) {
                // e.g. ((IAttributeAccessor)__ctrl).SetAttribute("{{_name}}", "{{_value}}");
                CodeMethodInvokeExpression methCallExpression = new CodeMethodInvokeExpression(
                    new CodeCastExpression(typeof(IAttributeAccessor), ctrlRefExpr),
                        "SetAttribute");

                methCallExpression.Parameters.Add(new CodePrimitiveExpression(Name));
                methCallExpression.Parameters.Add(new CodePrimitiveExpression(Value));
                return new CodeExpressionStatement(methCallExpression);
            }

            CodeExpression leftExpr, rightExpr = null;

            if (PropertyInfo != null) {
                leftExpr = CodeDomUtility.BuildPropertyReferenceExpression(ctrlRefExpr, Name);
            }
            else {
                // In case of a field, there should only be one (unlike properties)
                Debug.Assert(Name.IndexOf('.') < 0, "_name.IndexOf('.') < 0");
                leftExpr = new CodeFieldReferenceExpression(ctrlRefExpr, Name);
            }

            if (Type == typeof(string)) {
                rightExpr = generator.BuildStringPropertyExpression(this);
            }
            else {
                rightExpr = CodeDomUtility.GenerateExpressionForValue(PropertyInfo, Value, Type);
            }

            // Now that we have both side, add the assignment
            return new CodeAssignStatement(leftExpr, rightExpr);
        }