eventargssuffixiseventargsrule.cs

来自「全功能c#编译器」· CS 代码 · 共 73 行

CS
73
字号
// <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 AttributeSuffixIsAttribute.	
	/// </summary>
	public class EventArgsSuffixIsEventArgsRule : AbstractReflectionRule, ITypeRule
	{
		public override string Description {
			get {
				return "${res:ICSharpCode.AssemblyAnalyser.Rules.EventArgsSuffixIsEventArgs.Description}";
			}
		}
		
		public override string Details {
			get {
				return "${res:ICSharpCode.AssemblyAnalyser.Rules.EventArgsSuffixIsEventArgs.Details}";
			}
		}
		
		public Resolution Check(Type type)
		{
			if (typeof(System.EventArgs).IsAssignableFrom(type) && !type.Name.EndsWith("EventArgs")) {
				return new Resolution(this, "${res:ICSharpCode.AssemblyAnalyser.Rules.EventArgsSuffixIsEventArgs.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 EventArgsSuffixIsEventArgsRuleTest
	{
		class CorrectEventArgs : System.EventArgs
		{
		}
		[Test]
		public void TestCorrectEventArgs()
		{
			EventArgsSuffixIsEventArgsRule rule = new EventArgsSuffixIsEventArgsRule();
			Assertion.AssertNull(rule.Check(typeof(CorrectEventArgs)));
		}
		
		class IncorrectEventArgsWithWrongSuffix : System.EventArgs
		{
		}
		[Test]
		public void TestIncorrectEventArgs()
		{
			EventArgsSuffixIsEventArgsRule rule = new EventArgsSuffixIsEventArgsRule();
			Assertion.AssertNotNull(rule.Check(typeof(IncorrectEventArgsWithWrongSuffix)));
		}
		
	}
}
#endif
#endregion

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?