VB.Net Polymorphic Bug! [英] VB.Net Polymorphic Bug!

查看:60
本文介绍了VB.Net Polymorphic Bug!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



''阴影'属性不是多态的。 (请参阅主题''继承和延迟

绑定'')

它们应该是。

问题:

基类具有只读属性''X''。

派生类必须具有读/写属性''X''。

不能覆盖基类' 'X''因为结构不同。

所以你在派生类中隐藏基类X。

将派生类的一个实例传递给函数。

在函数中读取''X''。你得到的基类不是派生的

类。

解决方法是放松基类X的界面,使它成为

读/写并使用Overrides而不是Shadows。

可能在下一个版本中修复?

Bob


Hi,
''Shadowed'' properties are not polymorphic. (See thread ''Inheritance and late
binding'')
They should be.
Problem:
Base class has read only property ''X''.
Derived class must have read / write property ''X''.
Can''t override Base class ''X'' because of different structure.
So you Shadow the base class ''X'' in the derived class.
Pass an instance of the derived class to a function.
Read ''X'' in the function. You get the base class read not the derived
class.
Workaround is to relax the interface of the Base class ''X'' so that it is
read/write and use Overrides instead of Shadows.
Fixed in next build perhaps?
Bob


推荐答案

Bob,

Shadows的整个点。是他们不是多态的!


你应该只使用Shadows进行版本控制!例如,你发布了一个有一个Widget方法的版本一个MainForm的
。 Microsoft发布.NET

2.0包括Form.Widget。看作Form.Widget可能不兼容

与MainForm.Widget默认为Shadow,这意味着

MainForm.Widget不会覆盖Form.Widget。如果默认值覆盖

(多态),你可能会导致一些不愉快的&意想不到的,

更不用说很难找到bug了。


当我需要隐藏属性时我会做什么,例如当我需要添加时a

设计师属性的属性。我根据

基本属性实现它。哪个在你的样本中不起作用。


希望这有帮助

Jay


" Bob" < bo*@nowhere.com>在消息中写道

news:e9 **************** @ tk2msftngp13.phx.gbl ...
Bob,
The entire point of "Shadows" is that they are not polymorphic!

You should only use Shadows for version control! For example you release
version one MainForm that has a Widget method on it. Microsoft releases .NET
2.0 what includes Form.Widget. Seeing as Form.Widget may be incompatible
with MainForm.Widget the default is to Shadow which means that
MainForm.Widget does not override Form.Widget. If the default was overrides
(polymorphism) you would possibly be causing some unpleasant & unexpected,
not to mention very difficult to track down bugs.

What I do when I need to shadow a property, such as when I need to add an
Attribute to the property for the designer. I implement it in terms of the
base property. Which in your sample will not work.

Hope this helps
Jay

"Bob" <bo*@nowhere.com> wrote in message
news:e9****************@tk2msftngp13.phx.gbl...
< br'>''阴影''属性不是多态的。 (参见主题''继承和
最后
绑定'')
它们应该是。
问题:
基类只读属性''X''。
派生类必须具有读/写属性''X''。
由于结构不同,不能覆盖基类''X'。
所以你影子基类'派生类中的X。
将派生类的实例传递给函数。
在函数中读取X。你得到的基类不是派生的类。
解决方法是放松基类X的接口,以便它可以读/写并使用覆盖而不是阴影。
修复下一个版本?
Bob

Hi,
''Shadowed'' properties are not polymorphic. (See thread ''Inheritance and
late
binding'')
They should be.
Problem:
Base class has read only property ''X''.
Derived class must have read / write property ''X''.
Can''t override Base class ''X'' because of different structure.
So you Shadow the base class ''X'' in the derived class.
Pass an instance of the derived class to a function.
Read ''X'' in the function. You get the base class read not the derived
class.
Workaround is to relax the interface of the Base class ''X'' so that it is
read/write and use Overrides instead of Shadows.
Fixed in next build perhaps?
Bob



Bob,

阴影的全部内容。是他们不是多态的!


你应该只使用Shadows进行版本控制!例如,你发布了一个有一个Widget方法的版本一个MainForm的
。 Microsoft发布.NET

2.0包括Form.Widget。看作Form.Widget可能不兼容

与MainForm.Widget默认为Shadow,这意味着

MainForm.Widget不会覆盖Form.Widget。如果默认值覆盖

(多态),你可能会导致一些不愉快的&意想不到的,

更不用说很难找到bug了。


当我需要隐藏属性时我会做什么,例如当我需要添加时a

设计师属性的属性。我根据

基本属性实现它。哪个在你的样本中不起作用。


希望这有帮助

Jay


" Bob" < bo*@nowhere.com>在消息中写道

news:e9 **************** @ tk2msftngp13.phx.gbl ...
Bob,
The entire point of "Shadows" is that they are not polymorphic!

You should only use Shadows for version control! For example you release
version one MainForm that has a Widget method on it. Microsoft releases .NET
2.0 what includes Form.Widget. Seeing as Form.Widget may be incompatible
with MainForm.Widget the default is to Shadow which means that
MainForm.Widget does not override Form.Widget. If the default was overrides
(polymorphism) you would possibly be causing some unpleasant & unexpected,
not to mention very difficult to track down bugs.

What I do when I need to shadow a property, such as when I need to add an
Attribute to the property for the designer. I implement it in terms of the
base property. Which in your sample will not work.

Hope this helps
Jay

"Bob" <bo*@nowhere.com> wrote in message
news:e9****************@tk2msftngp13.phx.gbl...
< br'>''阴影''属性不是多态的。 (参见主题''继承和
最后
绑定'')
它们应该是。
问题:
基类只读属性''X''。
派生类必须具有读/写属性''X''。
由于结构不同,不能覆盖基类''X'。
所以你影子基类'派生类中的X。
将派生类的实例传递给函数。
在函数中读取X。你得到的基类不是派生的类。
解决方法是放松基类X的接口,以便它可以读/写并使用覆盖而不是阴影。
修复下一个版本?
Bob

Hi,
''Shadowed'' properties are not polymorphic. (See thread ''Inheritance and
late
binding'')
They should be.
Problem:
Base class has read only property ''X''.
Derived class must have read / write property ''X''.
Can''t override Base class ''X'' because of different structure.
So you Shadow the base class ''X'' in the derived class.
Pass an instance of the derived class to a function.
Read ''X'' in the function. You get the base class read not the derived
class.
Workaround is to relax the interface of the Base class ''X'' so that it is
read/write and use Overrides instead of Shadows.
Fixed in next build perhaps?
Bob



阴影不应该是是多态的。 Overridable / Overrides意味着
是多态的。真正的问题是你不能在读/写属性上指定不同的

访问器。这意味着,有一个

公共读取和私有写入可能会很好。我相信这会改变惠德贝(VS

2005)。


-

Scott Swigart
http://blog.swigartconsulting.com

" Bob" < bo*@nowhere.com>在消息中写道

news:e9 **************** @ tk2msftngp13.phx.gbl ...
Shadows isn''t supposed to be polymorphic. Overridable/Overrides is meant to
be polymorphic. The real problem is that you can''t specify different
accessors on the read/write properties. Meaning, it might be nice to have a
public read, and a private write. I believe this will change in Whidbey (VS
2005).

--
Scott Swigart
http://blog.swigartconsulting.com
"Bob" <bo*@nowhere.com> wrote in message
news:e9****************@tk2msftngp13.phx.gbl...
< br'>''阴影''属性不是多态的。 (参见主题''继承和
最后
绑定'')
它们应该是。
问题:
基类只读属性''X''。
派生类必须具有读/写属性''X''。
由于结构不同,不能覆盖基类''X'。
所以你影子基类'派生类中的X。
将派生类的实例传递给函数。
在函数中读取X。你得到的基类不是派生的类。
解决方法是放松基类X的接口,以便它可以读/写并使用覆盖而不是阴影。
修复下一个版本?
Bob

Hi,
''Shadowed'' properties are not polymorphic. (See thread ''Inheritance and
late
binding'')
They should be.
Problem:
Base class has read only property ''X''.
Derived class must have read / write property ''X''.
Can''t override Base class ''X'' because of different structure.
So you Shadow the base class ''X'' in the derived class.
Pass an instance of the derived class to a function.
Read ''X'' in the function. You get the base class read not the derived
class.
Workaround is to relax the interface of the Base class ''X'' so that it is
read/write and use Overrides instead of Shadows.
Fixed in next build perhaps?
Bob



这篇关于VB.Net Polymorphic Bug!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆