How to get and modify a property value through a custom Attribute?

后端 未结 4 1605
遇见更好的自我
遇见更好的自我 2020-12-06 10:18

I want to create a custom attribute that can be used on a property like:

[TrimInputString]
public string FirstName { get; set; }

that will

4条回答
  •  眼角桃花
    2020-12-06 10:36

    This can be done with Dado.ComponentModel.Mutations.

    public class User
    {
        [Trim]
        public string FirstName { get; set; }
    }
    
    // Then to preform mutation
    var user = new User() {
        FirstName = " David Glenn   "
    }
    
    new MutationContext(user).Mutate();
    

    You can see more documentation here.

提交回复
热议问题