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