我正在处理一个错误.在重新创建以下示例的错误时,我能够确定问题发生的原因.但我坚持要求更好的解决方案.所以给出以下程序:
public interface IFoo<T> {
T OutputType(T param);
}
class Foo : IFoo<Foo> {
public virtual Foo OutputType(Foo param) {
Console.WriteLine("foo");
return param;
}
}
class Bar : Foo, IFoo<Bar> {
public virtual Bar OutputType(Bar param) {
Console.WriteLine("bar");
return param;
}
}
class Program {
static void Main(string[] args) {
Bar bar = new Bar();
CallOutputType(bar);
bar.OutputType(bar);
}
static void CallOutputType<T>(T t) where T : Foo {
t.OutputType(t);
}
}
Run Code Online (Sandbox Code Playgroud)
我期待输出为:
bar
bar
Run Code Online (Sandbox Code Playgroud)
但我得到的是:
foo
bar
Run Code Online (Sandbox Code Playgroud)
看到像这样简化的问题很明显Bar.OutputType没有覆盖Foo.OutputType …
我如何从linq查询中的选择中获取随机行?
我试过了:
Bot bot = (from a in dc.Bot
select a).OrderBy(x => Guid.NewGuid()).First();
Run Code Online (Sandbox Code Playgroud)
但是不起作用,我也得到了同样的结果.
我最近为SQL Management Studio安装了一个用于智能/重构的插件.它导致我的Management Studio执行速度太慢而无法使用.我已经卸载了该产品,但它似乎仍然影响了Management Studio.是否可以在没有启用任何加载项的情况下运行?
.NET中的条件属性允许您在编译时禁用方法的调用.我正在寻找基本相同的东西,但在运行时.我觉得这样的东西应该存在于AOP框架中,但是我不知道这个名字所以我无法弄清楚它是否受支持.
举个例子,我想做这样的事情
[RuntimeConditional("Bob")]
public static void M() {
Console.WriteLine("Executed Class1.M");
}
//.....
//Determines if a method should execute.
public bool RuntimeConditional(string[] conditions) {
bool shouldExecute = conditions[0] == "Bob";
return shouldExecute;
}
Run Code Online (Sandbox Code Playgroud)
因此,在代码中有一个对M方法的调用,它首先调用RuntimeConditional并传入Bob以确定是否应该执行M.
我编写了一些使用父>子选择器来定位元素的CSS.特别是对于表格,所以我可以像这样对页眉和页脚应用某些样式
table > thead > tr > th ...
table > tbody > tr > td ...
//there are other uses in the css as well
Run Code Online (Sandbox Code Playgroud)
这在IE6中除外,效果很好.为了支持IE6,我最好的解决这个css的方法是什么?