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;
}
}
我该如何做到这一点?或任何解决方法?