1. 创建贵国所有其他阶层都能继承的抽象课程:
public abstract class MyBaseClass
{
public string MyCommonString { get; set; }
}
public class Foo : MyBaseClass
{
public MyBaseClass() { }
}
//Create instance of foo
Foo myFoo = new Foo();
//MyCommonString is accessible since you inherited from base
string commonString = myFoo.MyCommonString;
<EDIT (根据新的要求)
由于你不想触及LLL的原始班级,我采取这一[类似]做法:
public abstract class MyBaseClass
{
public string MyCommonString { get; set; }
}
//This class definition lives in the DLL and remains untouched
public class Foo
{
public Foo() { }
}
//This partial class definition lives in [insert new project name here]
public partial class Foo : MyBaseClass
{
public Foo () { }
}
Notice that Foo
is now a partial class. You re not touching the existing class definition in the DLL, you re extending it.
<EDIT (根据新的要求)
鉴于您的要求(没有编辑原有的班级),你再次要求的话是不可能的。