Overriding methods values in App.xaml.cs

后端 未结 2 1208
醉梦人生
醉梦人生 2021-01-24 17:18

I am working on Windows 8 Phone application,I have 2 things here one is Library project and other is normal app,Let me first explain my code:

In Library project<

相关标签:
2条回答
  • 2021-01-24 17:27

    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();
    
    0 讨论(0)
  • 2021-01-24 17:36

    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.

    0 讨论(0)
提交回复
热议问题