'C#' Tag

  • Redirecting using strong types in an asp.net web application project

    January 13, 2010

    It recently began to annoy me that every time I want to redirect to a page I have to use a string. Not a big deal I know but when you have broken links it can reflect badly on you as a developer, so I began to look for some solution that would allow for [...]

  • How to Mock the HttpContext in asp.net

    October 13, 2009

    I find mocking the http context rather difficult, you can’t inherit from it and making a wrapper class is a lot of work. Thankfully someone came up with a solution, unfortunately the link they included with the code is dead and I can’t seem to remember where I got the code, if anyone finds out [...]

  • Call MethodInfo.Invoke with an out parameter

    August 21, 2009

    Taken from http://www.galcho.com/Blog/P…
    Here is how to call a method with an out parameter using MethodInfo.Invoke, in this case the out parameter is the last one (int).
    int parNum = 0;
    string parText = “99″;
    object[] methodParms = new object[] { parText, parNum };
    MethodInfo methInfo = parNum.GetType().GetMethod(“TryParse”, new Type[] { typeof(string), typeof(int).MakeByRefType() });
    methInfo.Invoke(null, methodParms);
    parNum = (int)methodParms[1];
    Console.WriteLine(“Parsed number:{0}”, parNum);

  • ResolveUrl in your Business Logic

    March 15, 2009

    I’ve recently started moving a large amount of code on the project I’m working on from the presentation layer into a business logic layer. One of the problems I found was trying to link to other pages on the site without know where the application would be located or if it would be http or [...]

  • Generic Method Overloading in C#

    February 17, 2009

    Say you have an outer method:
    public OuterMethod(object x)
    {
    InnerMethod(x);
    }
    and an inner method with these overloads

    public InnerMethod(object x)
    {
    //Generic Actions
    }
    public InnerMethod(Person x)
    {
    //Person Specific Actions
    }
    public InnerMethod(Dog x)
    {
    // Dog Specific Actions
    }

    How do you make it so that when the outer method calls the inner method it completes the specific actions as well as the generic ones that allows you to [...]

 
Powered by Wordpress and MySQL. Theme by Shlomi Noach, openark.org