I want to create a custom attribute that can be used on a property like:
[TrimInputString]
public string FirstName { get; set; }
that will be functional equivalent of
private string _firstName
public string FirstName {
set {
_firstName = value.Trim();
}
get {
return _firstName;
}
}
So basically every time property is set the value will be trimmed.
How do I get the value parsed, modify that value and then set the property with the new value all from within the attribute?
[AttributeUsage(AttributeTargets.Property)]
public class TrimInputAttribute : Attribute {
public TrimInputAttribute() {
//not sure how to get and modify the property here
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…