Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/318.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
C# 使用C6语法将简单代码翻译为Vb.Net_C#_.net_Vb.net_Syntax_Code Translation - Fatal编程技术网

C# 使用C6语法将简单代码翻译为Vb.Net

C# 使用C6语法将简单代码翻译为Vb.Net,c#,.net,vb.net,syntax,code-translation,C#,.net,Vb.net,Syntax,Code Translation,有人能帮我把这个使用新C 6语法的简单代码段翻译成Vb.Net吗 在某些在线服务(如来自的服务)中进行翻译时,生成的LINQ查询是不完整的错误语法 试一试: <System.Runtime.CompilerServices.Extension()> _ Public Function RemoveAllNamespaces(this As XElement) As XElement Return New XElement(this.Name.LocalName,

有人能帮我把这个使用新C 6语法的简单代码段翻译成Vb.Net吗

在某些在线服务(如来自的服务)中进行翻译时,生成的LINQ查询是不完整的错误语法

试一试:

<System.Runtime.CompilerServices.Extension()> _
Public Function RemoveAllNamespaces(this As XElement) As XElement
    Return New XElement(this.Name.LocalName,
        (From n In this.Nodes
         Select (If(TypeOf n Is XElement, TryCast(n, XElement).RemoveAllNamespaces(), n))),
        If((this.HasAttributes), (From a In this.Attributes Select a), Nothing))
End Function
如果您要转换其他代码,以下是我采取的步骤:

添加了Extension属性,因为VB没有像C一样的语法来创建扩展方法。 用VB Ifcondition、true、false替换C三元运算符。 用VB TryCastobject替换了C强制转换,类型为。 将C类型检查替换为VB类型。对象的类型为。 将C null替换为VB Nothing。 试一试:

<System.Runtime.CompilerServices.Extension()> _
Public Function RemoveAllNamespaces(this As XElement) As XElement
    Return New XElement(this.Name.LocalName,
        (From n In this.Nodes
         Select (If(TypeOf n Is XElement, TryCast(n, XElement).RemoveAllNamespaces(), n))),
        If((this.HasAttributes), (From a In this.Attributes Select a), Nothing))
End Function
如果您要转换其他代码,以下是我采取的步骤:

添加了Extension属性,因为VB没有像C一样的语法来创建扩展方法。 用VB Ifcondition、true、false替换C三元运算符。 用VB TryCastobject替换了C强制转换,类型为。 将C类型检查替换为VB类型。对象的类型为。 将C null替换为VB Nothing。
包括xml注释,并更正另一个答案中的“RemoveAllNamespaces”错误,您的VB等价物是:

''' <summary>
'''     An XElement extension method that removes all namespaces described by @this.
''' </summary>
''' <param name="this">The @this to act on.</param>
''' <returns>An XElement.</returns>
<System.Runtime.CompilerServices.Extension> _
Public Function RemoveAllNamespaces(ByVal this As XElement) As XElement
    Return New XElement(this.Name.LocalName, (
        From n In this.Nodes()
        Select (If(TypeOf n Is XElement, RemoveAllNamespaces(TryCast(n, XElement)), n))),If(this.HasAttributes, (
            From a In this.Attributes()
            Select a), Nothing))
End Function

包括xml注释,并更正另一个答案中的“RemoveAllNamespaces”错误,您的VB等价物是:

''' <summary>
'''     An XElement extension method that removes all namespaces described by @this.
''' </summary>
''' <param name="this">The @this to act on.</param>
''' <returns>An XElement.</returns>
<System.Runtime.CompilerServices.Extension> _
Public Function RemoveAllNamespaces(ByVal this As XElement) As XElement
    Return New XElement(this.Name.LocalName, (
        From n In this.Nodes()
        Select (If(TypeOf n Is XElement, RemoveAllNamespaces(TryCast(n, XElement)), n))),If(this.HasAttributes, (
            From a In this.Attributes()
            Select a), Nothing))
End Function

Reflector v9非常出色地将其反编译到VB。你自己拿一份吧。这可能有用。反射器v9在将其反编译到VB时做得非常好。你自己拿一份吧。这可能有用。或者让你离得很近。