Sign in to follow this  

C# template class

Recommended Posts

I want to add a template class to my project, but i'm not really sure how to do this. I'm using XNA in which you can load a model in two different ways: Model model = Content.Load<Model>("modelname"); or SkinnedModel = Content.Load<SkinnedModel>("modelname"); So i can use Model or SkinnedModel. Now i thought templates would come in handy here. But i'm not sure if the following is possible. How would something like this work: class ModelType<T> { T t; public void LoadModel <T> ( string modelname ) { Content.Load<t>(modelname); } public T getModel ( ) { return t; //return the Model or SkinnedModel. Depends what was created } } So i can use it in a way like this (not sure how it works)
//Somewhere in my main function
ModelType mymodel = new ModelType<SkinnedModel>("model");
somefunc ( mymodel );

public void somefunc ( ModelType model )
    //do stuff with model
    //So this way it shouldn't matter if the ModelType is 'Model' or 'SkinnedModel'
In this case i passed SkinnedModel as ModelType to 'somefunc()' but it should also work if i passed 'Model' as ModelType to that function. That's what templates are for right?? If so, could someone please help me out with this?? Thanks for any help.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this