小编Mar*_*cel的帖子

为什么List <T>没有实现IOrderedEnumerable <T>?

我想使用有序的枚举,并使用接口作为返回类型而不是具体类型.我需要返回一组有序的对象.但是,当使用IList<T>实现时,我无法返回IOrderedEnumerable<T>,因为IList<T>不继承IOrderedEnumerable<T>.

在下面的示例中,我有一个视图模型,其中包含一个系列的存储库,实现为List<T>一系列对象,因为它们位于一个List<T>有序的对象中.我是一个访问器方法,我想返回一个系列的过滤集,其中只返回特定类型的系列对象,同时保持过滤元素之间的原始顺序.

/// <summary>
/// Represents the view model for this module.
/// </summary>
public class ViewModel : AbstractViewModel
{
    /// <summary>
    /// Gets the series repository.
    /// </summary>
    /// <value>The series repository.</value>
    public IList<ISeries> SeriesRepository { get; private set; }

    //...
}

//8<-----------------------------

    /// <summary>
    /// Gets the series of the specified type.
    /// </summary>
    public IOrderedEnumerable<T> Series<T>() where T : ISeries
    { …
Run Code Online (Sandbox Code Playgroud)

c# ienumerable ilist types where

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

为什么html表单上的重置按钮不会重置隐藏字段?

我发现了令人惊讶的事情:

<html>
<head>
<script type="text/javascript">
function f()
{
document.getElementById("h").value++;
document.getElementById("x").value++;
}
</script>
</head>
<body>

<form>
<input type="hidden" name="hidden" id="h" value="5"/>
<input type="text" id="x" value="5"/>
<input name='clear' type='reset' id='clear' value='Clear'>
</form>

<button type="button" onclick="f()">Increment</button>
<button type="button" onclick="alert(document.getElementById('h').value)">Show hidden</button>

</body>
</html> 
Run Code Online (Sandbox Code Playgroud)

在Firefox 4.0.1中尝试此操作,单击"清除"始终会将文本输入重置为5,但永远不会重置隐藏字段.

我(和其他人)根本没想到这种行为:我们期望隐藏的值也被重置!

任何人都可以指向解释为什么隐藏输入被重置按钮区别对待的文档或规范?

关于为什么这种行为是可取的解释也是受欢迎的.

html forms reset hidden-field

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

Fluent断言:断言一个或另一个值

使用流畅的断言,我想断言给定的字符串包含两个字符串之一:

actual.Should().Contain("oneWay").Or().Should().Contain("anotherWay"); 
// eiter value should pass the assertion.
// for example: "you may do it oneWay." should pass, but
// "you may do it thisWay." should not pass
Run Code Online (Sandbox Code Playgroud)

仅当包含这两个值时,断言才会失败.由于没有Or()运算符,这不起作用(甚至不编译).

这是我现在这样做的方式:

bool isVariant1 = actual.Contains(@"oneWay");
bool isVariant2 = actual.Contains(@"anotherWay");
bool anyVariant = (isVariant1 || isVariant2);
anyVariant.Should().BeTrue("because blahblah. Actual content was: " + actual);
Run Code Online (Sandbox Code Playgroud)

这很冗长,必须手动创建"因为"参数以获得有意义的输出.

有没有办法以更易读的方式做到这一点?一个解决方案也应适用于其他流利的断言类型,如Be(),HaveCount()等...

我在.NET 3.5上使用FluentAssertions 2.2.0.0版,如果这很重要的话.

c# combinations unit-testing assert fluent-assertions

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

Visual Studio中缺少状态栏?

注意:此问答是Kelly Brownsbergers博客的完整副本.我发布它是为了方便他人.

我的状态栏有时会消失.我曾经认为这是由于安装或插件的拙劣造成的.我最近升级到Team System Test Edition,我的状态栏再次消失.在过去的几个星期里,我一直在努力找出完全重新安装的时间.

.net statusbar visual-studio-2008 visual-studio

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

LINQ to SQL in和not in

LINQ to SQL中有什么innot in等于什么 ?

例如

select * from table in ( ...)
and 
select * from table not in (..)
Run Code Online (Sandbox Code Playgroud)

什么等于LINQ to SQL中的上述语句?

c# linq .net-3.5

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

如何提高WinForms MSChart的性能?

我用MSChart创建了一些简单的图表(类型为FastLine),并使用实时数据更新它们,如下所示:

MSCharts等级图表

为此,我将自定义类型的可观察集合绑定到图表,如下所示:

                // set chart data source
            this._Chart.DataSource = value; //is of type ObservableCollection<SpectrumLevels>

            //define x and y value members for each series
            this._Chart.Series[0].XValueMember = "Index";
            this._Chart.Series[1].XValueMember = "Index";
            this._Chart.Series[0].YValueMembers = "Channel0Level";
            this._Chart.Series[1].YValueMembers = "Channel1Level";

            // bind data to chart
            this._Chart.DataBind(); //lasts 1.5 seconds for 8000 points per series
Run Code Online (Sandbox Code Playgroud)

每次刷新时,数据集都会完全更改,而不是滚动更新!

通过分析器,我发现DataBind()呼叫大约需要1.5秒.其他电话可以忽略不计.

我怎样才能让它更快?

  • 我应该使用除ObservableCollection之外的其他类型吗?一个阵列可能?
  • 我应该使用其他形式的数据绑定吗?
  • 我可能错过了MSChart的一些调整吗?
  • 我应该使用一组稀疏的日期,每个像素只有一个值吗?
  • 我是否只是达到了MSCharts的性能限制?

从应用程序的类型来保持它"流畅",我们应该每秒多次刷新.

谢谢你的任何提示!

编辑:leppie提出的解决方案:

                this._Chart.Series[0].Points.Clear();
            foreach (var item in value) //iterates over the list of custom objects
            {
                    this._Chart.Series[0].Points.Add(new DataPoint
                    {
                        XValue …
Run Code Online (Sandbox Code Playgroud)

c# performance mschart winforms

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

如何为所有控制器编写动作过滤器

这是一个示例动作过滤器.我们知道当我们编写一个动作过滤器时,我们需要用这样的属性来装饰控制器,以便将它用于任何控制器.

我想知道是否有任何方法可以编写一个动作过滤器,它将适用于所有控制器,我不需要使用动作过滤器属性来装饰所有控制器.有任何想法吗?

[LogActionFilter]
public class HomeController : Controller
{}

public class LogActionFilter : ActionFilterAttribute

     {
          public override void OnActionExecuting(ActionExecutingContext filterContext)
          {
               Log("OnActionExecuting", filterContext.RouteData);       
          }

          public override void OnActionExecuted(ActionExecutedContext filterContext)
          {
               Log("OnActionExecuted", filterContext.RouteData);       
          }

          private void Log(string methodName, RouteData routeData)
          {
               var controllerName = routeData.Values["controller"];
               var actionName = routeData.Values["action"];
               var message = String.Format("{0} controller:{1} action:{2}", methodName, controllerName, actionName);
               Debug.WriteLine(message, "Action Filter Log");
          }

     }
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc attributes controller action-filter

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

在C#中,是否有一种SortedList <double>允许快速查询(使用LINQ)最近的值?

我正在寻找一个包含一组有序的双值的结构.我想查询此集合以查找与指定参考值最接近的值.

我看过了SortedList<double, double>,对我来说确实很好.但是,因为我不需要明确的键/值对.这似乎对我来说太过分了,我想知道我能不能做得更快.

条件:

  • 结构只初始化一次,永远不会改变(没有插入/删除)
  • 值的数量在100k的范围内.
  • 通常使用新引用来查询结构,这些引用必须快速执行.
  • 为了简单和速度,可以返回低于参考值的集合值,而不是实际上最接近的值
  • 我想在可能的情况下使用LINQ进行查询,以简化代码.
  • 我想尽可能不使用第三方代码..NET 3.5可用.
  • 速度比内存占用更重要

我目前使用以下代码,SortedValues前面提到的SortedList

    IEnumerable<double> nearest = from item in SortedValues.Keys
                                  where item <= suggestion
                                  select item;
    return nearest.ElementAt(nearest.Count() - 1);
Run Code Online (Sandbox Code Playgroud)

我能做得更快吗?

如果这段代码非常安全,我也不是100%肯定的.IEnumerable,我的查询的返回类型不再按定义排序.但是,具有大型测试数据库的单元测试表明它在实践中,所以这对我有用.你有关于这方面的提示吗?

PS我知道有很多类似的问题,但没有一个真正满足我的具体需求.特别是有一个C#数据结构像字典但没有值,但提问者只是想检查存在没找到任何东西.

.net c# linq sorting sortedlist

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

在.NET中将索引放入转发器控件的最简单方法是什么?

我想要一个ASP:NET WebForms Repeater控件来自动将索引放在每个输出行的旁边.我怎样才能做到这一点?

例:

   Name
1  John
2  Jack
3  Joe
Run Code Online (Sandbox Code Playgroud)

c# asp.net repeater asprepeater

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

项目文件预计在

我的代码中有这一行

<script src="@Url.Content("~/Scripts/jquery-1.7.2.min.js")" type="text/javascript"> </script>
Run Code Online (Sandbox Code Playgroud)

而这一部分

jquery-1.7.2.min.js
Run Code Online (Sandbox Code Playgroud)

由Visual Studio突出显示错误

项目文件预计在<path>.

这是什么意思,我该如何解决?

谢谢,

萨钦

javascript asp.net-mvc resharper jquery visual-studio-2010

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