<?xml version="1.0" encoding="utf-8" ?> | |
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet"> | |
<CodeSnippet Format="1.0.0"> | |
<Header> | |
<Author>Julien Vulliet (julien@mrvux.com)</Author> | |
<Description>Snippet to create a simple domain primitive</Description> | |
<Title>Domain Primitive</Title> | |
<Shortcut>domainPrimitiveClass</Shortcut> | |
<SnippetTypes> | |
<SnippetType>Expansion</SnippetType> | |
</SnippetTypes> | |
</Header> | |
<Snippet> | |
<Declarations> | |
<Literal> | |
<ID>classname</ID> | |
<ToolTip>Class Name</ToolTip> | |
<Default>Tuple</Default> | |
</Literal> | |
<Literal> | |
<ID>primitive</ID> | |
<ToolTip>Primitive Type</ToolTip> | |
<Default>int</Default> | |
</Literal> | |
</Declarations> | |
<Code Language="csharp"> | |
<![CDATA[ | |
public class $classname$ | |
{ | |
private readonly $primitive$ value; | |
public $classname$($primitive$ value) | |
{ | |
if (!IsValid(value)) | |
throw new ArgumentException("value", "Put exception message here"); | |
this.value = value; | |
} | |
public static bool IsValid($primitive$ candidate) | |
{ | |
//Add your validation logic here | |
} | |
public static implicit operator $primitive$($classname$ value) | |
{ | |
return value.value; | |
} | |
public override string ToString() | |
{ | |
return this.value.ToString(); | |
} | |
public override bool Equals(object obj) | |
{ | |
var other = obj as $classname$; | |
if (other == null) | |
return base.Equals(obj); | |
return object.Equals(this.value, other.value); | |
} | |
/// <see cref="System.Object.GetHashCode"/> | |
public override int GetHashCode() | |
{ | |
return this.value.GetHashCode(); | |
} | |
]]> | |
} | |
</Code> | |
</Snippet> | |
</CodeSnippet> | |
</CodeSnippets> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
Neat!