[DataContract]
public abstract class FooBase
{
[DataMember]
public int Bar { get; set; }
}
这是一个基类,我将它用作其他也是 DataContracts 的类的基类。这就是问题所在......
在 Proj1 中,我选择 Add Service Reference... (MyService),它会为我生成代码,包括 FooBase 代码。在 Proj2 中,我选择 Add Service Reference... (OtherService),它也是如此。
但是,我希望 Foo 基类位于它自己的程序集中,两个项目都可以引用......所以,最好是:
将 FooBase 类复制/粘贴到其他共享程序集中?
[DataContract]
public abstract class FooBase
{
[DataMember]
public int Bar { get; set; }
}
或者,将 FooBase 类的生成代码复制/粘贴到另一个共享程序集中?
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="FooBase", Namespace="http://schemas.datacontract.org/2004/07/MyNamespace")]
[System.SerializableAttribute()]
[System.Runtime.Serialization.KnownTypeAttribute(typeof(MyNamespace.Proj1.TypeA))]
[System.Runtime.Serialization.KnownTypeAttribute(typeof(MyNamespace.Proj1.TypeB))]
public partial class FooBase : object, System.Runtime.Serialization.IExtensibleDataObject, System.ComponentModel.INotifyPropertyChanged {
[System.NonSerializedAttribute()]
private System.Runtime.Serialization.ExtensionDataObject extensionDataField;
private int BarField;
[global::System.ComponentModel.BrowsableAttribute(false)]
public System.Runtime.Serialization.ExtensionDataObject ExtensionData {
get {
return this.extensionDataField;
}
set {
this.extensionDataField = value;
}
}
[System.Runtime.Serialization.DataMemberAttribute(IsRequired=true)]
public int Bar {
get {
return this.BarField;
}
set {
if ((this.BarField.Equals(value) != true)) {
this.BarField = value;
this.RaisePropertyChanged("Bar");
}
}
}
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
protected void RaisePropertyChanged(string propertyName) {
System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
if ((propertyChanged != null)) {
propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
}
}