小编Ode*_*ded的帖子

C#模糊扩展方法

LinqKit有一个扩展方法ForEach用于IEnumerable与相冲突System.Collections.Generic.IEnumerable.

Error   4   The call is ambiguous between the following methods or properties: 
'LinqKit.Extensions.ForEach<Domain>(System.Collections.Generic.IEnumerable<Domain>, System.Action<Domain>)' 
and 
'System.Linq.EnumerableExtensionMethods.ForEach<Domain>(System.Collections.Generic.IEnumerable<Domain>, System.Action<Domain>)'
Run Code Online (Sandbox Code Playgroud)

我怎样才能摆脱这个错误?

c# extension-methods

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

什么是ObjectMother?

什么是ObjectMother以及此模式的常见使用方案是什么?

unit-testing design-patterns

13
推荐指数
2
解决办法
6122
查看次数

如何调用同一对象内的对象的函数?

我有以下Javascript代码

add_num = {
  f: function(html, num) {
    alert(this.page);
  },

  page : function() {
    return parseInt(this.gup('page'));
  },

  gup : function(name) {
    name = name.replace(/[\[]/,'\\\[').replace(/[\]]/,'\\\]');
    var regex = new RegExp('[\\?&]'+name+'=([^&#]*)');
    var results = regex.exec(window.location.href);
    if(results == null)
      return '';
    else
      return results[1];
  }
}
Run Code Online (Sandbox Code Playgroud)

但是当我调用add_num.f()时,我从alert()获得的是实际的页面代码.也就是说,它返回

function() {
    return parseInt(this.gup('page'));
  }
Run Code Online (Sandbox Code Playgroud)

我期待一个数值而不是任何代码.

javascript oop

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

使用html agility pack获取课堂链接

有一堆与类alt的tr.我想得到所有链接(或最后一个)但我无法弄清楚如何使用html敏捷包.

我试过a的变种,但我只得到所有的链接或没有.它似乎只是在节点中得到一个没有意义的,因为我正在编写n.SelectNodes

html.LoadHtml(page);
var nS = html.DocumentNode.SelectNodes("//tr[@class='alt']");
foreach (var n in nS)
{
  var aS = n.SelectNodes("a");
  ...
}
Run Code Online (Sandbox Code Playgroud)

c# html-agility-pack

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

NotePad ++替换问题

我有一个使用NotePad ++进行大量文本编辑的文件.

例如

<span class="italic">some text</span><span class="bold">another text or some text</span>

我想用NotePad ++的正则表达式取代替换

<span class"italic>some text</span><i>some text</i><span class="bold">another text or some text</span><b>another text or some text</b>

我能够匹配跨度文本然而如何用NotePad ++替换它们

查找<span class="italic">text12312</span>并替换它<i>[a-zA-Z]*</i>实际上将"[a-zA-Z]*"文本放入替换字符串而不是"text12312".

regex notepad++

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

任何人都可以想到一种减少这种嵌套的if-else语句的优雅方法吗?

if (Request.QueryString["UseGroups"] != null)
{
  if (Request.QueryString["UseGroups"] == "True")
  {
    report.IncludeGroupFiltering = true;
  }
  else
  {
    report.IncludeGroupFiltering = false;
  }
}
else
{
  report.IncludeGroupFiltering = false;
}
Run Code Online (Sandbox Code Playgroud)

c#

13
推荐指数
3
解决办法
1152
查看次数

解码Base64图像

我在嵌入的HTML中有一个Base64图像,如何使用C#或VB.net对其进行解码.

c# base64 decode

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

如何让VS 2010识别某些CUDA功能

目前已经CUDA识别键CUDA C/C++函数,例如cudaMalloc,cudaFree,cudaEventCreate等.

它还识别某些类型,如dim3cudaEvent_t.

但是,它不识别其他功能和类型,例如纹理模板,__syncthreads功能或atomicCAS功能.

一切都编译得很好,但我已经厌倦了在整个地方看到红色下划线,我想看到当你输入任何可识别的功能时显示的示例参数.

如何让VS获得这些功能?

intellisense cuda keyword visual-studio-2010 code-completion

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

功能重载

让我们假设我定义了以下三种方法:

int F1(int, int);
int F1(float, float);
Float F1(int, int);
Run Code Online (Sandbox Code Playgroud)

我在这里叫方法F1:

Console.writeline(F1(5,6).ToString()));
Run Code Online (Sandbox Code Playgroud)

它会调用哪种方法,为什么?

.net c#

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

列出标志Enum中的所有位名称

我正在尝试创建一个帮助方法来列出Enum值中设置的所有位的名称(用于记录目的).我想要一个方法,它将返回一些变量中设置的所有枚举值的列表.在我的例子中

[Flag]
Enum HWResponse
{
   None = 0x0,
   Ready = 0x1,
   Working = 0x2,
   Error = 0x80,
}
Run Code Online (Sandbox Code Playgroud)

我喂它0x81,它应该为我提供一个IEnumerable<HWResponse>包含{Ready, Error}.

由于我没有找到更简单的方法,我尝试编写下面的代码,但我无法编译.

public static IEnumerable<T> MaskToList<T>(Enum mask) 
{
  if (typeof(T).IsSubclassOf(typeof(Enum)) == false)
    throw new ArgumentException();

  List<T> toreturn = new List<T>(100);

  foreach(T curValueBit in Enum.GetValues(typeof (T)).Cast<T>())
  {
    Enum bit = ((Enum) curValueBit);  // Here is the error

    if (mask.HasFlag(bit))
      toreturn.Add(curValueBit);
  }

  return toreturn;
}
Run Code Online (Sandbox Code Playgroud)

在这个版本的代码中,编译器抱怨它无法将T强制转换为Enum.

我做错了什么?有更好(更简单)的方法吗?我怎么能演员?

另外,我试着把方法写成

public static IEnumerable<T> MaskToList<T>(Enum mask) where T:Enum
Run Code Online (Sandbox Code Playgroud)

但Enum属于一种禁止'where'语法的特殊类型(使用C#4.0)

c# generics enums enumeration

11
推荐指数
2
解决办法
7550
查看次数