2015-12-21 67 views
-2

我在Bool类型的名为HasChar的远程服务器中有一个属性。我需要在Derived类中进行一些修改来重新定义它。但该基地物业并未标示为Partial,abstractextern。但我需要重新定义,我该如何实现?在派生类中,我需要访问基类的HasChar属性在派生类中,如果该值为False,那么我必须使BlogText作为String.Empty如何覆盖属性,而不标记为基本属性中的部分,抽象或外部?

注意:基类是远程服务器,我无法更改它或 启动更改。基本类别属性未标记为 Partial,abstractextern。不要创建任何其他属性来实现此目的。请提供与Override或类似的解决方案。

我的基类

public class BlogBase 
{ 
    private string _blogText = string.Empty; 
    public string BlogText 
    { 
     get { return _blogText; }; 
     set 
     { 
      _blogText = value; 
      HasChar = _blogText.Length >0 ? true : false; 
     } 
    } 

    public bool HasChar { get; set; } 

} 

我的派生类:粗码

public class BlogChild : BlogBase 
{ 
    private bool _hasChar = false; 
    public bool HasChar 
    { 
     get { return _hasChar; }; 
     set 
     { 
      _hasChar = value; 
      if(!_hasChar) 
       BlogText = string.Empty; 
     } 
    } 

} 
+1

尝试与“新”的关键字标记属性,或者做一些包装,并用它 – gabba

+0

@Alex我不能够改变的基类,请查看注释工作。 –

+0

@CodeCaster - 我向您展示了示例代码。我无法解释整个项目。我需要如上所述的要求。如果你理解这个要求,那么给你答案,否则不要。 –

回答

3

隐藏与new关键字的原始属性。

public new bool HasChar 
{ 
    private bool _hasChar; 
    get { return _hasChar; } 
    set 
    { 
     // do other stuff 
     _hasChar = value; 
    } 
} 
+0

请仔细阅读要求。然后请张贴答案。 –

+0

我错过了哪些要求? – Sami

+0

您检查派生类功能以及注意。 –