在开发期间我想刷新我的车把模板,如果它们是实时保存的.
我已经有一个websocket通道,可以在文件保存时通知我.此时,我可以通过更新script标记上的哈希来强制重新加载特定模板src.
如何通知所有使用此模板的视图,他们需要刷新并强制刷新?
(我怎样才能找到它们?如何触发刷新?)
出于某种原因,FXCop似乎认为我应该在Dispose中调用GC.SuppressFinalize,无论我是否有终结器.
我错过了什么吗?是否有理由在没有定义终结器的对象上调用GC.SuppressFinalize?
出于某种原因,似乎Adda HashSet上的Contains操作比元素已经存在时的操作要慢HashSet.
这是证明:
Stopwatch watch = new Stopwatch();
int size = 10000;
int iterations = 10000;
var s = new HashSet<int>();
for (int i = 0; i < size; i++) {
s.Add(i);
}
Console.WriteLine(watch.Time(() =>
{
for (int i = 0; i < size; i++) {
s.Add(i);
}
}, iterations));
s = new HashSet<int>();
for (int i = 0; i < size; i++) {
s.Add(i);
}
// outputs: 47,074,764
Console.WriteLine(watch.Time(() =>
{
for …Run Code Online (Sandbox Code Playgroud) 鉴于IEnumerable<T>行数和行数,我想将其转换为IEnumerable<IEnumerable<T>>如此:
输入:
Row Count: 3 List: [1,2,3,4,5,6,7]
产量
[ [1,4,7] [2,5] [3,6] ]
编辑 我希望这适用于任何IEnumerable而不依赖于T是一个Int32.
我怎么能用LINQ做到这一点?
事实证明以下看起来像有效的JavaScript,不是:
<html>
<body>
<script>
json = {test: "</script><script>alert('hello');</script>"};
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
当通过ajax api返回JSON时,相同的文本正如预期的那样工作.但是,当在线渲染时会导致基本的XSS问题.
给定一个任意正确的JSON字符串,我需要做什么服务器端才能使其在线呈现安全?
编辑 理想情况下,我希望修复程序也使用以下字符串:
json = {test: "<\/script><script>alert('hello');<\/script>"};
意思是,我不知道我的底层库是如何编码/char的,它可能已选择对其进行编码,或者它可能没有.(所以它可能正则表达式更强大)
我正在尝试使用带有EFCodeFirst的mvc-mini-profiler我正在创建一个DbProfiledConnection并将其传递给构造中的DbContext,如下所示.应用程序继续按预期工作,sql未向Profiler公开.
public class WebContext : DbContext
{
static DbConnection _connection = new SqlConnection(ConfigurationManager.ConnectionStrings["WebContext"].ConnectionString);
static DbConnection _profiledConnection = MvcMiniProfiler.Data.ProfiledDbConnection.Get(_connection);
public WebContext()
: base(_profiledConnection, true)
{
}
Run Code Online (Sandbox Code Playgroud)
我糟透了
我已修改它,以便在我的UnitOfWork中构建我的WebContext时,我传入ProfiledDbConnection
public UnitOfWork()
{
var profiledConnection = MvcMiniProfiler.Data.ProfiledDbConnection.Get(connection);
this.context = new MyContext(profiledConnection);
}
Run Code Online (Sandbox Code Playgroud)
我已经检查过并且在Application_BeginRequest中设置了MiniProfier Current,当我尝试查询数据库时,它会返回ProfiledDbConnection,并在ProfiledDbProviderServices类中抛出错误.
protected override string GetDbProviderManifestToken(DbConnection connection)
{
return tail.GetProviderManifestToken(connection);
}
Run Code Online (Sandbox Code Playgroud)
此方法返回"提供程序未返回ProviderManifestToken字符串".错误
asp.net-mvc entity-framework entity-framework-4.1 mvc-mini-profiler
我有一些对象:
class Foo {
public Guid id;
public string description;
}
var list = new List<Foo>();
list.Add(new Foo() { id = Guid.Empty, description = "empty" });
list.Add(new Foo() { id = Guid.Empty, description = "empty" });
list.Add(new Foo() { id = Guid.NewGuid(), description = "notempty" });
list.Add(new Foo() { id = Guid.NewGuid(), description = "notempty2" });
Run Code Online (Sandbox Code Playgroud)
我想以这样一种方式处理这个列表,即该id字段是唯一的,并抛弃非唯一对象(基于id).
我能想到的最好的是:
list = list.GroupBy(i => i.id).Select(g=>g.First()).ToList();
Run Code Online (Sandbox Code Playgroud)
是否有更好/更好/更快的方法来实现相同的结果.
该DebuggerStepThrough属性你可以跳过闯入某些方法/类/属性.
在DebuggerStepThrough被忽略时,澄清了c#编译器没有将此属性继承到编译器生成的IEnumerable<T>实现中.
这种失败的一个小例子是:
static void Main(string[] args)
{
var a = SkipMe().ToList();
}
[System.Diagnostics.DebuggerStepThrough]
static IEnumerable<int> SkipMe()
{
// comment out line below and the throw will be stepped over.
yield return 1;
throw new Exception();
}
Run Code Online (Sandbox Code Playgroud)
有没有办法让C#编译器将DebuggerStepThrough属性添加到自动生成的类型?
有没有办法让visual studio跳过调试到[CompilerGenerated]属性的任何类型?
-
附录:一些说明性的截图
按下后的结果 F5

Visual Studio版本:

我们缺少的属性:

我刚刚将Rails站点从Rails 2升级到Rails 3.2.
在我的旧控制器上我有:
class Foo::BarController < ApplicationController
layout nil
...
end
Run Code Online (Sandbox Code Playgroud)
但是现在我升级到Rails 3似乎我需要将其更改为:
layout false
Run Code Online (Sandbox Code Playgroud)
Rails指南的文档声称layout nil应该正常工作:
布局声明在层次结构中向下级联...
class OldPostsController <SpecialPostsController
布局为零
我的Gemfile.lock中有以下相关的gem
宝石
actionpack (3.2.6)
activemodel (= 3.2.6)
activesupport (= 3.2.6)
builder (~> 3.0.0)
erubis (~> 2.7.0)
builder (3.0.0)
erubis (2.7.0)
haml (3.1.6)
jquery-rails (2.0.2)
railties (>= 3.2.0, < 5.0)
Run Code Online (Sandbox Code Playgroud)
这是一个记录在案的变化,还是一个相关的宝石猴子修补的东西?
给出以下HTML:
#header {
position: fixed;
z-index: 1;
background-color: red;
width: 100%;
height: 150px;
top: 0;
}
#drop {
position: absolute;
top: 5px;
width: 100px;
background-color: green;
height: 400px;
z-index: 3;
}
#footer {
position: fixed;
z-index: 2;
background-color: blue;
width: 100%;
height: 150px;
bottom: 0;
}Run Code Online (Sandbox Code Playgroud)
<div id="header">
<div id="drop">
</div>
</div>
<div id="footer">
</div>Run Code Online (Sandbox Code Playgroud)
如何修改CSS只,所以#drop在两个前考虑#header和#footer.虽然保持#footer在前面#header?