据我所知,根据HTML规范,向元素添加自定义属性是无效的.这对XHTML也无效吗?
我认为XHTML是XML系列的一部分,因此是可扩展的.可扩展,是不是可以使用自定义属性?
戴夫
我发现很多情况我认为我可以使用relfection来解决问题,但我通常不这样做,因为我听到了很多"不使用反射,效率太低"的说法.
现在我处在一个我遇到问题的位置,我找不到任何其他解决方案而不是使用反射new T()
,如本问答中所述.
所以我想知道是否有人可以告诉我反思的具体用途,以及是否有一套指导方针来表明它何时合适以及什么时候不合适?
该System.DateTime
对象具有等方法AddYears(), AddMonths(), AddDays(), AddSeconds()
等.
我注意到没有AddWeeks()
.为什么是这样?
此外,我的要求是从52周前获得价格值.我知道这相当于1年,但他们具体约52周.
我这样做会是一样的:
yearOldPrice = _priceService.GetPriceForDate(price.Date.AddYears(-1));
Run Code Online (Sandbox Code Playgroud)
如
yearOldPrice = _priceService.GetPriceForDate(price.Date.AddDays(-7 * 52));
Run Code Online (Sandbox Code Playgroud)
我问这个假设.AddDays(-7 * 52)
是一样的.AddWeeks(-52)
,因为一周有7天.
我有以下扩展方法,它(自然地)存在于静态类中.
public static class MyExtensions
{
[Dependency]
private static IMyDataContext _myDataContext { get; set; }
public static void MyExtensionMethod(this MyType myType)
{
// do stuff
_myDataContext.DoAwesomeThing();
}
}
Run Code Online (Sandbox Code Playgroud)
该_myDataContext
对象为null.
通常我会使用UnityContainer
注册类型,但由于这是一个静态类,我不能.
我需要实例化_ myDataContext
以便在需要时它不为空?
是否可以指定SVG图像应该在CMYK中产生输出?如果是这样,这是一项大任务吗?如果图像的颜色是用RGB指定的,那么将它们转换为CMYK会很困难吗?
public readonly IEnumerable<string> PeriodToSelect = new string[] { "MONTH" };
var dataCollection = from p in somedata
from h in p.somemoredate
where h.Year > (DateTime.Now.Year - 2)
where PeriodToSelect.Contains(h.TimePeriod)
select new
{
p.Currency,
h.Year.Month, h.Value
};
Run Code Online (Sandbox Code Playgroud)
有人可以告诉我为什么在下面的代码行中抛出异常?
int count = dataCollection.Count();
Run Code Online (Sandbox Code Playgroud)
这是例外:
System.NullReferenceException: Object reference not set to an instance of an object.
at System.Linq.Enumerable.<SelectManyIterator>d__31`3.MoveNext()
at System.Linq.Enumerable.<SelectManyIterator>d__31`3.MoveNext()
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at ...
Run Code Online (Sandbox Code Playgroud) 我目前正在为客户进行网站开发.该站点将托管在客户主站点的子域中.客户的主要网站是
www.xyz.com
我正在处理的网站将托管在
funds.xyz.com
访问www.xyz.com的任何人都会在其计算机上写入一个cookie,其中包含指定用户所在区域的数据.我需要在我的网站上提供这些数据.我可以访问这个cookie吗?
我正在尝试实现根据主机缓存某些页面的功能.这是因为我可以拥有具有相同参数的页面的多个版本,并且请求方面唯一的区别是正在请求的主机.
因此,例如这两个URL将请求相同的页面,但它们的样式不同:
http://www.a.com/something/specific
Run Code Online (Sandbox Code Playgroud)
和
http://www.b.com/something/specific
Run Code Online (Sandbox Code Playgroud)
我将通过这里概述的示例:
http://msdn.microsoft.com/en-us/library/5ecf4420%28v=VS.90%29.aspx
但这对我没有意义.
我已将此添加到我的global.asax中:
public override string GetVaryByCustomString(HttpContext context, string arg)
{
if (arg == "host")
{
return "host=" + context.Request.Url.Host;
}
return base.GetVaryByCustomString(context, arg);
}
Run Code Online (Sandbox Code Playgroud)
并且示例声明"要以编程方式设置自定义字符串,请调用SetVaryByCustom方法并将其传递给要使用的自定义字符串",代码类似于以下内容:
Response.Cache.SetVaryByCustom("host");
Run Code Online (Sandbox Code Playgroud)
问题是我不知道该怎么办.我已经添加了前一行,MvcApplication_EndRequest
因为它似乎有意义,但我不认为这是正确的,因为当我设置断点时,GetVaryByCustomString
它们永远不会被击中.
有人可以告诉我我在这里失踪了吗?或者如果我需要以不同方式做到这一点?
编辑: RE Darin的答案如下,我已经用以下方式装饰我的行为:
[CustomOutputCache(CacheProfile = "FundScreener")] // or similar depending on the action
Run Code Online (Sandbox Code Playgroud)
其中CustomOutputCacheAttribute
定义为:
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public class CustomOutputCacheAttribute: OutputCacheAttribute
{
public override void OnResultExecuted(ResultExecutedContext filterContext)
{
AddLabelFilesDependency(filterContext);
base.OnResultExecuted(filterContext);
}
private static void AddLabelFilesDependency(ControllerContext …
Run Code Online (Sandbox Code Playgroud) 我有以下内容,但它失败了NullReferenceException
:
<td>@item.FundPerformance.Where(xx => fund.Id == xx.Id).FirstOrDefault().OneMonth ?? -</td>
Run Code Online (Sandbox Code Playgroud)
OneMonth
被定义为
public virtual decimal? OneMonth { get; set; }
Run Code Online (Sandbox Code Playgroud)
并且在失败时它的值为null.
我认为Null Coalesce运算符会测试它是否为null,如果是,则将值返回给运算符右侧?
为了使这项工作,我需要改变什么?
本文说明您无法使用Lambda表达式取消订阅事件.
例如,您可以订阅如下:
d.Barked += (s, e) => Console.WriteLine("Bark: {0}", e);
Run Code Online (Sandbox Code Playgroud)
但是你不能这样取消订阅:
d.Barked -= (s, e) => Console.WriteLine("Bark: {0}", e);
Run Code Online (Sandbox Code Playgroud)
为什么?这与代表取消订阅有什么区别,例如
EventHandler<string> handler = (s, e) => Console.WriteLine("Bark: {0}", e);
d.Barked += handler;
// ...
d.Barked -= handler;
Run Code Online (Sandbox Code Playgroud)