Exemple #1
0
 void EmitExpression(CodeExpression expr)
 {
     if (expr is CodeMethodInvokeExpression)
         EmitInvoke((CodeMethodInvokeExpression)expr);
     else if (expr is CodeArrayCreateExpression)
         EmitArray((CodeArrayCreateExpression)expr);
     else if (expr is CodePrimitiveExpression)
         EmitPrimitive((CodePrimitiveExpression)expr);
     else if (expr is CodeBinaryOperatorExpression)
         EmitBinary((CodeBinaryOperatorExpression)expr);
     else if (expr is CodeTernaryOperatorExpression)
         EmitTernary((CodeTernaryOperatorExpression)expr);
     else if (expr is CodeVariableReferenceExpression)
         EmitVariableReference((CodeVariableReferenceExpression)expr);
     else if (expr is CodeArgumentReferenceExpression)
         EmitArgumentReference((CodeArgumentReferenceExpression)expr);
     else if (expr is CodeFieldReferenceExpression)
         EmitFieldReference((CodeFieldReferenceExpression)expr);
     else if (expr is CodeTypeReferenceExpression)
         EmitTypeReference((CodeTypeReferenceExpression)expr);
     else if (expr is CodeArrayIndexerExpression)
         EmitArrayIndexer((CodeArrayIndexerExpression)expr);
     else if (expr is CodePropertyReferenceExpression)
         EmitPropertyReference((CodePropertyReferenceExpression)expr);
     else
         throw new ArgumentException("Unrecognised expression: " + expr.GetType());
 }
 public IExpression GetExpression(CodeExpression expression, CodeGeneratorOptions options)
 {
     if (expression==null)
     {
         throw new ArgumentNullException("expression");
     }
     return _expressionMap[expression.GetType()](expression, options);
 }
 public static bool Match(CodeExpression firstExpression, CodeExpression secondExpression)
 {
     if ((firstExpression == null) && (secondExpression == null))
     {
         return true;
     }
     if ((firstExpression == null) || (secondExpression == null))
     {
         return false;
     }
     if (firstExpression.GetType() != secondExpression.GetType())
     {
         return false;
     }
     return GetExpression(firstExpression).Match(firstExpression, secondExpression);
 }
 private static RuleExpressionInternal GetExpression(CodeExpression expression)
 {
     Type type = expression.GetType();
     int length = typeWrappers.Length;
     for (int i = 0; i < length; i++)
     {
         TypeWrapperTuple tuple = typeWrappers[i];
         if (type == tuple.codeDomType)
         {
             return tuple.internalExpression;
         }
     }
     IRuleExpression ruleExpr = expression as IRuleExpression;
     if (ruleExpr != null)
     {
         return new CustomExpressionWrapper(ruleExpr);
     }
     return null;
 }
Exemple #5
0
        private CodeTypeReference GetCodeTypeReferenceInCodeExpression(CodeExpression expression)
        {
            if (typeof(CodeTypeOfExpression) == expression.GetType())
            {
                return ((CodeTypeOfExpression)expression).Type;
            }

            if (typeof(CodeTypeReferenceExpression) == expression.GetType())
            {
                return ((CodeTypeReferenceExpression)expression).Type;
            }

            if (typeof(CodeFieldReferenceExpression) == expression.GetType())
            {
                return GetCodeTypeReferenceInCodeExpression(((CodeFieldReferenceExpression)expression).TargetObject);
            }

            if (typeof(CodeObjectCreateExpression) == expression.GetType())
            {
                return ((CodeObjectCreateExpression)expression).CreateType;
            }

            if (typeof(CodeCastExpression) == expression.GetType())
            {
                return ((CodeCastExpression)expression).TargetType;
            }

            if (typeof(CodeMethodInvokeExpression) == expression.GetType())
            {
                return GetCodeTypeReferenceInCodeExpression(((CodeMethodInvokeExpression)expression).Method);
            }

            if (typeof(CodeMethodReferenceExpression) == expression.GetType())
            {
                return GetCodeTypeReferenceInCodeExpression(((CodeMethodReferenceExpression)expression).TargetObject);
            }

            return null;
        }
		private static object GetValue (RuleExecution execution, CodeExpression obj)
		{
			if (obj.GetType () == typeof (System.CodeDom.CodePrimitiveExpression)) {
				return (((System.CodeDom.CodePrimitiveExpression) obj).Value);
			}

			if (obj.GetType () == typeof (CodeFieldReferenceExpression)) {
				return RuleExpressionCondition.CodeFieldReferenceValue (execution, obj);
			}

			if (obj.GetType () == typeof (CodePropertyReferenceExpression)) {
				return RuleExpressionCondition.CodePropertyReferenceValue (execution, obj);
			}

			return null;
		}
 public void GenerateExpression(CodeExpression expression)
 {
     if (expression is CodeArrayIndexerExpression)
         GenerateArrayIndexerExpression((CodeArrayIndexerExpression)expression);
     else if (expression is CodeBinaryOperatorExpression)
         GenerateBinaryOperatorExpression((CodeBinaryOperatorExpression)expression);
     else if (expression is CodeCastExpression)
         GenerateCastExpression((CodeCastExpression)expression);
     else if (expression is CodeDelegateCreateExpression)
         GenerateDelegateCreateExpression((CodeDelegateCreateExpression)expression);
     else if (expression is CodeFieldReferenceExpression)
         GenerateFieldReferenceExpression((CodeFieldReferenceExpression)expression);
     else if (expression is CodeMethodInvokeExpression)
         GenerateMethodInvokeExpression((CodeMethodInvokeExpression)expression);
     else if (expression is CodeMethodReferenceExpression)
         GenerateMethodReferenceExpression((CodeMethodReferenceExpression)expression);
     else if (expression is CodeObjectCreateExpression)
         GenerateObjectCreateExpression((CodeObjectCreateExpression)expression);
     else if (expression is CodePrimitiveExpression)
         GeneratePrimitiveExpression((CodePrimitiveExpression)expression);
     else if (expression is CodePropertyReferenceExpression)
         GeneratePropertyReferenceExpression((CodePropertyReferenceExpression)expression);
     else if (expression is CodeThisReferenceExpression)
         GenerateThisReferenceExpression((CodeThisReferenceExpression)expression);
     else if (expression is CodeTypeOfExpression)
         GenerateTypeOfExpression((CodeTypeOfExpression)expression);
     else if (expression is CodeArrayCreateExpression)
         GenerateArrayCreateExpression((CodeArrayCreateExpression)expression);
     else if (expression is CodeTypeReferenceExpression)
         GenerateTypeReferenceExpression((CodeTypeReferenceExpression)expression);
     else
         throw new NotSupportedException(expression.GetType().ToString());
 }
        /// <summary>
        /// Track down the real type of a CodeExpression's target.
        /// </summary>
        /// <param name="targetObject"></param>
        /// <param name="thisType"></param>
        /// <returns></returns>
        private static Type FindTargetType(CodeExpression targetObject, Type thisType)
        {
            Type targetType = GetType(targetObject, false);

            if (targetType != null)
            {
                return targetType;
            }
            else if (targetObject is CodeVariableReferenceExpression)
            {
                throw new ApplicationException("Cannot determine the type of a CodeVariableReferenceExpression: " + Serialize(targetObject));
            }
            else if (targetObject is CodeTypeOfExpression)
            {
                // Results in a System.Type.
                return typeof(Type);
            }
            else if (targetObject is CodeThisReferenceExpression)
            {
                if (thisType == null)
                {
                    throw new ApplicationException("There is a CodeThisReferenceExpression and the thisType supplied was null.");
                }

                return thisType;
            }
            else if (targetObject is CodePrimitiveExpression)
            {
                return ((CodePrimitiveExpression)targetObject).Value.GetType();
            }
            else if (targetObject is CodePropertyReferenceExpression)
            {
                Type toExamine = FindTargetType(((CodePropertyReferenceExpression)targetObject).TargetObject, thisType);
                PropertyInfo propInfo = toExamine.GetProperty(((CodePropertyReferenceExpression)targetObject).PropertyName);
                return propInfo.PropertyType;
            }
            else if (targetObject is CodeMethodInvokeExpression)
            {
                Type toExamine = FindTargetType(((CodeMethodInvokeExpression)targetObject).Method.TargetObject, thisType);
                MethodInfo methodInfo = toExamine.GetMethod(((CodeMethodInvokeExpression)targetObject).Method.MethodName);
                return methodInfo.ReturnType;
            }
            else if (targetObject is CodeFieldReferenceExpression)
            {
                Type toExamine = FindTargetType(((CodeFieldReferenceExpression)targetObject).TargetObject, thisType);
                String fieldName = ((CodeFieldReferenceExpression)targetObject).FieldName;
                FieldInfo fieldInfo = toExamine.GetField(fieldName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
                return fieldInfo.FieldType;
            }
            else if (targetObject is CodeTypeReferenceExpression)
            {
                CodeTypeReference typeReference = ((CodeTypeReferenceExpression)targetObject).Type;
                return thisType.Assembly.GetType(typeReference.BaseType);
            }
            throw new NotSupportedException("Specified CodeExpression type is not currently supported: " + targetObject.GetType().FullName);
        }
        private static void PrintExpression(TextWriter output, CodeExpression expression)
        {
            if (expression is CodeMethodInvokeExpression)
            {
                CodeMethodInvokeExpression cmi = (CodeMethodInvokeExpression)expression;
                if (cmi.Method.TargetObject == null)
                    output.Write("defaultscope");
                else
                    PrintExpression(output, cmi.Method.TargetObject);
                output.Write('.');
                output.Write(cmi.Method.MethodName);
                output.Write('(');
                for (int i = 0; i < cmi.Parameters.Count; ++i)
                {
                    if (i > 0)
                        output.Write(", ");
                    PrintExpression(output, cmi.Parameters[i]);
                }
                output.Write(')');
                return;
            }

            if (expression is CodeDelegateInvokeExpression)
            {
                CodeDelegateInvokeExpression die = (CodeDelegateInvokeExpression)expression;
                output.Write("delegatecall(");
                PrintExpression(output, die.TargetObject);
                output.Write(')');
                output.Write('(');
                for (int i = 0; i < die.Parameters.Count; ++i)
                {
                    if (i > 0)
                        output.Write(", ");
                    PrintExpression(output, die.Parameters[i]);
                }
                output.Write(')');
                return;
            }

            if (expression is CodePropertyReferenceExpression)
            {
                CodePropertyReferenceExpression cpre = (CodePropertyReferenceExpression)expression;
                if (cpre.TargetObject == null)
                    output.Write("defaultscope");
                else
                    PrintExpression(output, cpre.TargetObject);
                output.Write('.');
                output.Write(cpre.PropertyName);
                return;
            }

            if (expression is CodeFieldReferenceExpression)
            {
                CodeFieldReferenceExpression cpre = (CodeFieldReferenceExpression)expression;
                if (cpre.TargetObject == null)
                    output.Write("defaultscope");
                else
                    PrintExpression(output, cpre.TargetObject);
                output.Write('.');
                output.Write(cpre.FieldName);
                output.Write('$');
                return;
            }

            if (expression is CodePrimitiveExpression)
            {
                object value = ((CodePrimitiveExpression)expression).Value;
                if (value == null)
                    output.Write("null");
                else if (value.Equals(true))
                    output.Write("true");
                else if (value.Equals(false))
                    output.Write("false");
                else if (value is string)
                    output.Write("'{0}'", value.ToString().Replace("'", "\\'"));
                else
                    output.Write("{0}", value);
                return;
            }

            if (expression is CodeThisReferenceExpression)
            {
                output.Write("this");
                return;
            }

            if (expression is CodeBaseReferenceExpression)
            {
                output.Write("base");
                return;
            }

            if (expression is CodeArgumentReferenceExpression)
            {
                output.Write("arg({0})", ((CodeArgumentReferenceExpression)expression).ParameterName);
                return;
            }

            if (expression is CodeVariableReferenceExpression)
            {
                output.Write("var({0})", ((CodeVariableReferenceExpression)expression).VariableName);
                return;
            }

            if (expression is CodeTypeReferenceExpression)
            {
                output.Write("typeref(");
                CodeTypeReferenceExpression ctr = (CodeTypeReferenceExpression)expression;
                PrintTypeReference(output, ctr.Type);
                output.Write(')');
                return;
            }
            if (expression is CodeCastExpression)
            {
                CodeCastExpression cce = expression as CodeCastExpression;

                output.Write("cast(");
                PrintTypeReference(output, cce.TargetType);
                output.Write(", ");
                PrintExpression(output, cce.Expression);
                output.Write(')');
                return;
            }

            if (expression is CodeTypeOfExpression)
            {
                CodeTypeOfExpression ctoe = (CodeTypeOfExpression)expression;
                output.Write("typeof(");
                PrintTypeReference(output, ctoe.Type);
                output.Write(')');
                return;
            }

            if (expression is CodeObjectCreateExpression)
            {
                CodeObjectCreateExpression coce = (CodeObjectCreateExpression)expression;
                output.Write("new ");
                PrintTypeReference(output, coce.CreateType);
                output.Write('(');
                for (int i = 0; i < coce.Parameters.Count; ++i)
                {
                    if (i > 0)
                        output.Write(", ");
                    PrintExpression(output, coce.Parameters[i]);

                }

                output.Write(')');
                return;
            }

            if (expression is CodeArrayIndexerExpression)
            {
                CodeArrayIndexerExpression caie = (CodeArrayIndexerExpression)expression;
                output.Write("arrayitem(");
                PrintExpression(output, caie.TargetObject);
                for (int i = 0; i < caie.Indices.Count; ++i)
                {
                    output.Write(", ");
                    PrintExpression(output, caie.Indices[i]);
                }
                output.Write(')');
                return;
            }

            if (expression is CodeArrayCreateExpression)
            {
                CodeArrayCreateExpression cace = (CodeArrayCreateExpression)expression;
                output.Write("newarray(");
                PrintTypeReference(output, cace.CreateType);
                output.Write(',');
                PrintExpression(output, cace.SizeExpression);
                output.Write(')');
                return;
            }

            if (expression is CodeBinaryOperatorExpression)
            {
                CodeBinaryOperatorExpression cboe = (CodeBinaryOperatorExpression)expression;
                switch (cboe.Operator)
                {
                    case CodeBinaryOperatorType.ValueEquality:
                        output.Write("equals");
                        break;

                    case CodeBinaryOperatorType.IdentityEquality:
                        output.Write("refequal");
                        break;

                    case CodeBinaryOperatorType.IdentityInequality:
                        output.Write("refnotequal");
                        break;

                    case CodeBinaryOperatorType.Add:
                        output.Write("add");
                        break;

                    default:
                        output.Write("UNKNOWN CBOE: {0}", cboe.Operator);
                        break;
                }
                output.Write('(');
                PrintExpression(output, cboe.Left);
                output.Write(", ");
                PrintExpression(output, cboe.Right);
                output.Write(')');
                return;
            }

            if (expression is CodePropertySetValueReferenceExpression)
            {
                output.Write("setvalue");
                return;
            }

            if (expression is CodeDirectionExpression)
            {
                switch (((CodeDirectionExpression)expression).Direction)
                {
                    case FieldDirection.In:
                        PrintExpression(output, ((CodeDirectionExpression)expression).Expression);
                        break;

                    case FieldDirection.Out:
                        output.Write("out(");
                        PrintExpression(output, ((CodeDirectionExpression)expression).Expression);
                        output.Write(')');
                        break;

                    case FieldDirection.Ref:
                        output.Write("ref(");
                        PrintExpression(output, ((CodeDirectionExpression)expression).Expression);
                        output.Write(')');
                        break;
                }
                return;
            }

            output.Write("*** UNKNOWN EXPRESSION:" + expression.GetType() + " ***");
        }
 /// <devdoc>
 ///    <para>Generates code for the specified CodeDom code expression representation.</para>
 /// </devdoc>
 private void GenerateExpression(CodeExpression e) {
     if (e is CodeArrayCreateExpression) {
         GenerateArrayCreateExpression((CodeArrayCreateExpression)e);
     }
     else if (e is CodeBaseReferenceExpression) {
         GenerateBaseReferenceExpression((CodeBaseReferenceExpression)e);
     }
     else if (e is CodeBinaryOperatorExpression) {
         GenerateBinaryOperatorExpression((CodeBinaryOperatorExpression)e);
     }
     else if (e is CodeCastExpression) {
         GenerateCastExpression((CodeCastExpression)e);
     }
     else if (e is CodeDelegateCreateExpression) {
         GenerateDelegateCreateExpression((CodeDelegateCreateExpression)e);
     }
     else if (e is CodeFieldReferenceExpression) {
         GenerateFieldReferenceExpression((CodeFieldReferenceExpression)e);
     }
     else if (e is CodeArgumentReferenceExpression) {
         GenerateArgumentReferenceExpression((CodeArgumentReferenceExpression)e);
     }
     else if (e is CodeVariableReferenceExpression) {
         GenerateVariableReferenceExpression((CodeVariableReferenceExpression)e);
     }
     else if (e is CodeIndexerExpression) {
         GenerateIndexerExpression((CodeIndexerExpression)e);
     }
     else if (e is CodeArrayIndexerExpression) {
         GenerateArrayIndexerExpression((CodeArrayIndexerExpression)e);
     }
     else if (e is CodeSnippetExpression) {
         GenerateSnippetExpression((CodeSnippetExpression)e);
     }
     else if (e is CodeMethodInvokeExpression) {
         GenerateMethodInvokeExpression((CodeMethodInvokeExpression)e);
     }
     else if (e is CodeMethodReferenceExpression) {
         GenerateMethodReferenceExpression((CodeMethodReferenceExpression)e);
     }
     else if (e is CodeEventReferenceExpression) {
         GenerateEventReferenceExpression((CodeEventReferenceExpression)e);
     }
     else if (e is CodeDelegateInvokeExpression) {
         GenerateDelegateInvokeExpression((CodeDelegateInvokeExpression)e);
     }
     else if (e is CodeObjectCreateExpression) {
         GenerateObjectCreateExpression((CodeObjectCreateExpression)e);
     }
     else if (e is CodeParameterDeclarationExpression) {
         GenerateParameterDeclarationExpression((CodeParameterDeclarationExpression)e);
     }
     else if (e is CodeDirectionExpression) {
         GenerateDirectionExpression((CodeDirectionExpression)e);
     }
     else if (e is CodePrimitiveExpression) {
         GeneratePrimitiveExpression((CodePrimitiveExpression)e);
     }
     else if (e is CodePropertyReferenceExpression) {
         GeneratePropertyReferenceExpression((CodePropertyReferenceExpression)e);
     }
     else if (e is CodePropertySetValueReferenceExpression) {
         GeneratePropertySetValueReferenceExpression((CodePropertySetValueReferenceExpression)e);
     }
     else if (e is CodeThisReferenceExpression) {
         GenerateThisReferenceExpression((CodeThisReferenceExpression)e);
     }
     else if (e is CodeTypeReferenceExpression) {
         GenerateTypeReferenceExpression((CodeTypeReferenceExpression)e);
     }
     else if (e is CodeTypeOfExpression) {
         GenerateTypeOfExpression((CodeTypeOfExpression)e);
     }
     else if (e is CodeDefaultValueExpression) {
         GenerateDefaultValueExpression((CodeDefaultValueExpression)e);
     }
     else {
         if (e == null) {
             throw new ArgumentNullException("e");
         }
         else {
             throw new ArgumentException(SR.GetString(SR.InvalidElementType, e.GetType().FullName), "e");
         }
     }
 }
 public static RuleExpressionInfo Validate(RuleValidation validation, CodeExpression expression, bool isWritten)
 {
     if (validation == null)
     {
         throw new ArgumentNullException("validation");
     }
     RuleExpressionInfo info = null;
     if (!isWritten)
     {
         info = validation.ExpressionInfo(expression);
     }
     if (info != null)
     {
         return info;
     }
     RuleExpressionInternal ruleExpr = GetExpression(expression);
     if (ruleExpr == null)
     {
         ValidationError item = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.CodeExpressionNotHandled, new object[] { expression.GetType().FullName }), 0x548);
         item.UserData["ErrorObject"] = expression;
         if (validation.Errors == null)
         {
             string name = string.Empty;
             if ((validation.ThisType != null) && (validation.ThisType.Name != null))
             {
                 name = validation.ThisType.Name;
             }
             throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Messages.ErrorsCollectionMissing, new object[] { name }));
         }
         validation.Errors.Add(item);
         return null;
     }
     return validation.ValidateSubexpression(expression, ruleExpr, isWritten);
 }
Exemple #12
0
        private object MatchArgument(Type parameterType, CodeExpression arg)
        {
            Type argExprType = arg.GetType();

            if (TypeProvider.IsAssignable(parameterType, argExprType))
            {
                // The argument expression type is assignable to the parameter type,
                // so it goes through unscathed.
                return arg;
            }
            else
            {
                // See if the argument is a constant value, whose type is compatible with
                // the parameter.
                CodePrimitiveExpression argPrimitive = arg as CodePrimitiveExpression;
                if (argPrimitive != null)
                {
                    ValidationError error = null;
                    Type argPrimitiveType = validation.ExpressionInfo(argPrimitive).ExpressionType;
                    if (RuleValidation.TypesAreAssignable(argPrimitiveType, parameterType, argPrimitive, out error))
                    {
                        // The constant expression's type matched the parameter, so
                        // use the actual primitive's value as the argument.
                        return argPrimitive.Value;
                    }
                }
            }

            return null;
        }
		private CodeExpression TryGetCachedExpression (IDesignerSerializationManager manager, object value, 
													   CodeExpression parentExpression, object presetValue)
		{
			CodeExpression expression = null;
			if (value != null) // in order to support null value serialization
				expression = base.GetExpression (manager, value);
			if (expression == null) {
				if (parentExpression == null)
					manager.Context.Push (new ExpressionContext (null, null, value, presetValue));
				else
					manager.Context.Push (new ExpressionContext (parentExpression, parentExpression.GetType (), value, presetValue));
				expression = base.SerializeToExpression (manager, value);
				manager.Context.Pop ();
			}
			return expression;
		}
 private Expression Translate(CodeExpression expr){
   if (expr == null) return null;
   if (expr is CodeArgumentReferenceExpression) return this.Translate((CodeArgumentReferenceExpression)expr);
   if (expr is CodeArrayCreateExpression) return this.Translate((CodeArrayCreateExpression)expr);
   if (expr is CodeArrayIndexerExpression) return this.Translate((CodeArrayIndexerExpression)expr);
   if (expr is CodeBaseReferenceExpression) return this.Translate((CodeBaseReferenceExpression)expr);
   if (expr is CodeBinaryOperatorExpression) return this.Translate((CodeBinaryOperatorExpression)expr);
   if (expr is CodeCastExpression) return this.Translate((CodeCastExpression)expr);
   if (expr is CodeDelegateCreateExpression) return this.Translate((CodeDelegateCreateExpression)expr);
   if (expr is CodeDelegateInvokeExpression) return this.Translate((CodeDelegateInvokeExpression)expr);
   if (expr is CodeDirectionExpression) return this.Translate((CodeDirectionExpression)expr);
   if (expr is CodeEventReferenceExpression) return this.Translate((CodeEventReferenceExpression)expr);
   if (expr is CodeFieldReferenceExpression) return this.Translate((CodeFieldReferenceExpression)expr);
   if (expr is CodeIndexerExpression) return this.Translate((CodeIndexerExpression)expr);
   if (expr is CodeMethodInvokeExpression) return this.Translate((CodeMethodInvokeExpression)expr);
   if (expr is CodeMethodReferenceExpression) return this.Translate((CodeMethodReferenceExpression)expr);
   if (expr is CodeObjectCreateExpression) return this.Translate((CodeObjectCreateExpression)expr);
   if (expr is CodePrimitiveExpression) return this.Translate((CodePrimitiveExpression)expr);
   if (expr is CodePropertyReferenceExpression) return this.Translate((CodePropertyReferenceExpression)expr);
   if (expr is CodePropertySetValueReferenceExpression) return this.Translate((CodePropertySetValueReferenceExpression)expr);
   if (expr is CodeSnippetExpression) return this.Translate((CodeSnippetExpression)expr);
   if (expr is CodeThisReferenceExpression) return this.Translate((CodeThisReferenceExpression)expr);
   if (expr is CodeTypeOfExpression) return this.Translate((CodeTypeOfExpression)expr);
   if (expr is CodeTypeReferenceExpression) return this.Translate((CodeTypeReferenceExpression)expr);
   if (expr is CodeVariableReferenceExpression) return this.Translate((CodeVariableReferenceExpression)expr);
   Debug.Assert(false);
   this.HandleError(Error.DidNotExpect, expr.GetType().FullName);
   return null;
 }
        private static Operation GetPrecedence(CodeExpression expression)
        {
            // Assume the operation needs no parentheses.
            Operation operation = Operation.NoParentheses;

            ComputePrecedence computePrecedence;
            if (precedenceMap.TryGetValue(expression.GetType(), out computePrecedence))
                operation = computePrecedence(expression);

            return operation;
        }
Exemple #16
0
        private void RefactorFieldNamesInFieldReferences(CodeExpression expression, string newName)
        {
            // Do we have a field reference in the expression we are given?
            if(typeof(CodeFieldReferenceExpression) != expression.GetType())
            {
                return;
            }

            CodeFieldReferenceExpression frefStatement = (CodeFieldReferenceExpression)expression;

            // Is target object of field reference referring to a variable declaration?
            if (typeof(CodeVariableReferenceExpression) == frefStatement.TargetObject.GetType())
            {
                CodeVariableReferenceExpression vrefStatement = (CodeVariableReferenceExpression)frefStatement.TargetObject;
                // Get a reference to the variable declaration statement.
                CodeVariableDeclarationStatement vdeclStatement = stackVariables[vrefStatement.VariableName];

                // Is this a variable of type we are modifying now?
                if (vdeclStatement.Type.BaseType == newName)
                {
                    // Then we can convert the field names to PascalCase.
                    frefStatement.FieldName = PascalCaseConverterHelper.GetPascalCaseName(frefStatement.FieldName);
                }
            }
        }
            /// <summary>
            /// Rewrites references to entities with dictionary provider specific CodeDom to do the correct lookup.
            /// </summary>
            /// <param name="source">the CodeDom Expression to rewrite</param>
            /// <param name="didRewrite">indicates whether or not the expression was rewritten</param>
            /// <returns>the CodeDom expression appropriate for the dictionary provider</returns>
            protected override CodeExpression Rewrite(CodeExpression source, ref bool didRewrite)
            {
                var propertyRef = source as CodePropertyReferenceExpression;
                if (propertyRef != null)
                {
                    return this.RewritePropertyReference(propertyRef, ref didRewrite);
                }

                var lambdaExpression = source as CodeLambdaExpression;
                if (lambdaExpression != null)
                {
                    return this.RewriteLambdaExpression(lambdaExpression, ref didRewrite);
                }

                var arrayExpression = source as CodeAnonymousArrayExpression;
                if (arrayExpression != null)
                {
                    return this.RewriteAnonymousArray(arrayExpression, ref didRewrite);
                }

                ExceptionUtilities.Assert(
                    source.GetType().Namespace == typeof(CodeObject).Namespace,
                    "Taupo-defined code expressions need to be explicitly handled or the base tree rewriter will lose them");

                return base.Rewrite(source, ref didRewrite);
            }
		void VisitCodeExpression(CodeExpression expression)
		{
			if (expression != null) {
				WriteLine("VisitCodeExpression: " + expression.GetType().Name);
				CodePrimitiveExpression primitiveExpression = expression as CodePrimitiveExpression;
				CodeFieldReferenceExpression fieldReferenceExpression = expression as CodeFieldReferenceExpression;
				CodeThisReferenceExpression thisReferenceExpression = expression as CodeThisReferenceExpression;
				CodeObjectCreateExpression createExpression = expression as CodeObjectCreateExpression;
				CodeBinaryOperatorExpression binaryExpression = expression as CodeBinaryOperatorExpression;
				CodeMethodReferenceExpression methodReferenceExpression = expression as CodeMethodReferenceExpression;
				CodeMethodInvokeExpression methodInvokeExpression = expression as CodeMethodInvokeExpression;
				CodeVariableReferenceExpression variableReferenceExpression = expression as CodeVariableReferenceExpression;
				if (primitiveExpression != null) {
					VisitCodePrimitiveExpression(primitiveExpression);
				} else if (fieldReferenceExpression != null) {
					VisitCodeFieldReferenceExpression(fieldReferenceExpression);
				} else if (thisReferenceExpression != null) {
					VisitCodeThisReferenceExpression(thisReferenceExpression);
				} else if (createExpression != null) {
					VisitObjectCreateExpression(createExpression);
				} else if (binaryExpression != null) {
					VisitCodeBinaryOperatorExpression(binaryExpression);
				} else if (methodReferenceExpression != null) {
					VisitCodeMethodReferenceExpression(methodReferenceExpression);
				} else if (methodInvokeExpression != null) {
					VisitCodeMethodInvokeExpression(methodInvokeExpression);
				} else if (variableReferenceExpression != null) {
					VisitCodeVariableReferenceExpression(variableReferenceExpression);
				}
			} else {
				WriteLine("VisitCodeExpression: Null");
			}
		}
		void AppendExpression(CodeExpression expression)
		{
			if (expression is CodeMethodInvokeExpression) {
				AppendMethodInvokeExpression((CodeMethodInvokeExpression)expression);
			} else if (expression is CodePropertyReferenceExpression) {
				AppendPropertyReferenceExpression((CodePropertyReferenceExpression)expression);
			} else if (expression is CodeObjectCreateExpression) {
				AppendObjectCreateExpression((CodeObjectCreateExpression)expression);
			} else if (expression is CodePrimitiveExpression) {
				AppendPrimitiveExpression((CodePrimitiveExpression)expression);
			} else if (expression is CodeFieldReferenceExpression) {
				AppendFieldReferenceExpression((CodeFieldReferenceExpression)expression);
			} else if (expression is CodeThisReferenceExpression) {
				AppendThisReferenceExpression();
			} else if (expression is CodeTypeReferenceExpression) {
				AppendTypeReferenceExpression((CodeTypeReferenceExpression)expression);
			} else if (expression is CodeArrayCreateExpression) {
				AppendArrayCreateExpression((CodeArrayCreateExpression)expression);
			} else if (expression is CodeVariableReferenceExpression) {
				AppendVariableReferenceExpression((CodeVariableReferenceExpression)expression);
			} else if (expression is CodeDelegateCreateExpression) {
				AppendDelegateCreateExpression((CodeDelegateCreateExpression)expression);
			} else if (expression is CodeCastExpression) {
				AppendCastExpression((CodeCastExpression)expression);
			} else if (expression is CodeBinaryOperatorExpression) {
				AppendBinaryOperatorExpression((CodeBinaryOperatorExpression)expression);
			} else {
				Console.WriteLine("AppendExpression: " + expression.GetType().Name);
			}
		}
        public static RuleExpressionInfo Validate(RuleValidation validation, CodeExpression expression, bool isWritten)
        {
            if (validation == null)
                throw new ArgumentNullException("validation");

            // See if we've visited this node before.
            // Always check if written = true
            RuleExpressionInfo resultExprInfo = null;
            if (!isWritten)
                resultExprInfo = validation.ExpressionInfo(expression);
            if (resultExprInfo == null)
            {
                // First time we've seen this node.
                RuleExpressionInternal ruleExpr = GetExpression(expression);
                if (ruleExpr == null)
                {
                    string message = string.Format(CultureInfo.CurrentCulture, Messages.CodeExpressionNotHandled, expression.GetType().FullName);
                    ValidationError error = new ValidationError(message, ErrorNumbers.Error_CodeExpressionNotHandled);
                    error.UserData[RuleUserDataKeys.ErrorObject] = expression;

                    if (validation.Errors == null)
                    {
                        string typeName = string.Empty;
                        if ((validation.ThisType != null) && (validation.ThisType.Name != null))
                        {
                            typeName = validation.ThisType.Name;
                        }

                        string exceptionMessage = string.Format(
                            CultureInfo.CurrentCulture, Messages.ErrorsCollectionMissing, typeName);

                        throw new InvalidOperationException(exceptionMessage);
                    }
                    else
                    {
                        validation.Errors.Add(error);
                    }

                    return null;
                }

                resultExprInfo = validation.ValidateSubexpression(expression, ruleExpr, isWritten);
            }

            return resultExprInfo;
        }
		protected object DeserializeExpression (IDesignerSerializationManager manager, string name, CodeExpression expression) 
		{
			if (expression == null)
				throw new ArgumentNullException ("expression");
			if (manager == null)
				throw new ArgumentNullException ("manager");

			bool errorOccurred = false;
			object deserialized = null;

			// CodeThisReferenceExpression
			//
			CodeThisReferenceExpression thisExpr = expression as CodeThisReferenceExpression;
			if (thisExpr != null) {
				RootContext context = manager.Context[typeof (RootContext)] as RootContext;
				if (context != null) {
					deserialized = context.Value;
				} else {
					IDesignerHost host = manager.GetService (typeof (IDesignerHost)) as IDesignerHost;
					if (host != null)
						deserialized = host.RootComponent;
				}
			}
			
			// CodeVariableReferenceExpression
			//
			CodeVariableReferenceExpression varRef = expression as CodeVariableReferenceExpression;
			if (deserialized == null && varRef != null) {
				deserialized = manager.GetInstance (varRef.VariableName);
				if (deserialized == null) {
					ReportError (manager, "Variable '" + varRef.VariableName + "' not initialized prior to reference");
					errorOccurred = true;
				}
			}

			// CodeFieldReferenceExpression (used for Enum references as well)
			//
			CodeFieldReferenceExpression fieldRef = expression as CodeFieldReferenceExpression;
			if (deserialized == null && fieldRef != null) {
				deserialized = manager.GetInstance (fieldRef.FieldName);
				if (deserialized == null) {
					object fieldHolder = DeserializeExpression (manager, null, fieldRef.TargetObject);
					FieldInfo field = null;
					if (fieldHolder is Type) // static field
						field = ((Type)fieldHolder).GetField (fieldRef.FieldName, 
										      BindingFlags.GetField | BindingFlags.Public | BindingFlags.Static);
					else // instance field
						field = fieldHolder.GetType().GetField (fieldRef.FieldName, 
											BindingFlags.GetField | BindingFlags.Public | BindingFlags.Instance);
					if (field != null)
						deserialized = field.GetValue (fieldHolder);
				}
				if (deserialized == null)
					ReportError (manager, "Field '" + fieldRef.FieldName + "' not initialized prior to reference");
			}
				

			// CodePrimitiveExpression
			//
			CodePrimitiveExpression primitiveExp = expression as CodePrimitiveExpression;
			if (deserialized == null && primitiveExp != null)
				deserialized = primitiveExp.Value;

			// CodePropertyReferenceExpression
			//
			CodePropertyReferenceExpression propRef = expression as CodePropertyReferenceExpression;
			if (deserialized == null && propRef != null) {
				object target = DeserializeExpression (manager, null, propRef.TargetObject);
				if (target != null && target != _errorMarker) {
					bool found = false;
					if (target is Type) {
						PropertyInfo property = ((Type)target).GetProperty (propRef.PropertyName,
												    BindingFlags.GetProperty | 
												    BindingFlags.Public | BindingFlags.Static);
						if (property != null) {
							deserialized = property.GetValue (null, null);
							found = true;
						}

						// NRefactory seems to produce PropertyReferences to reference some fields and enums
						//
						FieldInfo field = ((Type)target).GetField (propRef.PropertyName,
											   BindingFlags.GetField | BindingFlags.Public | BindingFlags.Static);
						if (field != null) {
							deserialized = field.GetValue (null);
							found = true;
						}
					} else {
						PropertyDescriptor property = TypeDescriptor.GetProperties (target)[propRef.PropertyName];
						if (property != null) {
							deserialized = property.GetValue (target);
							found = true;
						}

						FieldInfo field = target.GetType().GetField (propRef.PropertyName,
											     BindingFlags.GetField | BindingFlags.Public | BindingFlags.Instance);
						if (field != null) {
							deserialized = field.GetValue (null);
							found = true;
						}
					}
					
					if (!found) {
						ReportError (manager, "Missing field '" + propRef.PropertyName + " 'in type " + 
							     (target is Type ? ((Type)target).Name : target.GetType ().Name) + "'");
						errorOccurred = true;
					}
				}
			}

			// CodeObjectCreateExpression
			//
			CodeObjectCreateExpression createExpr = expression as CodeObjectCreateExpression;
			if (deserialized == null && createExpr != null) {
				Type type = manager.GetType (createExpr.CreateType.BaseType);
				if (type == null) {
					ReportError (manager, "Type '" + createExpr.CreateType.BaseType + "' not found." + 
						     "Are you missing a reference?");
					errorOccurred = true;
				} else {
					object[] arguments = new object[createExpr.Parameters.Count];
					for (int i=0; i < createExpr.Parameters.Count; i++) {
						arguments[i] = this.DeserializeExpression (manager, null, createExpr.Parameters[i]);
						if (arguments[i] == _errorMarker) {
							errorOccurred = true;
							break;
						}
					}
					if (!errorOccurred) {
						bool addToContainer = false;
						if (typeof(IComponent).IsAssignableFrom (type))
							addToContainer = true;
						deserialized = this.DeserializeInstance (manager, type, arguments, name, addToContainer);
						if (deserialized == _errorMarker || deserialized == null) {
							string info = "Type to create: " + createExpr.CreateType.BaseType + System.Environment.NewLine +
								"Name: " + name + System.Environment.NewLine +
								"addToContainer: " + addToContainer.ToString () + System.Environment.NewLine +
								"Parameters Count: " + createExpr.Parameters.Count + System.Environment.NewLine;
	
							for (int i=0; i < arguments.Length; i++) {
								info += "Parameter Number: " + i.ToString () + System.Environment.NewLine +
									"Parameter Type: " + (arguments[i] == null ? "null" : arguments[i].GetType ().Name) +
									System.Environment.NewLine +
									"Parameter '" + i.ToString () + "' Value: " + arguments[i].ToString () + System.Environment.NewLine;
							}
							ReportError (manager, 
								     "Unable to create an instance of type '" + createExpr.CreateType.BaseType + "'",
								     info);
							errorOccurred = true;
						}
					}
				}
			}

			// CodeArrayCreateExpression
			//
			CodeArrayCreateExpression arrayCreateExpr = expression as CodeArrayCreateExpression;
			if (deserialized == null && arrayCreateExpr != null) {
				Type arrayType = manager.GetType (arrayCreateExpr.CreateType.BaseType);
				if (arrayType == null) {
					ReportError (manager, "Type '" + arrayCreateExpr.CreateType.BaseType + "' not found." + 
						     "Are you missing a reference?");
					errorOccurred = true;
				} else {
					ArrayList initializers = new ArrayList ();
					Type elementType = arrayType.GetElementType ();
					deserialized = Array.CreateInstance (arrayType, arrayCreateExpr.Initializers.Count);
					for (int i = 0; i < arrayCreateExpr.Initializers.Count; i++) {
						object element = this.DeserializeExpression (manager, null, arrayCreateExpr.Initializers[i]);
						errorOccurred = (element == _errorMarker);
						if (!errorOccurred) {
							if (arrayType.IsInstanceOfType (element)) {
								initializers.Add (element);
							} else {
								ReportError (manager, 
									     "Array initializer element type incompatible with array type.",
									     "Array Type: " + arrayType.Name + System.Environment.NewLine +
									     "Array Element Type: " + elementType + System.Environment.NewLine +
									     "Initializer Type: " + (element == null ? "null" : element.GetType ().Name));
								errorOccurred = true;
							}
						}
					}
					if (!errorOccurred)
						initializers.CopyTo ((Array)deserialized, 0);
				}
			}

			// CodeMethodInvokeExpression
			//
			CodeMethodInvokeExpression methodExpr = expression as CodeMethodInvokeExpression;
			if (deserialized == null && methodExpr != null) {
				object target = this.DeserializeExpression (manager, null, methodExpr.Method.TargetObject);
				object[] parameters = null;
				if (target == _errorMarker || target == null) {
					errorOccurred = true;
				} else {
					parameters = new object[methodExpr.Parameters.Count];
					for (int i=0; i < methodExpr.Parameters.Count; i++) {
						parameters[i] = this.DeserializeExpression (manager, null, methodExpr.Parameters[i]);
						if (parameters[i] == _errorMarker) {
							errorOccurred = true;
							break;
						}
					}
				}

				if (!errorOccurred) {
					MethodInfo method = null;
					if (target is Type) {
						method = GetExactMethod ((Type)target, methodExpr.Method.MethodName, 
												 BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Static,
												 parameters);
					} else {
						method = GetExactMethod (target.GetType(), methodExpr.Method.MethodName, 
												 BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Instance,
												 parameters);
					}
	
					if (method != null) {
						deserialized = method.Invoke (target, parameters);
					} else {
						string info = 
							"Method Name: " + methodExpr.Method.MethodName + System.Environment.NewLine +
							"Method is: " + (target is Type ? "static" : "instance") + System.Environment.NewLine +
							"Method Holder Type: " + (target is Type ? ((Type)target).Name : target.GetType ().Name) + System.Environment.NewLine +
							"Parameters Count: " + methodExpr.Parameters.Count + System.Environment.NewLine +
							System.Environment.NewLine;

						for (int i = 0; i < parameters.Length; i++) {
							info += "Parameter Number: " + i.ToString () + System.Environment.NewLine +
								"Parameter Type: " + (parameters[i] == null ? "null" : parameters[i].GetType ().Name) +
								System.Environment.NewLine +
								"Parameter " + i.ToString () + " Value: " + parameters[i].ToString () + System.Environment.NewLine;
						}
						ReportError (manager, 
							     "Method '" + methodExpr.Method.MethodName + "' missing in type '" + 
							     (target is Type ? ((Type)target).Name : target.GetType ().Name + "'"),
							     info);
						errorOccurred = true;
					}
				}
			}

			// CodeTypeReferenceExpression
			//
			CodeTypeReferenceExpression typeRef = expression as CodeTypeReferenceExpression;
			if (deserialized == null && typeRef != null) {
				deserialized = manager.GetType (typeRef.Type.BaseType);
				if (deserialized == null) {
					ReportError (manager, "Type '" + typeRef.Type.BaseType + "' not found." + 
						     "Are you missing a reference?");
					errorOccurred = true;
				}
			}

			// CodeCastExpression
			// 
			CodeCastExpression castExpr = expression as CodeCastExpression;
			if (deserialized == null && castExpr != null) {
				Type targetType = manager.GetType (castExpr.TargetType.BaseType);
				object instance = DeserializeExpression (manager, null, castExpr.Expression);
				if (instance != null && instance != _errorMarker && targetType != null) {
					IConvertible convertible = instance as IConvertible;
					if (convertible != null) {
						try {
							instance = convertible.ToType (targetType, null);
						} catch {
							errorOccurred = true;
						}
					} else {
						errorOccurred = true;
					}
					if (errorOccurred) {
						ReportError (manager, "Unable to convert type '" + instance.GetType ().Name + 
							     "' to type '" + castExpr.TargetType.BaseType + "'",
							     "Target Type: " + castExpr.TargetType.BaseType + System.Environment.NewLine +
							     "Instance Type: " + (instance == null ? "null" : instance.GetType ().Name) + System.Environment.NewLine +
							     "Instance Value: " + (instance == null ? "null" : instance.ToString()) + System.Environment.NewLine +
							     "Instance is IConvertible: " + (instance is IConvertible).ToString());
					}

					deserialized = instance;
				}
			}


			// CodeBinaryOperatorExpression
			//
			CodeBinaryOperatorExpression binOperator = expression as CodeBinaryOperatorExpression;
			if (deserialized == null && binOperator != null) {
				string errorText = null;
				IConvertible left = null;
				IConvertible right = null;
				switch (binOperator.Operator) {
					case CodeBinaryOperatorType.BitwiseOr:
						left = DeserializeExpression (manager, null, binOperator.Left) as IConvertible;
						right = DeserializeExpression (manager, null, binOperator.Right) as IConvertible;
						if (left is Enum && right is Enum) {
							deserialized = Enum.ToObject (left.GetType (), Convert.ToInt64 (left) | Convert.ToInt64 (right));
						} else {
							errorText = "CodeBinaryOperatorType.BitwiseOr allowed only on Enum types";
							errorOccurred = true;
						}
						break;
					default:
						errorText = "Unsupported CodeBinaryOperatorType: " + binOperator.Operator.ToString ();
						errorOccurred = true;
						break;
				}

				if (errorOccurred) {
					string info = "BinaryOperator Type: " + binOperator.Operator.ToString() + System.Environment.NewLine +
						"Left Type: " + (left == null ? "null" : left.GetType().Name) + System.Environment.NewLine +
						"Left Value: " + (left == null ? "null" : left.ToString ()) + System.Environment.NewLine +
						"Left Expression Type: " + binOperator.Left.GetType ().Name + System.Environment.NewLine +
						"Right Type: " + (right == null ? "null" : right.GetType().Name) + System.Environment.NewLine +
						"Right Value: " + (right == null ? "null" : right.ToString ()) + System.Environment.NewLine +
						"Right Expression Type: " + binOperator.Right.GetType ().Name;
					ReportError (manager, errorText, info);
				}
			}


			if (!errorOccurred) {
				if (deserialized == null && !(expression is CodePrimitiveExpression) && !(expression is CodeMethodInvokeExpression)) {
					ReportError (manager, "Unsupported Expression Type: " + expression.GetType ().Name);
					errorOccurred = true;
				}
			}

			if (errorOccurred)
				deserialized = _errorMarker;
			return deserialized;
		}
        public static bool Match(CodeExpression firstExpression, CodeExpression secondExpression)
        {
            // If they're both null, they match.
            if (firstExpression == null && secondExpression == null)
                return true;

            // If only one of them is null, there's no match.
            if (firstExpression == null || secondExpression == null)
                return false;

            if (firstExpression.GetType() != secondExpression.GetType())
                return false;

            RuleExpressionInternal ruleExpr1 = GetExpression(firstExpression);
            return ruleExpr1.Match(firstExpression, secondExpression);
        }
Exemple #23
0
		protected void GenerateExpression (CodeExpression e)
		{
			if (e == null)
				throw new ArgumentNullException ("e");

			try {
				e.Accept (visitor);
			} catch (NotImplementedException) {
				throw new ArgumentException ("Element type " + e.GetType () + " is not supported.", "e");
			}
		}
        private static RuleExpressionInternal GetExpression(CodeExpression expression)
        {
            Type exprType = expression.GetType();
            int numTypeWrappers = typeWrappers.Length;
            for (int i = 0; i < numTypeWrappers; ++i)
            {
                TypeWrapperTuple tuple = typeWrappers[i];
                if (exprType == tuple.codeDomType)
                    return tuple.internalExpression;
            }

            // It's not a builtin one... try a user extension expression.
            IRuleExpression ruleExpr = expression as IRuleExpression;
            if (ruleExpr != null)
                return new CustomExpressionWrapper(ruleExpr);

            return null;
        }
Exemple #25
0
        private Type EmitExpression(CodeExpression Expression, bool ForceTypes)
        {
            if (Expression == null)
                throw new ArgumentException("Expression can not be null", "Expression");

            Depth++;
            Debug("Emitting expression");
            Type Generated;

            if (Expression is CodeMethodInvokeExpression)
            {
                Generated = EmitMethodInvoke(Expression as CodeMethodInvokeExpression);
            }
            else if (Expression is CodeArrayCreateExpression)
            {
                EmitDynamicName(Expression as CodeArrayCreateExpression);
                Generated = typeof(string[]);
            }
            else if (Expression is CodePrimitiveExpression)
            {
                Generated = EmitPrimitive(Expression as CodePrimitiveExpression);
            }
            else if (Expression is CodeBinaryOperatorExpression)
            {
                Generated = EmitBinaryOperator(Expression as CodeBinaryOperatorExpression, ForceTypes);
            }
            else if (Expression is CodeTernaryOperatorExpression)
            {
                Generated = EmitTernaryOperator(Expression as CodeTernaryOperatorExpression);
            }
            else if (Expression is CodeVariableReferenceExpression)
            {
                Generated = EmitVariableReference(Expression as CodeVariableReferenceExpression);
            }
            else if (Expression is CodeFieldReferenceExpression)
            {
                Generated = EmitCodeFieldReference(Expression as CodeFieldReferenceExpression);
            }
            else if (Expression is CodeArgumentReferenceExpression)
            {
                EmitArgumentReference(Expression as CodeArgumentReferenceExpression);
                Generated = typeof(object[]);
            }
            else if (Expression is CodeArrayIndexerExpression)
            {
                EmitArrayIndexerExpression(Expression as CodeArrayIndexerExpression);
                Generated = typeof(object);
            }
            else if (Expression is CodeDelegateCreateExpression)
            {
                Generated = EmitDelegateCreateExpression((CodeDelegateCreateExpression) Expression);
            }
            else if (Expression is CodePropertyReferenceExpression)
            {
                Generated = EmitPropertyReferenceExpression((CodePropertyReferenceExpression) Expression);
            }
            else
            {
                Depth++;
                Debug("Unhandled expression: " + Expression.GetType());
                Generated = null;
                Depth--;
            }

            Depth--;

            return Generated;
        }
 private object MatchArgument(Type parameterType, CodeExpression arg)
 {
     Type fromType = arg.GetType();
     if (TypeProvider.IsAssignable(parameterType, fromType))
     {
         return arg;
     }
     CodePrimitiveExpression rhsExpression = arg as CodePrimitiveExpression;
     if (rhsExpression != null)
     {
         ValidationError error = null;
         if (RuleValidation.TypesAreAssignable(this.validation.ExpressionInfo(rhsExpression).ExpressionType, parameterType, rhsExpression, out error))
         {
             return rhsExpression.Value;
         }
     }
     return null;
 }