代码解释,C#到VB.NET [英] Code Interpretation, C# to VB.NET
本文介绍了代码解释,C#到VB.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
那里有人可以帮我解决下一个代码C#到VB.NET的问题吗?我正在使用WPF应用程序(VB.NET)。
注意:我的部件有问题:'//创建查询
var rowsFromFile =来自XDocument.Load中的c(
MyData.xml)。Elements lang =sql>& quot; Data& quot;)。Elements( & quot; Rows& quot;)。元素(& quot;& quot;)
select c;
我找不到翻译。
使用System;
使用System.IO;
使用System.Collections.Generic;
使用System.Linq;
使用System.Text;
使用System.Xml.Linq;
名称空间ListViewTest
{
公共类MyData
{
/// < 摘要 >
///将项目保存到bin文件夹中的MyData.xml文件。
/// < / summary > ;
/// < param name = items > < / param >
public void保存(System.Windows.Data.CollectionView项目)
{
XDocument xdoc = new XDocument( );
XElement xeRoot = new XElement(Data);
XElement xeSubRoot = new XElement(Rows);
foreach(项目中的var项目)
{
ListViewData lvc =(ListViewData)item;
XElement xRow = new XElement(Row);
xRow.Add(new XElement(col1,lvc.Col1));
xRow.Add(new XElement(col2,lvc.Col2));
xeSubRoot.Add(xRow);
}
xeRoot.Add(xeSubRoot);
xdoc.Add(xeRoot);
xdoc.Save(MyData.xml);
}
/// < 摘要 >
///从MyData.xml获取数据作为行。
/// < / summary > ;
/// < 返回 > < / returns >
public IEnumerable < object > GetRows()
{
List < ListViewData > rows = new List < ListViewData > ();
if(File.Exists(MyData.xml))
{
//在XDocument.Load中创建查询
var rowsFromFile = c(
MyData.xml)。元素(
数据)。元素(行)。元素(行)
选择c;
//执行查询
foreach(rowsFromFile中的var row)
{
rows.Add(new ListViewData(row.Element(col1)。Value ,
row.Element(col2)。Value));
}
}
返回行;
}
}
}
谢谢
解决方案
而是要求别人为你做你的工作(如何理解你的要求),你应该自动学习如何做这些翻译。
- 使用在线翻译之一。我不想指出任何一个特定的;请看这里: http://bit.ly/XFdX2G [ ^ ]。
在我的观察中,这个比其他人更准确:http://converter.telerik.com/ [ ^ ]。- 现在,这是一个非常精彩的离线解决方案:使用开源ILSpy:
http://www.ilspy.net/ [ ^ ],
http://en.wikipedia.org/wiki/.NET_Reflector [ ^ ]。
首先,您需要编译项目并获取已编译的程序集。它编译为CIL:
http://en.wikipedia.org/wiki/Common_Intermediate_Language [ ^ ]。
您可以将程序集加载到ILSpy中并对其进行反汇编。它有输出语言选项。选择C#或VB.NET,然后重新编译所需的部分代码。你已经完成了。
祝你好运,
-SA
Hi everybody,
Does anybody there can help me with tha traslation of the next code C# to VB.NET? I'm working in WPF Application (VB.NET).
NOTE: I have a problem with the part: ' // Create the query
var rowsFromFile = from c in XDocument.Load( "MyData.xml").Elements lang="sql">"Data").Elements("Rows").Elements("Row") select c;
I can't found the traslation.
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
namespace ListViewTest
{
public class MyData
{
/// <summary>
/// Saves items to MyData.xml file in bin folder.
/// </summary>
/// <param name="items"></param>
public void Save(System.Windows.Data.CollectionView items)
{
XDocument xdoc = new XDocument();
XElement xeRoot = new XElement("Data");
XElement xeSubRoot = new XElement("Rows");
foreach (var item in items)
{
ListViewData lvc = (ListViewData)item;
XElement xRow = new XElement("Row");
xRow.Add(new XElement("col1", lvc.Col1));
xRow.Add(new XElement("col2", lvc.Col2));
xeSubRoot.Add(xRow);
}
xeRoot.Add(xeSubRoot);
xdoc.Add(xeRoot);
xdoc.Save("MyData.xml");
}
/// <summary>
/// Gets data from MyData.xml as rows.
/// </summary>
/// <returns></returns>
public IEnumerable<object> GetRows()
{
List<ListViewData> rows = new List<ListViewData>();
if (File.Exists("MyData.xml"))
{
// Create the query
var rowsFromFile = from c in XDocument.Load(
"MyData.xml").Elements(
"Data").Elements("Rows").Elements("Row")
select c;
// Execute the query
foreach (var row in rowsFromFile)
{
rows.Add(new ListViewData(row.Element("col1").Value,
row.Element("col2").Value));
}
}
return rows;
}
}
}
Thanks
解决方案
Instead asking others to do your job for you (how else can one understand your request), you should learn the ways to do such translations automatically.
- Use one of on-line translators. I don't want to point to any particular one; just look here: http://bit.ly/XFdX2G[^].
In my observations, this one is more accurate than some others: http://converter.telerik.com/[^].- Now, a really wonderful off-line solution: use open-source ILSpy:
http://www.ilspy.net/[^],
http://en.wikipedia.org/wiki/.NET_Reflector[^].
First, you need to compile the project and obtain a compiled assembly. It is compiled to CIL:
http://en.wikipedia.org/wiki/Common_Intermediate_Language[^].
You can load assembly into ILSpy and disassemble it. It has the option for output language. Select either C# or VB.NET, and recompile the part of code you need. You are done.
Good luck,
—SA
这篇关于代码解释,C#到VB.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文