我目前正在编写一个小框架,将由公司内部的其他开发人员在内部使用.
我想提供良好的Intellisense信息,但我不知道如何记录抛出的异常.
在以下示例中:
public void MyMethod1()
{
MyMethod2();
// also may throw InvalidOperationException
}
public void MyMethod2()
{
System.IO.File.Open(somepath...); // this may throw FileNotFoundException
// also may throw DivideByZeroException
}
Run Code Online (Sandbox Code Playgroud)
我知道记录异常的标记是:
/// <exception cref="SomeException">when things go wrong.</exception>
Run Code Online (Sandbox Code Playgroud)
我不明白的是如何记录被调用的 代码引发的异常MyMethod1()
?
MyMethod2()
File.Open()
吗?记录可能的异常的最佳方法是什么?
[为css类的HTMLHelper属性启用intellisense]
我有这个HTMLhelper:
public IHtmlString MyTextBoxFor<TModel, TProperty>(
this HtmlHelper<TModel> html,
Expression<Func<TModel, TProperty>> propertyExpression,
string cssClass)
{
// ...
}
Run Code Online (Sandbox Code Playgroud)
我希望Resharper在传递"cssClass"参数的值时为我的应用程序中定义的CSS类提供IntelliSense.
Resharper可以识别一些代码注释属性,但没有一个与将方法参数标记为CSS类直接相关.
我能找到的最接近的是[HtmlAttributeValue(字符串名称)].我试着像这样申请cssClass参数:
public IHtmlString MyTextBoxFor<TModel, TProperty>(
this HtmlHelper<TModel> html,
Expression<Func<TModel, TProperty>> propertyExpression,
[HtmlAttributeValue("class")] string cssClass)
{
// ...
}
Run Code Online (Sandbox Code Playgroud)
但这不起作用.如果Resharper能够识别输入的类并且停止在jQuery选择器表达式中操作未知的CSS类(在上面的帮助器生成的文本框上操作),这也将是非常棒的.
编辑: 这是一个智能感知的屏幕截图,它适用于动作方法的"htmlAttributes"参数.这是通过在参数上使用[HtmlElementAttributes]注释来完成的.
我想要一个类似的注释,让我把css类放在一个字符串参数中,并让相同的intellisense出现在css类中.