基类:Fieldpublic abstract class Field {
   protected string value = null;   public string Value { 
       set { this.value = value; } 
       get { return this.value = this.value == null ? "" : this.value; } }
}派生类:StringField,IntField,DecimalFieldpublic class StringField :Field {
   public new string Value { 
       get { return base.value; } 
       set { base.value = value; } }
}public class IntField : Field {
   public new int Value { 
       set { base.value = value.ToString(); } 
       get { return int.Parse(base.value); } 
   }
}public class DecimalField :Field {
   public new decimal Value { 
       set { base.value = value.ToString(); }
       get { return decimal.Parse(base.value); } 
   }
}外部引用:Student
public class Student{
   StringField studentName = null;
   IntField age = null;
   DecimalField mathScore = null;   public StringField StudentName { get { return studentName; } set { studentName = value; } }
   public IntField Age { get { return age; } set { age = value; } }
   public DecimalField MathScore { get { return mathScore; } set { mathScore = value; } }
}问题:
   自己创建的WebService引用Student类时,代码:
   [WebMethod]
    public Student GetStudent() {
        StudentHandle s = new StudentHandle();
        return s.GetStudent();
    }
   出现以下异常:   类型 System.Int32 的成员 IntField.Value 隐藏类型 System.String 的基类成员 Field.Value。使用 XmlElementAttribute 或 XmlAttributeAttribute 指定一个新名称。

解决方案 »

  1.   

    当然可以有实体。改下你的虚基类,别让那个属性给序列化了。
    public abstract class Field { 
      protected string value = null; 
      
      [XmlIgnore]
      public string Value { 
          set { this.value = value; } 
          get { return this.value = this.value == null ? "" : this.value; } } 
      

  2.   

    困扰了2天的问题终于解决了,眼泪汪汪滴,谢谢qldsrx