帮助进行代码转换 [英] Help on code conversion

查看:167
本文介绍了帮助进行代码转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请按照此网址上的asp.net上的Tailspinspywork教程进行操作 http://www.asp.net/web-forms/tutorials/tailspin-spyworks/tailspin-spyworks-part-5 [ ^ ]。本教程是一个C#教程,我在视觉基本原因中跟进,但我仍然是visual basic.net的菜鸟。我使用developerfusion.com的工具将我的c#代码转换为vb.net。但是下面的代码抛出了一个严重错误,我从asp.net教程网站得到它。请在下面是代码,我需要帮助为什么代码无效。





使用System; 
使用System.Collections.Generic;
使用System.Linq;
使用System.Web;
使用System.Web.UI;
使用System.Web.UI.WebControls;
使用System.Diagnostics;

命名空间TailspinSpyworks
{
公共部分类AddToCart:System.Web.UI.Page
{
protected void Page_Load(object sender,EventArgs e)
{
string rawId = Request.QueryString [ProductID];
int productId;
if(!String.IsNullOrEmpty(rawId)&& Int32.TryParse(rawId,out productId))
{
MyShoppingCart usersShoppingCart = new MyShoppingCart();
String cartId = usersShoppingCart.GetShoppingCartId();
usersShoppingCart.AddItem(cartId,productId,1);
}
else
{
Debug.Fail(错误:我们不应该在没有ProductId的情况下到达AddToCart.aspx
。);
抛出新的异常(错误:在没有设置ProductId的情况下加载AddToCart.aspx
是非法的。);
}
Response.Redirect(MyShoppingCart.aspx);
}
}
}





这是由developerfusion.com生成的错误代码/>

Quote:

转换代码时出错,可能是由于语法错误:

- 第25行第28栏:字符串文字内不允许换行 - 第25行第28行:字符串文字内到达文件的结尾 - 第26行第52行:)预期 - 第26行第72栏:没有新的在字符串文字内允许行 - 第26行第72行:在字符串文字内到达文件的结尾 - 第27行第37行:在字符串文字内不允许换行 - 第27行第37行:在字符串内到达文件的结尾literal - line 28 col 80:字符串文字内不允许换行 - 第28行col 80:字符串文字内到达文件的结尾



请高人指点任何帮助。谢谢

解决方案

删除这两行:



 Debug.Fail(错误:我们不应该在没有ProductId的情况下使用AddToCart.aspx 
。);
抛出新的异常(错误:在没有设置ProductId的情况下加载AddToCart.aspx
是非法的。);





然后尝试转换它。

我怀疑这是问题所在。



如果转换,请自行手动创建这两行。


请避免关于VB.NET翻译的问题到C#或返回,因为这一切都可以自动完成。



您可以使用Reflector或其开源替换ILSpy或类似工具之一:

http://en.wikipedia.org/wiki/.NET_Reflector [ ^ ],

http://ilspy.net/ [ ^ ]。



此外,这是学习CIL的有效工具之一。它可能非常有用,而且我不太了解这种语言。 CIL知识非常重要,尤其是使用 System.Reflection.Emit ,这是一个非常强大的库。



您可以用一种语言编写代码,编译代码,使用ILSpy加载程序集,选择其他语言,并反编译您需要的代码部分。结果的准确性非常好。



这是一个独立的开源代码转换器: http://codeconvert.codeplex.com/ [ ^ ]。



有许多在线工具:

http://www.developerfusion.com/tools/convert/vb-to-csharp/ [ ^ ],

http://converter.telerik.com/ [ ^ ]。



你可以找到更多: http:/ /bit.ly/XFdX2G [ ^ ]。



在一些更复杂的情况下,准确度c值得怀疑。







我强烈建议如果你是在开发中。 NET,你应该至少了解一些C#,特别是如果你想使用其他人的解决方案。最好的解决方案将在C#中找到,而不是VB.NET。原因是:VB.NET几乎没有标准化,而C#在ECMA和ISO / IEC下非常全面和全面地标准化;其他原因是文化:大多数高级开发人员都不会认真对待VB.NET。



-SA

Please i was following along the Tailspinspywork tutorial on asp.net found on this url http://www.asp.net/web-forms/tutorials/tailspin-spyworks/tailspin-spyworks-part-5[^]. The tutorial is a C# tutorial and i was following along in visual basic cause but i am still a noob at visual basic.net. I used the facilities of developerfusion.com to convert my c# code to vb.net.But the following code is throwing a serious error and i got it from the asp.net tutorial website.Please below is the code and i need help to why the code was not working.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Diagnostics;

namespace TailspinSpyworks
{
    public partial class AddToCart : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string rawId = Request.QueryString["ProductID"];
            int productId;
            if (!String.IsNullOrEmpty(rawId) && Int32.TryParse(rawId, out productId))
            {
                MyShoppingCart usersShoppingCart = new MyShoppingCart();
                String cartId = usersShoppingCart.GetShoppingCartId();
                usersShoppingCart.AddItem(cartId, productId, 1);
            }
            else
            {
                Debug.Fail("ERROR : We should never get to AddToCart.aspx 
                                                   without a ProductId.");
                throw new Exception("ERROR : It is illegal to load AddToCart.aspx 
                                                   without setting a ProductId.");
            }
            Response.Redirect("MyShoppingCart.aspx");
        }
    }
}



This is the error code generated by developerfusion.com

Quote:

An error occured converting your code, probably due to a syntax error:
-- line 25 col 28: No new line is allowed inside a string literal -- line 25 col 28: End of file reached inside string literal -- line 26 col 52: ")" expected -- line 26 col 72: No new line is allowed inside a string literal -- line 26 col 72: End of file reached inside string literal -- line 27 col 37: No new line is allowed inside a string literal -- line 27 col 37: End of file reached inside string literal -- line 28 col 80: No new line is allowed inside a string literal -- line 28 col 80: End of file reached inside string literal


Please any help is highly appreciated.Thanks

解决方案

Remove these two lines:

Debug.Fail("ERROR : We should never get to AddToCart.aspx
                                                  without a ProductId.");
               throw new Exception("ERROR : It is illegal to load AddToCart.aspx
                                                  without setting a ProductId.");



Then try and convert it.
I suspect that is the issue.

If it converts, manually create those two lines yourself.


Please, avoid the questions on the translation from VB.NET to C# or back, because this all can be done automatically.

You can use Reflector or its open-source replacement ILSpy or one of similar tools:
http://en.wikipedia.org/wiki/.NET_Reflector[^],
http://ilspy.net/[^].

Additionally, this is one of effective tools to learn CIL. It can be very useful, and I don''t know a good reference on the language. CIL knowledge is very important, in particular, for using System.Reflection.Emit, an extremely powerful library.

You can write code in one language, compile it, load the assembly with ILSpy, choose another language, and decompile the code part you need. The accuracy of the results is very good.

This is a stand-along open-source code convertor: http://codeconvert.codeplex.com/[^].

There is a number of on-line tools:
http://www.developerfusion.com/tools/convert/vb-to-csharp/[^],
http://converter.telerik.com/[^].

You can find more: http://bit.ly/XFdX2G[^].

In some more complex cases, the accuracy can be questionable.

[EDIT]

I would strongly recommend that if you are develop in .NET, you should understand at least some C#, especially if you want to use solutions of other people. Best solutions will be found in C#, not VB.NET. The reasons are: VB.NET will hardly be ever standardized, while C# is standardized very thoroughly and comprehensively under ECMA and ISO/IEC; other reasons are cultural: most advanced developers don''t take VB.NET seriously no matter how good it might be.

—SA


这篇关于帮助进行代码转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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