Writing generic classes in C# for Unity?

Ok, whenever I attempt to implement generic classes, like this:

public class SimpleRegistry {
// Etc…
}

Unity complains that the class doesn’t have the same name as the file that contains it.

What’s up with this? Is generics authoring not supported by Unity?

I don’t think the current version of C# (the mono implementation) supports generics just yet. I could be wrong, but I think Unity 2.6 will support the newest version of mono.

I don’t know what generics authoring is, but you can create and use generic classes. Just add an empty class in your file that matches the file name. You need this hack, as Unity is currently unable to match generic classes to file names.

So to get your generic working (obviously replace MyFileName with the actual file name :P):

public class SimpleRegistry<T> 
{
// Etc...
} 

// internal to prevent accidental use:
internal class MyFileName{}

Ah yeah ok. By authoring I meant creating new generic classes, as opposed to using existing ones.

But I guess that hack will fix the problem. Would be neat though if Unity could handle it correctly.

Generics should work – you get a warning that sounds worse than it is, but it is basically just letting you know that that mismatch will prevent you from using your script in a way that you weren’t intending in the first place.