It would be interesting to create an attribute that allows doing:
[Riverside.CompilerPlatform.Features.Hooks.Validation.ValidationHookAttribute((instance) => { instance != string.Empty })]
public string Example; // this string may not be set to empty, otherwise an ArgumentException will be thrown
ValidationHookAttribute's constructor may require an interface that shows the generator what to do to validate the object.
For example, in the above example, the ValidationHookAttribute's constructor is being invoked with the Func<[string ?? object], bool> overload that allows evaluating a boolean expression to validate.
If the generated set method is called with a reference to an object of value string.Empty, ArgumentException will be thrown.
The exception to be used should default to ArgumentException, but can be customised like so:
[ValidationHook<NullReferenceException>((instance) => { instance != null })]
public string Example;
It would be interesting to create an attribute that allows doing:
ValidationHookAttribute's constructor may require an interface that shows the generator what to do to validate the object.For example, in the above example, the
ValidationHookAttribute's constructor is being invoked with theFunc<[string ?? object], bool>overload that allows evaluating a boolean expression to validate.If the generated
setmethod is called with a reference to an object of valuestring.Empty,ArgumentExceptionwill be thrown.The exception to be used should default to
ArgumentException, but can be customised like so: