Home Dashboard Directory Help
Search

ControlBuilder Generics not supported by Danila Korablin


Status: 

Closed
 as By Design Help for as By Design


3
0
Sign in
to vote
Type: Bug
ID: 538005
Opened: 3/2/2010 12:41:47 AM
Access Restriction: Public
0
Workaround(s)
view
2
User(s) can reproduce this bug

Description

I'm using http://www.codeproject.com/KB/aspnet/TypedRepeater.aspx TypedRepeater library in the VS 2005 and in 2008 but in the VS 2010 RC there is the bug with dynamic generated files.
Here is a part of the code:
===
public class RepeaterControlBuilder : ControlBuilder
{
    public override void Init(TemplateParser parser, ControlBuilder parentBuilder, Type type, string tagName, string id, System.Collections.IDictionary attribs)
    {
        string dataItemTypeName = attribs["DataItemTypeName"] as string;
        Type dataItemType = BuildManager.GetType(dataItemTypeName, true);
        Type repeaterFakeType = new RepeaterFakeType(dataItemType);

        base.Init(parser, parentBuilder, repeaterFakeType, tagName, id, attribs);
    }
}
internal class RepeaterFakeType : TypeDelegator
{
    public RepeaterFakeType(Type dataItemType)
        : base(typeof(Repeater<>).MakeGenericType(dataItemType))
    {
        this.repeaterItemType = typeof(RepeaterItem<>).MakeGenericType(dataItemType);
    }
    protected override PropertyInfo GetPropertyImpl(string name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers)
    {
        PropertyInfo info = base.GetPropertyImpl(name, bindingAttr, binder, returnType, types, modifiers);

    if(name == "ItemTemplate")
        info = new FakePropertyInfo(info, this.repeaterItemType);

    return info;
    }
}
Details
Sign in to post a comment.
Posted by Cobalt Software on 7/12/2010 at 11:01 PM
There's still an issue with this solution. In ASP .NET 4.0 the designer for pages and master pages writes out the 'Placeholder' control class name into the designer file, whereas previously the generified class was written out. This means that if the placeholder and generic substitute do not share a type then the page will fail with an error saying the element type declaration does not match the control type at run-time.

Is there some similiar method to control the type name that gets written out in the PageName.designer.cs/PageName.designer.vb now? I've tried pulling apart that whole thing with Reflector but nothing is standing out.
Posted by Danila Korablin on 3/8/2010 at 10:32 PM
Thank you for your response
Posted by Microsoft on 3/5/2010 at 11:58 AM
Hi Danila,

Thanks for reporting this. I had a look at this, and I believe the behavior you are observing is by design.

The difference in behavior you're seeing is due to a change in CodeTypeReference.ctor(Type type). The change made the constructor more robust for generic types. It now looks at the type object and its properties, instead of the earlier approach of calling type.FullName and parsing the resultant string. While this is good, it now makes the constructor depend on type.IsGenericType and other properties, whereas it didn't rely on them earlier.

The problem is that TypeDelegator doesn't implement IsGenericType and others (and falls back to the base implementation of "return false"). Implementing those will be a breaking change to other users of TypeDelegator, so that's not an option for us.

A workaround for this issue is overriding the required properties and methods in the user class that derives from TypeDelegator:
namespace AshMind.Web.UI.Research {
    internal class MyFakeType : TypeDelegator {
        public MyFakeType(Type typeArg)
            : base(typeof(List<>).MakeGenericType(typeArg)) {
        }
        public override bool IsGenericType
        {
            get
            {
                return this.typeImpl.IsGenericType;
            }
        }
        public override Type[] GetGenericArguments()
        {
            return this.typeImpl.GetGenericArguments();
        }
        public override bool ContainsGenericParameters
        {
            get
            {
                return this.typeImpl.ContainsGenericParameters;
            }
        }
    }
}

Once again, thanks for reporting this, and I hope this helps. We will also update the msdn documentation to make this clearer for other users of TypeDelegator.

Thanks,

Mueez Siddiqui
SDE - CLR Team
Posted by Microsoft on 3/2/2010 at 8:43 PM
Thanks for your feedback.

We are routing this issue to the appropriate group within the Visual Studio Product Team for triage and resolution.
These specialized experts will follow-up with your issue.
Sign in to post a workaround.
File Name Submitted By Submitted On File Size  
TypedRepeaterSource.zip (restricted) 3/2/2010 -