调用方法的义务 [英] Obligation to call a method

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

问题描述

在VB .NET中,当您创建用户控件类时,您有义务在构造函数中调用子InitializeComponent。

In VB .NET, when you create a user control class, you have the obligation to call the sub InitializeComponent within the constructor.

如果没有, 'll这样的警告消息:

If you don't you'll a warning message like this :


'bublic Sub New()'为
设计者生成的类型
MyUserControl应调用
InitializeComponent方法。

'Public Sub New()' in designer-generated type 'MyUserControl' should call InitializeComponent method.

发出此警告的机制是什么?我可以为自己的功能复制吗?

What is the mechanism used to raise this warning? Is it something I can reproduce for my own functions?

推荐答案

这是VB.NET编译器的内置行为。此示例类将触发它:

This is built-in behavior for the VB.NET compiler. This sample class triggers it:

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class Class1
    Public Sub New()
       '' Warning BC40054 generated here
    End Sub
End Class

该属性很重要。否则,这不是一般有用的行为,您不能告诉编译器使用自己的属性使它生成类似的警告。

The attribute matters. It is not otherwise generically useful behavior, you cannot tell the compiler to make it generate a similar warning using your own attribute.

这篇关于调用方法的义务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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