Variant又回来了!! [英] The Variant is back!!

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

问题描述

大家好!


只是想让大家知道我创造了一个Variant结构,受到旧VB6时代的启发。这是用C#编写的,但您可以构建一个CLR / .NET类库程序集并根据自己的喜好进行引用。


''以下是一个使用示例:


''以字符串1开头

Dim da As Variant = new Variant(" 1)


''添加2的整数,变成3

da = da + 2


''添加1.3的浮点数,变为4.3

da = da + 1.3F


''添加一个字符串,变为4.3wow

da = da +"哇" ;


''写'4.3wow"

Console.WriteLine(da)

我实际上可能会使用这只小狗。 :)


无论如何,在这里,源代码和所有,看一看,如果你发现它有用,一定要给它5颗星。

http:// www.planet-source-code.com/vb...2854&lngWId=10

问候,

Jon Davis

解决方案

Jon:


你显然在代码中投入了大量的工作 - 但是在邪恶和想法之间br />
和交叉发布 - 你只是要求火焰;-)


-

WG Ryan MVP(Windows Embedded )


TiBA解决方案
www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com

" Jon Davis" < jo*@REMOVE.ME.jondavis.net>在消息中写道

新闻:eb ************** @ TK2MSFTNGP10.phx.gbl ...

大家好!


只是想让大家知道我创建了一个Variant结构,受到了旧VB6时代的启发

。这是用C#编写的,但你可以构建一个CLR / .NET

类库程序集并根据自己的喜好进行引用。


''这是一个使用示例:


''以字符串1开头

Dim da As Variant = new Variant(" 1")


''加一个2的整数,变成3

da = da + 2


''加一个浮点数1.3,变成4.3

da = da + 1.3F


''添加一个字符串,变成4.3wow

da = da +" wow"


''write" 4.3wow"

Console.WriteLine(da)
$ b $我可能真的会用这只小狗。 :)


无论如何,在这里,源代码和所有,看一看,一定要给它

5星,如果你发现它有用。

http://www.planet-source-code.com/vb...2854&lngWId=10

问候,

Jon戴维斯


Jon,

查看VB.NET 2005,因为它增加了对重载运算符的支持

VB.NET。

http://lab.msdn .microsoft.com / vs2005 /

VB.NET 2002& 2003不支持重载运算符所以你的代码本身并不是b $ b工作,除非你调用op_Addition,你可能想要添加运算符

方法类似于System.Decimal有什么,比如Decimal.Add加上运算符
。我通常在运营商的

条款中实现重载运算符。方法。


你知道你可以使用System.Convert.ChangeType根据System.Type变量将一个对象

从一种类型转换为另一种类型?实际上你可能希望你的结构实现System.IConvertible,并使用

System.Convert类来为你转换类型......


另外,我会认真考虑在每种方法的所有If语句中实现策略模式而不是

。 (注意Convert.ChangeType将减少一个
的if语句数量,策略应该是几乎所有其余的元素。)


否则是一项非常令人印象深刻的工作!


希望这有帮助

Jay


" Jon Davis" < jo*@REMOVE.ME.jondavis.net>在消息中写道

新闻:eb ************** @ TK2MSFTNGP10.phx.gbl ...

大家好!


只是想让大家知道我创建了一个Variant结构,受到了旧VB6时代的启发

。这是用C#编写的,但你可以构建一个CLR / .NET

类库程序集并根据自己的喜好进行引用。


''这是一个使用示例:


''以字符串1开头

Dim da As Variant = new Variant(" 1")


''加一个2的整数,变成3

da = da + 2


''加一个浮点数1.3,变成4.3

da = da + 1.3F


''添加一个字符串,变成4.3wow

da = da +" wow"


''write" 4.3wow"

Console.WriteLine(da)
$ b $我可能真的会用这只小狗。 :)


无论如何,在这里,源代码和所有,看一看,一定要给它

5星,如果你发现它有用。

http://www.planet-source-code.com/vb...2854&lngWId=10

问候,

Jon戴维斯


感谢您的反馈,周杰伦!我会考虑修改ConvertTo()以使你建议的电话成为

。我也会看一下IConvertable。对于所有的if

语句,你可能对策略模式是正确的;但是,请考虑以前是一个选择的情况,比较类型''命名空间+'的字符串值


。 +它的名字属性!哎呀......呵呵。 :)


再次感谢,

Jon

" Jay B. Harlow [MVP - Outlook]" < JA ************ @ msn.com>在消息中写道

新闻:#1 ************** @ TK2MSFTNGP10.phx.gbl ...

Jon,
http://lab.msdn.microsoft.com/vs2005/

VB.NET 2002& 2003不支持重载运算符所以你的代码
本身并不起作用,除非你调用op_Addition,你可能想要添加类似于System.Decimal所具有的运算符方法,例如Decimal。在
中添加重载运算符。我通常在运算符的术语中实现重载运算符。方法。

你知道你可以使用System.Convert.ChangeType根据System.Type变量将
对象从一种类型转换为另一种类型吗?实际上你可能希望你的结构实现System.IConvertible,并利用
System.Convert类为你转换类型......

我也会认真对待考虑实施策略模式而不是每个方法中的所有If语句。 (注意Convert.ChangeType将减少
a的if语句数量,策略应该几乎所有其余的元素。)

另外一个非常令人印象深刻的工作!

希望这有助于
Jay

Jon Davis < jo*@REMOVE.ME.jondavis.net>在消息中写道
新闻:eb ************** @ TK2MSFTNGP10.phx.gbl ...
大家好!

只是想要让大家都知道我创造了一个Variant结构,
受旧VB6时代的启发。这是用C#编写的,但是您可以构建一个CLR / .NET类库程序集并根据自己的喜好进行引用。

''这是一个使用示例:

''以一串1开头。
Dim da As Variant = new Variant(1)

''添加2的整数,变为3
da = da + 2
''加一个1.3的浮点数,变成4.3
da = da + 1.3F
''添加一个字符串,变成4.3哇
da = da +哇

''写'4.3wow"
Console.WriteLine(da)

我可能真的会用这只小狗。 :)

无论如何,在这里,源代码和所有,看看,如果你发现它有用,一定要给它
5星。

http:// www.planet-source-code.com/vb...2854&lngWId=10

问候,
Jon Davis


Hi guys!

Just wanted to let you all know that I created a Variant structure, inspired by the old VB6 days. This is written in C#, but you can build a CLR/.NET class library assembly and reference it to your liking.

'' Here is an example of use:

'' start with a string of "1"
Dim da As Variant = new Variant("1")

'' add an integer of 2, becomes 3
da = da + 2

'' add a float of 1.3, becomes 4.3
da = da + 1.3F

'' add a string, becomes "4.3wow"
da = da + "wow"

'' write "4.3wow"
Console.WriteLine(da)
I might actually use this puppy. :)

Anyway, here it is, source code and all, take a look and be sure to give it 5 stars if you find it useful.

http://www.planet-source-code.com/vb...2854&lngWId=10
Regards,
Jon Davis

解决方案

Jon:

You obviously put a lot of work into the code - but between an evil and idea
and cross posting - you''re just asking for flames ;-)

--
W.G. Ryan MVP (Windows Embedded)

TiBA Solutions
www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"Jon Davis" <jo*@REMOVE.ME.jondavis.net> wrote in message
news:eb**************@TK2MSFTNGP10.phx.gbl...
Hi guys!

Just wanted to let you all know that I created a Variant structure, inspired
by the old VB6 days. This is written in C#, but you can build a CLR/.NET
class library assembly and reference it to your liking.

'' Here is an example of use:

'' start with a string of "1"
Dim da As Variant = new Variant("1")

'' add an integer of 2, becomes 3
da = da + 2

'' add a float of 1.3, becomes 4.3
da = da + 1.3F

'' add a string, becomes "4.3wow"
da = da + "wow"

'' write "4.3wow"
Console.WriteLine(da)
I might actually use this puppy. :)

Anyway, here it is, source code and all, take a look and be sure to give it
5 stars if you find it useful.

http://www.planet-source-code.com/vb...2854&lngWId=10
Regards,
Jon Davis


Jon,
Check out VB.NET 2005, as it adds support for the Overloaded Operators to
VB.NET.

http://lab.msdn.microsoft.com/vs2005/

VB.NET 2002 & 2003 do not support Overloaded Operators so your code doesn''t
work per se, unless you call op_Addition, you may want to add "operator"
methods similar to what System.Decimal has, such as Decimal.Add in addition
to the overloaded operators. I normally implement overloaded operators in
terms of the "operator" methods.

You do know that you can use System.Convert.ChangeType to convert an object
from one type to another based on a System.Type variable? In fact you may
want your structure to implement System.IConvertible, and make use of the
System.Convert class to convert types for you...

Also I would seriously consider implementing a Strategy Pattern instead of
all the If statements in each method. (note Convert.ChangeType will reduce a
number of if statements, the Strategy should element almost all the rest).

Otherwise a very impressive piece of work!

Hope this helps
Jay

"Jon Davis" <jo*@REMOVE.ME.jondavis.net> wrote in message
news:eb**************@TK2MSFTNGP10.phx.gbl...
Hi guys!

Just wanted to let you all know that I created a Variant structure, inspired
by the old VB6 days. This is written in C#, but you can build a CLR/.NET
class library assembly and reference it to your liking.

'' Here is an example of use:

'' start with a string of "1"
Dim da As Variant = new Variant("1")

'' add an integer of 2, becomes 3
da = da + 2

'' add a float of 1.3, becomes 4.3
da = da + 1.3F

'' add a string, becomes "4.3wow"
da = da + "wow"

'' write "4.3wow"
Console.WriteLine(da)
I might actually use this puppy. :)

Anyway, here it is, source code and all, take a look and be sure to give it
5 stars if you find it useful.

http://www.planet-source-code.com/vb...2854&lngWId=10
Regards,
Jon Davis


Thanks for the feedback, Jay! I''ll look into modifying ConvertTo() to make
the call you suggest. I''ll also look at IConvertable. As for all the If
statements, you might be right about a Strategy Pattern; consider, though,
that it was previously a select...case situation, comparing the string value
of the type''s Namespace + "." + its Name properties! Yikes... hehe. :)

Thanks again,
Jon
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:#1**************@TK2MSFTNGP10.phx.gbl...

Jon,
Check out VB.NET 2005, as it adds support for the Overloaded Operators to
VB.NET.

http://lab.msdn.microsoft.com/vs2005/

VB.NET 2002 & 2003 do not support Overloaded Operators so your code doesn''t work per se, unless you call op_Addition, you may want to add "operator"
methods similar to what System.Decimal has, such as Decimal.Add in addition to the overloaded operators. I normally implement overloaded operators in
terms of the "operator" methods.

You do know that you can use System.Convert.ChangeType to convert an object from one type to another based on a System.Type variable? In fact you may
want your structure to implement System.IConvertible, and make use of the
System.Convert class to convert types for you...

Also I would seriously consider implementing a Strategy Pattern instead of
all the If statements in each method. (note Convert.ChangeType will reduce a number of if statements, the Strategy should element almost all the rest).

Otherwise a very impressive piece of work!

Hope this helps
Jay

"Jon Davis" <jo*@REMOVE.ME.jondavis.net> wrote in message
news:eb**************@TK2MSFTNGP10.phx.gbl...
Hi guys!

Just wanted to let you all know that I created a Variant structure, inspired by the old VB6 days. This is written in C#, but you can build a CLR/.NET
class library assembly and reference it to your liking.

'' Here is an example of use:

'' start with a string of "1"
Dim da As Variant = new Variant("1")

'' add an integer of 2, becomes 3
da = da + 2

'' add a float of 1.3, becomes 4.3
da = da + 1.3F

'' add a string, becomes "4.3wow"
da = da + "wow"

'' write "4.3wow"
Console.WriteLine(da)
I might actually use this puppy. :)

Anyway, here it is, source code and all, take a look and be sure to give it 5 stars if you find it useful.

http://www.planet-source-code.com/vb...2854&lngWId=10

Regards,
Jon Davis



这篇关于Variant又回来了!!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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