Skip to content

Latest commit

 

History

History
31 lines (23 loc) · 709 Bytes

create-model-for-primitive-types.md

File metadata and controls

31 lines (23 loc) · 709 Bytes

Models for Primitive Types

  • Value property to return the primitive value
  • Overrided ToString for easy logging
  • Implicit conversion, so that the type can be used as if it's a primitive type
public class StringValue
{
    public string Value { get; }

    public StringValue(string value)
    {
        Value = value;
    }

    public override string ToString()
    {
        return Value;
    }

    public static implicit operator string(StringValue valueType) => valueType.Value;
}

public class Email : StringValue
{
    public Email(string value) : base(value) { }
}