Skip to content

Instantly share code, notes, and snippets.

@cbskgc
Created February 16, 2014 14:47
Show Gist options
  • Save cbskgc/9035355 to your computer and use it in GitHub Desktop.
Save cbskgc/9035355 to your computer and use it in GitHub Desktop.
If you have a sealed class and would like to standardize or automate setup, one of the solutions is to create a class with an operator overload.
public class DefaultController : Controller
{
public ActionResult Index()
{
Response.Cookies.Add(new AccountIdCookie(12345));
return View();
}
}
class AccountIdCookie
{
const string Name = "acct_id";
int _accountId;
public AccountIdCookie(int accountId)
{
_accountId = accountId;
}
public static implicit operator HttpCookie(AccountIdCookie accountIdCookie)
{
return new HttpCookie(Name, accountIdCookie._accountId.ToString());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment