小编Rob*_*ien的帖子

如何在Windows Store/WP8/WinRT的可移植类库中使用反射?

我需要找到以下代码的等价物,以便在便携式库中使用:

    Public Overridable Function GetPropertyValue(ByVal p_propertyName As String) As Object
        Dim bf As System.Reflection.BindingFlags
        bf = Reflection.BindingFlags.IgnoreCase Or Reflection.BindingFlags.Public Or Reflection.BindingFlags.Instance Or Reflection.BindingFlags.NonPublic
        Dim propInfo As System.Reflection.PropertyInfo = Me.GetType().GetProperty(p_propertyName, bf)
        Dim tempValue As Object = Nothing

        If propInfo Is Nothing Then
            Return Nothing
        End If

        Try
            tempValue = propInfo.GetValue(Me, Nothing)

        Catch ex As Exception
            Errors.Add(New Warp10.Framework.BaseObjects.BaseErrorMessage(String.Format("Could not Get Value from Property {0}, Error was :{1}", p_propertyName, ex.Message), -1))
            Return Nothing
        End Try

        Return tempValue

    End Function
Run Code Online (Sandbox Code Playgroud)

BindingFlags似乎不存在.System.Reflection.PropertyInfo是一个有效的类型,但我无法弄清楚如何填充它.有什么建议?

vb.net reflection windows-runtime windows-phone-8

4
推荐指数
1
解决办法
2464
查看次数

如何在Windows 8/RT xaml中显示消息框?

可能重复:
Windows 8商店应用程序是否具有等效的MessageBox?

是否有相当于这个代码:

If MessageBox.Show("Text","Title", MessageBoxButtons.YesNo) = MessageBoxButton.No Then
   Blah()
End If
Run Code Online (Sandbox Code Playgroud)

我搜索了高低不同的东西,没有运气.

.net vb.net windows-runtime winrt-xaml

4
推荐指数
1
解决办法
1万
查看次数

为什么不能在c#中将null转换为类型参数T?

我正在将一堆代码从VB转换为C#,而我正在遇到一个方法的问题.这个VB方法效果很好:

Public Function FindItem(ByVal p_propertyName As String, ByVal p_value As Object) As T

    Dim index As Int32

    index = FindIndex(p_propertyName, p_value)

    If index >= 0 Then
        Return Me(index)
    End If

    Return Nothing

End Function
Run Code Online (Sandbox Code Playgroud)

它允许为T返回Nothing(null)

C#等价物不起作用:

public T FindItem(string p_propertyName, object p_value)
{
  Int32 index = FindIndex(p_propertyName, p_value);

  if (index >= 0) {
    return this[index];
  }
  return null;
}
Run Code Online (Sandbox Code Playgroud)

它不会使用此错误进行编译:

类型'T'必须是不可为空的值类型,以便在泛型类型或方法中将其用作参数'T' 'System.Nullable<T>'

我需要能够具有相同的功能,否则会破坏很多代码.我错过了什么?

c# vb.net vb.net-to-c#

4
推荐指数
1
解决办法
3173
查看次数

VB相当于c# new byte[0]

我正在尝试将一些 C# 转换为 VB。调用这个方法:

public static void WriteLineA(Stream Stream, byte[] Line);
Run Code Online (Sandbox Code Playgroud)

C# 调用如下所示:

SBASUtils.__Global.WriteLineA(messageStream, new byte[0]);
Run Code Online (Sandbox Code Playgroud)

所有 C# > VB 转换器都将字节转换为:

New Byte(-1) {}
Run Code Online (Sandbox Code Playgroud)

编译器不喜欢这样。任何帮助,将不胜感激。

谢谢!

c# vb.net

3
推荐指数
1
解决办法
1342
查看次数

在调用方法中不使用Await启动异步任务

窗口商店应用程序具有我需要在应用程序启动时调用的长时间运行方法,但我不需要等待它完成.我希望它作为后台任务运行.如果转到应用程序的某个部分(报告),那么我将检查并在必要时等待该任务.

Public Shared Async Function UpdateVehicleSummaries(p_vehicleID As Int32) As Task(Of Boolean)
    Dim tempVehicle As Koolsoft.MARS.BusinessObjects.Vehicle

    For Each tempVehicle In Vehicles
        If p_vehicleID = 0 Or p_vehicleID = tempVehicle.VehicleID Then
            UpdateVehicleStats(tempVehicle)
        End If
    Next

    Return True

End Function
Run Code Online (Sandbox Code Playgroud)

它被称为这样

Dim updateTask As Task(Of Boolean) = UpdateVehicleSummaries(0)
Run Code Online (Sandbox Code Playgroud)

它没有Await调用,我得到它将同步运行的警告.我如何启动这样的东西并让它以异步方式运行?我希望它在自己的线程/任务上运行而不会阻塞接口线程.有任何想法吗?

感谢名单!

vb.net multitasking windows-runtime windows-store

3
推荐指数
1
解决办法
2万
查看次数