ReSharper可以删除基类吗?

问题描述 投票:0回答:1

我有一个情况:

class Dog : Animal {
...
}

我想将其更改为:

class Dog {
...
}

其中Animal中的所有成员变量和方法都复制到Dog中。

有没有办法做到这一点?

c# resharper
1个回答
0
投票

只需在基类中使用protected关键字在您要继承它的属性上并在基类中使用virtual作为方法和子类中的override

示例

class Animal
        {
            protected string Name { set; get; }
            protected string Type { set; get; }
            public virtual void    Test()
            {
                //some code
            }
        }
class Dog : Animal
{
            public Dog(string name)
            {
                this.Name = name;
                this.Type = "Dog";
            }
            public override void Test()
            {
                //this call the test function in the base class
                base.Test();
            }
}
© www.soinside.com 2019 - 2024. All rights reserved.