开发者

How to make asp.net parse markup tag property as list

开发者 https://www.devze.com 2023-01-14 03:31 出处:网络
Is there a way that I can extend asp.net to开发者_开发知识库 accept the markup <c:MyControl runat=\"server\" MyList=\"1,2,6,7,22\" />

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>  {.....}
0

精彩评论

暂无评论...
验证码 换一张
取 消