Creating a JavascriptConverter for a Generic Type

Suppose I have a generic class called MyClass<T> how can I create a JavascriptConverter that will be used for any T possible (be it MyClass<OtherClass>, MyClass<SimpleClass>)?

I tried to to the following in my converter:

public Enumerable<Type> SupportedTypes
{
  get
  {
    return new List<Type>(){ typeof(MyClass<>) };
  }
}

But to no avail.

Any ideas? is this possible? If not, is there any other way to acheive the same result?

Answers


If you really want this, with no filters at all:

using System.Linq;

....

var concreteGenericTypes =
    (from assembly in AppDomain.CurrentDomain.GetAssemblies()
     from T in assembly.GetTypes()
     where T.IsClass && T.GetConstructor(new Type[] { }) != null
     select typeof(MyClass<>).MakeGenericType(T)).ToList();

It gets all loaded assemblies, then all types for those assemblies, then filters according to your generic where conditions, finally it makes a concrete generic type from your class and the type.


Need Your Help

How can I make <legend> text wrap?

html css cross-browser

Usually &lt;legend&gt; text is pretty short so I had no idea this was a problem until I ran into it yesterday. I was trying and failing to set a 50% width on a &lt;fieldset&gt;, but it wouldn't wor...

How to test tables linked with foreign keys?

php mysql

I am working with mysql and codeigniter using the redbean ORM. After implementing a foreign key for many to many assosciation I got the following error when I run:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.