, . , "FirstName" :
public class FirstName
{
private string _Value;
public string Value
{
get
{
return _Value;
}
set
{
if (string.IsNullOrEmpty(value))
throw new ArgumentNullException("Value cannot be null");
if (value.Length > 128)
throw new ArgumentOutOfRangeException("Value cannot be longer than 128 characters");
_Value = value;
}
}
public FirstName(string initialValue)
{
Value = initialValue;
}
}
, :
public interface IPersonInfo
{
FirstName FirstName { get; set; }
String LastName { get; set; }
}
.. .
, , :
public FirstName MyFirstName;
var x = MyFirstName.Value;
, , . - , (ints > 0) count (int >= 0), ..
Strings are more complex because they often have length restrictions in addition to value types (for example, no special characters, numbers, etc. This may be possible to accommodate using the read-only length property specified in the constructor of the inheriting class.
source
share