CodePaste Logo
New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Language: C#

Resolve the MEF bug

314 Views
Copy Code Show/Hide Line Numbers
//this is the MEF Team Code
namespace System.ComponentModel.Composition.AttributedModel
{
    internal class AttributedPartCreationInfo : IReflectionPartCreationInfo
    {
private IEnumerable<MemberInfo> GetImportMembers(Type type)
{
    if (type.IsAbstract)
    {
        yield break;
    }
 
    foreach (MemberInfo member in GetDeclaredOnlyImportMembers(type))
    {
        yield return member;
    }
 
    // Walk up the type chain until you hit object.
    if (type.BaseType != null)
    {
        Type baseType = type.BaseType;
 
        // Stopping at object instead of null to help with performance. It is a noticable performance
        // gain (~5%) if we don't have to try and pull the attributes we know don't exist on object.
        // We also need the null check in case we're passed a type that doesn't live in the runtime context.
        while (baseType != null && baseType != CompositionServices.ObjectType)
        {
            foreach (MemberInfo member in GetDeclaredOnlyImportMembers(baseType))
            {
                yield return member;
            }
            baseType = baseType.BaseType;
        }
    }
}
}
}
//********************
//this my code to Resolve the mef bug
namespace System.ComponentModel.Composition.AttributedModel
{
    internal class AttributedPartCreationInfo : IReflectionPartCreationInfo
    {
private IEnumerable<MemberInfo> GetImportMembers(Type type)
{
    if (type.IsAbstract)
    {
        yield break;
    }
    var typeStack = new Stack<Type>();
    typeStack.Push(type);
    if (type.BaseType != null)
    {
        Type baseType = type.BaseType;
        typeStack.Push(baseType);
        while (baseType != null && baseType != CompositionServices.ObjectType)
        {
            baseType = baseType.BaseType;
            typeStack.Push(baseType);
        }
    }
    while (typeStack.Count>0)
    {
        var checkType = typeStack.Pop();
        foreach (MemberInfo member in GetDeclaredOnlyImportMembers(checkType))
        {
            yield return member;
        }
    }
}
}
}
by codding4fun
  June 08, 2010 @ 1:32am
Tags:
Description:
this is the resolve of the scenario here: http://codepaste.net/ca3epq

Add a comment


Report Abuse
brought to you by:
West Wind Techologies



If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate