本文整理汇总了C#中ValidationContext类的典型用法代码示例。如果您正苦于以下问题:C# ValidationContext类的具体用法?C# ValidationContext怎么用?C# ValidationContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ValidationContext类属于命名空间,在下文中一共展示了ValidationContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Validate
public INodeVisitor Validate(ValidationContext context)
{
return new EnterLeaveListener(_ =>
{
_.Match<InlineFragment>(node =>
{
var type = context.TypeInfo.GetLastType();
if (node.Type != null && type != null && !type.IsCompositeType())
{
context.ReportError(new ValidationError(
context.OriginalQuery,
"5.4.1.3",
InlineFragmentOnNonCompositeErrorMessage(context.Print(node.Type)),
node.Type));
}
});
_.Match<FragmentDefinition>(node =>
{
var type = context.TypeInfo.GetLastType();
if (type != null && !type.IsCompositeType())
{
context.ReportError(new ValidationError(
context.OriginalQuery,
"5.4.1.3",
FragmentOnNonCompositeErrorMessage(node.Name, context.Print(node.Type)),
node.Type));
}
});
});
}
示例2: ValidateSpaceInPropertyName
private void ValidateSpaceInPropertyName(ValidationContext context)
{
if (!string.IsNullOrEmpty(Name) && Name.IndexOf(" ") > 0)
{
context.LogError("Property names cannot contain spaces", "AW001ValidateSpaceInPropertyNameError", this);
}
}
示例3: Validate
public INodeVisitor Validate(ValidationContext context)
{
return new EnterLeaveListener(_ =>
{
_.Match<Field>(f => Field(context.TypeInfo.GetLastType(), f, context));
});
}
示例4: Validate
public INodeVisitor Validate(ValidationContext context)
{
var knownFragments = new Dictionary<string, FragmentDefinition>();
return new EnterLeaveListener(_ =>
{
_.Match<FragmentDefinition>(fragmentDefinition =>
{
var fragmentName = fragmentDefinition.Name;
if (knownFragments.ContainsKey(fragmentName))
{
var error = new ValidationError(
context.OriginalQuery,
"5.4.1.1",
DuplicateFragmentNameMessage(fragmentName),
knownFragments[fragmentName],
fragmentDefinition);
context.ReportError(error);
}
else
{
knownFragments[fragmentName] = fragmentDefinition;
}
});
});
}
示例5: CanExecute
/// <summary>
/// Determines whether or not a rule should execute.
/// </summary>
/// <param name="rule">The rule</param>
/// <param name="propertyPath">Property path (eg Customer.Address.Line1)</param>
/// <param name="context">Contextual information</param>
/// <returns>Whether or not the validator can execute.</returns>
public bool CanExecute(IValidationRule rule, string propertyPath, ValidationContext context) {
if (string.IsNullOrEmpty(rule.RuleSet)) return true;
if (!string.IsNullOrEmpty(rule.RuleSet) && rulesetsToExecute.Length > 0 && rulesetsToExecute.Contains(rule.RuleSet)) return true;
if (rulesetsToExecute.Contains("*")) return true;
return false;
}
开发者ID:grammarware,项目名称:fodder,代码行数:14,代码来源:src_ServiceStack_ServiceInterface_Validation_MultiRuleSetValidatorSelector.cs
示例6: ValidateTypeNameNotEmpty
internal void ValidateTypeNameNotEmpty(ValidationContext context)
{
try
{
// Ensure not empty
if (string.IsNullOrEmpty(this.TypeName))
{
context.LogError(
string.Format(
CultureInfo.CurrentCulture,
Resources.Validate_WizardSettingsTypeIsNotEmpty,
this.Name),
Resources.Validate_WizardSettingsTypeIsNotEmptyCode, this.Extends);
}
}
catch (Exception ex)
{
tracer.Error(
ex,
Resources.ValidationMethodFailed_Error,
Reflector<WizardSettings>.GetMethod(n => n.ValidateTypeNameNotEmpty(context)).Name);
throw;
}
}
示例7: Validate
public override IEnumerable<ModelValidationResult> Validate(object container) {
if (Metadata.Model != null) {
var selector = customizations.ToValidatorSelector();
var interceptor = customizations.GetInterceptor() ?? (validator as IValidatorInterceptor);
var context = new ValidationContext(Metadata.Model, new PropertyChain(), selector);
if(interceptor != null) {
// Allow the user to provide a customized context
// However, if they return null then just use the original context.
context = interceptor.BeforeMvcValidation(ControllerContext, context) ?? context;
}
var result = validator.Validate(context);
if(interceptor != null) {
// allow the user to provice a custom collection of failures, which could be empty.
// However, if they return null then use the original collection of failures.
result = interceptor.AfterMvcValidation(ControllerContext, context, result) ?? result;
}
if (!result.IsValid) {
return ConvertValidationResultToModelValidationResults(result);
}
}
return Enumerable.Empty<ModelValidationResult>();
}
示例8: ValidateClassNames
public void ValidateClassNames(ValidationContext context, IClass cls)
{
// Property and Role names must be unique within a class hierarchy.
List<string> foundNames = new List<string>();
List<IProperty> allPropertiesInHierarchy = new List<IProperty>();
List<IProperty> superRoles = new List<IProperty>();
FindAllAssocsInSuperClasses(superRoles, cls.SuperClasses);
foreach (IProperty p in cls.GetOutgoingAssociationEnds()) { superRoles.Add(p); }
foreach (IProperty p in superRoles) { allPropertiesInHierarchy.Add(p); }
foreach (IProperty p in cls.Members) { allPropertiesInHierarchy.Add(p); }
foreach (IProperty attribute in allPropertiesInHierarchy)
{
string name = attribute.Name;
if (!string.IsNullOrEmpty(name) && foundNames.Contains(name))
{
context.LogError(
string.Format("Duplicate property or role name '{0}' in class '{1}'", name, cls.Name),
"001", cls);
}
foundNames.Add(name);
}
}
示例9: Validate
public override IEnumerable<ModelValidationResult> Validate(object container)
{
// NOTE: Container is never used here, because IValidatableObject doesn't give you
// any way to get access to your container.
object model = Metadata.ModelValue;
if (model == null)
{
return Enumerable.Empty<ModelValidationResult>();
}
var validatable = model as IValidatableObject;
if (validatable == null)
{
throw new InvalidOperationException(
String.Format(
CultureInfo.CurrentCulture,
"ValidatableObjectAdapter_IncompatibleType {0} {1}",
typeof(IValidatableObject).FullName,
model.GetType().FullName
)
);
}
var validationContext = new ValidationContext(validatable, null, null);
return ConvertResults(validatable.Validate(validationContext));
}
示例10: ValidateCustomizedSettingsOverriddenByCustomizableState
internal void ValidateCustomizedSettingsOverriddenByCustomizableState(ValidationContext context)
{
try
{
if (this.IsCustomizationEnabled)
{
if ((this.IsCustomizable == CustomizationState.False)
&& (this.Policy.IsModified == true))
{
context.LogWarning(
string.Format(CultureInfo.CurrentCulture, Properties.Resources.Validate_CustomizedSettingsOverriddenByCustomizableState, this.Name),
Properties.Resources.Validate_CustomizedSettingsOverriddenByCustomizableStateCode, this);
}
}
}
catch (Exception ex)
{
tracer.Error(
ex,
Resources.ValidationMethodFailed_Error,
Reflector<CustomizableElementSchemaBase>.GetMethod(n => n.ValidateCustomizedSettingsOverriddenByCustomizableState(context)).Name);
throw;
}
}
示例11: ValidateNameIsUnique
internal void ValidateNameIsUnique(ValidationContext context)
{
try
{
IEnumerable<AutomationSettingsSchema> sameNamedElements = this.Owner.AutomationSettings
.Where(setting => setting.Name.Equals(this.Name, System.StringComparison.OrdinalIgnoreCase));
if (sameNamedElements.Count() > 1)
{
// Check if one of the properties is a system property
if (sameNamedElements.FirstOrDefault(property => property.IsSystem == true) != null)
{
context.LogError(
string.Format(CultureInfo.CurrentCulture, Properties.Resources.Validate_AutomationSettingsNameSameAsSystem, this.Name),
Properties.Resources.Validate_AutomationSettingsNameSameAsSystemCode, this);
}
else
{
context.LogError(
string.Format(CultureInfo.CurrentCulture, Properties.Resources.Validate_AutomationSettingsNameIsNotUnique, this.Name),
Properties.Resources.Validate_AutomationSettingsNameIsNotUniqueCode, this);
}
}
}
catch (Exception ex)
{
tracer.Error(
ex,
Resources.ValidationMethodFailed_Error,
Reflector<AutomationSettingsSchema>.GetMethod(n => n.ValidateNameIsUnique(context)).Name);
throw;
}
}
示例12: Validate
public INodeVisitor Validate(ValidationContext context)
{
var frequency = new Dictionary<string, string>();
return new EnterLeaveListener(_ =>
{
_.Match<Operation>(
enter: op =>
{
if (context.Document.Operations.Count < 2)
{
return;
}
if (string.IsNullOrWhiteSpace(op.Name))
{
return;
}
if (frequency.ContainsKey(op.Name))
{
var error = new ValidationError(
context.OriginalQuery,
"5.1.1.1",
DuplicateOperationNameMessage(op.Name),
op);
context.ReportError(error);
}
else
{
frequency[op.Name] = op.Name;
}
});
});
}
示例13: Validate
public INodeVisitor Validate(ValidationContext context)
{
var variableDefs = new List<VariableDefinition>();
return new EnterLeaveListener(_ =>
{
_.Match<VariableDefinition>(def => variableDefs.Add(def));
_.Match<Operation>(
enter: op => variableDefs = new List<VariableDefinition>(),
leave: op =>
{
var usages = context.GetRecursiveVariables(op).Select(usage => usage.Node.Name);
variableDefs.Apply(variableDef =>
{
var variableName = variableDef.Name;
if (!usages.Contains(variableName))
{
var error = new ValidationError(context.OriginalQuery, "5.7.5", UnusedVariableMessage(variableName, op.Name), variableDef);
context.ReportError(error);
}
});
});
});
}
示例14: Validate
public bool Validate(object model, Type type, ModelMetadataProvider metadataProvider, HttpActionContext actionContext, string keyPrefix) {
if (type == null) {
throw new ArgumentNullException("type");
}
if (metadataProvider == null) {
throw new ArgumentNullException("metadataProvider");
}
if (actionContext == null) {
throw new ArgumentNullException("actionContext");
}
if (model != null && MediaTypeFormatterCollection.IsTypeExcludedFromValidation(model.GetType())) {
// no validation for some DOM like types
return true;
}
ModelValidatorProvider[] validatorProviders = actionContext.GetValidatorProviders().ToArray();
// Optimization : avoid validating the object graph if there are no validator providers
if (validatorProviders == null || validatorProviders.Length == 0) {
return true;
}
ModelMetadata metadata = metadataProvider.GetMetadataForType(() => model, type);
ValidationContext validationContext = new ValidationContext {
MetadataProvider = metadataProvider,
ActionContext = actionContext,
ModelState = actionContext.ModelState,
Visited = new HashSet<object>(),
KeyBuilders = new Stack<IKeyBuilder>(),
RootPrefix = keyPrefix
};
return this.ValidateNodeAndChildren(metadata, validationContext, container: null);
}
示例15: PropertyValidatorContext
public PropertyValidatorContext(ValidationContext parentContext, PropertyRule rule, string propertyName, object propertyValue)
{
ParentContext = parentContext;
Rule = rule;
PropertyName = propertyName;
propertyValueContainer = new Lazy<object>(() => propertyValue);
}