小编min*_*ill的帖子

如何从网址读取csv文件?

我试图创建一个获取URL的Web服务,www.domain.co.uk/prices.csv然后读取csv文件.这可能吗?怎么样?理想情况下无需下载csv文件?

c# csv

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

c#中递归泛型类型的问题

我有一些C#代码在mono和Microsoft的.net编译器下编译得很好,但只能在单声道上运行.错误消息是(我添加的换行符)

Unhandled Exception: System.TypeLoadException:
Could not load type 'Hasse.Groups.Heavy.Product.PowerGroup`1'
from assembly 'Hasse, Version=1.0.x.y, Culture=neutral, PublicKeyToken=null'
because it has recursive generic definition.
Run Code Online (Sandbox Code Playgroud)

该类型实际上有一个递归的泛型定义,所以我的问题是:为什么它与单声道一起工作?[代码运行并产生预期结果]

完整的源代码在这里:https://github.com/miniBill/Hasse

减少仍然崩溃的代码在这里:

public class Group<T> : IWrappableGroup<WrapperGroup<T>> {}

public class WrapperElement<T> {}

public interface IWrappableGroup<U> {}

public class WrapperGroup<T> : Group<WrapperElement<T>> {}

class MainClass {
    public static void Main(string[] args){
        var ng = new Group<object>();
    }
}
Run Code Online (Sandbox Code Playgroud)

以下证明它适用于单声道:http://ideone.com/ZvA3I

c# generics mono recursion exception-handling

14
推荐指数
1
解决办法
1117
查看次数

Eclipse中的lint for android会产生错误的结果

如果我跑"lint".在项目目录中我得到了预期的警告,但如果我从eclipse中运行它,我会得到无意义的错误和警告,例如:

  • 资源R.array.settings_derivatives似乎未使用[事实上,它被使用]
  • xyz未在清单中注册[事实上,它已注册]
  • 调用需要API级别3(当前最小值为1):android.view.SurfaceView#isInEditMode [实际上minSdkVersion设置为7]

编辑:如果我创建一个新工作区并导入现有项目,我会得到正确的错误

eclipse android android-lint

9
推荐指数
1
解决办法
6708
查看次数

为什么C#编译器不能为返回值推导出类型参数?

我有这个代码(为了清晰起见,最小化):

interface IEither<out TL, out TR> {
}

class Left<TL, TR> : IEither<TL, TR> {
    public Left(TL value) { }
}

static class Either {
    public static IEither<TL, TR> Left<TL, TR> (this TL left) {
        return new Left<TL, TR> (left);
    }
}
Run Code Online (Sandbox Code Playgroud)

为什么我不能说:

static class Foo
{
    public static IEither<string, int> Bar ()
    {
        //return "Hello".Left (); // Doesn't compile
        return "Hello".Left<string, int> (); // Compiles
    }
}
Run Code Online (Sandbox Code Playgroud)

我得到一个错误说明'string' does not contain a definition for 'Left' and no extension …

c# generics type-inference

9
推荐指数
2
解决办法
1305
查看次数

在WebView中嵌入自定义视图

我有一个自定义视图,我想"嵌入"WebView.

通过嵌入我的意思是:

  • 自定义视图拦截其区域上的onTouch事件
  • 自定义视图看起来像是网页的一部分,因此它会与周围的文本一起滚动

我编写了自定义视图,因此我可以根据需要进行编辑

android android-layout

7
推荐指数
1
解决办法
2087
查看次数

Tell Resharper that a lambda argument is not null

I have a method like this:

void Foo(object x, Action<object> f) {
    if (x != null)
        f (x);
}
Run Code Online (Sandbox Code Playgroud)

And I would like to use it like this:

void Bar () {
    Foo ("baz", g => g.ToString());
    Foo (null, g => g.ToString());
}
Run Code Online (Sandbox Code Playgroud)

But Resharper is complaining that the g in the lambdas might be null. Is it possibile to annotate the method to tell Resharper that g will never be null?

c# resharper lambda

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

ProtectedMemory.Unprotect 输出垃圾

我有这个代码来存储和恢复授权令牌(字母数字):

public static void Store (string token)
{
    byte[] buffer = Encoding.UTF8.GetBytes (token.PadRight (32));
    ProtectedMemory.Protect (buffer, MemoryProtectionScope.SameLogon);
    Settings.Default.UserToken = buffer.ToHexString ();
    Settings.Default.Save ();
}

public static string Retrieve ()
{
    byte[] buffer = Settings.Default.UserToken.FromHexString ();
    if (buffer.Length == 0)
        return String.Empty;
    ProtectedMemory.Unprotect (buffer, MemoryProtectionScope.SameLogon);
    return Encoding.UTF8.GetString (buffer).Trim ();
}
Run Code Online (Sandbox Code Playgroud)

它大部分工作正常,尽管有时我会得到垃圾(很多FD字节,和一些可读的字节)。我怀疑只有当我重新启动时才会发生这种情况,但我在重现它时遇到了一些困难。

这是预期的行为吗?也就是说,是否MemoryProtectionScope.SameLogon意味着重启后数据将始终无法读取?难道我做错了什么?

FromHexString方法ToHexString完全符合您的期望。

c# dpapi access-token

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

Network PC的DirectoryInfo抛出ArgumentException

我正在尝试将TreeView控件绑定到LAN上的机器ASUS-PC的公共文件夹.

华硕PC形式图片

但是,我无法弄清楚如何解析"ASUS-PC"目录,因为我无法从路径创建DirectoryInfo对象"\\\\ASUS-PC".

DirectoryInfo dir = new DirectoryInfo("\\\\ASUS-PC");
Run Code Online (Sandbox Code Playgroud)

上面的行抛出带有消息的ArgumentExceptionThe UNC path should be of the form \\server\share.

下面的代码只为root创建一个哑节点,因此我无法在该PC上显示所有公共文件夹.

如何提取路径"\\ ASUS-PC"的目录列表?

public void BindDirectoryToTreeView(string directoryPathToBind) {
  if (!String.IsNullOrEmpty(directoryPathToBind) && Directory.Exists(directoryPathToBind)) {
    treeView1.Nodes.Clear();
    TreeNode rootNode = null;
    char[] ps = treeView1.PathSeparator.ToCharArray();
    string[] split = directoryPathToBind.Split(ps);
    var folders = split.Where(str => !String.IsNullOrEmpty(str));
    for (int i = 0; i < folders.Count(); i++) {
      var folder = folders.ElementAt(i);
      int index = directoryPathToBind.IndexOf(folder);
      int length = index …
Run Code Online (Sandbox Code Playgroud)

c# directory smb

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

正确使用P/Invoke

我需要从c#调用外部dll.这是标题定义:

enum WatchMode { 
   WATCH_MODE_SYSTEM = 0,          
   WATCH_MODE_APPLICATION  = 1 };  

LONG ADS_API WDT_GetMode ( LONG i_hHandle, WatchMode * o_pWatchMode );
Run Code Online (Sandbox Code Playgroud)

我在C#中添加了枚举和调用:

public enum WatchMode
{
    WATCH_MODE_SYSTEM = 0,
    WATCH_MODE_APPLICATION = 1       
}
[DllImport("AdsWatchdog.dll")]
internal static extern long WDT_GetMode(long hHandle, ref WatchMode watchmode);
Run Code Online (Sandbox Code Playgroud)

这会生成AccessViolationException.我知道dll正在"工作",因为我还添加了一个调用GetHandle,返回hHandle上面提到的.我试图将参数更改为int(ref int watchmode)但得到相同的错误.没有人知道我怎么能拨打上述电话吗?

c# windows pinvoke interop

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