public class SettingsBase
{
}
public class SettingsDerived : SettingsBase
{
}
public class yyy
{
public void StartUpMethod(Action<SettingsDerived> settings)
{
//something goes here..
SettingsDerived ds = new SettingsDerived();
settings(ds);//take out SettingsDerived properties..
SettingsBase bs = Method1(settings as Action<SettingsBase>);//as operator returns null because settings is not of type Action<SettingsBase>
//again do something on s based on extracted SettingsDerived
}
public SettingsBase Method1(Action<SettingsBase> settings)
{
SettingsBase s = new SettingsBase();
//something goes here
settings(s);
return s;
}
}
how do I achieve this? OR any work around?
You can't, it doesn't make sense.
the settings action you pass to
StartUpMethod
is typed to Derived and will be entitled to use the interface ofSettingsDerived
. You can't then give it a base class and expect it to just handle it.eg, if I have...
I'm entitled to do :-
but in the method1 you are trying to give it a
SettingsBase s = new SettingsBase();
which won't have the
DerivedSetting