Skip to content

Feature: Add APIs for implicit validation or 'hooks' #12

@Lamparter

Description

@Lamparter

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;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions