I want to enforce type constraint when I define a 'type mapping' dictionary, such as this:
internal static class BindingResources
{
/// <summary>
/// Key== IDialogWindowVM, Value ==Window
/// </summary>
public static readonly Dictionary<Type, Type> ViewModelDictionary =
new Dictionary<Type, Type>()
{
{typeof(CreateGroupVM), typeof(CreateGroupUI)},
{typeof(CreateNewNetworkVM), typeof(CreateNewNetwork)}
};
}
I want to ensure that CreateGroupVM is of the interface IDialogWindowVM, and CreateGroupUI is inherited from Window class. If these conditions are not satisfied that I shall get a compilation error instead of a runtime error.
If this even possible, if yes, how to do it? If no, why?