Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 让构造函数警告开发人员不正确的值?_Vb.net_Visual Studio 2008_Constructor_Warnings - Fatal编程技术网

Vb.net 让构造函数警告开发人员不正确的值?

Vb.net 让构造函数警告开发人员不正确的值?,vb.net,visual-studio-2008,constructor,warnings,Vb.net,Visual Studio 2008,Constructor,Warnings,我的目标是创建一个类,只要设置了连接和查询,就可以将相同的文件类型和结构导入任何数据库。我们有一个“通用”数据库模式,但无论何时创建SQLite应用程序,都不能保证开发人员会使用相同的模式。因此,在主构造函数中,我将定义公共查询。但是如果它们定义了查询,我想确保有四个特定的查询,因为它们将是我唯一使用的查询。现在,我想在构造器中检查它,以便开发人员能够捕捉到它。用户捕捉它是毫无意义的,因为这样产品就不应该发布了。那么,有没有办法检查构造函数上的参数以确保其“有效”。我知道VisualStudio

我的目标是创建一个类,只要设置了连接和查询,就可以将相同的文件类型和结构导入任何数据库。我们有一个“通用”数据库模式,但无论何时创建SQLite应用程序,都不能保证开发人员会使用相同的模式。因此,在主构造函数中,我将定义公共查询。但是如果它们定义了查询,我想确保有四个特定的查询,因为它们将是我唯一使用的查询。现在,我想在构造器中检查它,以便开发人员能够捕捉到它。用户捕捉它是毫无意义的,因为这样产品就不应该发布了。那么,有没有办法检查构造函数上的参数以确保其“有效”。我知道VisualStudio会用type自动执行此操作,但我不知道是否有方法检查值以确保它们是所需的。我想做的只是抛出一个警告,而不是阻止它生成(他们可能会传入一个从数据库生成的值,谁知道呢)。

我在另一个SO线程中看到过这种称为“Stringy typing”的方法。不,不可能,只有在运行时才能找到字符串包含的内容。即使在运行时测试它的价值是不确定的,查询语句也可能有更多的错误。您似乎正在重新创建存储过程,考虑使用DBASE引擎支持。

NP.NAH,我认为最接近的是实际上强烈地键入这些参数。创建
IPBString
FigureString
等,这样开发人员就别无选择,只能传递正确的内容。不过这似乎有点过分了。使用如何?

这样做的原因似乎是因为我们试图在代码中保留所有决策,因此当我们分发产品时,最终用户不太可能看到其背后的逻辑。工作保障.)但这不是我的决定(
Private _bgWorker As BackgroundWorker = Nothing
Private _bgWorkerMessage As String = String.Empty
Private _bgPercentComplete As Integer = 0
Private _dictQueries As Dictionary(Of String, String) = New Dictionary(Of String, String)

Public Sub New()
    _dictQueries.Add("IPB", "")
    _dictQueries.Add("Figure", "")
    _dictQueries.Add("Part", "")
    _dictQueries.Add("Tags", "")
End Sub

Public Sub New(ByRef bgWorker As BackgroundWorker)
    Me.New()
    _bgWorker = bgWorker
End Sub

Public Sub New(ByVal dictQueries As Dictionary(Of String, String))
    Me.New()
    If Not dictQueries.ContainsKey("IPB") Or Not dictQueries.ContainsKey("Figure") Or Not dictQueries.ContainsKey("Part") Or Not dictQueries.ContainsKey("Tags") Then
        'I want to throw an exception/warning right here, or make it error out'
    End If
    _dictQueries = dictQueries
End Sub

Public Sub New(ByRef bgWorker As BackgroundWorker, ByVal dictQueries As Dictionary(Of String, String))
    Me.New(bgWorker)
    If Not dictQueries.ContainsKey("IPB") Or Not dictQueries.ContainsKey("Figure") Or Not dictQueries.ContainsKey("Part") Or Not dictQueries.ContainsKey("Tags") Then
        'I want to throw an exception/warning right here, or make it error out'
    End If
    _dictQueries = dictQueries
End Sub