Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

Tuesday, October 8, 2013

Reflection C# .NET

Reflection:

If we are working on many project in one solution of visual studio and need to find the type of anything, e.g. Enum. We can use the following code to find from current executing assembly from current assembly references.
private static Type GetEnumTypeFromAssembly(String enumTypeName)
{
     var currentAssembly = Assembly.GetExecutingAssembly();
     Type type = null;
     foreach (var assemblyname in 
                           currentAssembly.GetReferencedAssemblies())
     {
           type = Assembly.Load(assemblyname).GetType((enumTypeName));
           if (type != null)
           {
                break;
           }
     }
     return type;
}

Friday, June 29, 2012

C# Closures Explained

closure in C# takes the form of an in-line delegate/anonymous method. A closure is attached to its parent method meaning that variables defined parents method body can be referenced within the anonymous method. 


A good article on C# Closures....


C# Closures Explained