Good morning all,
I am currently playing around with a splash screen wrapped in a manager class.
This manager class has a factory method and everything works fine.
public static SplashScreenManager Factory(SplashScreenManagerOptions splashScreenManagerOptions)
Now I am thinking that it would be nice to pass in a parameter in order to let the user choose what kind of screen he/she want's to use.
public static SplashScreenManager Factory(SplashScreenBase splashScreenBase, SplashScreenManagerOptions splashScreenManagerOptions)
Problem here is that I have to obtain the Type of the splashScreenBase and then create a new instance of it using reflection, due to the fact that the splashScreenForm will be run in it's own thread. So the user has to pass in an instance only to have another instance created... even if that works fine I do not feel good because I do not know what kind of initializing and stuff will have to happen twice.
So I thought about using constraints. Here's what I've come up with so far:
public static SplashScreenManager Factory<T>(T splashScreenFormType, SplashScreenManagerOptions splashScreenManagerOptions) where T : SplashScreenBase
Ok, this doesn't do what I was thinking about... it only restricts the paramter to be of type SplashScreenBase, not a surprise really...
What I really wanted to do is the following.
The parameter should be of type Type and should be assignable from SplashScreenBase...
So basically it should be a restricted parameter typeof(Type) to only contain certain Types.
Does that makes sense? I hope so ;)
UPDATE:
here is a better illustration of what I want to do:
public static SplashScreenManager Factory<T>(T splashScreenFormType, SplashScreenManagerOptions splashScreenManagerOptions) where T : Type [&& T is a Type that is derived from SplashScreenBase]
This code of course does not compile, but it should show what the goal is :)
Can that be done somehow? In the constraints docs I couldn't find anything that would let me archive my goal... if it is ever doable...
Andy thoughts are kindly appreciated,
cheers
Andy