Created
May 19, 2012 02:23
-
-
Save pinzolo/2728701 to your computer and use it in GitHub Desktop.
Typeクラス拡張
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Reflection; | |
namespace MktSys.Lib.Extensions | |
{ | |
/// <summary> | |
/// Type クラス拡張メソッド定義クラス | |
/// </summary> | |
public static class TypeExtension | |
{ | |
/// <summary> | |
/// 指定の型が指定のインターフェースを実装しているかどうかを判別する。 | |
/// </summary> | |
/// <param name="type">型情報</param> | |
/// <param name="i">インターフェース型情報</param> | |
/// <returns>指定のインターフェースを実装しているならば true、していない場合 false</returns> | |
public static bool Implements(this Type type, Type i) | |
{ | |
if (i == null) | |
{ | |
throw new ArgumentNullException("i"); | |
} | |
if (!i.IsInterface) | |
{ | |
throw new ArgumentException("インターフェース型が指定されていません。", "i"); | |
} | |
//var filter = new TypeFilter((t, obj) => t == (System.Type)obj); | |
//return type.FindInterfaces(filter, i).Length > 0; | |
// こっちのほうが簡単だった | |
return i.IsAssignableFrom(t); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment