| 1 |
/* |
| 2 |
Copyright (C) 2009-2012 Jeroen Frijters |
| 3 |
|
| 4 |
This software is provided 'as-is', without any express or implied |
| 5 |
warranty. In no event will the authors be held liable for any damages |
| 6 |
arising from the use of this software. |
| 7 |
|
| 8 |
Permission is granted to anyone to use this software for any purpose, |
| 9 |
including commercial applications, and to alter it and redistribute it |
| 10 |
freely, subject to the following restrictions: |
| 11 |
|
| 12 |
1. The origin of this software must not be misrepresented; you must not |
| 13 |
claim that you wrote the original software. If you use this software |
| 14 |
in a product, an acknowledgment in the product documentation would be |
| 15 |
appreciated but is not required. |
| 16 |
2. Altered source versions must be plainly marked as such, and must not be |
| 17 |
misrepresented as being the original software. |
| 18 |
3. This notice may not be removed or altered from any source distribution. |
| 19 |
|
| 20 |
Jeroen Frijters |
| 21 |
[email protected] |
| 22 |
|
| 23 |
*/ |
| 24 |
using System; |
| 25 |
using System.Collections.Generic; |
| 26 |
using System.Text; |
| 27 |
using IKVM.Reflection.Metadata; |
| 28 |
|
| 29 |
namespace IKVM.Reflection.Reader |
| 30 |
{ |
| 31 |
sealed class EventInfoImpl : EventInfo |
| 32 |
{ |
| 33 |
private readonly ModuleReader module; |
| 34 |
private readonly Type declaringType; |
| 35 |
private readonly int index; |
| 36 |
private bool isPublic; |
| 37 |
private bool isNonPrivate; |
| 38 |
private bool isStatic; |
| 39 |
private bool flagsCached; |
| 40 |
|
| 41 |
internal EventInfoImpl(ModuleReader module, Type declaringType, int index) |
| 42 |
{ |
| 43 |
this.module = module; |
| 44 |
this.declaringType = declaringType; |
| 45 |
this.index = index; |
| 46 |
} |
| 47 |
|
| 48 |
public override bool Equals(object obj) |
| 49 |
{ |
| 50 |
EventInfoImpl other = obj as EventInfoImpl; |
| 51 |
return other != null && other.declaringType == declaringType && other.index == index; |
| 52 |
} |
| 53 |
|
| 54 |
public override int GetHashCode() |
| 55 |
{ |
| 56 |
return declaringType.GetHashCode() * 123 + index; |
| 57 |
} |
| 58 |
|
| 59 |
public override EventAttributes Attributes |
| 60 |
{ |
| 61 |
get { return (EventAttributes)module.Event.records[index].EventFlags; } |
| 62 |
} |
| 63 |
|
| 64 |
public override MethodInfo GetAddMethod(bool nonPublic) |
| 65 |
{ |
| 66 |
return module.MethodSemantics.GetMethod(module, this.MetadataToken, nonPublic, MethodSemanticsTable.AddOn); |
| 67 |
} |
| 68 |
|
| 69 |
public override MethodInfo GetRaiseMethod(bool nonPublic) |
| 70 |
{ |
| 71 |
return module.MethodSemantics.GetMethod(module, this.MetadataToken, nonPublic, MethodSemanticsTable.Fire); |
| 72 |
} |
| 73 |
|
| 74 |
public override MethodInfo GetRemoveMethod(bool nonPublic) |
| 75 |
{ |
| 76 |
return module.MethodSemantics.GetMethod(module, this.MetadataToken, nonPublic, MethodSemanticsTable.RemoveOn); |
| 77 |
} |
| 78 |
|
| 79 |
public override MethodInfo[] GetOtherMethods(bool nonPublic) |
| 80 |
{ |
| 81 |
return module.MethodSemantics.GetMethods(module, this.MetadataToken, nonPublic, MethodSemanticsTable.Other); |
| 82 |
} |
| 83 |
|
| 84 |
public override MethodInfo[] __GetMethods() |
| 85 |
{ |
| 86 |
return module.MethodSemantics.GetMethods(module, this.MetadataToken, true, -1); |
| 87 |
} |
| 88 |
|
| 89 |
public override Type EventHandlerType |
| 90 |
{ |
| 91 |
get { return module.ResolveType(module.Event.records[index].EventType, declaringType); } |
| 92 |
} |
| 93 |
|
| 94 |
public override string Name |
| 95 |
{ |
| 96 |
get { return module.GetString(module.Event.records[index].Name); } |
| 97 |
} |
| 98 |
|
| 99 |
public override Type DeclaringType |
| 100 |
{ |
| 101 |
get { return declaringType; } |
| 102 |
} |
| 103 |
|
| 104 |
public override Module Module |
| 105 |
{ |
| 106 |
get { return module; } |
| 107 |
} |
| 108 |
|
| 109 |
public override int MetadataToken |
| 110 |
{ |
| 111 |
get { return (EventTable.Index << 24) + index + 1; } |
| 112 |
} |
| 113 |
|
| 114 |
internal override bool IsPublic |
| 115 |
{ |
| 116 |
get |
| 117 |
{ |
| 118 |
if (!flagsCached) |
| 119 |
{ |
| 120 |
ComputeFlags(); |
| 121 |
} |
| 122 |
return isPublic; |
| 123 |
} |
| 124 |
} |
| 125 |
|
| 126 |
internal override bool IsNonPrivate |
| 127 |
{ |
| 128 |
get |
| 129 |
{ |
| 130 |
if (!flagsCached) |
| 131 |
{ |
| 132 |
ComputeFlags(); |
| 133 |
} |
| 134 |
return isNonPrivate; |
| 135 |
} |
| 136 |
} |
| 137 |
|
| 138 |
internal override bool IsStatic |
| 139 |
{ |
| 140 |
get |
| 141 |
{ |
| 142 |
if (!flagsCached) |
| 143 |
{ |
| 144 |
ComputeFlags(); |
| 145 |
} |
| 146 |
return isStatic; |
| 147 |
} |
| 148 |
} |
| 149 |
|
| 150 |
private void ComputeFlags() |
| 151 |
{ |
| 152 |
module.MethodSemantics.ComputeFlags(module, this.MetadataToken, out isPublic, out isNonPrivate, out isStatic); |
| 153 |
flagsCached = true; |
| 154 |
} |
| 155 |
|
| 156 |
internal override bool IsBaked |
| 157 |
{ |
| 158 |
get { return true; } |
| 159 |
} |
| 160 |
|
| 161 |
internal override int GetCurrentToken() |
| 162 |
{ |
| 163 |
return this.MetadataToken; |
| 164 |
} |
| 165 |
} |
| 166 |
} |