我想包装一些对象以便为它们提供其他属性。但是,当我与在基类上定义的属性进行交互时,原始的未包装对象将发生更改。
我是一个类层次结构,例如:
(json/write-str (lacinia/execute compiled-schema query variables context))
如果我有一个程序,那么:
public class SomeBase
{
public SomeObj Source { get; set; }
public SomeObj Target { get; set; }
public SomeBase(SomeObj source, SomeObj target)
{
Source = source;
Target = target;
}
}
public class SomeDerrived : SomeBase
{
public SomeDerrived(SomeBase s) : base(s.Source, s.Target) {}
}
public class SomeObj {}
有没有办法做到这一点?
就像SomeBase s = new SomeBase(new SomeObj(), new SomeObj());
SomeDerrived sd = new SomeDerrived(s);
WriteLine(s.Source.GetHashCode());
WriteLine(sd.Source.GetHashCode()); //The two hash codes are identical as I'd have expected.
sd.Source = new SomeObj();
WriteLine(s.Source.GetHashCode()); //Why does this not have the hash code of `sd`?
WriteLine(sd.Source.GetHashCode());
isa SomeDerrived
一样,我认为这些属性将是相同的吗?