-
Notifications
You must be signed in to change notification settings - Fork 4.5k
/
CallbackValidator.cs
39 lines (33 loc) · 1.12 KB
/
CallbackValidator.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
namespace System.Configuration
{
public sealed class CallbackValidator : ConfigurationValidatorBase
{
private readonly ValidatorCallback _callback;
private readonly Type _type;
public CallbackValidator(Type type, ValidatorCallback callback) : this(callback)
{
if (type == null) throw new ArgumentNullException(nameof(type));
_type = type;
}
// Do not check for null type here to handle the callback attribute case
internal CallbackValidator(ValidatorCallback callback)
{
if (callback is null)
{
throw new ArgumentNullException(nameof(callback));
}
_type = null;
_callback = callback;
}
public override bool CanValidate(Type type)
{
return (type == _type) || (_type == null);
}
public override void Validate(object value)
{
_callback(value);
}
}
}