从net471到.NET Standard noob问题 [英] from net471 to .NET Standard noob questions

查看:105
本文介绍了从net471到.NET Standard noob问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常老的VB项目,我希望对其进行现代化改造,从而创建了一个新的解决方案(稍后将代码转换为C#),并将库和Web项目重新添加到该新解决方案中以消除旧项目具有旧的.publishproj,对mscorlib 2.0的引用(尽管尽最大努力通过重新添加引用来解决)以及其他一些可能会消失的问题.

I have a very old VB project I am looking to modernize to which I created a new solution (will convert code to C# later on), am re-adding the libraries and web projects to the new solution to eliminate the old project having old .publishproj, references to mscorlib 2.0 (despite best efforts to resolve through re-adding references) and several other issues that will likely go away.

在此过程中,我想尝试使用标准化PCL的.NET Standard,以便将来与Xamarin,Mono等一起使用.我不完全了解.NET Standard,因此需要一些输入(尝试2.0基于我所阅读的2.0的缩放效果)

In the process, I figured to try to go to .NET Standard for the standardized PCL that will allow for future use with Xamarin, Mono, etc. I am not fully versed in .NET Standard so need some input (attempting 2.0 based on the scaling effect of 2.0 down from what I read)

我遇到的问题是:

1)我有一些.NET Framework中的基本CORE函数,但.NET Standard中没有这些函数:

1) I have several basic CORE functions from the .NET Framework that are not recognized in .NET Standard:

IsNumeric,IsNothing,IsDBNull,IIF

IsNumeric, IsNothing, IsDBNull, IIF

关于这是为什么的任何建议?

Any suggestions as to why this is?

(重新编辑以删除保留) 谢谢jmcilhinney的回答:-)

(re-edit to remove Hold) Thank you to jmcilhinney for answering :-)

推荐答案

IsNumericIsNothingIsDBNullIIf的所有四个都是VB特定的.如果其他语言从未引用过Microsoft.VisualBasic程序集,则无法将它们作为.NET Standard的一部分.您真的不应该以前使用它们中的任何一个,因为它们是VB6的保留.

All four of IsNumeric, IsNothing, IsDBNull and IIf are VB-specific. They can't be part of .NET Standard if they've never been accessible to other languages without referencing the Microsoft.VisualBasic assembly. You really shouldn't have been using any of them previously anyway as they are holdovers from VB6.

对于IsNumeric,无论如何它在内部使用Double.TryParse.实际上,Double.TryParse是专门为改善IsNumeric的性能而编写的.如果您想知道String是否可以转换为该类型,则应该自己使用适当数字类型的TryParse方法.

In the case of IsNumeric, it uses Double.TryParse internally anyway. In fact, Double.TryParse was written specifically to improve the performance of IsNumeric. You should be using the TryParse method of the appropriate numeric type yourself if you want to know whether a String can be converted to that type.

IsNothing的情况下,您应该简单地将您的引用与Nothing进行比较,例如代替:

In the case of IsNothing, you should simply be comparing your reference to Nothing, e.g. instead of:

If IsNothing(myThing) Then

您应该使用:

If myThing Is Nothing then

对于IsDBNull,您应该执行上述操作,例如代替:

In the case of IsDBNull, you should be doing much as above, e.g. instead of:

If IsDBNull(myThing) Then 

您应该使用:

If myThing Is DBNull.Value Then

也就是说,DataRow和数据读取器都有各自专用的方法来告诉您它们的字段之一是否为NULL.

That said, both a DataRow and a data reader have their own dedicated methods to tell you whether one of their fields is NULL.

IIf的情况下,总是存在问题,因为在很多情况下,这是人们试图像运算符一样对待的一种方法.我认为实际上是VB 2008引入了一个If运算符,该运算符的工作方式与C#三元运算符非常相似,因此从那以后您就应该一直在使用它,例如代替:

In the case of IIf, it always had it's issues because it is a method that people tried to treat like an operator in many cases. I think it was VB 2008 that actually did introduce an If operator that works much like the C# ternary operator, so you should have been using that since then anyway, e.g. instead of:

myVar = IIf(someBooleanExpression, someValue, someOtherValue)

您应该一直在使用:

myVar = If(someBooleanExpression, someValue, someOtherValue)

IIfIf之间有一些细微的区别,但我将让您了解If如何为自己工作.

There are some subtle differences between IIf and If but I'll leave you to read about how If works for yourself.

这篇关于从net471到.NET Standard noob问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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