• Code
  • Tags
  • Users
  • Titles
  • Log in
  • Feedback
  • FAQ
Share Code
Welcome to ForkCan.com

ForkCan is all about sharing code in a social way.

Discuss, debate or argue with other devs about their or your own code.

Give other devs feedback or make a Fork (Make a better version of a shared code).

Rate the code, if you use the code mark it as used so others can see if the shared code is used by someone.

Help each other to be better devs and to be more productive.


Features not working yet:

Flag a post


QR Code

Tiny Url

http://4kcan.com/s/MjM4

Related Code
Generic Entity Framework 4.0 Base Repository
ForEach Extension method for IEnumerable<T>
Invoke Extension Method
Use of Extension methods to hide "infrastructure code"
Unity Service Locator for ASP.NET MVC 3.0 Beta 1
Null Dot "Operator" Extension Method
Generic Entity Framework 4.0 Base Repository with Paging
Generic linq-to-sql repository
WCF RIA Services Unity 2.0 DomainService Factory
A Default Entity Framework 4.0 ObjectContext Factory
UnitOfWork Action filter for ASP.NET MVC and nHibernate
Make sure the web.config pages/namespace can be used together with ASP.NET MVC 3 P1 and Razor
Email validation with Regular Expression
Reflection dynamically get private fields or properties
Custom C# exception class
Url Validation with Regular Expression
Method to hash passwords

Number of sealed / unsealed types in the framework

A Console application to determine the number of sealed and unsealed types in the framework

0
220 0 0 0 0 0

static class Program
{
    static void Main(string[] args)
    {
        var publicFrameworkTypes = new HashSet<Type>(
            from assembly in AppDomain.CurrentDomain.GetAssemblies()
            from type in assembly.GetTypes()
            where type.FullName.StartsWith("System")
            where type.IsPublic
            where !type.IsValueType
            where !type.IsInterface
            where !type.IsPointer
            where !type.IsPrimitive
            select type);

        Console.WriteLine("publicFrameworkTypes.Count: " + publicFrameworkTypes.Count());

        // Non-leaf types are types that have descendents within the framework.
        var nonLeafTypes = new HashSet<Type>(
            from type in publicFrameworkTypes
            from nonLeafType in type.GetBaseTypes()
            where nonLeafType.IsPublic
            where publicFrameworkTypes.Contains(nonLeafType)
            select nonLeafType);

        Console.WriteLine("nonLeafTypes.Count: " + nonLeafTypes.Count());

        // Leaf types are types that don't have any descendents within the framwork.
        var leafTypes = new HashSet<Type>(publicFrameworkTypes);
        leafTypes.ExceptWith(nonLeafTypes);

        Console.WriteLine("leafTypes.Count: " + leafTypes.Count());

        var sealedLeafTypes = (
            from leafType in leafTypes
            where leafType.IsSealed || !leafType.HasPublicConstructors()
            select leafType).ToArray();

        var openLeafTypes = (
            from leafType in leafTypes
            where !(leafType.IsSealed || !leafType.HasPublicConstructors())
            select leafType).ToArray();

        Console.WriteLine("Open types: {0} = {1:p}", openLeafTypes.Length,
            (double)openLeafTypes.Length / (double)leafTypes.Count);
        Console.WriteLine("Sealed types: {0} = {1:p}", sealedLeafTypes.Length,
            (double)sealedLeafTypes.Length / (double)leafTypes.Count);

        Console.WriteLine("Done");
        Console.ReadLine();
    }

    private static IEnumerable<Type> GetBaseTypes(this Type type)
    {
        var baseType = GetGenericTypeDefinition(type.BaseType);

        while (baseType != null)
        {
            yield return baseType;
            baseType = GetGenericTypeDefinition(baseType.BaseType);
        }
    }

    private static Type GetGenericTypeDefinition(Type type)
    {
        return type != null && type.IsGenericType ? type.GetGenericTypeDefinition() : type;
    }

    private static bool HasPublicConstructors(this Type type)
    {
        return type.GetConstructors(BindingFlags.Instance | BindingFlags.Public).Any();
    }
}

Share: twitter | facebook   Action: used | fork | flag

.net

Mark '.net' tag as 'like'

Mark '.net' tag as 'ignore'

c#

Mark 'c#' tag as 'like'

Mark 'c#' tag as 'ignore'

framework-design

Mark 'framework-design' tag as 'like'

Mark 'framework-design' tag as 'ignore'

sealed

Mark 'sealed' tag as 'like'

Mark 'sealed' tag as 'ignore'


 Steven
500
September 03, 2010 9:26 AM

Fork

 Number of sealed / unsealed types in the framework - Steven Friday 03, 2010 9:26 AM


0 Feedback


You must log in before you can give any feedback


0 Discussion(s)

Newest Oldest

You must log in before you can post a comment

Squeed
Made by: Fredrik Normén 2010