Created
March 18, 2015 13:40
-
-
Save mrvux/fd4d8db7e950727afa46 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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
Neat!