How to make asp.net parse markup tag property as list
Is there a way that I can extend asp.net to开发者_开发知识库 accept the markup
<c:MyControl runat="server" MyList="1,2,6,7,22" />
Where MyList is a List<int>
or List<string>
or even List<someEnum>
?
So I want asp.net to parse automatically all lists (that can be parsed) generically.
I know I could take the way around it and make MyList a string, then parse that into a list, but then I just end up with more properties than I want tbh.
I don't know of anyway to get asp.net to to that automatically. But if you're willing to go for a intermediate base class, then it's should be difficult. i.e.:
public class ListProcessorControl: Control {.....}
public class MyControl : ListProcessorControl {.....}
Now, you'd need some way to saying what king of list that is. Either:
<c:MyControl runat="server" MyList="1,2,6,7,22" TypeOfMyList="System.Int32" />
or make the base class generic:
public class ListProcessorControl<T>: Control {.....}
public class MyControl : ListProcessorControl<int> {.....}
精彩评论