VB.NET错误表达式不会产生值

时间:2014-01-03 11:29:12

标签: vb.net

我使用facebook c#sdk开发'facebook应用程序 我将以下代码转换为vb.net:

var mediaObject = new FacebookMediaObject
 {
      ContentType = "image/jpeg",
      FileName = Path.GetFileName(_filename)
  }.SetValue(File.ReadAllBytes(_filename));

转换后的代码:

  Dim mediaObject = New FacebookMediaObject() With { _
  .ContentType = "image/jpeg", _
 .FileName = Path.GetFileName(_filename) _
}.SetValue(File.ReadAllBytes(_filename))

但它给了我以下错误:
Expression doesn't produce a value.
有人可以建议一个解决方案吗?

1 个答案:

答案 0 :(得分:0)

在VS2008中,它将作为

工作
Dim mediaObject = New FacebookMediaObject With { _
                      .ContentType = "image/jpeg", _
                      .FileName = Path.GetFileName(_filename) _
                      }
mediaObject.SetValue(File.ReadAllBytes(_filename))

或许您希望SetValue成为一个函数(!):

Imports System.IO

Module Module1

    Public Class FacebookMediaObject
        'TODO: make these properties
        Public ContentType As String
        Public FileName As String
        Public Contents As Byte()

        Public Function SetValue(ByVal b() As Byte) As FacebookMediaObject
            Contents = b
            Return Me
        End Function

    End Class

    Sub Main()

        Dim _filename As String = "whatever"

        Dim mediaObject = (New FacebookMediaObject With { _
                           .ContentType = "image/jpeg", _
                           .FileName = Path.GetFileName(_filename) _
                           }).SetValue(File.ReadAllBytes(_filename))

    End Sub

End Module
相关问题