public abstract class DefBase : IList, IDictionary
{
// 既是Interface方法,又被声明为virtual
public virtual IEnumerator GetEnumerator()
{
if (_al != null)
return _al.GetEnumerator();
else if (_ht != null)
return _ht.GetEnumerator();
else
{
// 抛出基类无法处理异常
throw new Exception(
}
}
}
public class MyDef: DefBase, IList, IEnumerable
{
// 既是Interface方法,又被声明为override
public override IEnumerator GetEnumerator()
{
try
{
// 先调用DefBase的Interface方法,
// 如果基类无法处理,截获其抛出的异常
return base.GetEnumerator();
}
catch
{
if (this._ostOrm != null)
return GetList().GetEnumerator();
else if (this._xmlNode != null)
return _xmlNode.GetEnumerator();
else if (this._xmlDoc != null)
return _xmlDoc.GetEnumerator();
else
throw new Exception(