Skip to content

Instantly share code, notes, and snippets.


mrvux/Domain Snippet

Created Mar 18, 2015
What would you like to do?
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="">
<CodeSnippet Format="1.0.0">
<Author>Julien Vulliet (</Author>
<Description>Snippet to create a simple domain primitive</Description>
<Title>Domain Primitive</Title>
<ToolTip>Class Name</ToolTip>
<ToolTip>Primitive Type</ToolTip>
<Code Language="csharp">
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();

This comment has been minimized.

Copy link

@JulianMay JulianMay commented Sep 20, 2017


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment