| 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 PropertyInfoImpl : PropertyInfo |
| 32 |
{ |
| 33 |
private readonly ModuleReader module; |
| 34 |
private readonly Type declaringType; |
| 35 |
private readonly int index; |
| 36 |
private PropertySignature sig; |
| 37 |
private bool isPublic; |
| 38 |
private bool isNonPrivate; |
| 39 |
private bool isStatic; |
| 40 |
private bool flagsCached; |
| 41 |
|
| 42 |
internal PropertyInfoImpl(ModuleReader module, Type declaringType, int index) |
| 43 |
{ |
| 44 |
this.module = module; |
| 45 |
this.declaringType = declaringType; |
| 46 |
this.index = index; |
| 47 |
} |
| 48 |
|
| 49 |
public override bool Equals(object obj) |
| 50 |
{ |
| 51 |
PropertyInfoImpl other = obj as PropertyInfoImpl; |
| 52 |
return other != null && other.DeclaringType == declaringType && other.index == index; |
| 53 |
} |
| 54 |
|
| 55 |
public override int GetHashCode() |
| 56 |
{ |
| 57 |
return declaringType.GetHashCode() * 77 + index; |
| 58 |
} |
| 59 |
|
| 60 |
internal override PropertySignature PropertySignature |
| 61 |
{ |
| 62 |
get |
| 63 |
{ |
| 64 |
if (sig == null) |
| 65 |
{ |
| 66 |
sig = PropertySignature.ReadSig(module, module.GetBlob(module.Property.records[index].Type), declaringType); |
| 67 |
} |
| 68 |
return sig; |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
public override PropertyAttributes Attributes |
| 73 |
{ |
| 74 |
get { return (PropertyAttributes)module.Property.records[index].Flags; } |
| 75 |
} |
| 76 |
|
| 77 |
public override object GetRawConstantValue() |
| 78 |
{ |
| 79 |
return module.Constant.GetRawConstantValue(module, this.MetadataToken); |
| 80 |
} |
| 81 |
|
| 82 |
public override bool CanRead |
| 83 |
{ |
| 84 |
get { return GetGetMethod(true) != null; } |
| 85 |
} |
| 86 |
|
| 87 |
public override bool CanWrite |
| 88 |
{ |
| 89 |
get { return GetSetMethod(true) != null; } |
| 90 |
} |
| 91 |
|
| 92 |
public override MethodInfo GetGetMethod(bool nonPublic) |
| 93 |
{ |
| 94 |
return module.MethodSemantics.GetMethod(module, this.MetadataToken, nonPublic, MethodSemanticsTable.Getter); |
| 95 |
} |
| 96 |
|
| 97 |
public override MethodInfo GetSetMethod(bool nonPublic) |
| 98 |
{ |
| 99 |
return module.MethodSemantics.GetMethod(module, this.MetadataToken, nonPublic, MethodSemanticsTable.Setter); |
| 100 |
} |
| 101 |
|
| 102 |
public override MethodInfo[] GetAccessors(bool nonPublic) |
| 103 |
{ |
| 104 |
return module.MethodSemantics.GetMethods(module, this.MetadataToken, nonPublic, MethodSemanticsTable.Getter | MethodSemanticsTable.Setter | MethodSemanticsTable.Other); |
| 105 |
} |
| 106 |
|
| 107 |
public override Type DeclaringType |
| 108 |
{ |
| 109 |
get { return declaringType; } |
| 110 |
} |
| 111 |
|
| 112 |
public override Module Module |
| 113 |
{ |
| 114 |
get { return module; } |
| 115 |
} |
| 116 |
|
| 117 |
public override int MetadataToken |
| 118 |
{ |
| 119 |
get { return (PropertyTable.Index << 24) + index + 1; } |
| 120 |
} |
| 121 |
|
| 122 |
public override string Name |
| 123 |
{ |
| 124 |
get { return module.GetString(module.Property.records[index].Name); } |
| 125 |
} |
| 126 |
|
| 127 |
internal override bool IsPublic |
| 128 |
{ |
| 129 |
get |
| 130 |
{ |
| 131 |
if (!flagsCached) |
| 132 |
{ |
| 133 |
ComputeFlags(); |
| 134 |
} |
| 135 |
return isPublic; |
| 136 |
} |
| 137 |
} |
| 138 |
|
| 139 |
internal override bool IsNonPrivate |
| 140 |
{ |
| 141 |
get |
| 142 |
{ |
| 143 |
if (!flagsCached) |
| 144 |
{ |
| 145 |
ComputeFlags(); |
| 146 |
} |
| 147 |
return isNonPrivate; |
| 148 |
} |
| 149 |
} |
| 150 |
|
| 151 |
internal override bool IsStatic |
| 152 |
{ |
| 153 |
get |
| 154 |
{ |
| 155 |
if (!flagsCached) |
| 156 |
{ |
| 157 |
ComputeFlags(); |
| 158 |
} |
| 159 |
return isStatic; |
| 160 |
} |
| 161 |
} |
| 162 |
|
| 163 |
private void ComputeFlags() |
| 164 |
{ |
| 165 |
module.MethodSemantics.ComputeFlags(module, this.MetadataToken, out isPublic, out isNonPrivate, out isStatic); |
| 166 |
flagsCached = true; |
| 167 |
} |
| 168 |
|
| 169 |
internal override bool IsBaked |
| 170 |
{ |
| 171 |
get { return true; } |
| 172 |
} |
| 173 |
|
| 174 |
internal override int GetCurrentToken() |
| 175 |
{ |
| 176 |
return this.MetadataToken; |
| 177 |
} |
| 178 |
} |
| 179 |
} |