我想使用有序的枚举,并使用接口作为返回类型而不是具体类型.我需要返回一组有序的对象.但是,当使用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) 我发现了令人惊讶的事情:
<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,但永远不会重置隐藏字段.
我(和其他人)根本没想到这种行为:我们期望隐藏的值也被重置!
任何人都可以指向解释为什么隐藏输入被重置按钮区别对待的文档或规范?
关于为什么这种行为是可取的解释也是受欢迎的.
使用流畅的断言,我想断言给定的字符串包含两个字符串之一:
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版,如果这很重要的话.
注意:此问答是Kelly Brownsbergers博客的完整副本.我发布它是为了方便他人.
我的状态栏有时会消失.我曾经认为这是由于安装或插件的拙劣造成的.我最近升级到Team System Test Edition,我的状态栏再次消失.在过去的几个星期里,我一直在努力找出完全重新安装的时间.
LINQ to SQL中有什么in和not in等于什么 ?
例如
select * from table in ( ...)
and
select * from table not in (..)
Run Code Online (Sandbox Code Playgroud)
什么等于LINQ to SQL中的上述语句?
我用MSChart创建了一些简单的图表(类型为FastLine),并使用实时数据更新它们,如下所示:

为此,我将自定义类型的可观察集合绑定到图表,如下所示:
// 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秒.其他电话可以忽略不计.
我怎样才能让它更快?
从应用程序的类型来保持它"流畅",我们应该每秒多次刷新.
谢谢你的任何提示!
编辑: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) 这是一个示例动作过滤器.我们知道当我们编写一个动作过滤器时,我们需要用这样的属性来装饰控制器,以便将它用于任何控制器.
我想知道是否有任何方法可以编写一个动作过滤器,它将适用于所有控制器,我不需要使用动作过滤器属性来装饰所有控制器.有任何想法吗?
[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) 我正在寻找一个包含一组有序的双值的结构.我想查询此集合以查找与指定参考值最接近的值.
我看过了SortedList<double, double>,对我来说确实很好.但是,因为我不需要明确的键/值对.这似乎对我来说太过分了,我想知道我能不能做得更快.
条件:
我目前使用以下代码,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#数据结构像字典但没有值,但提问者只是想检查存在没找到任何东西.
我想要一个ASP:NET WebForms Repeater控件来自动将索引放在每个输出行的旁边.我怎样才能做到这一点?
例:
Name
1 John
2 Jack
3 Joe
Run Code Online (Sandbox Code Playgroud) 我的代码中有这一行
<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>.
这是什么意思,我该如何解决?
谢谢,
萨钦
c# ×6
.net ×2
asp.net-mvc ×2
linq ×2
.net-3.5 ×1
asp.net ×1
asprepeater ×1
assert ×1
attributes ×1
combinations ×1
controller ×1
forms ×1
hidden-field ×1
html ×1
ienumerable ×1
ilist ×1
javascript ×1
jquery ×1
mschart ×1
performance ×1
repeater ×1
reset ×1
resharper ×1
sortedlist ×1
sorting ×1
statusbar ×1
types ×1
unit-testing ×1
where ×1
winforms ×1