本文整理汇总了C#中IValidator.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# IValidator.GetType方法的具体用法?C# IValidator.GetType怎么用?C# IValidator.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IValidator
的用法示例。
在下文中一共展示了IValidator.GetType方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoEmit
/// <summary>
/// Emit implementation starting point
/// </summary>
/// <param name="v">The v.</param>
/// <param name="sb">The sb.</param>
/// <returns></returns>
protected StringBuilder DoEmit(IValidator v, StringBuilder sb)
{
if (v.GetType().IsGenericType && typeof(ValidationSite<,>).IsAssignableFrom(v.GetType().GetGenericTypeDefinition()))
return EmitSites(v, sb);
else
return EmitNamespace(v, sb);
}
示例2: GenerateForValidator
void GenerateForValidator(IValidator inputValidator, TypeMetaData metaData, string parentKey, bool isParentConcept = false, bool isParentModelRule = false)
{
var inputValidatorType = inputValidator.GetType();
var genericArguments = inputValidatorType.BaseType.GetGenericArguments();
var descriptor = inputValidator.CreateDescriptor();
var members = descriptor.GetMembersWithValidators();
foreach (var member in members)
{
var rules = descriptor.GetRulesForMember(member.Key);
foreach (var rule in rules)
{
foreach (var validator in rule.Validators)
{
var isModelRule = member.Key == ModelRule<string>.ModelRulePropertyName;
var currentKey = GetKeyForMember(parentKey, isParentConcept, isParentModelRule, member, isModelRule);
if (validator is ChildValidatorAdaptor)
{
GenerateForChildValidator(metaData, genericArguments, member, validator, isModelRule, currentKey);
}
else if (validator is IPropertyValidator)
{
GenerateFor(metaData, currentKey, validator);
}
}
}
}
}
示例3: GetValue
void GetValue(IValidator inputValidator, ValidationMetaData metaData, string parentKey, bool isParentConcept = false, bool isParentModelRule = false)
{
var inputValidatorType = inputValidator.GetType();
#if(NETFX_CORE)
var genericArguments = inputValidatorType.GetTypeInfo().BaseType.GenericTypeArguments;
#else
var genericArguments = inputValidatorType.BaseType.GetGenericArguments();
#endif
var descriptor = inputValidator.CreateDescriptor();
var members = descriptor.GetMembersWithValidators();
foreach (var member in members)
{
var rules = descriptor.GetRulesForMember(member.Key);
foreach (var rule in rules)
{
foreach (var validator in rule.Validators)
{
var isModelRule = member.Key == ModelRule<string>.ModelRulePropertyName;
var currentKey = string.Empty;
if (isParentConcept || isParentModelRule || isModelRule)
currentKey = parentKey;
else
currentKey = string.IsNullOrEmpty(parentKey) ? member.Key : string.Format("{0}.{1}", parentKey, member.Key.ToCamelCase());
if (validator is ChildValidatorAdaptor)
{
var isConcept = false;
if (genericArguments.Length == 1)
{
var type = isModelRule ? genericArguments[0] : GetPropertyInfo(genericArguments[0], member.Key).PropertyType;
isConcept = type.IsConcept();
}
var childValidator = (validator as ChildValidatorAdaptor).Validator;
GetValue(childValidator, metaData, currentKey, isConcept, isModelRule);
}
else if (validator is IPropertyValidator)
{
GenerateFor(metaData, currentKey, validator as IPropertyValidator);
}
}
}
}
}
示例4: GenerateForValidator
void GenerateForValidator(
IValidator inputValidator,
TypeMetaData metaData,
string parentKey,
bool shouldUseParentKey = false)
{
var inputValidatorType = inputValidator.GetType();
var genericArguments = inputValidatorType.BaseType.GetGenericArguments();
var descriptor = inputValidator.CreateDescriptor();
var members = descriptor.GetMembersWithValidators();
foreach (var member in members)
{
var isModelRule = member.Key == ModelRule<string>.ModelRulePropertyName || member.Key == string.Empty;
var currentKey = (shouldUseParentKey || isModelRule) ? parentKey : GetKeyForMember(parentKey, member);
var isConcept = new Lazy<bool>(() => IsConcept(genericArguments, isModelRule, member));
foreach (var rule in descriptor.GetRulesForMember(member.Key))
{
foreach (var validator in rule.Validators)
{
var childValidatorAdaptor = validator as ChildValidatorAdaptor;
if (childValidatorAdaptor != null)
{
var childValidator = childValidatorAdaptor.GetValidator(NullContext);
GenerateForValidator(childValidator, metaData, currentKey, isModelRule || isConcept.Value);
}
else
{
GenerateFor(metaData, currentKey, validator);
}
}
}
}
}
示例5: GetValidator
/// <summary>
/// Gets the validator. If the field is <c>null</c>, it will query the service locator.
/// </summary>
/// <returns>IValidator.</returns>
private IValidator GetValidator()
{
if (_validator == null)
{
if (!_hasRetrievedValidatorOnce)
{
var dependencyResolver = this.GetDependencyResolver();
var validatorProvider = dependencyResolver.TryResolve<IValidatorProvider>();
if (validatorProvider != null)
{
_validator = validatorProvider.GetValidator(GetType());
if (_validator != null)
{
Log.Debug("Found validator '{0}' for view model '{1}' via the registered IValidatorProvider", _validator.GetType().FullName, GetType().FullName);
}
}
_hasRetrievedValidatorOnce = true;
}
}
return _validator;
}
示例6: AddValidation
/// <summary>
/// Adds a new validation.
/// </summary>
/// <param name="source">The source that will provide the value to be validated.</param>
/// <param name="validator">The <see cref="IValidator"/> that will validate the value.</param>
/// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="validator"/> is null.</exception>
public void AddValidation(string source, IValidator validator)
{
if (string.IsNullOrEmpty(source))
throw new ArgumentNullException("source");
if ((object)validator == null)
throw new ArgumentNullException("validator");
m_validations.Add(string.Format("{0}+{1}", source, validator.GetType().Name), validator);
}
示例7: ChildCollectionValidatorAdaptor
public ChildCollectionValidatorAdaptor(IValidator childValidator)
{
this.childValidatorProvider = (_) => childValidator;
this.childValidatorType = childValidator.GetType();
}
示例8: GetSimpleTypeName
/// <summary>
/// Gets the simple name of the type.
/// </summary>
/// <param name="child">The child.</param>
/// <returns></returns>
private string GetSimpleTypeName(IValidator child)
{
var name = child.GetType().FullName;
var ind = name.IndexOf('`');
if (ind > -1)
return name.Substring(0, ind);
return name;
}