I'm building a generic ASP.NET server control that has an attribute used to specify a type name. I'm using a control builder to generate the generic version of my control by passing the attribute value to Type.GetType(string)
. This works great. However, if the type that I want to specify is generic, I have to use syntax like this:
<gwb:GenericControl runat="server"
TypeName="System.Collections.Generic.List`1[System.String]" />
I'd like to be able to type it like this:
<gwb:GenericControl runat="server"
TypeName="System.Collections.Generic.List<System.String>" />
I know I could manually parse the value for angle brackets and convert them to square brackets, and add in the appropriate backtick-numeric prefix, but I was wondering if there was any built-in way to do this conversion? I assume the Generic<T>
syntax is specific to C# (or at least different in VB.NET) so I'm guessing I'd also have to parse any other language-specific syntax.
I've noticed that ASP.NET MVC does this in the Inherits
attribute of the Page
directive, but I'm not sure how.
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master"
Inherits="System.Web.Mvc.ViewPage<MyModel>" %>