Skip to content

Instantly share code, notes, and snippets.

View chrishasz's full-sized avatar

Chris Hasz chrishasz

View GitHub Profile
@chrishasz
chrishasz / localStorageService.ts
Last active January 11, 2022 19:27
A type-generic class to read and write project or extension-wide data in VSCode's durable key-value storage
'use strict';
import { Memento } from "vscode";
export class LocalStorageService {
constructor(private storage: Memento) { }
public getValue<T>(key : string) : T{
return this.storage.get<T>(key, null);
@chrishasz
chrishasz / Generic Collection Accessor, with default value
Created October 1, 2013 06:22
Generic method for accessing collections, with a default value override for when Type.DefaultValue returns unsafe data. This specific implementation manages query strings.
public static T GetQueryString<T>(string key, T defaultValue) where T : IConvertible
{
T result = defaultValue;
if (!String.IsNullOrEmpty(HttpContext.Current.Request.QueryString[key]))
{
string value = HttpContext.Current.Request.QueryString[key];
try
{
@chrishasz
chrishasz / AjaxOnlyAttribute
Created September 30, 2013 17:51
ASP.NET MVC AjaxOnly Decoration for Controller Actions. Pair with ReturnPartial() for clean, request-controlled partial markup. Usage: [AjaxOnly] public ActionResult Action( ... ) { return PartialView(); }
public class AjaxOnlyAttribute : ActionMethodSelectorAttribute
{
public override Boolean IsValidForRequest(ControllerContext controllerContext, MethodInfo methodInfo)
{
return controllerContext.HttpContext.Request.IsAjaxRequest();
}
}