1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196
|
/*
Copyright (C) 2011-2012 Jeroen Frijters
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Jeroen Frijters
jeroen@frijters.net
*/
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace IKVM.Reflection
{
[Serializable]
public sealed class MissingAssemblyException : InvalidOperationException
{
[NonSerialized]
private readonly MissingAssembly assembly;
internal MissingAssemblyException(MissingAssembly assembly)
: base("Assembly '" + assembly.FullName + "' is a missing assembly and does not support the requested operation.")
{
this.assembly = assembly;
}
private MissingAssemblyException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
: base(info, context)
{
}
public Assembly Assembly
{
get { return assembly; }
}
}
[Serializable]
public sealed class MissingModuleException : InvalidOperationException
{
[NonSerialized]
private readonly MissingModule module;
internal MissingModuleException(MissingModule module)
: base("Module from missing assembly '" + module.Assembly.FullName + "' does not support the requested operation.")
{
this.module = module;
}
private MissingModuleException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
: base(info, context)
{
}
public Module Module
{
get { return module; }
}
}
[Serializable]
public sealed class MissingMemberException : InvalidOperationException
{
[NonSerialized]
private readonly MemberInfo member;
internal MissingMemberException(MemberInfo member)
: base("Member '" + member + "' is a missing member and does not support the requested operation.")
{
this.member = member;
}
private MissingMemberException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
: base(info, context)
{
}
public MemberInfo MemberInfo
{
get { return member; }
}
}
public struct MissingGenericMethodBuilder
{
private readonly MissingMethod method;
public MissingGenericMethodBuilder(Type declaringType, CallingConventions callingConvention, string name, int genericParameterCount)
{
method = new MissingMethod(declaringType, name, new MethodSignature(null, null, new PackedCustomModifiers(), callingConvention, genericParameterCount));
}
public Type[] GetGenericArguments()
{
return method.GetGenericArguments();
}
public void SetSignature(Type returnType, CustomModifiers returnTypeCustomModifiers, Type[] parameterTypes, CustomModifiers[] parameterTypeCustomModifiers)
{
method.signature = new MethodSignature(
returnType ?? method.Module.universe.System_Void,
Util.Copy(parameterTypes),
PackedCustomModifiers.CreateFromExternal(returnTypeCustomModifiers, parameterTypeCustomModifiers, parameterTypes.Length),
method.signature.CallingConvention,
method.signature.GenericParameterCount);
}
[Obsolete("Please use SetSignature(Type, CustomModifiers, Type[], CustomModifiers[]) instead.")]
public void SetSignature(Type returnType, Type[] returnTypeRequiredCustomModifiers, Type[] returnTypeOptionalCustomModifiers, Type[] parameterTypes, Type[][] parameterTypeRequiredCustomModifiers, Type[][] parameterTypeOptionalCustomModifiers)
{
method.signature = new MethodSignature(
returnType ?? method.Module.universe.System_Void,
Util.Copy(parameterTypes),
PackedCustomModifiers.CreateFromExternal(returnTypeOptionalCustomModifiers, returnTypeRequiredCustomModifiers, parameterTypeOptionalCustomModifiers, parameterTypeRequiredCustomModifiers, parameterTypes.Length),
method.signature.CallingConvention,
method.signature.GenericParameterCount);
}
public MethodInfo Finish()
{
return method;
}
}
sealed class MissingAssembly : Assembly
{
private readonly MissingModule module;
internal MissingAssembly(Universe universe, string name)
: base(universe)
{
module = new MissingModule(this, -1);
this.fullName = name;
}
public override Type[] GetTypes()
{
throw new MissingAssemblyException(this);
}
public override AssemblyName GetName()
{
return new AssemblyName(fullName);
}
public override string ImageRuntimeVersion
{
get { throw new MissingAssemblyException(this); }
}
public override Module ManifestModule
{
get { return module; }
}
public override MethodInfo EntryPoint
{
get { throw new MissingAssemblyException(this); }
}
public override string Location
{
get { throw new MissingAssemblyException(this); }
}
public override AssemblyName[] GetReferencedAssemblies()
{
throw new MissingAssemblyException(this);
}
public override Module[] GetModules(bool getResourceModules)
{
throw new MissingAssemblyException(this);
}
public override Module[] GetLoadedModules(bool getResourceModules)
{
throw new MissingAssemblyException(this);
}
public override Module GetModule(string name)
{
throw new MissingAssemblyException(this);
}
public override string[] GetManifestResourceNames()
{
throw new MissingAssemblyException(this);
}
public override ManifestResourceInfo GetManifestResourceInfo(string resourceName)
{
throw new MissingAssemblyException(this);
}
public override System.IO.Stream GetManifestResourceStream(string resourceName)
{
throw new MissingAssemblyException(this);
}
public override bool __IsMissing
{
get { return true; }
}
internal override Type FindType(TypeName typeName)
{
return null;
}
internal override Type FindTypeIgnoreCase(TypeName lowerCaseName)
{
return null;
}
internal override IList<CustomAttributeData> GetCustomAttributesData(Type attributeType)
{
throw new MissingAssemblyException(this);
}
}
sealed class MissingModule : NonPEModule
{
private readonly Assembly assembly;
private readonly int index;
internal MissingModule(Assembly assembly, int index)
: base(assembly.universe)
{
this.assembly = assembly;
this.index = index;
}
public override int MDStreamVersion
{
get { throw new MissingModuleException(this); }
}
public override Assembly Assembly
{
get { return assembly; }
}
public override string FullyQualifiedName
{
get { throw new MissingModuleException(this); }
}
public override string Name
{
get
{
if (index == -1)
{
throw new MissingModuleException(this);
}
return assembly.ManifestModule.GetString(assembly.ManifestModule.File.records[index].Name);
}
}
public override Guid ModuleVersionId
{
get { throw new MissingModuleException(this); }
}
public override string ScopeName
{
get { throw new MissingModuleException(this); }
}
internal override Type FindType(TypeName typeName)
{
return null;
}
internal override Type FindTypeIgnoreCase(TypeName lowerCaseName)
{
return null;
}
internal override void GetTypesImpl(System.Collections.Generic.List<Type> list)
{
throw new MissingModuleException(this);
}
public override void __GetDataDirectoryEntry(int index, out int rva, out int length)
{
throw new MissingModuleException(this);
}
public override IList<CustomAttributeData> __GetPlaceholderAssemblyCustomAttributes(bool multiple, bool security)
{
throw new MissingModuleException(this);
}
public override long __RelativeVirtualAddressToFileOffset(int rva)
{
throw new MissingModuleException(this);
}
public override __StandAloneMethodSig __ResolveStandAloneMethodSig(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
{
throw new MissingModuleException(this);
}
public override int __Subsystem
{
get { throw new MissingModuleException(this); }
}
internal override void ExportTypes(int fileToken, IKVM.Reflection.Emit.ModuleBuilder manifestModule)
{
throw new MissingModuleException(this);
}
public override void GetPEKind(out PortableExecutableKinds peKind, out ImageFileMachine machine)
{
throw new MissingModuleException(this);
}
public override bool __IsMissing
{
get { return true; }
}
protected override Exception InvalidOperationException()
{
return new MissingModuleException(this);
}
protected override Exception NotSupportedException()
{
return new MissingModuleException(this);
}
protected override Exception ArgumentOutOfRangeException()
{
return new MissingModuleException(this);
}
public override byte[] __ModuleHash
{
get
{
if (index == -1)
{
throw new MissingModuleException(this);
}
if (assembly.ManifestModule.File.records[index].HashValue == 0)
{
return null;
}
IKVM.Reflection.Reader.ByteReader br = assembly.ManifestModule.GetBlob(assembly.ManifestModule.File.records[index].HashValue);
return br.ReadBytes(br.Length);
}
}
}
sealed class MissingType : Type
{
private readonly Module module;
private readonly Type declaringType;
private readonly string ns;
private readonly string name;
private Type[] typeArgs;
private int token;
private int flags;
internal MissingType(Module module, Type declaringType, string ns, string name)
{
this.module = module;
this.declaringType = declaringType;
this.ns = ns;
this.name = name;
MarkEnumOrValueType(ns, name);
}
internal override MethodBase FindMethod(string name, MethodSignature signature)
{
MethodInfo method = new MissingMethod(this, name, signature);
if (name == ".ctor")
{
return new ConstructorInfoImpl(method);
}
return method;
}
internal override FieldInfo FindField(string name, FieldSignature signature)
{
return new MissingField(this, name, signature);
}
internal override Type FindNestedType(TypeName name)
{
return null;
}
internal override Type FindNestedTypeIgnoreCase(TypeName lowerCaseName)
{
return null;
}
public override bool __IsMissing
{
get { return true; }
}
public override Type DeclaringType
{
get { return declaringType; }
}
public override string __Name
{
get { return name; }
}
public override string __Namespace
{
get { return ns; }
}
public override string Name
{
get { return TypeNameParser.Escape(name); }
}
public override string FullName
{
get { return GetFullName(); }
}
public override Module Module
{
get { return module; }
}
public override int MetadataToken
{
get { return token; }
}
public override bool IsValueType
{
get
{
switch (typeFlags & (TypeFlags.ValueType | TypeFlags.NotValueType))
{
case TypeFlags.ValueType:
return true;
case TypeFlags.NotValueType:
return false;
default:
if (module.universe.ResolveMissingTypeIsValueType(this))
{
typeFlags |= TypeFlags.ValueType;
}
else
{
typeFlags |= TypeFlags.NotValueType;
}
return (typeFlags & TypeFlags.ValueType) != 0;
}
}
}
public override Type BaseType
{
get { throw new MissingMemberException(this); }
}
public override TypeAttributes Attributes
{
get { throw new MissingMemberException(this); }
}
public override Type[] __GetDeclaredTypes()
{
throw new MissingMemberException(this);
}
public override Type[] __GetDeclaredInterfaces()
{
throw new MissingMemberException(this);
}
public override MethodBase[] __GetDeclaredMethods()
{
throw new MissingMemberException(this);
}
public override __MethodImplMap __GetMethodImplMap()
{
throw new MissingMemberException(this);
}
public override FieldInfo[] __GetDeclaredFields()
{
throw new MissingMemberException(this);
}
public override EventInfo[] __GetDeclaredEvents()
{
throw new MissingMemberException(this);
}
public override PropertyInfo[] __GetDeclaredProperties()
{
throw new MissingMemberException(this);
}
public override CustomModifiers __GetCustomModifiers()
{
throw new MissingMemberException(this);
}
public override Type[] GetGenericArguments()
{
throw new MissingMemberException(this);
}
public override CustomModifiers[] __GetGenericArgumentsCustomModifiers()
{
throw new MissingMemberException(this);
}
public override StructLayoutAttribute StructLayoutAttribute
{
get { throw new MissingMemberException(this); }
}
public override bool IsGenericType
{
get { throw new MissingMemberException(this); }
}
public override bool IsGenericTypeDefinition
{
get { throw new MissingMemberException(this); }
}
internal override Type GetGenericTypeArgument(int index)
{
if (typeArgs == null)
{
typeArgs = new Type[index + 1];
}
else if (typeArgs.Length <= index)
{
Array.Resize(ref typeArgs, index + 1);
}
return typeArgs[index] ?? (typeArgs[index] = new MissingTypeParameter(this, index));
}
internal override Type BindTypeParameters(IGenericBinder binder)
{
return this;
}
internal override Type SetMetadataTokenForMissing(int token, int flags)
{
this.token = token;
this.flags = flags;
return this;
}
internal override bool IsBaked
{
get { throw new MissingMemberException(this); }
}
public override bool __IsTypeForwarder
{
// CorTypeAttr.tdForwarder
get { return (flags & 0x00200000) != 0; }
}
}
sealed class MissingTypeParameter : IKVM.Reflection.Reader.TypeParameterType
{
private readonly MemberInfo owner;
private readonly int index;
internal MissingTypeParameter(MemberInfo owner, int index)
{
this.owner = owner;
this.index = index;
}
public override Module Module
{
get { return owner.Module; }
}
public override string Name
{
get { return null; }
}
public override int GenericParameterPosition
{
get { return index; }
}
public override MethodBase DeclaringMethod
{
get { return owner as MethodBase; }
}
public override Type DeclaringType
{
get { return owner as Type; }
}
internal override Type BindTypeParameters(IGenericBinder binder)
{
if (owner is MethodBase)
{
return binder.BindMethodParameter(this);
}
else
{
return binder.BindTypeParameter(this);
}
}
internal override bool IsBaked
{
get { return owner.IsBaked; }
}
}
sealed class MissingMethod : MethodInfo
{
private readonly Type declaringType;
private readonly string name;
internal MethodSignature signature;
private MethodInfo forwarder;
private Type[] typeArgs;
internal MissingMethod(Type declaringType, string name, MethodSignature signature)
{
this.declaringType = declaringType;
this.name = name;
this.signature = signature;
}
private MethodInfo Forwarder
{
get
{
MethodInfo method = TryGetForwarder();
if (method == null)
{
throw new MissingMemberException(this);
}
return method;
}
}
private MethodInfo TryGetForwarder()
{
if (forwarder == null && !declaringType.__IsMissing)
{
MethodBase mb = declaringType.FindMethod(name, signature);
ConstructorInfo ci = mb as ConstructorInfo;
if (ci != null)
{
forwarder = ci.GetMethodInfo();
}
else
{
forwarder = (MethodInfo)mb;
}
}
return forwarder;
}
public override bool __IsMissing
{
get { return TryGetForwarder() == null; }
}
public override Type ReturnType
{
get { return signature.GetReturnType(this); }
}
public override ParameterInfo ReturnParameter
{
get { return new ParameterInfoImpl(this, -1); }
}
internal override MethodSignature MethodSignature
{
get { return signature; }
}
internal override int ParameterCount
{
get { return signature.GetParameterCount(); }
}
private sealed class ParameterInfoImpl : ParameterInfo
{
private readonly MissingMethod method;
private readonly int index;
internal ParameterInfoImpl(MissingMethod method, int index)
{
this.method = method;
this.index = index;
}
private ParameterInfo Forwarder
{
get { return index == -1 ? method.Forwarder.ReturnParameter : method.Forwarder.GetParameters()[index]; }
}
public override string Name
{
get { return Forwarder.Name; }
}
public override Type ParameterType
{
get { return index == -1 ? method.signature.GetReturnType(method) : method.signature.GetParameterType(method, index); }
}
public override ParameterAttributes Attributes
{
get { return Forwarder.Attributes; }
}
public override int Position
{
get { return index; }
}
public override object RawDefaultValue
{
get { return Forwarder.RawDefaultValue; }
}
public override CustomModifiers __GetCustomModifiers()
{
return index == -1
? method.signature.GetReturnTypeCustomModifiers(method)
: method.signature.GetParameterCustomModifiers(method, index);
}
public override bool __TryGetFieldMarshal(out FieldMarshal fieldMarshal)
{
return Forwarder.__TryGetFieldMarshal(out fieldMarshal);
}
public override MemberInfo Member
{
get { return method; }
}
public override int MetadataToken
{
get { return Forwarder.MetadataToken; }
}
internal override Module Module
{
get { return method.Module; }
}
public override string ToString()
{
return Forwarder.ToString();
}
}
public override ParameterInfo[] GetParameters()
{
ParameterInfo[] parameters = new ParameterInfo[signature.GetParameterCount()];
for (int i = 0; i < parameters.Length; i++)
{
parameters[i] = new ParameterInfoImpl(this, i);
}
return parameters;
}
public override MethodAttributes Attributes
{
get { return Forwarder.Attributes; }
}
public override MethodImplAttributes GetMethodImplementationFlags()
{
return Forwarder.GetMethodImplementationFlags();
}
public override MethodBody GetMethodBody()
{
return Forwarder.GetMethodBody();
}
public override int __MethodRVA
{
get { return Forwarder.__MethodRVA; }
}
public override CallingConventions CallingConvention
{
get { return signature.CallingConvention; }
}
internal override int ImportTo(IKVM.Reflection.Emit.ModuleBuilder module)
{
MethodInfo method = TryGetForwarder();
if (method != null)
{
return method.ImportTo(module);
}
return module.ImportMethodOrField(declaringType, this.Name, this.MethodSignature);
}
public override string Name
{
get { return name; }
}
public override Type DeclaringType
{
get { return declaringType.IsModulePseudoType ? null : declaringType; }
}
public override Module Module
{
get { return declaringType.Module; }
}
public override bool Equals(object obj)
{
MissingMethod other = obj as MissingMethod;
return other != null
&& other.declaringType == declaringType
&& other.name == name
&& other.signature.Equals(signature);
}
public override int GetHashCode()
{
return declaringType.GetHashCode() ^ name.GetHashCode() ^ signature.GetHashCode();
}
internal override MethodBase BindTypeParameters(Type type)
{
MethodInfo forwarder = TryGetForwarder();
if (forwarder != null)
{
return forwarder.BindTypeParameters(type);
}
return new GenericMethodInstance(type, this, null);
}
public override bool ContainsGenericParameters
{
get { return Forwarder.ContainsGenericParameters; }
}
public override Type[] GetGenericArguments()
{
MethodInfo method = TryGetForwarder();
if (method != null)
{
return Forwarder.GetGenericArguments();
}
if (typeArgs == null)
{
typeArgs = new Type[signature.GenericParameterCount];
for (int i = 0; i < typeArgs.Length; i++)
{
typeArgs[i] = new MissingTypeParameter(this, i);
}
}
return Util.Copy(typeArgs);
}
internal override Type GetGenericMethodArgument(int index)
{
return GetGenericArguments()[index];
}
internal override int GetGenericMethodArgumentCount()
{
return Forwarder.GetGenericMethodArgumentCount();
}
public override MethodInfo GetGenericMethodDefinition()
{
return Forwarder.GetGenericMethodDefinition();
}
internal override MethodInfo GetMethodOnTypeDefinition()
{
return Forwarder.GetMethodOnTypeDefinition();
}
internal override bool HasThis
{
get { return (signature.CallingConvention & (CallingConventions.HasThis | CallingConventions.ExplicitThis)) == CallingConventions.HasThis; }
}
public override bool IsGenericMethod
{
get { return IsGenericMethodDefinition; }
}
public override bool IsGenericMethodDefinition
{
get { return signature.GenericParameterCount != 0; }
}
public override MethodInfo MakeGenericMethod(params Type[] typeArguments)
{
MethodInfo method = TryGetForwarder();
if (method != null)
{
return method.MakeGenericMethod(typeArguments);
}
return new GenericMethodInstance(declaringType, this, typeArguments);
}
public override int MetadataToken
{
get { return Forwarder.MetadataToken; }
}
internal override int GetCurrentToken()
{
return Forwarder.GetCurrentToken();
}
internal override bool IsBaked
{
get { return Forwarder.IsBaked; }
}
}
sealed class MissingField : FieldInfo
{
private readonly Type declaringType;
private readonly string name;
private readonly FieldSignature signature;
private FieldInfo forwarder;
internal MissingField(Type declaringType, string name, FieldSignature signature)
{
this.declaringType = declaringType;
this.name = name;
this.signature = signature;
}
private FieldInfo Forwarder
{
get
{
FieldInfo field = TryGetForwarder();
if (field == null)
{
throw new MissingMemberException(this);
}
return field;
}
}
private FieldInfo TryGetForwarder()
{
if (forwarder == null && !declaringType.__IsMissing)
{
forwarder = declaringType.FindField(name, signature);
}
return forwarder;
}
public override bool __IsMissing
{
get { return TryGetForwarder() == null; }
}
public override FieldAttributes Attributes
{
get { return Forwarder.Attributes; }
}
public override void __GetDataFromRVA(byte[] data, int offset, int length)
{
Forwarder.__GetDataFromRVA(data, offset, length);
}
public override int __FieldRVA
{
get { return Forwarder.__FieldRVA; }
}
public override bool __TryGetFieldOffset(out int offset)
{
return Forwarder.__TryGetFieldOffset(out offset);
}
public override object GetRawConstantValue()
{
return Forwarder.GetRawConstantValue();
}
internal override FieldSignature FieldSignature
{
get { return signature; }
}
internal override int ImportTo(IKVM.Reflection.Emit.ModuleBuilder module)
{
FieldInfo field = TryGetForwarder();
if (field != null)
{
return field.ImportTo(module);
}
return module.ImportMethodOrField(declaringType, this.Name, this.FieldSignature);
}
public override string Name
{
get { return name; }
}
public override Type DeclaringType
{
get { return declaringType.IsModulePseudoType ? null : declaringType; }
}
public override Module Module
{
get { return declaringType.Module; }
}
internal override FieldInfo BindTypeParameters(Type type)
{
FieldInfo forwarder = TryGetForwarder();
if (forwarder != null)
{
return forwarder.BindTypeParameters(type);
}
return new GenericFieldInstance(type, this);
}
public override int MetadataToken
{
get { return Forwarder.MetadataToken; }
}
public override bool Equals(object obj)
{
MissingField other = obj as MissingField;
return other != null
&& other.declaringType == declaringType
&& other.name == name
&& other.signature.Equals(signature);
}
public override int GetHashCode()
{
return declaringType.GetHashCode() ^ name.GetHashCode() ^ signature.GetHashCode();
}
public override string ToString()
{
return this.FieldType.Name + " " + this.Name;
}
internal override int GetCurrentToken()
{
return Forwarder.GetCurrentToken();
}
internal override bool IsBaked
{
get { return Forwarder.IsBaked; }
}
}
// NOTE this is currently only used by CustomAttributeData (because there is no other way to refer to a property)
sealed class MissingProperty : PropertyInfo
{
private readonly Type declaringType;
private readonly string name;
private readonly PropertySignature signature;
internal MissingProperty(Type declaringType, string name, PropertySignature signature)
{
this.declaringType = declaringType;
this.name = name;
this.signature = signature;
}
public override PropertyAttributes Attributes
{
get { throw new MissingMemberException(this); }
}
public override bool CanRead
{
get { throw new MissingMemberException(this); }
}
public override bool CanWrite
{
get { throw new MissingMemberException(this); }
}
public override MethodInfo GetGetMethod(bool nonPublic)
{
throw new MissingMemberException(this);
}
public override MethodInfo GetSetMethod(bool nonPublic)
{
throw new MissingMemberException(this);
}
public override MethodInfo[] GetAccessors(bool nonPublic)
{
throw new MissingMemberException(this);
}
public override object GetRawConstantValue()
{
throw new MissingMemberException(this);
}
internal override bool IsPublic
{
get { throw new MissingMemberException(this); }
}
internal override bool IsNonPrivate
{
get { throw new MissingMemberException(this); }
}
internal override bool IsStatic
{
get { throw new MissingMemberException(this); }
}
internal override PropertySignature PropertySignature
{
get { return signature; }
}
public override string Name
{
get { return name; }
}
public override Type DeclaringType
{
get { return declaringType; }
}
public override Module Module
{
get { return declaringType.Module; }
}
internal override bool IsBaked
{
get { return declaringType.IsBaked; }
}
internal override int GetCurrentToken()
{
throw new MissingMemberException(this);
}
}
}
|