mercredi 17 janvier 2018

C# Class Inheritance Pattern Multiple Classes

I have two abstract classes that contain some base methods(Removed from this example for brevity);

public abstract class PluginBase
{
    protected SettingBase LocalSettings { get; set; }
}

public abstract class SettingBase
{
}

I am then creating a new class using PluginBase, and along with it I create a class using SettingBase

public class MyPlugin : PluginBase
{

}

public class MySettings : SettingBase
{
    private static string MyValue;
}

I then load an instance of "MySettings", into the "LocalSettings" property.

Within MyPlugin I would then like to access the "MyValue" property of the "LocalSettings" property. I know I can access it like this;

((MySettings)LocalSettings).MyValue;

But I am looking for a nicer way to do this, preferably without the need to constantly reference the new type every time, something like this;

MyLocalSettings.MyValue

Aucun commentaire:

Enregistrer un commentaire