本文整理匯總了C#中System.Workflow.Activities.Rules.RuleValidation.IsAuthorized方法的典型用法代碼示例。如果您正苦於以下問題:C# RuleValidation.IsAuthorized方法的具體用法?C# RuleValidation.IsAuthorized怎麽用?C# RuleValidation.IsAuthorized使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Workflow.Activities.Rules.RuleValidation
的用法示例。
在下文中一共展示了RuleValidation.IsAuthorized方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Validate
internal override RuleExpressionInfo Validate(CodeExpression expression, RuleValidation validation, bool isWritten)
{
CodeFieldReferenceExpression newParent = (CodeFieldReferenceExpression) expression;
if (newParent.TargetObject == null)
{
ValidationError item = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.NullFieldTarget, new object[] { newParent.FieldName }), 0x53d);
item.UserData["ErrorObject"] = newParent;
validation.Errors.Add(item);
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.NullFieldTarget, new object[] { newParent.FieldName }), 0x546);
error2.UserData["ErrorObject"] = newParent;
validation.Errors.Add(error2);
return null;
}
BindingFlags @public = BindingFlags.Public;
if (newParent.TargetObject is CodeTypeReferenceExpression)
{
@public |= BindingFlags.FlattenHierarchy | BindingFlags.Static;
}
else
{
@public |= BindingFlags.Instance;
}
if (validation.AllowInternalMembers(expressionType))
{
@public |= BindingFlags.NonPublic;
}
FieldInfo field = expressionType.GetField(newParent.FieldName, @public);
if (field == null)
{
ValidationError error3 = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.UnknownField, new object[] { newParent.FieldName, RuleDecompiler.DecompileType(expressionType) }), 0x54a);
error3.UserData["ErrorObject"] = newParent;
validation.Errors.Add(error3);
return null;
}
if (field.FieldType == null)
{
ValidationError error4 = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.CouldNotDetermineMemberType, new object[] { newParent.FieldName }), 0x194);
error4.UserData["ErrorObject"] = newParent;
validation.Errors.Add(error4);
return null;
}
if (isWritten && field.IsLiteral)
{
ValidationError error5 = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.FieldSetNotAllowed, new object[] { newParent.FieldName, RuleDecompiler.DecompileType(expressionType) }), 0x17a);
error5.UserData["ErrorObject"] = newParent;
validation.Errors.Add(error5);
return null;
}
if (!validation.ValidateMemberAccess(newParent.TargetObject, expressionType, field, field.Name, newParent))
{
return null;
}
validation.IsAuthorized(field.FieldType);
return new RuleFieldExpressionInfo(field);
}
示例2: Validate
internal override RuleExpressionInfo Validate(CodeExpression expression, RuleValidation validation, bool isWritten)
{
string message;
CodeFieldReferenceExpression fieldRefExpr = (CodeFieldReferenceExpression)expression;
if (fieldRefExpr.TargetObject == null)
{
message = string.Format(CultureInfo.CurrentCulture, Messages.NullFieldTarget, fieldRefExpr.FieldName);
ValidationError error = new ValidationError(message, ErrorNumbers.Error_ParameterNotSet);
error.UserData[RuleUserDataKeys.ErrorObject] = fieldRefExpr;
validation.Errors.Add(error);
return null;
}
// Early exit from this if a cycle is detected.
if (!validation.PushParentExpression(fieldRefExpr))
return null;
RuleExpressionInfo targetExprInfo = RuleExpressionWalker.Validate(validation, fieldRefExpr.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.NullFieldTarget, fieldRefExpr.FieldName);
ValidationError error = new ValidationError(message, ErrorNumbers.Error_BindingTypeMissing);
error.UserData[RuleUserDataKeys.ErrorObject] = fieldRefExpr;
validation.Errors.Add(error);
return null;
}
BindingFlags bindingFlags = BindingFlags.Public;
if (fieldRefExpr.TargetObject is CodeTypeReferenceExpression)
bindingFlags |= BindingFlags.Static | BindingFlags.FlattenHierarchy;
else
bindingFlags |= BindingFlags.Instance;
if (validation.AllowInternalMembers(targetType))
bindingFlags |= BindingFlags.NonPublic;
FieldInfo fi = targetType.GetField(fieldRefExpr.FieldName, bindingFlags);
if (fi == null)
{
message = string.Format(CultureInfo.CurrentCulture, Messages.UnknownField, fieldRefExpr.FieldName, RuleDecompiler.DecompileType(targetType));
ValidationError error = new ValidationError(message, ErrorNumbers.Error_CannotResolveMember);
error.UserData[RuleUserDataKeys.ErrorObject] = fieldRefExpr;
validation.Errors.Add(error);
return null;
}
if (fi.FieldType == null)
{
// This can only happen with a design-time type.
message = string.Format(CultureInfo.CurrentCulture, Messages.CouldNotDetermineMemberType, fieldRefExpr.FieldName);
ValidationError error = new ValidationError(message, ErrorNumbers.Error_CouldNotDetermineMemberType);
error.UserData[RuleUserDataKeys.ErrorObject] = fieldRefExpr;
validation.Errors.Add(error);
return null;
}
if (isWritten && fi.IsLiteral)
{
message = string.Format(CultureInfo.CurrentCulture, Messages.FieldSetNotAllowed, fieldRefExpr.FieldName, RuleDecompiler.DecompileType(targetType));
ValidationError error = new ValidationError(message, ErrorNumbers.Error_InvalidAssignTarget);
error.UserData[RuleUserDataKeys.ErrorObject] = fieldRefExpr;
validation.Errors.Add(error);
return null;
}
if (!validation.ValidateMemberAccess(fieldRefExpr.TargetObject, targetType, fi, fi.Name, fieldRefExpr))
return null;
// Is it possible to set fi by validation.ResolveFieldOrProperty(targetType, fieldExpr.FieldName)?
validation.IsAuthorized(fi.FieldType);
return new RuleFieldExpressionInfo(fi);
}