小编Her*_* Yu的帖子

如何从 Windows 7 上的 C# 程序读取 Android 手机上的文件?

当我使用 USB 数据线将我的 Android 手机连接到我的 Windows 7 时,Windows 会弹出一个窗口并Computer\HTC VLE_U\Internal storage从 Windows 资源管理器中向我显示手机的内部存储。但是没有与此手机存储链接的驱动器号!在 Windows 资源管理器中,我可以操作文件系统。

如何从 C# 程序操作相同的文件或文件夹?

当我测试时,

DirectoryInfo di = new DirectoryInfo(@"C:\"); 
Run Code Online (Sandbox Code Playgroud)

有效,但是

DirectoryInfo di = new DirectoryInfo(@"Computer\HTC VLE_U\Internal storage");
Run Code Online (Sandbox Code Playgroud)

失败的。

但在 Windows 资源管理器中,它是Computer\HTC VLE_U\Internal storage!没有盘符!

是的,这是 MTP 设备。

我在 Stack Overflow 中看到了这个答案,但在运行此代码后,返回结果对我来说是空的

var drives = DriveInfo.GetDrives();
var removableFatDrives = drives.Where(
    c=>c.DriveType == DriveType.Removable &&
    c.DriveFormat == "FAT" && 
    c.IsReady);
var androids = from c in removableFatDrives
    from d in c.RootDirectory.EnumerateDirectories()
    where …
Run Code Online (Sandbox Code Playgroud)

c# windows android

8
推荐指数
1
解决办法
3980
查看次数

我怎么知道我的程序在单元测试环境下

我有一个控制台应用程序。在发布环境中,此时它可以完美运行。在 IDE 调试环境中,我不想关闭控制台窗口,所以我添加了这个函数,并在我的程序的最后调用它。

[Conditional("DEBUG")]
public static void DebugWaitAKey(string message = "Press any key")
{
    Console.WriteLine(message);
    Console.ReadKey();
}
Run Code Online (Sandbox Code Playgroud)

当我调试程序时,它对我来说效果很好。但是通过单元测试,它在退出之前仍然等待一个键!

解决方法只是我的程序的单元测试发行版,或测试其他功能。但我确实想要一些可以识别当前会话正在进行单元测试的东西,并在这个函数中使用该标志。

.net c# console unit-testing visual-studio

5
推荐指数
1
解决办法
1586
查看次数

标签 统计

c# ×2

.net ×1

android ×1

console ×1

unit-testing ×1

visual-studio ×1

windows ×1