Using Generics with Script#

390 views Asked by At

I'm trying to refactor some of our Script# code to reduce duplicate code. I'm trying to use generics to accomplish this but Script# refuses to build when I add this code (the only message it gives me is 'Build failed'):

public abstract class PageManagerBase<TItem>
{
    public List<TItem> _items;
}

Does anyone know if there's a workaround for this?

2

There are 2 answers

0
Steve Hobbs On BEST ANSWER

Script# supports generics for internal types only, so things like Dictionary<TKey, TValue>, or List<T>, but doesn't support custom types that you would create yourself.

So, you can use the ones that are already provided for you, but you can't create your own.

0
Leon On

I don't think script# supports generics yet. check out the roadmap over here http://projects.nikhilk.net/ScriptSharp