本文整理匯總了C#中System.Workflow.Activities.Rules.RuleValidation.ResolveType方法的典型用法代碼示例。如果您正苦於以下問題:C# RuleValidation.ResolveType方法的具體用法?C# RuleValidation.ResolveType怎麽用?C# RuleValidation.ResolveType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Workflow.Activities.Rules.RuleValidation
的用法示例。
在下文中一共展示了RuleValidation.ResolveType方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Validate
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);
//.........這裏部分代碼省略.........
示例2: Validate
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))
{
//.........這裏部分代碼省略.........
示例3: Validate
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));
}
示例4: Validate
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;
}
示例5: Validate
//.........這裏部分代碼省略.........
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;
}
示例6: Validate
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;
}