を持つメソッドを取得しますServerType
の値。したがって、私がServerType.Server
でこのメソッドを呼び出すと、属性としてServer1
を含むすべてのメソッドが返されます。リフレクションを使用すると、私は、このデリゲートを持っている特定の属性値
私は今のところこれを作った:
public static IEnumerable<Doublet<PacketHandlerAttribute, PacketHandler>> GetPacketHandlers(ServerType server)
{
foreach (Type type in Assembly.GetExecutingAssembly().GetTypes())
{
foreach (MethodInfo method in type.GetMethods())
{
PacketHandlerAttribute attribute = (PacketHandlerAttribute)method.GetCustomAttribute(typeof(PacketHandlerAttribute));
if (attribute != null)
{
if (attribute.Server == server)
{
yield return new Doublet<PacketHandlerAttribute, PacketHandler>(attribute, (PacketHandler)Delegate.CreateDelegate(typeof(PacketHandler), method));
}
}
}
}
}
を私はこれを行うための正しい方法だかどうか尋ねると思った、そしてどのようにこれはLINQを短縮することができますか?
?あなたが望むものははっきりしない。 – Kyle
@Kyle私はそれを確認する方法がわからないので、私はではありません。メソッドに属性が含まれているかどうかをチェックする方法は分かっていますが、 'server'引数を調べる方法がわかりません。 –