internal override RuleExpressionInfo Validate(CodeExpression expression, RuleValidation validation, bool isWritten) { CodeTypeReferenceExpression expression2 = (CodeTypeReferenceExpression)expression; if (expression2.Type == null) { ValidationError item = new ValidationError(Messages.NullTypeType, 0x53d); item.UserData["ErrorObject"] = expression2; validation.Errors.Add(item); return(null); } if (isWritten) { ValidationError error2 = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.CannotWriteToExpression, new object[] { typeof(CodeTypeReferenceExpression).ToString() }), 0x17a); error2.UserData["ErrorObject"] = expression2; validation.Errors.Add(error2); return(null); } return(new RuleExpressionInfo(validation.ResolveType(expression2.Type))); }
internal override RuleExpressionInfo Validate(CodeExpression expression, RuleValidation validation, bool isWritten) { CodeCastExpression expression2 = (CodeCastExpression)expression; if (isWritten) { ValidationError item = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.CannotWriteToExpression, new object[] { typeof(CodeCastExpression).ToString() }), 0x17a); item.UserData["ErrorObject"] = expression2; validation.Errors.Add(item); return(null); } if (expression2.Expression == null) { ValidationError error2 = new ValidationError(Messages.NullCastExpr, 0x53d); error2.UserData["ErrorObject"] = expression2; validation.Errors.Add(error2); return(null); } if (expression2.Expression is CodeTypeReferenceExpression) { ValidationError error = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.CodeExpressionNotHandled, new object[] { expression2.Expression.GetType().FullName }), 0x548); error.UserData["ErrorObject"] = expression2.Expression; validation.AddError(error); return(null); } if (expression2.TargetType == null) { ValidationError error4 = new ValidationError(Messages.NullCastType, 0x53d); error4.UserData["ErrorObject"] = expression2; validation.Errors.Add(error4); return(null); } RuleExpressionInfo info = RuleExpressionWalker.Validate(validation, expression2.Expression, false); if (info == null) { return(null); } Type expressionType = info.ExpressionType; Type type = validation.ResolveType(expression2.TargetType); if (type == null) { return(null); } if (expressionType == typeof(NullLiteral)) { if (ConditionHelper.IsNonNullableValueType(type)) { ValidationError error5 = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.CastOfNullInvalid, new object[] { RuleDecompiler.DecompileType(type) }), 0x53d); error5.UserData["ErrorObject"] = expression2; validation.Errors.Add(error5); return(null); } } else { Type type3 = expressionType; if (ConditionHelper.IsNullableValueType(type3)) { type3 = type3.GetGenericArguments()[0]; } Type type4 = type; if (ConditionHelper.IsNullableValueType(type4)) { type4 = type4.GetGenericArguments()[0]; } bool flag = false; if (type3.IsValueType && type4.IsValueType) { if (type3.IsEnum) { flag = type4.IsEnum || IsNumeric(type4); } else if (type4.IsEnum) { flag = IsNumeric(type3); } else if (type3 == typeof(char)) { flag = IsNumeric(type4); } else if (type4 == typeof(char)) { flag = IsNumeric(type3); } else if (type3.IsPrimitive && type4.IsPrimitive) { try { Convert.ChangeType(Activator.CreateInstance(type3), type4, CultureInfo.CurrentCulture); flag = true; } catch (Exception) { flag = false; } } } if (!flag) { ValidationError error6; flag = RuleValidation.ExplicitConversionSpecified(expressionType, type, out error6); if (error6 != null) { error6.UserData["ErrorObject"] = expression2; validation.Errors.Add(error6); return(null); } } if (!flag) { ValidationError error7 = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.CastIncompatibleTypes, new object[] { RuleDecompiler.DecompileType(expressionType), RuleDecompiler.DecompileType(type) }), 0x53d); error7.UserData["ErrorObject"] = expression2; validation.Errors.Add(error7); return(null); } } return(new RuleExpressionInfo(type)); }
internal override RuleExpressionInfo Validate(CodeExpression expression, RuleValidation validation, bool isWritten) { CodeCastExpression expression2 = (CodeCastExpression) expression; if (isWritten) { ValidationError item = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.CannotWriteToExpression, new object[] { typeof(CodeCastExpression).ToString() }), 0x17a); item.UserData["ErrorObject"] = expression2; validation.Errors.Add(item); return null; } if (expression2.Expression == null) { ValidationError error2 = new ValidationError(Messages.NullCastExpr, 0x53d); error2.UserData["ErrorObject"] = expression2; validation.Errors.Add(error2); return null; } if (expression2.Expression is CodeTypeReferenceExpression) { ValidationError error = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.CodeExpressionNotHandled, new object[] { expression2.Expression.GetType().FullName }), 0x548); error.UserData["ErrorObject"] = expression2.Expression; validation.AddError(error); return null; } if (expression2.TargetType == null) { ValidationError error4 = new ValidationError(Messages.NullCastType, 0x53d); error4.UserData["ErrorObject"] = expression2; validation.Errors.Add(error4); return null; } RuleExpressionInfo info = RuleExpressionWalker.Validate(validation, expression2.Expression, false); if (info == null) { return null; } Type expressionType = info.ExpressionType; Type type = validation.ResolveType(expression2.TargetType); if (type == null) { return null; } if (expressionType == typeof(NullLiteral)) { if (ConditionHelper.IsNonNullableValueType(type)) { ValidationError error5 = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.CastOfNullInvalid, new object[] { RuleDecompiler.DecompileType(type) }), 0x53d); error5.UserData["ErrorObject"] = expression2; validation.Errors.Add(error5); return null; } } else { Type type3 = expressionType; if (ConditionHelper.IsNullableValueType(type3)) { type3 = type3.GetGenericArguments()[0]; } Type type4 = type; if (ConditionHelper.IsNullableValueType(type4)) { type4 = type4.GetGenericArguments()[0]; } bool flag = false; if (type3.IsValueType && type4.IsValueType) { if (type3.IsEnum) { flag = type4.IsEnum || IsNumeric(type4); } else if (type4.IsEnum) { flag = IsNumeric(type3); } else if (type3 == typeof(char)) { flag = IsNumeric(type4); } else if (type4 == typeof(char)) { flag = IsNumeric(type3); } else if (type3.IsPrimitive && type4.IsPrimitive) { try { Convert.ChangeType(Activator.CreateInstance(type3), type4, CultureInfo.CurrentCulture); flag = true; } catch (Exception) { flag = false; } } } if (!flag) { ValidationError error6; flag = RuleValidation.ExplicitConversionSpecified(expressionType, type, out error6); if (error6 != null) { error6.UserData["ErrorObject"] = expression2; validation.Errors.Add(error6); return null; } } if (!flag) { ValidationError error7 = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.CastIncompatibleTypes, new object[] { RuleDecompiler.DecompileType(expressionType), RuleDecompiler.DecompileType(type) }), 0x53d); error7.UserData["ErrorObject"] = expression2; validation.Errors.Add(error7); return null; } } return new RuleExpressionInfo(type); }
internal override RuleExpressionInfo Validate(CodeExpression expression, RuleValidation validation, bool isWritten) { CodeTypeReferenceExpression expression2 = (CodeTypeReferenceExpression) expression; if (expression2.Type == null) { ValidationError item = new ValidationError(Messages.NullTypeType, 0x53d); item.UserData["ErrorObject"] = expression2; validation.Errors.Add(item); return null; } if (isWritten) { ValidationError error2 = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.CannotWriteToExpression, new object[] { typeof(CodeTypeReferenceExpression).ToString() }), 0x17a); error2.UserData["ErrorObject"] = expression2; validation.Errors.Add(error2); return null; } return new RuleExpressionInfo(validation.ResolveType(expression2.Type)); }
internal override RuleExpressionInfo Validate(CodeExpression expression, RuleValidation validation, bool isWritten) { CodeArrayCreateExpression newParent = (CodeArrayCreateExpression)expression; if (isWritten) { ValidationError item = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.CannotWriteToExpression, new object[] { typeof(CodeObjectCreateExpression).ToString() }), 0x17a); item.UserData["ErrorObject"] = newParent; validation.Errors.Add(item); return(null); } if (newParent.CreateType == null) { ValidationError error2 = new ValidationError(Messages.NullTypeType, 0x53d); error2.UserData["ErrorObject"] = newParent; validation.Errors.Add(error2); return(null); } Type lhsType = validation.ResolveType(newParent.CreateType); if (lhsType == null) { return(null); } if (lhsType.IsArray) { ValidationError error3 = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.ArrayTypeInvalid, new object[] { lhsType.Name }), 0x53d); error3.UserData["ErrorObject"] = newParent; validation.Errors.Add(error3); return(null); } try { if (!validation.PushParentExpression(newParent)) { return(null); } if (newParent.Size < 0) { ValidationError error4 = new ValidationError(Messages.ArraySizeInvalid, 0x53d); error4.UserData["ErrorObject"] = newParent; validation.Errors.Add(error4); return(null); } if (newParent.SizeExpression != null) { RuleExpressionInfo info = RuleExpressionWalker.Validate(validation, newParent.SizeExpression, false); if (info == null) { return(null); } if (((info.ExpressionType != typeof(int)) && (info.ExpressionType != typeof(uint))) && ((info.ExpressionType != typeof(long)) && (info.ExpressionType != typeof(ulong)))) { ValidationError error5 = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.ArraySizeTypeInvalid, new object[] { info.ExpressionType.Name }), 0x53d); error5.UserData["ErrorObject"] = newParent; validation.Errors.Add(error5); return(null); } } bool flag = false; for (int i = 0; i < newParent.Initializers.Count; i++) { CodeExpression expression3 = newParent.Initializers[i]; if (expression3 == null) { ValidationError error6 = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.MissingInitializer, new object[] { lhsType.Name }), 0x53d); error6.UserData["ErrorObject"] = newParent; validation.Errors.Add(error6); return(null); } RuleExpressionInfo info2 = RuleExpressionWalker.Validate(validation, expression3, false); if (info2 == null) { flag = true; } else { ValidationError error7; if (!RuleValidation.StandardImplicitConversion(info2.ExpressionType, lhsType, expression3, out error7)) { if (error7 != null) { error7.UserData["ErrorObject"] = newParent; validation.Errors.Add(error7); } error7 = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.InitializerMismatch, new object[] { i, lhsType.Name }), 0x545); error7.UserData["ErrorObject"] = newParent; validation.Errors.Add(error7); return(null); } } } if (flag) { return(null); } double size = -1.0; if (newParent.SizeExpression != null) { CodePrimitiveExpression sizeExpression = newParent.SizeExpression as CodePrimitiveExpression; if ((sizeExpression != null) && (sizeExpression.Value != null)) { size = (double)Executor.AdjustType(sizeExpression.Value.GetType(), sizeExpression.Value, typeof(double)); } if (newParent.Size > 0) { ValidationError error8 = new ValidationError(Messages.ArraySizeBoth, 0x53d); error8.UserData["ErrorObject"] = newParent; validation.Errors.Add(error8); return(null); } } else if (newParent.Size > 0) { size = newParent.Size; } if ((size >= 0.0) && (newParent.Initializers.Count > size)) { ValidationError error9 = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.InitializerCountMismatch, new object[] { newParent.Initializers.Count, size }), 0x545); error9.UserData["ErrorObject"] = newParent; validation.Errors.Add(error9); return(null); } } finally { validation.PopParentExpression(); } return(new RuleExpressionInfo(lhsType.MakeArrayType())); }
internal override RuleExpressionInfo Validate(CodeExpression expression, RuleValidation validation, bool isWritten) { CodeArrayCreateExpression newParent = (CodeArrayCreateExpression) expression; if (isWritten) { ValidationError item = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.CannotWriteToExpression, new object[] { typeof(CodeObjectCreateExpression).ToString() }), 0x17a); item.UserData["ErrorObject"] = newParent; validation.Errors.Add(item); return null; } if (newParent.CreateType == null) { ValidationError error2 = new ValidationError(Messages.NullTypeType, 0x53d); error2.UserData["ErrorObject"] = newParent; validation.Errors.Add(error2); return null; } Type lhsType = validation.ResolveType(newParent.CreateType); if (lhsType == null) { return null; } if (lhsType.IsArray) { ValidationError error3 = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.ArrayTypeInvalid, new object[] { lhsType.Name }), 0x53d); error3.UserData["ErrorObject"] = newParent; validation.Errors.Add(error3); return null; } try { if (!validation.PushParentExpression(newParent)) { return null; } if (newParent.Size < 0) { ValidationError error4 = new ValidationError(Messages.ArraySizeInvalid, 0x53d); error4.UserData["ErrorObject"] = newParent; validation.Errors.Add(error4); return null; } if (newParent.SizeExpression != null) { RuleExpressionInfo info = RuleExpressionWalker.Validate(validation, newParent.SizeExpression, false); if (info == null) { return null; } if (((info.ExpressionType != typeof(int)) && (info.ExpressionType != typeof(uint))) && ((info.ExpressionType != typeof(long)) && (info.ExpressionType != typeof(ulong)))) { ValidationError error5 = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.ArraySizeTypeInvalid, new object[] { info.ExpressionType.Name }), 0x53d); error5.UserData["ErrorObject"] = newParent; validation.Errors.Add(error5); return null; } } bool flag = false; for (int i = 0; i < newParent.Initializers.Count; i++) { CodeExpression expression3 = newParent.Initializers[i]; if (expression3 == null) { ValidationError error6 = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.MissingInitializer, new object[] { lhsType.Name }), 0x53d); error6.UserData["ErrorObject"] = newParent; validation.Errors.Add(error6); return null; } RuleExpressionInfo info2 = RuleExpressionWalker.Validate(validation, expression3, false); if (info2 == null) { flag = true; } else { ValidationError error7; if (!RuleValidation.StandardImplicitConversion(info2.ExpressionType, lhsType, expression3, out error7)) { if (error7 != null) { error7.UserData["ErrorObject"] = newParent; validation.Errors.Add(error7); } error7 = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.InitializerMismatch, new object[] { i, lhsType.Name }), 0x545); error7.UserData["ErrorObject"] = newParent; validation.Errors.Add(error7); return null; } } } if (flag) { return null; } double size = -1.0; if (newParent.SizeExpression != null) { CodePrimitiveExpression sizeExpression = newParent.SizeExpression as CodePrimitiveExpression; if ((sizeExpression != null) && (sizeExpression.Value != null)) { size = (double) Executor.AdjustType(sizeExpression.Value.GetType(), sizeExpression.Value, typeof(double)); } if (newParent.Size > 0) { ValidationError error8 = new ValidationError(Messages.ArraySizeBoth, 0x53d); error8.UserData["ErrorObject"] = newParent; validation.Errors.Add(error8); return null; } } else if (newParent.Size > 0) { size = newParent.Size; } if ((size >= 0.0) && (newParent.Initializers.Count > size)) { ValidationError error9 = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.InitializerCountMismatch, new object[] { newParent.Initializers.Count, size }), 0x545); error9.UserData["ErrorObject"] = newParent; validation.Errors.Add(error9); return null; } } finally { validation.PopParentExpression(); } return new RuleExpressionInfo(lhsType.MakeArrayType()); }
internal override RuleExpressionInfo Validate(CodeExpression expression, RuleValidation validation, bool isWritten) { ValidationError error; CodeObjectCreateExpression newParent = (CodeObjectCreateExpression)expression; if (isWritten) { error = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.CannotWriteToExpression, new object[] { typeof(CodeObjectCreateExpression).ToString() }), 0x17a); error.UserData["ErrorObject"] = newParent; validation.Errors.Add(error); return(null); } if (newParent.CreateType == null) { error = new ValidationError(Messages.NullTypeType, 0x53d); error.UserData["ErrorObject"] = newParent; validation.Errors.Add(error); return(null); } Type type = validation.ResolveType(newParent.CreateType); if (type == null) { return(null); } List <CodeExpression> argumentExprs = new List <CodeExpression>(); try { if (!validation.PushParentExpression(newParent)) { return(null); } bool flag = false; for (int i = 0; i < newParent.Parameters.Count; i++) { CodeExpression expression3 = newParent.Parameters[i]; if (expression3 == null) { error = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.NullConstructorParameter, new object[] { i.ToString(CultureInfo.CurrentCulture), RuleDecompiler.DecompileType(type) }), 0x53d); error.UserData["ErrorObject"] = newParent; validation.Errors.Add(error); flag = true; } else { if (RuleExpressionWalker.Validate(validation, expression3, false) == null) { flag = true; } argumentExprs.Add(expression3); } } if (flag) { return(null); } } finally { validation.PopParentExpression(); } BindingFlags constructorBindingFlags = BindingFlags.Public | BindingFlags.Instance; if (validation.AllowInternalMembers(type)) { constructorBindingFlags |= BindingFlags.NonPublic; } if (type.IsValueType && (argumentExprs.Count == 0)) { return(new RuleExpressionInfo(type)); } if (type.IsAbstract) { error = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.UnknownConstructor, new object[] { RuleDecompiler.DecompileType(type) }), 0x137); error.UserData["ErrorObject"] = newParent; validation.Errors.Add(error); return(null); } RuleConstructorExpressionInfo info2 = validation.ResolveConstructor(type, constructorBindingFlags, argumentExprs, out error); if (info2 == null) { error = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.UnknownConstructor, new object[] { RuleDecompiler.DecompileType(type) }), 0x137); error.UserData["ErrorObject"] = newParent; validation.Errors.Add(error); return(null); } return(info2); }
internal override RuleExpressionInfo Validate(CodeExpression expression, RuleValidation validation, bool isWritten) { Type expressionType = null; RuleMethodInvokeExpressionInfo info = null; ValidationError item = null; BindingFlags @public = BindingFlags.Public; CodeMethodInvokeExpression newParent = (CodeMethodInvokeExpression)expression; if (isWritten) { item = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.CannotWriteToExpression, new object[] { typeof(CodeMethodInvokeExpression).ToString() }), 0x17a); item.UserData["ErrorObject"] = newParent; validation.Errors.Add(item); return(null); } if ((newParent.Method == null) || (newParent.Method.TargetObject == null)) { item = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.NullMethodTarget, new object[] { newParent.Method.MethodName }), 0x53d); item.UserData["ErrorObject"] = newParent; validation.Errors.Add(item); return(null); } if ((newParent.Method.TypeArguments != null) && (newParent.Method.TypeArguments.Count > 0)) { item = new ValidationError(Messages.GenericMethodsNotSupported, 0x548); item.UserData["ErrorObject"] = newParent; validation.Errors.Add(item); return(null); } try { if (!validation.PushParentExpression(newParent)) { return(null); } RuleExpressionInfo info2 = RuleExpressionWalker.Validate(validation, newParent.Method.TargetObject, false); if (info2 == null) { return(null); } expressionType = info2.ExpressionType; if (expressionType == null) { return(null); } if (expressionType == typeof(NullLiteral)) { item = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.NullMethodTarget, new object[] { newParent.Method.MethodName }), 0x546); item.UserData["ErrorObject"] = newParent; validation.Errors.Add(item); expressionType = null; } List <CodeExpression> argumentExprs = new List <CodeExpression>(); bool flag = false; if (newParent.Parameters != null) { for (int i = 0; i < newParent.Parameters.Count; i++) { CodeExpression expression3 = newParent.Parameters[i]; if (expression3 == null) { item = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.NullMethodParameter, new object[] { i.ToString(CultureInfo.CurrentCulture), newParent.Method.MethodName }), 0x53d); item.UserData["ErrorObject"] = newParent; validation.Errors.Add(item); expressionType = null; } else { if (expression3 is CodeTypeReferenceExpression) { item = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.CodeExpressionNotHandled, new object[] { expression3.GetType().FullName }), 0x548); item.UserData["ErrorObject"] = expression3; validation.AddError(item); flag = true; } if (RuleExpressionWalker.Validate(validation, expression3, false) == null) { flag = true; } argumentExprs.Add(expression3); } } } if (expressionType == null) { return(null); } if (flag) { return(null); } if (newParent.Method.TargetObject is CodeTypeReferenceExpression) { @public |= BindingFlags.FlattenHierarchy | BindingFlags.Static; } else { @public |= BindingFlags.Instance; } if (validation.AllowInternalMembers(expressionType)) { @public |= BindingFlags.NonPublic; } info = validation.ResolveMethod(expressionType, newParent.Method.MethodName, @public, argumentExprs, out item); if ((info == null) && newParent.UserData.Contains("QualifiedName")) { string qualifiedName = newParent.UserData["QualifiedName"] as string; Type type2 = validation.ResolveType(qualifiedName); if (type2 != null) { validation.DetermineExtensionMethods(type2.Assembly); info = validation.ResolveMethod(expressionType, newParent.Method.MethodName, @public, argumentExprs, out item); } } if (info == null) { item.UserData["ErrorObject"] = newParent; validation.Errors.Add(item); return(null); } } finally { validation.PopParentExpression(); } MethodInfo methodInfo = info.MethodInfo; if (methodInfo.ReturnType == null) { item = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.CouldNotDetermineMemberType, new object[] { newParent.Method.MethodName }), 0x194); item.UserData["ErrorObject"] = newParent; validation.Errors.Add(item); return(null); } if (!validation.ValidateMemberAccess(newParent.Method.TargetObject, expressionType, methodInfo, newParent.Method.MethodName, newParent)) { return(null); } object[] customAttributes = methodInfo.GetCustomAttributes(typeof(RuleAttribute), true); if ((customAttributes != null) && (customAttributes.Length > 0)) { Stack <MemberInfo> stack = new Stack <MemberInfo>(); stack.Push(methodInfo); bool flag2 = true; foreach (RuleAttribute attribute in customAttributes) { if (!attribute.Validate(validation, methodInfo, expressionType, methodInfo.GetParameters())) { flag2 = false; } } stack.Pop(); if (!flag2) { return(null); } } if (methodInfo is ExtensionMethodInfo) { newParent.UserData["QualifiedName"] = methodInfo.DeclaringType.AssemblyQualifiedName; } return(info); }
internal override RuleExpressionInfo Validate(CodeExpression expression, RuleValidation validation, bool isWritten) { string message; CodeArrayCreateExpression createExpression = (CodeArrayCreateExpression)expression; if (isWritten) { message = string.Format(CultureInfo.CurrentCulture, Messages.CannotWriteToExpression, typeof(CodeObjectCreateExpression).ToString()); ValidationError error = new ValidationError(message, ErrorNumbers.Error_InvalidAssignTarget); error.UserData[RuleUserDataKeys.ErrorObject] = createExpression; validation.Errors.Add(error); return null; } if (createExpression.CreateType == null) { ValidationError error = new ValidationError(Messages.NullTypeType, ErrorNumbers.Error_ParameterNotSet); error.UserData[RuleUserDataKeys.ErrorObject] = createExpression; validation.Errors.Add(error); return null; } Type resultType = validation.ResolveType(createExpression.CreateType); if (resultType == null) return null; // size CodeDom has limited support for arrays (only 1 dimensional, not more) // we limit CodeArrayCreateExpression to a single dimension // (i.e. CodeArrayCreateExpression cannot define int[5,3] or int[5][3], // but it is possible to define int[][3] and then use initializers to // fill it in. But we only support int[] or int[3].) if (resultType.IsArray) { message = string.Format(CultureInfo.CurrentCulture, Messages.ArrayTypeInvalid, resultType.Name); ValidationError error = new ValidationError(message, ErrorNumbers.Error_ParameterNotSet); error.UserData[RuleUserDataKeys.ErrorObject] = createExpression; validation.Errors.Add(error); return null; } try { // Early exit from this if a cycle is detected. if (!validation.PushParentExpression(createExpression)) return null; if (createExpression.Size < 0) { ValidationError error = new ValidationError(Messages.ArraySizeInvalid, ErrorNumbers.Error_ParameterNotSet); error.UserData[RuleUserDataKeys.ErrorObject] = createExpression; validation.Errors.Add(error); return null; } // look up size (if specified) if (createExpression.SizeExpression != null) { RuleExpressionInfo sizeInfo = RuleExpressionWalker.Validate(validation, createExpression.SizeExpression, false); if (sizeInfo == null) return null; if ((sizeInfo.ExpressionType != typeof(int)) && (sizeInfo.ExpressionType != typeof(uint)) && (sizeInfo.ExpressionType != typeof(long)) && (sizeInfo.ExpressionType != typeof(ulong))) { message = string.Format(CultureInfo.CurrentCulture, Messages.ArraySizeTypeInvalid, sizeInfo.ExpressionType.Name); ValidationError error = new ValidationError(message, ErrorNumbers.Error_ParameterNotSet); error.UserData[RuleUserDataKeys.ErrorObject] = createExpression; validation.Errors.Add(error); return null; } } bool parameterInvalid = false; for (int i = 0; i < createExpression.Initializers.Count; ++i) { CodeExpression init = createExpression.Initializers[i]; if (init == null) { message = string.Format(CultureInfo.CurrentCulture, Messages.MissingInitializer, resultType.Name); ValidationError error = new ValidationError(message, ErrorNumbers.Error_ParameterNotSet); error.UserData[RuleUserDataKeys.ErrorObject] = createExpression; validation.Errors.Add(error); return null; } RuleExpressionInfo parameterInfo = RuleExpressionWalker.Validate(validation, init, false); if (parameterInfo == null) { parameterInvalid = true; } else { // can we convert the result type to the array type? ValidationError error; if (!RuleValidation.StandardImplicitConversion(parameterInfo.ExpressionType, resultType, init, out error)) { // types must match if (error != null) { // we got an error from the conversion, so give it back as well as a new error error.UserData[RuleUserDataKeys.ErrorObject] = createExpression; validation.Errors.Add(error); } message = string.Format(CultureInfo.CurrentCulture, Messages.InitializerMismatch, i, resultType.Name); error = new ValidationError(message, ErrorNumbers.Error_OperandTypesIncompatible); error.UserData[RuleUserDataKeys.ErrorObject] = createExpression; validation.Errors.Add(error); return null; } } } // if any errors get out if (parameterInvalid) return null; // now it gets tricky. CodeArrayCreateExpression constructors allow: // 1) size as int // 2) size as CodeExpression // 3) initializers as params array // However, we allow a size and initializers, so try to verify size >= #initializers // size can be an int, uint, long, or ulong double size = -1; if (createExpression.SizeExpression != null) { CodePrimitiveExpression prim = createExpression.SizeExpression as CodePrimitiveExpression; if ((prim != null) && (prim.Value != null)) size = (double)Executor.AdjustType(prim.Value.GetType(), prim.Value, typeof(double)); if (createExpression.Size > 0) { // both size and SizeExpression specified, complain ValidationError error = new ValidationError(Messages.ArraySizeBoth, ErrorNumbers.Error_ParameterNotSet); error.UserData[RuleUserDataKeys.ErrorObject] = createExpression; validation.Errors.Add(error); return null; } } else if (createExpression.Size > 0) size = createExpression.Size; if ((size >= 0) && (createExpression.Initializers.Count > size)) { message = string.Format(CultureInfo.CurrentCulture, Messages.InitializerCountMismatch, createExpression.Initializers.Count, size); ValidationError error = new ValidationError(message, ErrorNumbers.Error_OperandTypesIncompatible); error.UserData[RuleUserDataKeys.ErrorObject] = createExpression; validation.Errors.Add(error); return null; } } finally { validation.PopParentExpression(); } return new RuleExpressionInfo(resultType.MakeArrayType()); }
internal override RuleExpressionInfo Validate(CodeExpression expression, RuleValidation validation, bool isWritten) { string message; ValidationError error; CodeObjectCreateExpression createExpression = (CodeObjectCreateExpression)expression; if (isWritten) { message = string.Format(CultureInfo.CurrentCulture, Messages.CannotWriteToExpression, typeof(CodeObjectCreateExpression).ToString()); error = new ValidationError(message, ErrorNumbers.Error_InvalidAssignTarget); error.UserData[RuleUserDataKeys.ErrorObject] = createExpression; validation.Errors.Add(error); return null; } if (createExpression.CreateType == null) { error = new ValidationError(Messages.NullTypeType, ErrorNumbers.Error_ParameterNotSet); error.UserData[RuleUserDataKeys.ErrorObject] = createExpression; validation.Errors.Add(error); return null; } Type resultType = validation.ResolveType(createExpression.CreateType); if (resultType == null) return null; // look up parameters List<CodeExpression> parameters = new List<CodeExpression>(); try { // Early exit from this if a cycle is detected. if (!validation.PushParentExpression(createExpression)) return null; bool hasInvalidArgument = false; for (int i = 0; i < createExpression.Parameters.Count; ++i) { CodeExpression parameter = createExpression.Parameters[i]; if (parameter == null) { message = string.Format(CultureInfo.CurrentCulture, Messages.NullConstructorParameter, i.ToString(CultureInfo.CurrentCulture), RuleDecompiler.DecompileType(resultType)); error = new ValidationError(message, ErrorNumbers.Error_ParameterNotSet); error.UserData[RuleUserDataKeys.ErrorObject] = createExpression; validation.Errors.Add(error); hasInvalidArgument = true; } else { RuleExpressionInfo parameterInfo = RuleExpressionWalker.Validate(validation, parameter, false); if (parameterInfo == null) hasInvalidArgument = true; parameters.Add(parameter); } } // quit if parameters not valid if (hasInvalidArgument) return null; } finally { validation.PopParentExpression(); } // see if we can find the matching constructor BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.Instance; if (validation.AllowInternalMembers(resultType)) bindingFlags |= BindingFlags.NonPublic; // creating a value-type object with no parameters can always be done if ((resultType.IsValueType) && (parameters.Count == 0)) return new RuleExpressionInfo(resultType); // error if type is an abstract type if (resultType.IsAbstract) { message = string.Format(CultureInfo.CurrentCulture, Messages.UnknownConstructor, RuleDecompiler.DecompileType(resultType)); error = new ValidationError(message, ErrorNumbers.Error_MethodNotExists); error.UserData[RuleUserDataKeys.ErrorObject] = createExpression; validation.Errors.Add(error); return null; } RuleConstructorExpressionInfo constructorInvokeInfo = validation.ResolveConstructor(resultType, bindingFlags, parameters, out error); if (constructorInvokeInfo == null) { message = string.Format(CultureInfo.CurrentCulture, Messages.UnknownConstructor, RuleDecompiler.DecompileType(resultType)); error = new ValidationError(message, ErrorNumbers.Error_MethodNotExists); error.UserData[RuleUserDataKeys.ErrorObject] = createExpression; validation.Errors.Add(error); return null; } return constructorInvokeInfo; }
internal override RuleExpressionInfo Validate(CodeExpression expression, RuleValidation validation, bool isWritten) { string message; CodeCastExpression castExpr = (CodeCastExpression)expression; if (isWritten) { message = string.Format(CultureInfo.CurrentCulture, Messages.CannotWriteToExpression, typeof(CodeCastExpression).ToString()); ValidationError error = new ValidationError(message, ErrorNumbers.Error_InvalidAssignTarget); error.UserData[RuleUserDataKeys.ErrorObject] = castExpr; validation.Errors.Add(error); return null; } if (castExpr.Expression == null) { ValidationError error = new ValidationError(Messages.NullCastExpr, ErrorNumbers.Error_ParameterNotSet); error.UserData[RuleUserDataKeys.ErrorObject] = castExpr; validation.Errors.Add(error); return null; } if (castExpr.Expression is CodeTypeReferenceExpression) { message = string.Format(CultureInfo.CurrentCulture, Messages.CodeExpressionNotHandled, castExpr.Expression.GetType().FullName); ValidationError error = new ValidationError(message, ErrorNumbers.Error_CodeExpressionNotHandled); error.UserData[RuleUserDataKeys.ErrorObject] = castExpr.Expression; validation.AddError(error); return null; } if (castExpr.TargetType == null) { ValidationError error = new ValidationError(Messages.NullCastType, ErrorNumbers.Error_ParameterNotSet); error.UserData[RuleUserDataKeys.ErrorObject] = castExpr; validation.Errors.Add(error); return null; } // Figure out the operand type. RuleExpressionInfo operandInfo = RuleExpressionWalker.Validate(validation, castExpr.Expression, false); if (operandInfo == null) return null; Type fromType = operandInfo.ExpressionType; Type toType = validation.ResolveType(castExpr.TargetType); if (toType == null) return null; if (fromType == typeof(NullLiteral)) { // Casting from null value. if (ConditionHelper.IsNonNullableValueType(toType)) { message = string.Format(CultureInfo.CurrentCulture, Messages.CastOfNullInvalid, RuleDecompiler.DecompileType(toType)); ValidationError error = new ValidationError(message, ErrorNumbers.Error_ParameterNotSet); error.UserData[RuleUserDataKeys.ErrorObject] = castExpr; validation.Errors.Add(error); return null; } } else { // Unwrap nullables to make life easy. Type fromType2 = fromType; if (ConditionHelper.IsNullableValueType(fromType2)) fromType2 = fromType2.GetGenericArguments()[0]; Type toType2 = toType; if (ConditionHelper.IsNullableValueType(toType2)) toType2 = toType2.GetGenericArguments()[0]; bool canConvert = false; if (fromType2.IsValueType && toType2.IsValueType) { // Convert.ChangeType doesn't handle enum <--> numeric // and float/double/decimal <--> char, which are allowed if (fromType2.IsEnum) { canConvert = (toType2.IsEnum) || IsNumeric(toType2); } else if (toType2.IsEnum) { // don't need to check fromType for enum since it's handled above canConvert = IsNumeric(fromType2); } else if (fromType2 == typeof(char)) { canConvert = IsNumeric(toType2); } else if (toType2 == typeof(char)) { canConvert = IsNumeric(fromType2); } else if (fromType2.IsPrimitive && toType2.IsPrimitive) { try { // note: this also allows bool <--> numeric conversions object fromValueDefault = Activator.CreateInstance(fromType2); Convert.ChangeType(fromValueDefault, toType2, CultureInfo.CurrentCulture); canConvert = true; } catch (Exception) { canConvert = false; } } } if (!canConvert) { // We can cast up or down an inheritence hierarchy, // as well as support explicit and implicit overrides ValidationError error; canConvert = RuleValidation.ExplicitConversionSpecified(fromType, toType, out error); if (error != null) { error.UserData[RuleUserDataKeys.ErrorObject] = castExpr; validation.Errors.Add(error); return null; } } if (!canConvert) { message = string.Format(CultureInfo.CurrentCulture, Messages.CastIncompatibleTypes, RuleDecompiler.DecompileType(fromType), RuleDecompiler.DecompileType(toType)); ValidationError error = new ValidationError(message, ErrorNumbers.Error_ParameterNotSet); error.UserData[RuleUserDataKeys.ErrorObject] = castExpr; validation.Errors.Add(error); return null; } } return new RuleExpressionInfo(toType); }
internal override RuleExpressionInfo Validate(CodeExpression expression, RuleValidation validation, bool isWritten) { CodeTypeReferenceExpression typeRefExpr = (CodeTypeReferenceExpression)expression; if (typeRefExpr.Type == null) { ValidationError error = new ValidationError(Messages.NullTypeType, ErrorNumbers.Error_ParameterNotSet); error.UserData[RuleUserDataKeys.ErrorObject] = typeRefExpr; validation.Errors.Add(error); return null; } if (isWritten) { string message = string.Format(CultureInfo.CurrentCulture, Messages.CannotWriteToExpression, typeof(CodeTypeReferenceExpression).ToString()); ValidationError error = new ValidationError(message, ErrorNumbers.Error_InvalidAssignTarget); error.UserData[RuleUserDataKeys.ErrorObject] = typeRefExpr; validation.Errors.Add(error); return null; } Type resultType = validation.ResolveType(typeRefExpr.Type); return new RuleExpressionInfo(resultType); }
internal override RuleExpressionInfo Validate(CodeExpression expression, RuleValidation validation, bool isWritten) { Type targetType = null; RuleMethodInvokeExpressionInfo methodInvokeInfo = null; string message; ValidationError error = null; BindingFlags bindingFlags = BindingFlags.Public; CodeMethodInvokeExpression invokeExpr = (CodeMethodInvokeExpression)expression; if (isWritten) { message = string.Format(CultureInfo.CurrentCulture, Messages.CannotWriteToExpression, typeof(CodeMethodInvokeExpression).ToString()); error = new ValidationError(message, ErrorNumbers.Error_InvalidAssignTarget); error.UserData[RuleUserDataKeys.ErrorObject] = invokeExpr; validation.Errors.Add(error); return null; } if ((invokeExpr.Method == null) || (invokeExpr.Method.TargetObject == null)) { message = string.Format(CultureInfo.CurrentCulture, Messages.NullMethodTarget, invokeExpr.Method.MethodName); error = new ValidationError(message, ErrorNumbers.Error_ParameterNotSet); error.UserData[RuleUserDataKeys.ErrorObject] = invokeExpr; validation.Errors.Add(error); return null; // Fatal error; discontinue validation of this object. } if ((invokeExpr.Method.TypeArguments != null) && (invokeExpr.Method.TypeArguments.Count > 0)) { error = new ValidationError(Messages.GenericMethodsNotSupported, ErrorNumbers.Error_CodeExpressionNotHandled); error.UserData[RuleUserDataKeys.ErrorObject] = invokeExpr; validation.Errors.Add(error); return null; } try { // Early exit from this if a cycle is detected. if (!validation.PushParentExpression(invokeExpr)) return null; RuleExpressionInfo targetExprInfo = RuleExpressionWalker.Validate(validation, invokeExpr.Method.TargetObject, false); if (targetExprInfo == null) // error occurred, so simply return return null; targetType = targetExprInfo.ExpressionType; if (targetType == null) return null; // if an error occurred (targetType == null), continue on to validate the arguments if (targetType == typeof(NullLiteral)) { message = string.Format(CultureInfo.CurrentCulture, Messages.NullMethodTarget, invokeExpr.Method.MethodName); error = new ValidationError(message, ErrorNumbers.Error_BindingTypeMissing); error.UserData[RuleUserDataKeys.ErrorObject] = invokeExpr; validation.Errors.Add(error); targetType = null; // force exit after validating the arguments } List<CodeExpression> argExprs = new List<CodeExpression>(); bool hasInvalidArgument = false; if (invokeExpr.Parameters != null) { for (int i = 0; i < invokeExpr.Parameters.Count; ++i) { CodeExpression argExpr = invokeExpr.Parameters[i]; if (argExpr == null) { message = string.Format(CultureInfo.CurrentCulture, Messages.NullMethodParameter, i.ToString(CultureInfo.CurrentCulture), invokeExpr.Method.MethodName); error = new ValidationError(message, ErrorNumbers.Error_ParameterNotSet); error.UserData[RuleUserDataKeys.ErrorObject] = invokeExpr; validation.Errors.Add(error); targetType = null; // force exit after validating the rest of the arguments } else { if (argExpr is CodeTypeReferenceExpression) { message = string.Format(CultureInfo.CurrentCulture, Messages.CodeExpressionNotHandled, argExpr.GetType().FullName); error = new ValidationError(message, ErrorNumbers.Error_CodeExpressionNotHandled); error.UserData[RuleUserDataKeys.ErrorObject] = argExpr; validation.AddError(error); hasInvalidArgument = true; } // Validate the argument. RuleExpressionInfo argExprInfo = RuleExpressionWalker.Validate(validation, argExpr, false); if (argExprInfo == null) hasInvalidArgument = true; argExprs.Add(argExpr); } } } // Stop further validation if there was a problem with the target expression. if (targetType == null) return null; // Stop further validation if there was a problem with any of the arguments. if (hasInvalidArgument) return null; if (invokeExpr.Method.TargetObject is CodeTypeReferenceExpression) bindingFlags |= BindingFlags.Static | BindingFlags.FlattenHierarchy; else bindingFlags |= BindingFlags.Instance; if (validation.AllowInternalMembers(targetType)) bindingFlags |= BindingFlags.NonPublic; // Everything okay so far, try to resolve the method. methodInvokeInfo = validation.ResolveMethod(targetType, invokeExpr.Method.MethodName, bindingFlags, argExprs, out error); if ((methodInvokeInfo == null) && (invokeExpr.UserData.Contains(RuleUserDataKeys.QualifiedName))) { // failed to resolve the method, but a fully qualified type name is around // load the type, add it to the assemblies, and try again string qualifiedName = invokeExpr.UserData[RuleUserDataKeys.QualifiedName] as string; Type containingClassType = validation.ResolveType(qualifiedName); if (containingClassType != null) { validation.DetermineExtensionMethods(containingClassType.Assembly); methodInvokeInfo = validation.ResolveMethod(targetType, invokeExpr.Method.MethodName, bindingFlags, argExprs, out error); } } if (methodInvokeInfo == null) { error.UserData[RuleUserDataKeys.ErrorObject] = invokeExpr; validation.Errors.Add(error); return null; } } finally { validation.PopParentExpression(); } MethodInfo mi = methodInvokeInfo.MethodInfo; if (mi.ReturnType == null) { // This can only happen with a design-time type. message = string.Format(CultureInfo.CurrentCulture, Messages.CouldNotDetermineMemberType, invokeExpr.Method.MethodName); error = new ValidationError(message, ErrorNumbers.Error_CouldNotDetermineMemberType); error.UserData[RuleUserDataKeys.ErrorObject] = invokeExpr; validation.Errors.Add(error); return null; } if (!validation.ValidateMemberAccess(invokeExpr.Method.TargetObject, targetType, mi, invokeExpr.Method.MethodName, invokeExpr)) return null; // Validate any RuleAttributes, if present. object[] attrs = mi.GetCustomAttributes(typeof(RuleAttribute), true); if (attrs != null && attrs.Length > 0) { Stack<MemberInfo> methodStack = new Stack<MemberInfo>(); methodStack.Push(mi); bool allAttributesValid = true; foreach (RuleAttribute ruleAttr in attrs) { if (!ruleAttr.Validate(validation, mi, targetType, mi.GetParameters())) allAttributesValid = false; } methodStack.Pop(); if (!allAttributesValid) return null; } // if this is an extension method, save the type information if (mi is ExtensionMethodInfo) { invokeExpr.UserData[RuleUserDataKeys.QualifiedName] = mi.DeclaringType.AssemblyQualifiedName; } return methodInvokeInfo; }
internal override RuleExpressionInfo Validate(CodeExpression expression, RuleValidation validation, bool isWritten) { Type expressionType = null; RuleMethodInvokeExpressionInfo info = null; ValidationError item = null; BindingFlags @public = BindingFlags.Public; CodeMethodInvokeExpression newParent = (CodeMethodInvokeExpression) expression; if (isWritten) { item = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.CannotWriteToExpression, new object[] { typeof(CodeMethodInvokeExpression).ToString() }), 0x17a); item.UserData["ErrorObject"] = newParent; validation.Errors.Add(item); return null; } if ((newParent.Method == null) || (newParent.Method.TargetObject == null)) { item = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.NullMethodTarget, new object[] { newParent.Method.MethodName }), 0x53d); item.UserData["ErrorObject"] = newParent; validation.Errors.Add(item); return null; } if ((newParent.Method.TypeArguments != null) && (newParent.Method.TypeArguments.Count > 0)) { item = new ValidationError(Messages.GenericMethodsNotSupported, 0x548); item.UserData["ErrorObject"] = newParent; validation.Errors.Add(item); return null; } try { if (!validation.PushParentExpression(newParent)) { return null; } RuleExpressionInfo info2 = RuleExpressionWalker.Validate(validation, newParent.Method.TargetObject, false); if (info2 == null) { return null; } expressionType = info2.ExpressionType; if (expressionType == null) { return null; } if (expressionType == typeof(NullLiteral)) { item = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.NullMethodTarget, new object[] { newParent.Method.MethodName }), 0x546); item.UserData["ErrorObject"] = newParent; validation.Errors.Add(item); expressionType = null; } List<CodeExpression> argumentExprs = new List<CodeExpression>(); bool flag = false; if (newParent.Parameters != null) { for (int i = 0; i < newParent.Parameters.Count; i++) { CodeExpression expression3 = newParent.Parameters[i]; if (expression3 == null) { item = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.NullMethodParameter, new object[] { i.ToString(CultureInfo.CurrentCulture), newParent.Method.MethodName }), 0x53d); item.UserData["ErrorObject"] = newParent; validation.Errors.Add(item); expressionType = null; } else { if (expression3 is CodeTypeReferenceExpression) { item = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.CodeExpressionNotHandled, new object[] { expression3.GetType().FullName }), 0x548); item.UserData["ErrorObject"] = expression3; validation.AddError(item); flag = true; } if (RuleExpressionWalker.Validate(validation, expression3, false) == null) { flag = true; } argumentExprs.Add(expression3); } } } if (expressionType == null) { return null; } if (flag) { return null; } if (newParent.Method.TargetObject is CodeTypeReferenceExpression) { @public |= BindingFlags.FlattenHierarchy | BindingFlags.Static; } else { @public |= BindingFlags.Instance; } if (validation.AllowInternalMembers(expressionType)) { @public |= BindingFlags.NonPublic; } info = validation.ResolveMethod(expressionType, newParent.Method.MethodName, @public, argumentExprs, out item); if ((info == null) && newParent.UserData.Contains("QualifiedName")) { string qualifiedName = newParent.UserData["QualifiedName"] as string; Type type2 = validation.ResolveType(qualifiedName); if (type2 != null) { validation.DetermineExtensionMethods(type2.Assembly); info = validation.ResolveMethod(expressionType, newParent.Method.MethodName, @public, argumentExprs, out item); } } if (info == null) { item.UserData["ErrorObject"] = newParent; validation.Errors.Add(item); return null; } } finally { validation.PopParentExpression(); } MethodInfo methodInfo = info.MethodInfo; if (methodInfo.ReturnType == null) { item = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.CouldNotDetermineMemberType, new object[] { newParent.Method.MethodName }), 0x194); item.UserData["ErrorObject"] = newParent; validation.Errors.Add(item); return null; } if (!validation.ValidateMemberAccess(newParent.Method.TargetObject, expressionType, methodInfo, newParent.Method.MethodName, newParent)) { return null; } object[] customAttributes = methodInfo.GetCustomAttributes(typeof(RuleAttribute), true); if ((customAttributes != null) && (customAttributes.Length > 0)) { Stack<MemberInfo> stack = new Stack<MemberInfo>(); stack.Push(methodInfo); bool flag2 = true; foreach (RuleAttribute attribute in customAttributes) { if (!attribute.Validate(validation, methodInfo, expressionType, methodInfo.GetParameters())) { flag2 = false; } } stack.Pop(); if (!flag2) { return null; } } if (methodInfo is ExtensionMethodInfo) { newParent.UserData["QualifiedName"] = methodInfo.DeclaringType.AssemblyQualifiedName; } return info; }
internal override RuleExpressionInfo Validate(CodeExpression expression, RuleValidation validation, bool isWritten) { ValidationError error; CodeObjectCreateExpression newParent = (CodeObjectCreateExpression) expression; if (isWritten) { error = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.CannotWriteToExpression, new object[] { typeof(CodeObjectCreateExpression).ToString() }), 0x17a); error.UserData["ErrorObject"] = newParent; validation.Errors.Add(error); return null; } if (newParent.CreateType == null) { error = new ValidationError(Messages.NullTypeType, 0x53d); error.UserData["ErrorObject"] = newParent; validation.Errors.Add(error); return null; } Type type = validation.ResolveType(newParent.CreateType); if (type == null) { return null; } List<CodeExpression> argumentExprs = new List<CodeExpression>(); try { if (!validation.PushParentExpression(newParent)) { return null; } bool flag = false; for (int i = 0; i < newParent.Parameters.Count; i++) { CodeExpression expression3 = newParent.Parameters[i]; if (expression3 == null) { error = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.NullConstructorParameter, new object[] { i.ToString(CultureInfo.CurrentCulture), RuleDecompiler.DecompileType(type) }), 0x53d); error.UserData["ErrorObject"] = newParent; validation.Errors.Add(error); flag = true; } else { if (RuleExpressionWalker.Validate(validation, expression3, false) == null) { flag = true; } argumentExprs.Add(expression3); } } if (flag) { return null; } } finally { validation.PopParentExpression(); } BindingFlags constructorBindingFlags = BindingFlags.Public | BindingFlags.Instance; if (validation.AllowInternalMembers(type)) { constructorBindingFlags |= BindingFlags.NonPublic; } if (type.IsValueType && (argumentExprs.Count == 0)) { return new RuleExpressionInfo(type); } if (type.IsAbstract) { error = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.UnknownConstructor, new object[] { RuleDecompiler.DecompileType(type) }), 0x137); error.UserData["ErrorObject"] = newParent; validation.Errors.Add(error); return null; } RuleConstructorExpressionInfo info2 = validation.ResolveConstructor(type, constructorBindingFlags, argumentExprs, out error); if (info2 == null) { error = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.UnknownConstructor, new object[] { RuleDecompiler.DecompileType(type) }), 0x137); error.UserData["ErrorObject"] = newParent; validation.Errors.Add(error); return null; } return info2; }