public class EnumRouteConstraint<T> : IRouteConstraint
where T : struct
{
private static readonly Lazy<HashSet<string>> _enumNames; // <--
static EnumRouteConstraint()
{
if (!typeof(T).IsEnum)
{
throw new ArgumentException(
Resources.Error.EnumRouteConstraint.FormatWith(typeof(T).FullName));
}
string[] names = Enum.GetNames(typeof(T));
_enumNames = new Lazy<HashSet<string>>(() => new HashSet<string>
(
names.Select(name => name), StringComparer.InvariantCultureIgnoreCase
));
}
public bool Match(HttpContextBase httpContext, Route route,
string parameterName, RouteValueDictionary values,
RouteDirection routeDirection)
{
bool match = _enumNames.Value.Contains(values[parameterName].ToString());
return match;
}
}
Run Code Online (Sandbox Code Playgroud)
这是错的吗?我会假设这实际上有一个static readonly字段用于EnumRouteConstraint<T>我碰巧实例化的每一个.
在此查询中:
public static IEnumerable<IServerOnlineCharacter> GetUpdated()
{
var context = DataContext.GetDataContext();
return context.ServerOnlineCharacters
.OrderBy(p => p.ServerStatus.ServerDateTime)
.GroupBy(p => p.RawName)
.Select(p => p.Last());
}
Run Code Online (Sandbox Code Playgroud)
我不得不把它切换到这个才能工作
public static IEnumerable<IServerOnlineCharacter> GetUpdated()
{
var context = DataContext.GetDataContext();
return context.ServerOnlineCharacters
.OrderByDescending(p => p.ServerStatus.ServerDateTime)
.GroupBy(p => p.RawName)
.Select(p => p.FirstOrDefault());
}
Run Code Online (Sandbox Code Playgroud)
我甚p.First()至无法使用镜像第一个查询.
为什么在这样一个强大的ORM系统中存在这样的基本限制?
表达式树可能不包含使用可选参数的调用或调用
return this.RedirectToAction<MerchantController>(x => x.Edit(merchantId));
Run Code Online (Sandbox Code Playgroud)
编辑有第二个可空的参数.
为什么是这样?
做其中任何一项都有什么实质性的区别吗?
delete a.x;
Run Code Online (Sandbox Code Playgroud)
VS
a.x = undefined;
Run Code Online (Sandbox Code Playgroud)
哪里
a = {
x: 'boo'
};
Run Code Online (Sandbox Code Playgroud)
可以说它们是等价的吗?
(我没有考虑像"V8喜欢不用delete得更好"之类的东西)
应该何时在实际的表上使用View?我应该期望这会产生什么收益?
总的来说,在表格上使用视图有什么好处?我不应该以视图首先看起来的方式设计表格吗?
我想设置code不在a标签内的元素.
实现这一目标的最佳方法是什么?
code:not(a code)似乎根本不起作用,至少在Chrome上,尽管看起来应该如此
我也无法从控制台上工作.
我可以使用其他任何css方法吗?
有没有办法全局声明#define?
就像我想拥有一个文件,例如,
#define MONO
Run Code Online (Sandbox Code Playgroud)
我希望所有源代码文件都知道这个预处理器指令已经定义.我怎么做到这一点?
除了今天之外,我如何本地化DayOfWeek?
以下工作在当天适用:
DateTime.Now.ToString("dddd", new CultureInfo("it-IT"));
Run Code Online (Sandbox Code Playgroud)
但是我如何本地化一周的所有日子?
编辑:我想出的一个可能(也可能是非常非常错误的)解决方案可能是创建DateTime一整周的值,然后使用date.ToString("dddd", new CultureInfo("it-IT"));它们,但这在很多层面上似乎都是错误的.