onlyexceptionssuffixexceptionrule.cs
来自「全功能c#编译器」· CS 代码 · 共 81 行
CS
81 行
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Mike Krueger" email="mike@icsharpcode.net"/>
// <version value="$version"/>
// </file>
using System;
using System.Reflection;
namespace ICSharpCode.AssemblyAnalyser.Rules
{
/// <summary>
/// Description of OnlyExceptionsSuffixExceptionRule.
/// </summary>
public class OnlyExceptionsSuffixExceptionRule : AbstractReflectionRule, ITypeRule
{
public override string Description {
get {
return "${res:ICSharpCode.AssemblyAnalyser.Rules.OnlyExceptionsSuffixException.Description}";
}
}
public override string Details {
get {
return "${res:ICSharpCode.AssemblyAnalyser.Rules.OnlyExceptionsSuffixException.Details}";
}
}
public OnlyExceptionsSuffixExceptionRule()
{
base.certainty = 99;
base.priorityLevel = PriorityLevel.CriticalError;
}
public Resolution Check(Type type)
{
if (!typeof(System.Exception).IsAssignableFrom(type) && type.Name.EndsWith("Exception")) {
return new Resolution(this, "${res:ICSharpCode.AssemblyAnalyser.Rules.OnlyExceptionsSuffixException.Resolution}", type.FullName, new string[,] { { "TypeName", type.FullName }});
}
return null;
}
}
}
#region Unit Test
#if TEST
namespace ICSharpCode.AssemblyAnalyser.Rules
{
using NUnit.Framework;
[TestFixture]
public class OnlyExceptionsSuffixExceptionRuleTest
{
class MyException : System.Exception
{
}
class OtherClass
{}
[Test]
public void TestCorrectException()
{
OnlyExceptionsSuffixExceptionRule rule = new OnlyExceptionsSuffixExceptionRule();
Assertion.AssertNull(rule.Check(typeof(MyException)));
Assertion.AssertNull(rule.Check(typeof(OtherClass)));
}
class NotAnException
{
}
[Test]
public void TestIncorrectException()
{
OnlyExceptionsSuffixExceptionRule rule = new OnlyExceptionsSuffixExceptionRule();
Assertion.AssertNotNull(rule.Check(typeof(NotAnException)));
}
}
}
#endif
#endregion
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?