0

Is it possible to use an attribute to modify a model value?

eg.

[TrimInput]
public string SomeName {get;set;}

public string TrimInputAttribute : Attribute
{
    /// do something here?
}
3

1 Answer 1

1

Yes, it is - but you need something to EXECUTE it. Attributes never execute any code.

What you can do is having a "ModelFixer" class that has a method that you call - and that is evaluationg the attributes and doing the operations.

All other attributes work like that - there is always a component USING the attribute (which sometimes is the runtime or the compiler).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.