Tuesday, May 22, 2012

How to let a method accept two types of data as argument?

this is somewhat the same question as I've asked some time ago:
How to let a method accept two types of data as argument?



Yet the current situation differs.. a lot.



Take this:



public FormResourceSelector(Dictionary<string, Effect> resourceList, string type)


Alright, nothing wrong with it.
Now I try to run this:



FormResourceSelector frs = new FormResourceSelector(AreaEffect.EFFECTS, "Area effect");
FormResourceSelector frs2 = new FormResourceSelector(DistanceEffect.EFFECTS, "Distance effect");


Both AreaEffect and DistanceEffect (custom classes) derive from Effect.



public class AreaEffect : Effect
{
public static Dictionary<string, AreaEffect> EFFECTS = new Dictionary<string, AreaEffect>();
...
}


For some reason I get the following error while making the new FormResourceSelector instance:



Argument 1: cannot convert from 'System.Collections.Generic.Dictionary<string,SCreator.AreaEffect>' to 'System.Collections.Generic.Dictionary<string,SCreator.Effect>'  


at:



new FormResourceSelector(AreaEffect.EFFECTS, "Area effect");


I suspect the dictonary being a harass, but I don't really know how to fix this.



Thanks for helping me out :).



~ Tgys



EDIT: Easiest would be to allow input of both Dictionary and Dictionary as resourceList in the first code snippet I've given.





No comments:

Post a Comment