本文整理匯總了C#中System.Workflow.Activities.Rules.RuleValidation.ResolveProperty方法的典型用法代碼示例。如果您正苦於以下問題:C# RuleValidation.ResolveProperty方法的具體用法?C# RuleValidation.ResolveProperty怎麽用?C# RuleValidation.ResolveProperty使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Workflow.Activities.Rules.RuleValidation
的用法示例。
在下文中一共展示了RuleValidation.ResolveProperty方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Validate
internal override RuleExpressionInfo Validate(CodeExpression expression, RuleValidation validation, bool isWritten)
{
CodePropertyReferenceExpression newParent = (CodePropertyReferenceExpression) expression;
if (newParent.TargetObject == null)
{
ValidationError error = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.NullPropertyTarget, new object[] { newParent.PropertyName }), 0x53d);
error.UserData["ErrorObject"] = newParent;
validation.Errors.Add(error);
return null;
}
if (!validation.PushParentExpression(newParent))
{
return null;
}
RuleExpressionInfo info = RuleExpressionWalker.Validate(validation, newParent.TargetObject, false);
validation.PopParentExpression();
if (info == null)
{
return null;
}
Type expressionType = info.ExpressionType;
if (expressionType == null)
{
return null;
}
if (expressionType == typeof(NullLiteral))
{
ValidationError error2 = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.NullPropertyTarget, new object[] { newParent.PropertyName }), 0x546);
error2.UserData["ErrorObject"] = newParent;
validation.Errors.Add(error2);
return null;
}
bool nonPublic = false;
BindingFlags bindingFlags = BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance;
if (validation.AllowInternalMembers(expressionType))
{
bindingFlags |= BindingFlags.NonPublic;
nonPublic = true;
}
PropertyInfo item = validation.ResolveProperty(expressionType, newParent.PropertyName, bindingFlags);
if (item == null)
{
ValidationError error3 = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.UnknownProperty, new object[] { newParent.PropertyName, RuleDecompiler.DecompileType(expressionType) }), 0x54a);
error3.UserData["ErrorObject"] = newParent;
validation.Errors.Add(error3);
return null;
}
if (item.PropertyType == null)
{
ValidationError error4 = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.CouldNotDetermineMemberType, new object[] { newParent.PropertyName }), 0x194);
error4.UserData["ErrorObject"] = newParent;
validation.Errors.Add(error4);
return null;
}
MethodInfo accessorMethod = isWritten ? item.GetSetMethod(nonPublic) : item.GetGetMethod(nonPublic);
if (accessorMethod == null)
{
string format = isWritten ? Messages.UnknownPropertySet : Messages.UnknownPropertyGet;
ValidationError error5 = new ValidationError(string.Format(CultureInfo.CurrentCulture, format, new object[] { newParent.PropertyName, RuleDecompiler.DecompileType(expressionType) }), 0x54a);
error5.UserData["ErrorObject"] = newParent;
validation.Errors.Add(error5);
return null;
}
if (!validation.ValidateMemberAccess(newParent.TargetObject, expressionType, accessorMethod, newParent.PropertyName, newParent))
{
return null;
}
object[] customAttributes = item.GetCustomAttributes(typeof(RuleAttribute), true);
if ((customAttributes != null) && (customAttributes.Length > 0))
{
Stack<MemberInfo> stack = new Stack<MemberInfo>();
stack.Push(item);
bool flag2 = true;
foreach (RuleAttribute attribute in customAttributes)
{
if (!attribute.Validate(validation, item, expressionType, null))
{
flag2 = false;
}
}
stack.Pop();
if (!flag2)
{
return null;
}
}
return new RulePropertyExpressionInfo(item, item.PropertyType, false);
}
開發者ID:pritesh-mandowara-sp,項目名稱:DecompliedDotNetLibraries,代碼行數:88,代碼來源:PropertyReferenceExpression.cs
示例2: Validate
internal override RuleExpressionInfo Validate(CodeExpression expression, RuleValidation validation, bool isWritten)
{
string message;
CodePropertyReferenceExpression propGetExpr = (CodePropertyReferenceExpression)expression;
if (propGetExpr.TargetObject == null)
{
message = string.Format(CultureInfo.CurrentCulture, Messages.NullPropertyTarget, propGetExpr.PropertyName);
ValidationError error = new ValidationError(message, ErrorNumbers.Error_ParameterNotSet);
error.UserData[RuleUserDataKeys.ErrorObject] = propGetExpr;
validation.Errors.Add(error);
return null;
}
// Early exit from this if a cycle is detected.
if (!validation.PushParentExpression(propGetExpr))
return null;
RuleExpressionInfo targetExprInfo = RuleExpressionWalker.Validate(validation, propGetExpr.TargetObject, false);
validation.PopParentExpression();
if (targetExprInfo == null) // error occurred, so simply return
return null;
Type targetType = targetExprInfo.ExpressionType;
if (targetType == null) // no type, so must have been an error already
return null;
if (targetType == typeof(NullLiteral))
{
message = string.Format(CultureInfo.CurrentCulture, Messages.NullPropertyTarget, propGetExpr.PropertyName);
ValidationError error = new ValidationError(message, ErrorNumbers.Error_BindingTypeMissing);
error.UserData[RuleUserDataKeys.ErrorObject] = propGetExpr;
validation.Errors.Add(error);
return null;
}
bool includeNonPublic = false;
BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy;
if (validation.AllowInternalMembers(targetType))
{
bindingFlags |= BindingFlags.NonPublic;
includeNonPublic = true;
}
PropertyInfo pi = validation.ResolveProperty(targetType, propGetExpr.PropertyName, bindingFlags);
if (pi == null)
{
message = string.Format(CultureInfo.CurrentCulture, Messages.UnknownProperty, propGetExpr.PropertyName, RuleDecompiler.DecompileType(targetType));
ValidationError error = new ValidationError(message, ErrorNumbers.Error_CannotResolveMember);
error.UserData[RuleUserDataKeys.ErrorObject] = propGetExpr;
validation.Errors.Add(error);
return null;
}
if (pi.PropertyType == null)
{
// This can only happen with a design-time type.
message = string.Format(CultureInfo.CurrentCulture, Messages.CouldNotDetermineMemberType, propGetExpr.PropertyName);
ValidationError error = new ValidationError(message, ErrorNumbers.Error_CouldNotDetermineMemberType);
error.UserData[RuleUserDataKeys.ErrorObject] = propGetExpr;
validation.Errors.Add(error);
return null;
}
MethodInfo accessorMethod = isWritten ? pi.GetSetMethod(includeNonPublic) : pi.GetGetMethod(includeNonPublic);
if (accessorMethod == null)
{
string baseMessage = isWritten ? Messages.UnknownPropertySet : Messages.UnknownPropertyGet;
message = string.Format(CultureInfo.CurrentCulture, baseMessage, propGetExpr.PropertyName, RuleDecompiler.DecompileType(targetType));
ValidationError error = new ValidationError(message, ErrorNumbers.Error_CannotResolveMember);
error.UserData[RuleUserDataKeys.ErrorObject] = propGetExpr;
validation.Errors.Add(error);
return null;
}
if (!validation.ValidateMemberAccess(propGetExpr.TargetObject, targetType, accessorMethod, propGetExpr.PropertyName, propGetExpr))
return null;
// Validate any RuleAttributes, if present.
object[] attrs = pi.GetCustomAttributes(typeof(RuleAttribute), true);
if (attrs != null && attrs.Length > 0)
{
Stack<MemberInfo> methodStack = new Stack<MemberInfo>();
methodStack.Push(pi);
bool allAttributesValid = true;
foreach (RuleAttribute ruleAttr in attrs)
{
if (!ruleAttr.Validate(validation, pi, targetType, null))
allAttributesValid = false;
}
methodStack.Pop();
if (!allAttributesValid)
return null;
}
//.........這裏部分代碼省略.........