Skip to content

Instantly share code, notes, and snippets.

@hugoware
hugoware / UserControlScanner.cs
Created April 5, 2010 02:04
Scans an ASP.NET WebApplication project to find UserControls and adds them to the web.config file
/*
* Hugo Bonacci
* http://hugoware.net
*
* UserControls in Web Application projects do not appear unless
* you use the Register tag at the top of the page or add them and
* their virtual path to the web.config file.
*
* This code allows you to add the namespace of your UserControls
* to the web.config file and it will automatically scan for any
@hugoware
hugoware / ImpersonationContext.cs
Created April 6, 2010 16:59
Uses anonymous methods to wrap impersonation with .NET
using System;
using System.Runtime.InteropServices;
using System.Security.Principal;
using System.Text.RegularExpressions;
namespace Security {
/// <summary>
/// Allows you to execute code with an alternate set of credentials
/// </summary>
@hugoware
hugoware / MVC_ContentArea_ContentDisplayArea.cs
Created April 7, 2010 03:01
Uses WebControls to allow content to be written to multiple areas on the same view using ASP.NET MVC
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
namespace MvcWebControls {
/// <summary>
@hugoware
hugoware / WorkSequence.cs
Created April 20, 2010 03:29
Use lambdas to set a series of methods to perform and then rollback if an exception takes place
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
//Requires ImpersonationContext that can be found
//at http://gist.github.com/357819
using Hugoware.Security;
namespace Hugoware {
/*
* Series of extension methods to make working with
* enumerated types and bitwise operations easier.
*
* //create the typical object
* RegexOptions options = RegexOptions.None;
*
* //Assign a value
* options = options.Include(RegexOptions.IgnoreCase); //IgnoreCase
*
/// <summary>
/// Attempts to identify an anonymous value using the type name and a variety of common traits
/// (Unlikely this is the best way to determine)
/// </summary>
public static bool IsAnonymousType(object value) {
//make sure this has a value
if (value == null) { return false; }
//check if this is anonymous type using the name and
@hugoware
hugoware / Dynamic.cs
Created July 15, 2010 05:06
Semi-dynamic object for .NET code
//More information about this code
//http://somewebguy.wordpress.com/2010/07/15/almost-sorta-real-dynamic-in-net/
//
// Usage:
//
// var item = new Dynamic();
//
// Assign single values
// item.value = "something";
//
@hugoware
hugoware / Culture.cs
Created October 27, 2010 15:20
Performs work in anonymous functions under a different context before switching back
// Quickly switch to a different culture to perform work without
// switching the entire thread
// Usage:
// Console.WriteLine("Starts in English : {0}", DateTime.Now);
//
// Culture.As(Culture.Type.German, () => {
// Console.WriteLine("Now in German : {0}", DateTime.Now);
// });
//
@hugoware
hugoware / MimeTypeLocator.cs
Created May 5, 2011 18:59
Simple mime-type lookup
public class MimeTypeLocator {
#region Available Types
private static Dictionary<string, string> _MimeTypes = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase) {
{ "323", "text/h323" },
{ "acx", "application/internet-property-stream" },
{ "ai", "application/postscript" },
{ "aif", "audio/x-aiff" },
{ "aifc", "audio/x-aiff" },
@hugoware
hugoware / ProcessVS.vb
Created May 11, 2011 13:47
Attach To Process Visual Studio Macros
'requests a name and attaches to that process
Public Sub AttachToNamedProcess()
Dim process As String = InputBox("What process name", "Process Name", "w3wp.exe")
'make sure something was provided
If process Is Nothing Then process = ""
process = process.Trim()
If String.IsNullOrEmpty(process) Then Return
_AttachToProcess(process, False)
End Sub