czwartek, 29 sierpnia 2013

c# Override Property with different compatible Type

I need a base class with a property where I can derive classes with the same property but different (compatible) types and use operation get and set from base class.




public abstract class Plugin<T> 
{
        private T _pluginConfiguration;

        public virtual T PluginConfiguration
        {
            get
            {
                // some operation
                return _pluginConfiguration;
            }

            set
            {
                // some operation  
                _pluginConfiguration = value;
            }
        }
}

-------------------

public class FilePlugin : Plugin<FileConfiguration>
{
        PluginConfiguration = new FileConfiguration(); // execute abstract class setter
       
        PluginConfiguration.ServerName= "TestServer";  // execute abstract class getter
}
------------------


Resources:
http://stackoverflow.com/questions/1048884/c-overriding-return-types
http://stackoverflow.com/questions/3141325/override-property-with-different-compatible-type
http://stackoverflow.com/questions/6351025/overriding-an-abstract-property-with-a-derived-return-type-in-c-sharp
http://stackoverflow.com/questions/3551012/override-a-property-with-a-derived-type-and-same-name-c-sharp
http://stackoverflow.com/questions/8108012/c-properties-with-different-return-types-on-derived-classes
http://stackoverflow.com/questions/157119/c-sharp-can-i-override-with-derived-types

Brak komentarzy:

Prześlij komentarz