Overriding methods values in App.xaml.cs

匆匆过客 提交于 2019-12-02 03:21:44

Now I understand, you want to call overriden values from your project in your library.

You cannot do that with classical C# mechanisms, for that you need dependency injection. Something along these lines:

// library
public interface IA
{
    List<string> ListOfEmployees();
}

public class ABase : IA
{
    public virtual List<string> ListOfEmployees() {}
}


public static class Repository
{
    private static IA _a;

    public static IA A
    {
        get { return _a = _a ?? new ABase(); }
        set { _a = value; }
    }
}

// in your app

class Properties : ABase
{
    public override List<string> ListOfEmployees() { /* ... */ }
}

Repository.A = new Properties();

Change the override keyword to new and you'll get the behaviour you're after. Check out this link for more information on when to use which.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!