- Rewrote custom modifier handling to retain ordering.

- Added ConstructorInfo.__ReturnParameter to expose custom modifiers.
- Added __GetCustomModifiers() to various *Info types.
- Added CustomModifiers type to encapsulate a custom modifier sequence.
- Added CustomModifiersBuilder to create a CustomModifiers sequence.
- Marked a number of IKVM.Reflection specific methods Obsolete, because they are replaced with method that take CustomModifiers value(s).
This commit is contained in:
jfrijters 2011-12-01 06:30:50 +00:00
Родитель ed23e4ca4e
Коммит 3c49c20346
26 изменённых файлов: 902 добавлений и 669 удалений

Просмотреть файл

@ -58,6 +58,11 @@ namespace IKVM.Reflection
get { return GetMethodInfo().ContainsGenericParameters; }
}
public ParameterInfo __ReturnParameter
{
get { return new ParameterInfoWrapper(this, GetMethodInfo().ReturnParameter); }
}
public sealed override ParameterInfo[] GetParameters()
{
ParameterInfo[] parameters = GetMethodInfo().GetParameters();
@ -104,14 +109,9 @@ namespace IKVM.Reflection
get { return forward.RawDefaultValue; }
}
public override Type[] GetOptionalCustomModifiers()
public override CustomModifiers __GetCustomModifiers()
{
return forward.GetOptionalCustomModifiers();
}
public override Type[] GetRequiredCustomModifiers()
{
return forward.GetRequiredCustomModifiers();
return forward.__GetCustomModifiers();
}
public override MemberInfo Member

Просмотреть файл

@ -473,7 +473,7 @@ namespace IKVM.Reflection
{
type = org;
}
FieldSignature sig = FieldSignature.Create(fieldType, null, null);
FieldSignature sig = FieldSignature.Create(fieldType, new CustomModifiers());
return type.FindField(name, sig)
?? type.Module.universe.GetMissingFieldOrThrow(type, name, sig);
}
@ -496,7 +496,7 @@ namespace IKVM.Reflection
{
type = org;
}
return type.Module.universe.GetMissingPropertyOrThrow(type, name, PropertySignature.Create(CallingConventions.Standard | CallingConventions.HasThis, propertyType, null, null, null, null, null));
return type.Module.universe.GetMissingPropertyOrThrow(type, name, PropertySignature.Create(CallingConventions.Standard | CallingConventions.HasThis, propertyType, null, new PackedCustomModifiers()));
}
[Obsolete("Use Constructor.DeclaringType instead.")]

333
reflect/CustomModifiers.cs Normal file
Просмотреть файл

@ -0,0 +1,333 @@
/*
Copyright (C) 2011 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.Diagnostics;
using System.Text;
using IKVM.Reflection.Emit;
using IKVM.Reflection.Reader;
namespace IKVM.Reflection
{
public struct CustomModifiers : IEquatable<CustomModifiers>, IEnumerable<CustomModifiers.Entry>
{
private static readonly Type ModOpt = new MarkerType();
private static readonly Type ModReq = new MarkerType();
private static readonly Type Initial = ModOpt;
private readonly Type[] types;
internal CustomModifiers(List<CustomModifiersBuilder.Item> list)
{
bool required = Initial == ModReq;
int count = list.Count;
foreach (CustomModifiersBuilder.Item item in list)
{
if (item.required != required)
{
required = item.required;
count++;
}
}
types = new Type[count];
required = Initial == ModReq;
int index = 0;
foreach (CustomModifiersBuilder.Item item in list)
{
if (item.required != required)
{
required = item.required;
types[index++] = required ? ModReq : ModOpt;
}
types[index++] = item.type;
}
}
private CustomModifiers(Type[] types)
{
Debug.Assert(types == null || types.Length != 0);
this.types = types;
}
public struct Enumerator : IEnumerator<Entry>
{
private readonly Type[] types;
private int index;
private bool required;
internal Enumerator(Type[] types)
{
this.types = types;
this.index = -1;
this.required = Initial == ModReq;
}
void System.Collections.IEnumerator.Reset()
{
this.index = -1;
this.required = Initial == ModReq;
}
public Entry Current
{
get { return new Entry(types[index], required); }
}
public bool MoveNext()
{
if (types == null || index == types.Length)
{
return false;
}
index++;
if (index == types.Length)
{
return false;
}
else if (types[index] == ModOpt)
{
required = false;
index++;
}
else if (types[index] == ModReq)
{
required = true;
index++;
}
return true;
}
object System.Collections.IEnumerator.Current
{
get { return Current; }
}
void IDisposable.Dispose()
{
}
}
public struct Entry
{
private readonly Type type;
private readonly bool required;
internal Entry(Type type, bool required)
{
this.type = type;
this.required = required;
}
public Type Type
{
get { return type; }
}
public bool IsRequired
{
get { return required; }
}
}
public Enumerator GetEnumerator()
{
return new Enumerator(types);
}
IEnumerator<Entry> IEnumerable<Entry>.GetEnumerator()
{
return GetEnumerator();
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
public bool IsEmpty
{
get { return types == null; }
}
public bool Equals(CustomModifiers other)
{
return Util.ArrayEquals(types, other.types);
}
public override bool Equals(object obj)
{
CustomModifiers? other = obj as CustomModifiers?;
return other != null && Equals(other.Value);
}
public override int GetHashCode()
{
return Util.GetHashCode(types);
}
public override string ToString()
{
if (types == null)
{
return string.Empty;
}
StringBuilder sb = new StringBuilder();
string sep = "";
foreach (Entry e in this)
{
sb.Append(sep).Append(e.IsRequired ? "modreq(" : "modopt(").Append(e.Type.FullName).Append(')');
sep = " ";
}
return sb.ToString();
}
private Type[] GetRequiredOrOptional(bool required)
{
if (types == null)
{
return Type.EmptyTypes;
}
int count = 0;
foreach (Entry e in this)
{
if (e.IsRequired == required)
{
count++;
}
}
Type[] result = new Type[count];
foreach (Entry e in this)
{
if (e.IsRequired == required)
{
// FXBUG reflection (and ildasm) return custom modifiers in reverse order
// while SRE writes them in the specified order
result[--count] = e.Type;
}
}
return result;
}
internal Type[] GetRequired()
{
return GetRequiredOrOptional(true);
}
internal Type[] GetOptional()
{
return GetRequiredOrOptional(false);
}
internal CustomModifiers Bind(IGenericBinder binder)
{
if (types == null)
{
return this;
}
Type[] result = types;
for (int i = 0; i < types.Length; i++)
{
if (types[i] == ModOpt || types[i] == ModReq)
{
continue;
}
Type type = types[i].BindTypeParameters(binder);
if (!ReferenceEquals(type, types[i]))
{
if (result == types)
{
result = (Type[])types.Clone();
}
result[i] = type;
}
}
return new CustomModifiers(result);
}
internal static CustomModifiers Read(ModuleReader module, ByteReader br, IGenericContext context)
{
byte b = br.PeekByte();
if (!IsCustomModifier(b))
{
return new CustomModifiers();
}
List<Type> list = new List<Type>();
Type mode = Initial;
do
{
Type cmod = br.ReadByte() == Signature.ELEMENT_TYPE_CMOD_REQD ? ModReq : ModOpt;
if (mode != cmod)
{
mode = cmod;
list.Add(mode);
}
list.Add(Signature.ReadTypeDefOrRefEncoded(module, br, context));
b = br.PeekByte();
}
while (IsCustomModifier(b));
return new CustomModifiers(list.ToArray());
}
internal static void Skip(ByteReader br)
{
byte b = br.PeekByte();
while (IsCustomModifier(b))
{
br.ReadByte();
br.ReadCompressedInt();
b = br.PeekByte();
}
}
internal static CustomModifiers FromReqOpt(Type[] req, Type[] opt)
{
List<Type> list = null;
if (opt != null && opt.Length != 0)
{
list = new List<Type>(opt);
}
if (req != null && req.Length != 0)
{
if (list == null)
{
list = new List<Type>();
}
list.Add(ModReq);
list.AddRange(req);
}
if (list == null)
{
return new CustomModifiers();
}
else
{
return new CustomModifiers(list.ToArray());
}
}
private static bool IsCustomModifier(byte b)
{
return b == Signature.ELEMENT_TYPE_CMOD_OPT || b == Signature.ELEMENT_TYPE_CMOD_REQD;
}
}
}

Просмотреть файл

@ -1,5 +1,5 @@
/*
Copyright (C) 2008 Jeroen Frijters
Copyright (C) 2008-2011 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
@ -45,6 +45,12 @@ namespace IKVM.Reflection.Emit
return methodBuilder.GetHashCode();
}
public void __SetSignature(Type returnType, CustomModifiers returnTypeCustomModifiers, Type[] parameterTypes, CustomModifiers[] parameterTypeCustomModifiers)
{
methodBuilder.__SetSignature(returnType, returnTypeCustomModifiers, parameterTypes, parameterTypeCustomModifiers);
}
[Obsolete("Please use __SetSignature(Type, CustomModifiers, Type[], CustomModifiers[]) instead.")]
public void __SetSignature(Type returnType, Type[] returnTypeRequiredCustomModifiers, Type[] returnTypeOptionalCustomModifiers, Type[] parameterTypes, Type[][] parameterTypeRequiredCustomModifiers, Type[][] parameterTypeOptionalCustomModifiers)
{
methodBuilder.SetSignature(returnType, returnTypeRequiredCustomModifiers, returnTypeOptionalCustomModifiers, parameterTypes, parameterTypeRequiredCustomModifiers, parameterTypeOptionalCustomModifiers);

Просмотреть файл

@ -0,0 +1,75 @@
/*
Copyright (C) 2011 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.Text;
namespace IKVM.Reflection.Emit
{
public sealed class CustomModifiersBuilder
{
private readonly List<Item> list = new List<Item>();
internal struct Item
{
internal Type type;
internal bool required;
}
public void AddRequired(Type type)
{
Item item;
item.type = type;
item.required = true;
list.Add(item);
}
public void AddOptional(Type type)
{
Item item;
item.type = type;
item.required = false;
list.Add(item);
}
// this adds the custom modifiers in the same order as the normal SRE APIs
// (the advantage over using the SRE APIs is that a CustomModifiers object is slightly more efficient,
// because unlike the Type arrays it doesn't need to be copied)
public void Add(Type[] requiredCustomModifiers, Type[] optionalCustomModifiers)
{
foreach (CustomModifiers.Entry entry in CustomModifiers.FromReqOpt(requiredCustomModifiers, optionalCustomModifiers))
{
Item item;
item.type = entry.Type;
item.required = entry.IsRequired;
list.Add(item);
}
}
public CustomModifiers Create()
{
return new CustomModifiers(list);
}
}
}

Просмотреть файл

@ -38,13 +38,13 @@ namespace IKVM.Reflection.Emit
private readonly int signature;
private readonly FieldSignature fieldSig;
internal FieldBuilder(TypeBuilder type, string name, Type fieldType, Type[] requiredCustomModifiers, Type[] optionalCustomModifiers, FieldAttributes attribs)
internal FieldBuilder(TypeBuilder type, string name, Type fieldType, CustomModifiers customModifiers, FieldAttributes attribs)
{
this.typeBuilder = type;
this.name = name;
this.pseudoToken = type.ModuleBuilder.AllocPseudoToken();
this.nameIndex = type.ModuleBuilder.Strings.Add(name);
this.fieldSig = FieldSignature.Create(fieldType, optionalCustomModifiers, requiredCustomModifiers);
this.fieldSig = FieldSignature.Create(fieldType, customModifiers);
ByteBuffer sig = new ByteBuffer(5);
fieldSig.WriteSig(this.typeBuilder.ModuleBuilder, sig);
this.signature = this.typeBuilder.ModuleBuilder.Blobs.Add(sig);

Просмотреть файл

@ -42,7 +42,7 @@ namespace IKVM.Reflection.Emit
private int signature;
private Type returnType;
private Type[] parameterTypes;
private Type[][][] modifiers; // see PackedCustomModifiers
private PackedCustomModifiers customModifiers;
private MethodAttributes attributes;
private MethodImplAttributes implFlags;
private ILGenerator ilgen;
@ -338,11 +338,21 @@ namespace IKVM.Reflection.Emit
}
public void SetSignature(Type returnType, Type[] returnTypeRequiredCustomModifiers, Type[] returnTypeOptionalCustomModifiers, Type[] parameterTypes, Type[][] parameterTypeRequiredCustomModifiers, Type[][] parameterTypeOptionalCustomModifiers)
{
SetSignature(returnType, parameterTypes, PackedCustomModifiers.CreateFromExternal(returnTypeOptionalCustomModifiers, returnTypeRequiredCustomModifiers,
parameterTypeOptionalCustomModifiers, parameterTypeRequiredCustomModifiers, Util.NullSafeLength(parameterTypes)));
}
public void __SetSignature(Type returnType, CustomModifiers returnTypeCustomModifiers, Type[] parameterTypes, CustomModifiers[] parameterTypeCustomModifiers)
{
SetSignature(returnType, parameterTypes, PackedCustomModifiers.CreateFromExternal(returnTypeCustomModifiers, parameterTypeCustomModifiers, Util.NullSafeLength(parameterTypes)));
}
private void SetSignature(Type returnType, Type[] parameterTypes, PackedCustomModifiers customModifiers)
{
this.returnType = returnType ?? this.Module.universe.System_Void;
this.parameterTypes = Util.Copy(parameterTypes);
this.modifiers = PackedCustomModifiers.CreateFromExternal(returnTypeOptionalCustomModifiers, returnTypeRequiredCustomModifiers,
parameterTypeOptionalCustomModifiers, parameterTypeRequiredCustomModifiers, this.parameterTypes.Length);
this.customModifiers = customModifiers;
}
public GenericTypeParameterBuilder[] DefineGenericParameters(params string[] names)
@ -488,23 +498,9 @@ namespace IKVM.Reflection.Emit
}
}
private Type[] GetCustomModifiers(int optOrReq)
public override CustomModifiers __GetCustomModifiers()
{
if (method.modifiers == null || method.modifiers[parameter + 1] == null)
{
return Type.EmptyTypes;
}
return Util.Copy(method.modifiers[parameter + 1][optOrReq]);
}
public override Type[] GetOptionalCustomModifiers()
{
return GetCustomModifiers(0);
}
public override Type[] GetRequiredCustomModifiers()
{
return GetCustomModifiers(1);
return method.customModifiers.GetParameterCustomModifiers(parameter);
}
public override MemberInfo Member
@ -671,7 +667,7 @@ namespace IKVM.Reflection.Emit
{
if (methodSignature == null)
{
methodSignature = MethodSignature.MakeFromBuilder(returnType, parameterTypes, modifiers, callingConvention, gtpb == null ? 0 : gtpb.Length);
methodSignature = MethodSignature.MakeFromBuilder(returnType, parameterTypes, customModifiers, callingConvention, gtpb == null ? 0 : gtpb.Length);
}
return methodSignature;
}

Просмотреть файл

@ -259,6 +259,12 @@ namespace IKVM.Reflection.Emit
return new EnumBuilder(tb, fb);
}
public FieldBuilder __DefineField(string name, Type type, CustomModifiers customModifiers, FieldAttributes attributes)
{
return moduleType.__DefineField(name, type, customModifiers, attributes);
}
[Obsolete("Please use __DefineField(string, Type, CustomModifiers, FieldAttributes) instead.")]
public FieldBuilder __DefineField(string name, Type type, Type[] requiredCustomModifiers, Type[] optionalCustomModifiers, FieldAttributes attributes)
{
return moduleType.DefineField(name, type, requiredCustomModifiers, optionalCustomModifiers, attributes);
@ -1627,7 +1633,7 @@ namespace IKVM.Reflection.Emit
{
if (methodSignature == null)
{
methodSignature = MethodSignature.MakeFromBuilder(returnType, parameterTypes, null, callingConvention, 0);
methodSignature = MethodSignature.MakeFromBuilder(returnType, parameterTypes, new PackedCustomModifiers(), callingConvention, 0);
}
return methodSignature;
}

Просмотреть файл

@ -1,5 +1,5 @@
/*
Copyright (C) 2008, 2010 Jeroen Frijters
Copyright (C) 2008-2011 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
@ -35,12 +35,10 @@ namespace IKVM.Reflection.Emit
private readonly byte type;
private readonly List<Type> args = new List<Type>();
private readonly List<LocalBuilder> locals = new List<LocalBuilder>();
private readonly List<Type[]> requiredCustomModifiers = new List<Type[]>();
private readonly List<Type[]> optionalCustomModifiers = new List<Type[]>();
private readonly List<CustomModifiers> customModifiers = new List<CustomModifiers>();
private readonly List<Type> optionalArgs = new List<Type>();
private Type returnType;
private Type[] returnTypeRequiredCustomModifiers;
private Type[] returnTypeOptionalCustomModifiers;
private CustomModifiers returnTypeCustomModifiers;
private CallingConventions callingConvention;
private CallingConvention unmanagedCallConv;
private bool unmanaged;
@ -86,8 +84,6 @@ namespace IKVM.Reflection.Emit
{
SignatureHelper sig = new SignatureHelper(mod as ModuleBuilder, Signature.PROPERTY);
sig.returnType = returnType;
sig.returnTypeOptionalCustomModifiers = Type.EmptyTypes;
sig.returnTypeRequiredCustomModifiers = Type.EmptyTypes;
foreach (Type type in parameterTypes)
{
sig.AddArgument(type);
@ -105,8 +101,7 @@ namespace IKVM.Reflection.Emit
SignatureHelper sig = new SignatureHelper(mod as ModuleBuilder, Signature.PROPERTY);
sig.callingConvention = callingConvention;
sig.returnType = returnType;
sig.returnTypeOptionalCustomModifiers = requiredReturnTypeCustomModifiers;
sig.returnTypeRequiredCustomModifiers = optionalReturnTypeCustomModifiers;
sig.returnTypeCustomModifiers = CustomModifiers.FromReqOpt(requiredReturnTypeCustomModifiers, optionalReturnTypeCustomModifiers);
sig.AddArguments(parameterTypes, requiredParameterTypeCustomModifiers, optionalParameterTypeCustomModifiers);
return sig;
}
@ -175,10 +170,10 @@ namespace IKVM.Reflection.Emit
}
break;
case Signature.FIELD:
FieldSignature.Create(args[0], optionalCustomModifiers[0], requiredCustomModifiers[0]).WriteSig(module, bb);
FieldSignature.Create(args[0], customModifiers[0]).WriteSig(module, bb);
break;
case Signature.PROPERTY:
Signature.WritePropertySig(module, bb, callingConvention, returnType, returnTypeRequiredCustomModifiers, returnTypeOptionalCustomModifiers, args.ToArray(), requiredCustomModifiers.ToArray(), optionalCustomModifiers.ToArray());
Signature.WritePropertySig(module, bb, callingConvention, returnType, returnTypeCustomModifiers, args.ToArray(), customModifiers.ToArray());
break;
case Signature.LOCAL_SIG:
Signature.WriteLocalVarSig(module, bb, locals);
@ -202,18 +197,19 @@ namespace IKVM.Reflection.Emit
public void AddArgument(Type argument, bool pinned)
{
AddArgument(argument, pinned, Type.EmptyTypes, Type.EmptyTypes);
__AddArgument(argument, pinned, new CustomModifiers());
}
public void AddArgument(Type argument, Type[] requiredCustomModifiers, Type[] optionalCustomModifiers)
{
AddArgument(argument, false, requiredCustomModifiers, optionalCustomModifiers);
__AddArgument(argument, false, CustomModifiers.FromReqOpt(requiredCustomModifiers, optionalCustomModifiers));
}
private void AddArgument(Type argument, bool pinned, Type[] requiredCustomModifiers, Type[] optionalCustomModifiers)
public void __AddArgument(Type argument, bool pinned, CustomModifiers customModifiers)
{
if (type == Signature.LOCAL_SIG)
{
// TODO support custom modifiers in local sig
locals.Add(new LocalBuilder(argument, 0, pinned));
}
else if (optional)
@ -223,8 +219,7 @@ namespace IKVM.Reflection.Emit
else
{
this.args.Add(argument);
this.requiredCustomModifiers.Add(requiredCustomModifiers);
this.optionalCustomModifiers.Add(optionalCustomModifiers);
this.customModifiers.Add(customModifiers);
}
}
@ -232,7 +227,7 @@ namespace IKVM.Reflection.Emit
{
for (int i = 0; i < arguments.Length; i++)
{
AddArgument(arguments[i], false, requiredCustomModifiers[i], optionalCustomModifiers[i]);
__AddArgument(arguments[i], false, CustomModifiers.FromReqOpt(requiredCustomModifiers[i], optionalCustomModifiers[i]));
}
}
}

Просмотреть файл

@ -351,7 +351,12 @@ namespace IKVM.Reflection.Emit
public FieldBuilder DefineField(string fieldName, Type type, Type[] requiredCustomModifiers, Type[] optionalCustomModifiers, FieldAttributes attributes)
{
FieldBuilder fb = new FieldBuilder(this, fieldName, type, requiredCustomModifiers, optionalCustomModifiers, attributes);
return __DefineField(fieldName, type, CustomModifiers.FromReqOpt(requiredCustomModifiers, optionalCustomModifiers), attributes);
}
public FieldBuilder __DefineField(string fieldName, Type type, CustomModifiers customModifiers, FieldAttributes attributes)
{
FieldBuilder fb = new FieldBuilder(this, fieldName, type, customModifiers, attributes);
fields.Add(fb);
return fb;
}
@ -364,28 +369,33 @@ namespace IKVM.Reflection.Emit
public PropertyBuilder DefineProperty(string name, PropertyAttributes attributes, Type returnType, Type[] returnTypeRequiredCustomModifiers, Type[] returnTypeOptionalCustomModifiers,
Type[] parameterTypes, Type[][] parameterTypeRequiredCustomModifiers, Type[][] parameterTypeOptionalCustomModifiers)
{
return DefinePropertyImpl(name, attributes, CallingConventions.Standard, true, returnType, returnTypeRequiredCustomModifiers, returnTypeOptionalCustomModifiers,
parameterTypes, parameterTypeRequiredCustomModifiers, parameterTypeOptionalCustomModifiers);
return DefinePropertyImpl(name, attributes, CallingConventions.Standard, true, returnType, parameterTypes,
PackedCustomModifiers.CreateFromExternal(returnTypeOptionalCustomModifiers, returnTypeRequiredCustomModifiers, parameterTypeOptionalCustomModifiers, parameterTypeRequiredCustomModifiers, Util.NullSafeLength(parameterTypes)));
}
public PropertyBuilder DefineProperty(string name, PropertyAttributes attributes, CallingConventions callingConvention,
Type returnType, Type[] returnTypeRequiredCustomModifiers, Type[] returnTypeOptionalCustomModifiers,
Type[] parameterTypes, Type[][] parameterTypeRequiredCustomModifiers, Type[][] parameterTypeOptionalCustomModifiers)
{
return DefinePropertyImpl(name, attributes, callingConvention, false, returnType, returnTypeRequiredCustomModifiers, returnTypeOptionalCustomModifiers,
parameterTypes, parameterTypeRequiredCustomModifiers, parameterTypeOptionalCustomModifiers);
return DefinePropertyImpl(name, attributes, callingConvention, false, returnType, parameterTypes,
PackedCustomModifiers.CreateFromExternal(returnTypeOptionalCustomModifiers, returnTypeRequiredCustomModifiers, parameterTypeOptionalCustomModifiers, parameterTypeRequiredCustomModifiers, Util.NullSafeLength(parameterTypes)));
}
public PropertyBuilder __DefineProperty(string name, PropertyAttributes attributes, CallingConventions callingConvention,
Type returnType, CustomModifiers returnTypeCustomModifiers, Type[] parameterTypes, CustomModifiers[] parameterTypeCustomModifiers)
{
return DefinePropertyImpl(name, attributes, callingConvention, false, returnType, parameterTypes,
PackedCustomModifiers.CreateFromExternal(returnTypeCustomModifiers, parameterTypeCustomModifiers, Util.NullSafeLength(parameterTypes)));
}
private PropertyBuilder DefinePropertyImpl(string name, PropertyAttributes attributes, CallingConventions callingConvention, bool patchCallingConvention,
Type returnType, Type[] returnTypeRequiredCustomModifiers, Type[] returnTypeOptionalCustomModifiers,
Type[] parameterTypes, Type[][] parameterTypeRequiredCustomModifiers, Type[][] parameterTypeOptionalCustomModifiers)
Type returnType, Type[] parameterTypes, PackedCustomModifiers customModifiers)
{
if (properties == null)
{
properties = new List<PropertyBuilder>();
}
PropertySignature sig = PropertySignature.Create(callingConvention, returnType, returnTypeOptionalCustomModifiers, returnTypeRequiredCustomModifiers,
parameterTypes, parameterTypeOptionalCustomModifiers, parameterTypeRequiredCustomModifiers);
PropertySignature sig = PropertySignature.Create(callingConvention, returnType, parameterTypes, customModifiers);
PropertyBuilder pb = new PropertyBuilder(this, name, attributes, sig, patchCallingConvention);
properties.Add(pb);
return pb;
@ -628,14 +638,9 @@ namespace IKVM.Reflection.Emit
return Util.Copy(gtpb);
}
public override Type[][] __GetGenericArgumentsOptionalCustomModifiers()
public override CustomModifiers[] __GetGenericArgumentsCustomModifiers()
{
return gtpb == null ? Empty<Type[]>.Array : Util.Copy(new Type[gtpb.Length][]);
}
public override Type[][] __GetGenericArgumentsRequiredCustomModifiers()
{
return gtpb == null ? Empty<Type[]>.Array : Util.Copy(new Type[gtpb.Length][]);
return gtpb == null ? Empty<CustomModifiers>.Array : new CustomModifiers[gtpb.Length];
}
internal override Type GetGenericTypeArgument(int index)
@ -1152,14 +1157,9 @@ namespace IKVM.Reflection.Emit
return underlyingType.GetGenericTypeArgument(index);
}
public override Type[][] __GetGenericArgumentsOptionalCustomModifiers()
public override CustomModifiers[] __GetGenericArgumentsCustomModifiers()
{
return underlyingType.__GetGenericArgumentsOptionalCustomModifiers();
}
public override Type[][] __GetGenericArgumentsRequiredCustomModifiers()
{
return underlyingType.__GetGenericArgumentsRequiredCustomModifiers();
return underlyingType.__GetGenericArgumentsCustomModifiers();
}
public override bool IsGenericType

Просмотреть файл

@ -48,14 +48,19 @@ namespace IKVM.Reflection
get { return this.FieldSignature.FieldType; }
}
public CustomModifiers __GetCustomModifiers()
{
return this.FieldSignature.GetCustomModifiers();
}
public Type[] GetOptionalCustomModifiers()
{
return this.FieldSignature.GetOptionalCustomModifiers();
return __GetCustomModifiers().GetOptional();
}
public Type[] GetRequiredCustomModifiers()
{
return this.FieldSignature.GetRequiredCustomModifiers();
return __GetCustomModifiers().GetRequired();
}
public bool IsStatic

Просмотреть файл

@ -34,19 +34,17 @@ namespace IKVM.Reflection
sealed class FieldSignature : Signature
{
private readonly Type fieldType;
private readonly Type[] optionalCustomModifiers;
private readonly Type[] requiredCustomModifiers;
private readonly CustomModifiers mods;
internal static FieldSignature Create(Type fieldType, Type[] optionalCustomModifiers, Type[] requiredCustomModifiers)
internal static FieldSignature Create(Type fieldType, CustomModifiers customModifiers)
{
return new FieldSignature(fieldType, Util.Copy(optionalCustomModifiers), Util.Copy(requiredCustomModifiers));
return new FieldSignature(fieldType, customModifiers);
}
private FieldSignature(Type fieldType, Type[] optionalCustomModifiers, Type[] requiredCustomModifiers)
private FieldSignature(Type fieldType, CustomModifiers mods)
{
this.fieldType = fieldType;
this.optionalCustomModifiers = optionalCustomModifiers;
this.requiredCustomModifiers = requiredCustomModifiers;
this.mods = mods;
}
public override bool Equals(object obj)
@ -54,13 +52,12 @@ namespace IKVM.Reflection
FieldSignature other = obj as FieldSignature;
return other != null
&& other.fieldType.Equals(fieldType)
&& Util.ArrayEquals(other.optionalCustomModifiers, optionalCustomModifiers)
&& Util.ArrayEquals(other.requiredCustomModifiers, requiredCustomModifiers);
&& other.mods.Equals(mods);
}
public override int GetHashCode()
{
return fieldType.GetHashCode() ^ Util.GetHashCode(optionalCustomModifiers) ^ Util.GetHashCode(requiredCustomModifiers);
return fieldType.GetHashCode() ^ mods.GetHashCode();
}
internal Type FieldType
@ -68,22 +65,16 @@ namespace IKVM.Reflection
get { return fieldType; }
}
internal Type[] GetOptionalCustomModifiers()
internal CustomModifiers GetCustomModifiers()
{
return Util.Copy(optionalCustomModifiers);
}
internal Type[] GetRequiredCustomModifiers()
{
return Util.Copy(requiredCustomModifiers);
return mods;
}
internal FieldSignature ExpandTypeParameters(Type declaringType)
{
return new FieldSignature(
fieldType.BindTypeParameters(declaringType),
BindTypeParameters(declaringType, optionalCustomModifiers),
BindTypeParameters(declaringType, requiredCustomModifiers));
mods.Bind(declaringType));
}
internal static FieldSignature ReadSig(ModuleReader module, ByteReader br, IGenericContext context)
@ -92,19 +83,15 @@ namespace IKVM.Reflection
{
throw new BadImageFormatException();
}
Type fieldType;
Type[] optionalCustomModifiers;
Type[] requiredCustomModifiers;
ReadCustomModifiers(module, br, context, out requiredCustomModifiers, out optionalCustomModifiers);
fieldType = ReadType(module, br, context);
return new FieldSignature(fieldType, optionalCustomModifiers, requiredCustomModifiers);
CustomModifiers mods = CustomModifiers.Read(module, br, context);
Type fieldType = ReadType(module, br, context);
return new FieldSignature(fieldType, mods);
}
internal override void WriteSig(ModuleBuilder module, ByteBuffer bb)
{
bb.Write(FIELD);
WriteCustomModifiers(module, bb, ELEMENT_TYPE_CMOD_OPT, optionalCustomModifiers);
WriteCustomModifiers(module, bb, ELEMENT_TYPE_CMOD_REQD, requiredCustomModifiers);
WriteCustomModifiers(module, bb, mods);
WriteType(module, bb, fieldType);
}
}

Просмотреть файл

@ -395,18 +395,9 @@ namespace IKVM.Reflection
get { return parameterInfo.RawDefaultValue; }
}
public override Type[] GetOptionalCustomModifiers()
public override CustomModifiers __GetCustomModifiers()
{
Type[] modifiers = parameterInfo.GetOptionalCustomModifiers();
Type.InplaceBindTypeParameters(method, modifiers);
return modifiers;
}
public override Type[] GetRequiredCustomModifiers()
{
Type[] modifiers = parameterInfo.GetRequiredCustomModifiers();
Type.InplaceBindTypeParameters(method, modifiers);
return modifiers;
return parameterInfo.__GetCustomModifiers().Bind(method);
}
public override MemberInfo Member

Просмотреть файл

@ -50,9 +50,11 @@
<Compile Include="CustomAttributeData.cs" />
<Compile Include="CustomAttributeNamedArgument.cs" />
<Compile Include="CustomAttributeTypedArgument.cs" />
<Compile Include="CustomModifiers.cs" />
<Compile Include="Emit\AssemblyBuilder.cs" />
<Compile Include="Emit\ConstructorBuilder.cs" />
<Compile Include="Emit\CustomAttributeBuilder.cs" />
<Compile Include="Emit\CustomModifiersBuilder.cs" />
<Compile Include="Emit\EnumBuilder.cs" />
<Compile Include="Emit\Enums.cs" />
<Compile Include="Emit\EventBuilder.cs" />

Просмотреть файл

@ -171,7 +171,7 @@ namespace IKVM.Reflection
private static void AddNamedArgument(List<CustomAttributeNamedArgument> list, Type attributeType, string fieldName, Type valueType, object value)
{
// some fields are not available on the .NET Compact Framework version of MarshalAsAttribute
FieldInfo field = attributeType.FindField(fieldName, FieldSignature.Create(valueType, null, null));
FieldInfo field = attributeType.FindField(fieldName, FieldSignature.Create(valueType, new CustomModifiers()));
if (field != null)
{
list.Add(new CustomAttributeNamedArgument(field, new CustomAttributeTypedArgument(valueType, value)));

Просмотреть файл

@ -1,5 +1,5 @@
/*
Copyright (C) 2009-2010 Jeroen Frijters
Copyright (C) 2009-2011 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
@ -34,11 +34,11 @@ namespace IKVM.Reflection
{
private readonly Type returnType;
private readonly Type[] parameterTypes;
private readonly Type[][][] modifiers; // see PackedCustomModifiers
private readonly PackedCustomModifiers modifiers;
private readonly CallingConventions callingConvention;
private readonly int genericParamCount;
internal MethodSignature(Type returnType, Type[] parameterTypes, Type[][][] modifiers, CallingConventions callingConvention, int genericParamCount)
internal MethodSignature(Type returnType, Type[] parameterTypes, PackedCustomModifiers modifiers, CallingConventions callingConvention, int genericParamCount)
{
this.returnType = returnType;
this.parameterTypes = parameterTypes;
@ -55,7 +55,7 @@ namespace IKVM.Reflection
&& other.genericParamCount == genericParamCount
&& other.returnType.Equals(returnType)
&& Util.ArrayEquals(other.parameterTypes, parameterTypes)
&& Util.ArrayEquals(other.modifiers, modifiers);
&& other.modifiers.Equals(modifiers);
}
public override int GetHashCode()
@ -63,7 +63,7 @@ namespace IKVM.Reflection
return genericParamCount ^ 77 * (int)callingConvention
^ 3 * returnType.GetHashCode()
^ Util.GetHashCode(parameterTypes) * 5
^ Util.GetHashCode(modifiers) * 55;
^ modifiers.GetHashCode() * 55;
}
private sealed class UnboundGenericMethodContext : IGenericContext
@ -119,14 +119,10 @@ namespace IKVM.Reflection
context = new UnboundGenericMethodContext(context);
}
int paramCount = br.ReadCompressedInt();
Type[][][] modifiers = null;
Type[] optionalCustomModifiers;
Type[] requiredCustomModifiers;
ReadCustomModifiers(module, br, context, out requiredCustomModifiers, out optionalCustomModifiers);
CustomModifiers[] modifiers = null;
PackedCustomModifiers.Pack(ref modifiers, 0, CustomModifiers.Read(module, br, context), paramCount + 1);
returnType = ReadRetType(module, br, context);
parameterTypes = new Type[paramCount];
PackedCustomModifiers.SetModifiers(ref modifiers, 0, 0, optionalCustomModifiers, paramCount + 1);
PackedCustomModifiers.SetModifiers(ref modifiers, 0, 1, requiredCustomModifiers, paramCount + 1);
for (int i = 0; i < parameterTypes.Length; i++)
{
if ((callingConvention & CallingConventions.VarArgs) != 0 && br.PeekByte() == SENTINEL)
@ -138,12 +134,10 @@ namespace IKVM.Reflection
}
break;
}
ReadCustomModifiers(module, br, context, out requiredCustomModifiers, out optionalCustomModifiers);
PackedCustomModifiers.SetModifiers(ref modifiers, i + 1, 0, optionalCustomModifiers, paramCount + 1);
PackedCustomModifiers.SetModifiers(ref modifiers, i + 1, 1, requiredCustomModifiers, paramCount + 1);
PackedCustomModifiers.Pack(ref modifiers, i + 1, CustomModifiers.Read(module, br, context), paramCount + 1);
parameterTypes[i] = ReadParam(module, br, context);
}
return new MethodSignature(returnType, parameterTypes, modifiers, callingConvention, genericParamCount);
return new MethodSignature(returnType, parameterTypes, PackedCustomModifiers.Wrap(modifiers), callingConvention, genericParamCount);
}
internal static __StandAloneMethodSig ReadStandAloneMethodSig(ModuleReader module, ByteReader br, IGenericContext context)
@ -194,7 +188,7 @@ namespace IKVM.Reflection
throw new BadImageFormatException();
}
int paramCount = br.ReadCompressedInt();
SkipCustomModifiers(br);
CustomModifiers.Skip(br);
Type returnType = ReadRetType(module, br, context);
List<Type> parameterTypes = new List<Type>();
List<Type> optionalParameterTypes = new List<Type>();
@ -206,7 +200,7 @@ namespace IKVM.Reflection
br.ReadByte();
curr = optionalParameterTypes;
}
SkipCustomModifiers(br);
CustomModifiers.Skip(br);
curr.Add(ReadParam(module, br, context));
}
return new __StandAloneMethodSig(unmanaged, unmanagedCallingConvention, callingConvention, returnType, parameterTypes.ToArray(), optionalParameterTypes.ToArray());
@ -227,14 +221,9 @@ namespace IKVM.Reflection
return returnType.BindTypeParameters(binder);
}
internal Type[] GetReturnTypeOptionalCustomModifiers(IGenericBinder binder)
internal CustomModifiers GetReturnTypeCustomModifiers(IGenericBinder binder)
{
return BindTypeParameters(binder, modifiers, 0, 0);
}
internal Type[] GetReturnTypeRequiredCustomModifiers(IGenericBinder binder)
{
return BindTypeParameters(binder, modifiers, 0, 1);
return modifiers.GetReturnTypeCustomModifiers().Bind(binder);
}
internal Type GetParameterType(IGenericBinder binder, int index)
@ -242,14 +231,9 @@ namespace IKVM.Reflection
return parameterTypes[index].BindTypeParameters(binder);
}
internal Type[] GetParameterOptionalCustomModifiers(IGenericBinder binder, int index)
internal CustomModifiers GetParameterCustomModifiers(IGenericBinder binder, int index)
{
return BindTypeParameters(binder, modifiers, index + 1, 0);
}
internal Type[] GetParameterRequiredCustomModifiers(IGenericBinder binder, int index)
{
return BindTypeParameters(binder, modifiers, index + 1, 1);
return modifiers.GetParameterCustomModifiers(index).Bind(binder);
}
internal CallingConventions CallingConvention
@ -293,7 +277,7 @@ namespace IKVM.Reflection
Binder binder = new Binder(type, methodArgs);
return new MethodSignature(returnType.BindTypeParameters(binder),
BindTypeParameters(binder, parameterTypes),
BindTypeParameters(binder, modifiers),
modifiers.Bind(binder),
callingConvention, genericParamCount);
}
@ -316,13 +300,13 @@ namespace IKVM.Reflection
}
}
internal static MethodSignature MakeFromBuilder(Type returnType, Type[] parameterTypes, Type[][][] modifiers, CallingConventions callingConvention, int genericParamCount)
internal static MethodSignature MakeFromBuilder(Type returnType, Type[] parameterTypes, PackedCustomModifiers modifiers, CallingConventions callingConvention, int genericParamCount)
{
if (genericParamCount > 0)
{
returnType = returnType.BindTypeParameters(Unbinder.Instance);
parameterTypes = BindTypeParameters(Unbinder.Instance, parameterTypes);
modifiers = BindTypeParameters(Unbinder.Instance, modifiers);
modifiers = modifiers.Bind(Unbinder.Instance);
}
return new MethodSignature(returnType, parameterTypes, modifiers, callingConvention, genericParamCount);
}
@ -404,94 +388,116 @@ namespace IKVM.Reflection
}
bb.WriteCompressedInt(parameterCount);
// RetType
if (modifiers != null && modifiers[0] != null)
{
WriteCustomModifiers(module, bb, ELEMENT_TYPE_CMOD_OPT, modifiers[0][0]);
WriteCustomModifiers(module, bb, ELEMENT_TYPE_CMOD_REQD, modifiers[0][1]);
}
WriteCustomModifiers(module, bb, modifiers.GetReturnTypeCustomModifiers());
WriteType(module, bb, returnType);
// Param
for (int i = 0; i < parameterTypes.Length; i++)
{
if (modifiers != null && modifiers[i + 1] != null)
{
WriteCustomModifiers(module, bb, ELEMENT_TYPE_CMOD_OPT, modifiers[i + 1][0]);
WriteCustomModifiers(module, bb, ELEMENT_TYPE_CMOD_REQD, modifiers[i + 1][1]);
}
WriteCustomModifiers(module, bb, modifiers.GetParameterCustomModifiers(i));
WriteType(module, bb, parameterTypes[i]);
}
}
}
static class PackedCustomModifiers
struct PackedCustomModifiers
{
// modifiers are packed in a very specific way (and required to be so, otherwise equality checks will fail)
// For modifiers[x][y][z]:
// x = parameter index, 0 = return type, 1 = first parameters, ...
// y = 0 = optional custom modifiers, 1 = required custom modifiers
// z = the custom modifiers
// At any level the reference can be null (and *must* be null, if there are no modifiers below that level).
// Empty arrays are not allowed at any level.
// element 0 is the return type, the rest are the parameters
private readonly CustomModifiers[] customModifiers;
// this can be used to "add" elements to the modifiers array (and the elements are assumed to already be in normalized form)
internal static void SetModifiers(ref Type[][][] modifiers, int index, int optOrReq, Type[] add, int count)
private PackedCustomModifiers(CustomModifiers[] customModifiers)
{
if (add != null)
this.customModifiers = customModifiers;
}
public override int GetHashCode()
{
return Util.GetHashCode(customModifiers);
}
public override bool Equals(object obj)
{
PackedCustomModifiers? other = obj as PackedCustomModifiers?;
return other != null && Equals(other.Value);
}
internal bool Equals(PackedCustomModifiers other)
{
return Util.ArrayEquals(customModifiers, other.customModifiers);
}
internal CustomModifiers GetReturnTypeCustomModifiers()
{
if (customModifiers == null)
{
if (modifiers == null)
{
modifiers = new Type[count][][];
}
if (modifiers[index] == null)
{
modifiers[index] = new Type[2][];
}
modifiers[index][optOrReq] = add;
return new CustomModifiers();
}
return customModifiers[0];
}
internal CustomModifiers GetParameterCustomModifiers(int index)
{
if (customModifiers == null)
{
return new CustomModifiers();
}
return customModifiers[index + 1];
}
internal PackedCustomModifiers Bind(IGenericBinder binder)
{
if (customModifiers == null)
{
return new PackedCustomModifiers();
}
CustomModifiers[] expanded = new CustomModifiers[customModifiers.Length];
for (int i = 0; i < customModifiers.Length; i++)
{
expanded[i] = customModifiers[i].Bind(binder);
}
return new PackedCustomModifiers(expanded);
}
// this method make a copy of the incoming arrays (where necessary) and returns a normalized modifiers array
internal static Type[][][] CreateFromExternal(Type[] returnOptional, Type[] returnRequired, Type[][] parameterOptional, Type[][] parameterRequired, int parameterCount)
internal static PackedCustomModifiers CreateFromExternal(Type[] returnOptional, Type[] returnRequired, Type[][] parameterOptional, Type[][] parameterRequired, int parameterCount)
{
Type[][][] modifiers = null;
SetModifiers(ref modifiers, 0, 0, NormalizeAndCopy(returnOptional), parameterCount + 1);
SetModifiers(ref modifiers, 0, 1, NormalizeAndCopy(returnRequired), parameterCount + 1);
CustomModifiers[] modifiers = null;
Pack(ref modifiers, 0, CustomModifiers.FromReqOpt(returnRequired, returnOptional), parameterCount + 1);
for (int i = 0; i < parameterCount; i++)
{
SetModifiers(ref modifiers, i + 1, 0, NormalizeAndCopy(parameterOptional, i), parameterCount + 1);
SetModifiers(ref modifiers, i + 1, 1, NormalizeAndCopy(parameterRequired, i), parameterCount + 1);
Pack(ref modifiers, i + 1, CustomModifiers.FromReqOpt(Util.NullSafeElementAt(parameterRequired, i), Util.NullSafeElementAt(parameterOptional, i)), parameterCount + 1);
}
return modifiers;
return new PackedCustomModifiers(modifiers);
}
private static Type[] NormalizeAndCopy(Type[] array)
internal static PackedCustomModifiers CreateFromExternal(CustomModifiers returnTypeCustomModifiers, CustomModifiers[] parameterTypeCustomModifiers, int parameterCount)
{
if (array == null || array.Length == 0)
CustomModifiers[] customModifiers = null;
Pack(ref customModifiers, 0, returnTypeCustomModifiers, parameterCount + 1);
if (parameterTypeCustomModifiers != null)
{
return null;
}
Type[] copy = null;
for (int i = 0; i < array.Length; i++)
{
if (array[i] != null)
for (int i = 0; i < parameterCount; i++)
{
if (copy == null)
{
copy = new Type[array.Length];
}
copy[i] = array[i];
Pack(ref customModifiers, i + 1, parameterTypeCustomModifiers[i], parameterCount + 1);
}
}
return copy;
return new PackedCustomModifiers(customModifiers);
}
private static Type[] NormalizeAndCopy(Type[][] array, int index)
internal static PackedCustomModifiers Wrap(CustomModifiers[] modifiers)
{
if (array == null || array.Length == 0)
return new PackedCustomModifiers(modifiers);
}
internal static void Pack(ref CustomModifiers[] array, int index, CustomModifiers mods, int count)
{
if (!mods.IsEmpty)
{
return null;
if (array == null)
{
array = new CustomModifiers[count];
}
array[index] = mods;
}
return NormalizeAndCopy(array[index]);
}
}
}

Просмотреть файл

@ -102,7 +102,7 @@ namespace IKVM.Reflection
public MissingGenericMethodBuilder(Type declaringType, CallingConventions callingConvention, string name, int genericParameterCount)
{
method = new MissingMethod(declaringType, name, new MethodSignature(null, null, null, callingConvention, genericParameterCount));
method = new MissingMethod(declaringType, name, new MethodSignature(null, null, new PackedCustomModifiers(), callingConvention, genericParameterCount));
}
public Type[] GetGenericArguments()
@ -110,6 +110,17 @@ namespace IKVM.Reflection
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(
@ -469,12 +480,7 @@ namespace IKVM.Reflection
throw new MissingMemberException(this);
}
public override Type[] __GetRequiredCustomModifiers()
{
throw new MissingMemberException(this);
}
public override Type[] __GetOptionalCustomModifiers()
public override CustomModifiers __GetCustomModifiers()
{
throw new MissingMemberException(this);
}
@ -484,12 +490,7 @@ namespace IKVM.Reflection
throw new MissingMemberException(this);
}
public override Type[][] __GetGenericArgumentsRequiredCustomModifiers()
{
throw new MissingMemberException(this);
}
public override Type[][] __GetGenericArgumentsOptionalCustomModifiers()
public override CustomModifiers[] __GetGenericArgumentsCustomModifiers()
{
throw new MissingMemberException(this);
}
@ -693,22 +694,11 @@ namespace IKVM.Reflection
get { return Forwarder.RawDefaultValue; }
}
public override Type[] GetOptionalCustomModifiers()
public override CustomModifiers __GetCustomModifiers()
{
if (index == -1)
{
return Util.Copy(method.signature.GetReturnTypeOptionalCustomModifiers(method));
}
return Util.Copy(method.signature.GetParameterOptionalCustomModifiers(method, index));
}
public override Type[] GetRequiredCustomModifiers()
{
if (index == -1)
{
return Util.Copy(method.signature.GetReturnTypeRequiredCustomModifiers(method));
}
return Util.Copy(method.signature.GetParameterRequiredCustomModifiers(method, index));
return index == -1
? method.signature.GetReturnTypeCustomModifiers(method)
: method.signature.GetParameterCustomModifiers(method, index);
}
public override MemberInfo Member

Просмотреть файл

@ -58,12 +58,21 @@ namespace IKVM.Reflection
public abstract ParameterAttributes Attributes { get; }
public abstract int Position { get; }
public abstract object RawDefaultValue { get; }
public abstract Type[] GetOptionalCustomModifiers();
public abstract Type[] GetRequiredCustomModifiers();
public abstract CustomModifiers __GetCustomModifiers();
public abstract MemberInfo Member { get; }
public abstract int MetadataToken { get; }
internal abstract Module Module { get; }
public Type[] GetOptionalCustomModifiers()
{
return __GetCustomModifiers().GetOptional();
}
public Type[] GetRequiredCustomModifiers()
{
return __GetCustomModifiers().GetRequired();
}
public bool IsIn
{
get { return (Attributes & ParameterAttributes.In) != 0; }

Просмотреть файл

@ -84,14 +84,9 @@ namespace IKVM.Reflection
get { throw new InvalidOperationException(); }
}
public override Type[] GetOptionalCustomModifiers()
public override CustomModifiers __GetCustomModifiers()
{
return property.PropertySignature.GetOptionalCustomModifiers(parameter);
}
public override Type[] GetRequiredCustomModifiers()
{
return property.PropertySignature.GetRequiredCustomModifiers(parameter);
return property.PropertySignature.GetParameterCustomModifiers(parameter);
}
public override MemberInfo Member
@ -125,14 +120,19 @@ namespace IKVM.Reflection
get { return this.PropertySignature.PropertyType; }
}
public CustomModifiers __GetCustomModifiers()
{
return this.PropertySignature.GetCustomModifiers();
}
public Type[] GetRequiredCustomModifiers()
{
return this.PropertySignature.GetRequiredCustomModifiers();
return __GetCustomModifiers().GetRequired();
}
public Type[] GetOptionalCustomModifiers()
{
return this.PropertySignature.GetOptionalCustomModifiers();
return __GetCustomModifiers().GetOptional();
}
public bool IsSpecialName

Просмотреть файл

@ -1,5 +1,5 @@
/*
Copyright (C) 2009 Jeroen Frijters
Copyright (C) 2009-2011 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
@ -35,26 +35,20 @@ namespace IKVM.Reflection
{
private CallingConventions callingConvention;
private readonly Type propertyType;
private readonly Type[] optionalCustomModifiers;
private readonly Type[] requiredCustomModifiers;
private readonly Type[] parameterTypes;
private readonly Type[][] parameterOptionalCustomModifiers;
private readonly Type[][] parameterRequiredCustomModifiers;
private readonly PackedCustomModifiers customModifiers;
internal static PropertySignature Create(CallingConventions callingConvention, Type propertyType, Type[] optionalCustomModifiers, Type[] requiredCustomModifiers, Type[] parameterTypes, Type[][] parameterTypeOptionalCustomModifiers, Type[][] parameterTypeRequiredCustomModifiers)
internal static PropertySignature Create(CallingConventions callingConvention, Type propertyType, Type[] parameterTypes, PackedCustomModifiers customModifiers)
{
return new PropertySignature(callingConvention, propertyType, Util.Copy(optionalCustomModifiers), Util.Copy(requiredCustomModifiers), Util.Copy(parameterTypes), Util.Copy(parameterTypeOptionalCustomModifiers), Util.Copy(parameterTypeRequiredCustomModifiers));
return new PropertySignature(callingConvention, propertyType, Util.Copy(parameterTypes), customModifiers);
}
private PropertySignature(CallingConventions callingConvention, Type propertyType, Type[] optionalCustomModifiers, Type[] requiredCustomModifiers, Type[] parameterTypes, Type[][] parameterTypeOptionalCustomModifiers, Type[][] parameterTypeRequiredCustomModifiers)
private PropertySignature(CallingConventions callingConvention, Type propertyType, Type[] parameterTypes, PackedCustomModifiers customModifiers)
{
this.callingConvention = callingConvention;
this.propertyType = propertyType;
this.optionalCustomModifiers = optionalCustomModifiers;
this.requiredCustomModifiers = requiredCustomModifiers;
this.parameterTypes = parameterTypes;
this.parameterOptionalCustomModifiers = parameterTypeOptionalCustomModifiers;
this.parameterRequiredCustomModifiers = parameterTypeRequiredCustomModifiers;
this.customModifiers = customModifiers;
}
public override bool Equals(object obj)
@ -62,13 +56,12 @@ namespace IKVM.Reflection
PropertySignature other = obj as PropertySignature;
return other != null
&& other.propertyType.Equals(propertyType)
&& Util.ArrayEquals(other.optionalCustomModifiers, optionalCustomModifiers)
&& Util.ArrayEquals(other.requiredCustomModifiers, requiredCustomModifiers);
&& other.customModifiers.Equals(customModifiers);
}
public override int GetHashCode()
{
return propertyType.GetHashCode() ^ Util.GetHashCode(optionalCustomModifiers) ^ Util.GetHashCode(requiredCustomModifiers);
return propertyType.GetHashCode() ^ customModifiers.GetHashCode();
}
internal int ParameterCount
@ -96,14 +89,9 @@ namespace IKVM.Reflection
get { return propertyType; }
}
internal Type[] GetOptionalCustomModifiers()
internal CustomModifiers GetCustomModifiers()
{
return Util.Copy(optionalCustomModifiers);
}
internal Type[] GetRequiredCustomModifiers()
{
return Util.Copy(requiredCustomModifiers);
return customModifiers.GetReturnTypeCustomModifiers();
}
internal PropertySignature ExpandTypeParameters(Type declaringType)
@ -111,11 +99,8 @@ namespace IKVM.Reflection
return new PropertySignature(
callingConvention,
propertyType.BindTypeParameters(declaringType),
BindTypeParameters(declaringType, optionalCustomModifiers),
BindTypeParameters(declaringType, requiredCustomModifiers),
BindTypeParameters(declaringType, parameterTypes),
BindTypeParameters(declaringType, parameterOptionalCustomModifiers),
BindTypeParameters(declaringType, parameterRequiredCustomModifiers));
customModifiers.Bind(declaringType));
}
internal override void WriteSig(ModuleBuilder module, ByteBuffer bb)
@ -135,21 +120,13 @@ namespace IKVM.Reflection
}
bb.Write(flags);
bb.WriteCompressedInt(parameterTypes == null ? 0 : parameterTypes.Length);
WriteCustomModifiers(module, bb, ELEMENT_TYPE_CMOD_REQD, requiredCustomModifiers);
WriteCustomModifiers(module, bb, ELEMENT_TYPE_CMOD_OPT, optionalCustomModifiers);
WriteCustomModifiers(module, bb, customModifiers.GetReturnTypeCustomModifiers());
WriteType(module, bb, propertyType);
if (parameterTypes != null)
{
for (int i = 0; i < parameterTypes.Length; i++)
{
if (parameterRequiredCustomModifiers != null)
{
WriteCustomModifiers(module, bb, ELEMENT_TYPE_CMOD_REQD, parameterRequiredCustomModifiers[i]);
}
if (parameterOptionalCustomModifiers != null)
{
WriteCustomModifiers(module, bb, ELEMENT_TYPE_CMOD_OPT, parameterOptionalCustomModifiers[i]);
}
WriteCustomModifiers(module, bb, customModifiers.GetParameterCustomModifiers(i));
WriteType(module, bb, parameterTypes[i]);
}
}
@ -160,14 +137,9 @@ namespace IKVM.Reflection
return parameterTypes[parameter];
}
internal Type[] GetOptionalCustomModifiers(int parameter)
internal CustomModifiers GetParameterCustomModifiers(int parameter)
{
return parameterOptionalCustomModifiers == null ? Type.EmptyTypes : parameterOptionalCustomModifiers[parameter];
}
internal Type[] GetRequiredCustomModifiers(int parameter)
{
return parameterRequiredCustomModifiers == null ? Type.EmptyTypes : parameterRequiredCustomModifiers[parameter];
return customModifiers.GetParameterCustomModifiers(parameter);
}
internal CallingConventions CallingConvention
@ -192,32 +164,18 @@ namespace IKVM.Reflection
callingConvention |= CallingConventions.ExplicitThis;
}
Type returnType;
Type[] returnTypeRequiredCustomModifiers;
Type[] returnTypeOptionalCustomModifiers;
Type[] parameterTypes;
Type[][] parameterRequiredCustomModifiers;
Type[][] parameterOptionalCustomModifiers;
int paramCount = br.ReadCompressedInt();
ReadCustomModifiers(module, br, context, out returnTypeRequiredCustomModifiers, out returnTypeOptionalCustomModifiers);
CustomModifiers[] mods = null;
PackedCustomModifiers.Pack(ref mods, 0, CustomModifiers.Read(module, br, context), paramCount + 1);
returnType = ReadRetType(module, br, context);
parameterTypes = new Type[paramCount];
parameterRequiredCustomModifiers = null;
parameterOptionalCustomModifiers = null;
for (int i = 0; i < parameterTypes.Length; i++)
{
if (IsCustomModifier(br.PeekByte()))
{
if (parameterOptionalCustomModifiers == null)
{
parameterOptionalCustomModifiers = new Type[parameterTypes.Length][];
parameterRequiredCustomModifiers = new Type[parameterTypes.Length][];
}
ReadCustomModifiers(module, br, context, out parameterRequiredCustomModifiers[i], out parameterOptionalCustomModifiers[i]);
}
PackedCustomModifiers.Pack(ref mods, i + 1, CustomModifiers.Read(module, br, context), paramCount + 1);
parameterTypes[i] = ReadParam(module, br, context);
}
return new PropertySignature(callingConvention, returnType, returnTypeOptionalCustomModifiers, returnTypeRequiredCustomModifiers,
parameterTypes, parameterOptionalCustomModifiers, parameterRequiredCustomModifiers);
return new PropertySignature(callingConvention, returnType, parameterTypes, PackedCustomModifiers.Wrap(mods));
}
}
}

Просмотреть файл

@ -351,7 +351,7 @@ namespace IKVM.Reflection.Reader
private static void AddNamedArgument(List<CustomAttributeNamedArgument> list, Type attributeType, string fieldName, Type valueType, object value)
{
// some fields are not available on the .NET Compact Framework version of DllImportAttribute
FieldInfo field = attributeType.FindField(fieldName, FieldSignature.Create(valueType, null, null));
FieldInfo field = attributeType.FindField(fieldName, FieldSignature.Create(valueType, new CustomModifiers()));
if (field != null)
{
list.Add(new CustomAttributeNamedArgument(field, new CustomAttributeTypedArgument(valueType, value)));
@ -449,14 +449,11 @@ namespace IKVM.Reflection.Reader
}
}
public override Type[] GetRequiredCustomModifiers()
public override CustomModifiers __GetCustomModifiers()
{
return Util.Copy(position == -1 ? method.MethodSignature.GetReturnTypeRequiredCustomModifiers(method) : method.MethodSignature.GetParameterRequiredCustomModifiers(method, position));
}
public override Type[] GetOptionalCustomModifiers()
{
return Util.Copy(position == -1 ? method.MethodSignature.GetReturnTypeOptionalCustomModifiers(method) : method.MethodSignature.GetParameterOptionalCustomModifiers(method, position));
return position == -1
? method.MethodSignature.GetReturnTypeCustomModifiers(method)
: method.MethodSignature.GetParameterCustomModifiers(method, position);
}
public override MemberInfo Member

Просмотреть файл

@ -297,16 +297,10 @@ namespace IKVM.Reflection.Reader
return typeArgs[index];
}
public override Type[][] __GetGenericArgumentsOptionalCustomModifiers()
public override CustomModifiers[] __GetGenericArgumentsCustomModifiers()
{
PopulateGenericArguments();
return Util.Copy(new Type[typeArgs.Length][]);
}
public override Type[][] __GetGenericArgumentsRequiredCustomModifiers()
{
PopulateGenericArguments();
return Util.Copy(new Type[typeArgs.Length][]);
return new CustomModifiers[typeArgs.Length];
}
public override bool IsGenericType

Просмотреть файл

@ -100,31 +100,28 @@ namespace IKVM.Reflection
}
int genArgCount = br.ReadCompressedInt();
Type[] args = new Type[genArgCount];
Type[][] reqmod = null;
Type[][] optmod = null;
CustomModifiers[] mods = null;
for (int i = 0; i < genArgCount; i++)
{
// LAMESPEC the Type production (23.2.12) doesn't include CustomMod* for genericinst, but C++ uses it, the verifier allows it and ildasm also supports it
CustomModifiers mods = ReadCustomModifiers(module, br, context);
if (mods.required != null || mods.optional != null)
CustomModifiers cm = CustomModifiers.Read(module, br, context);
if (!cm.IsEmpty)
{
if (reqmod == null)
if (mods == null)
{
reqmod = new Type[genArgCount][];
optmod = new Type[genArgCount][];
mods = new CustomModifiers[genArgCount];
}
reqmod[i] = mods.required;
optmod[i] = mods.optional;
mods[i] = cm;
}
args[i] = ReadType(module, br, context);
}
return GenericTypeInstance.Make(type, args, reqmod, optmod);
return GenericTypeInstance.Make(type, args, mods);
}
internal static Type ReadTypeSpec(ModuleReader module, ByteReader br, IGenericContext context)
{
// LAMESPEC a TypeSpec can contain custom modifiers (C++/CLI generates "newarr (TypeSpec with custom modifiers)")
SkipCustomModifiers(br);
CustomModifiers.Skip(br);
// LAMESPEC anything can be adorned by (useless) custom modifiers
// also, VAR and MVAR are also used in TypeSpec (contrary to what the spec says)
return ReadType(module, br, context);
@ -229,14 +226,14 @@ namespace IKVM.Reflection
case ELEMENT_TYPE_GENERICINST:
return ReadGenericInst(module, br, context);
case ELEMENT_TYPE_SZARRAY:
mods = ReadCustomModifiers(module, br, context);
return ReadType(module, br, context).__MakeArrayType(mods.required, mods.optional);
mods = CustomModifiers.Read(module, br, context);
return ReadType(module, br, context).__MakeArrayType(mods);
case ELEMENT_TYPE_ARRAY:
mods = ReadCustomModifiers(module, br, context);
return ReadType(module, br, context).__MakeArrayType(br.ReadCompressedInt(), ReadArrayBounds(br), ReadArrayBounds(br), mods.required, mods.optional);
mods = CustomModifiers.Read(module, br, context);
return ReadType(module, br, context).__MakeArrayType(br.ReadCompressedInt(), ReadArrayBounds(br), ReadArrayBounds(br), mods);
case ELEMENT_TYPE_PTR:
mods = ReadCustomModifiers(module, br, context);
return ReadTypeOrVoid(module, br, context).__MakePointerType(mods.required, mods.optional);
mods = CustomModifiers.Read(module, br, context);
return ReadTypeOrVoid(module, br, context).__MakePointerType(mods);
case ELEMENT_TYPE_FNPTR:
return ReadFunctionPointer(module, br, context);
default:
@ -260,14 +257,14 @@ namespace IKVM.Reflection
}
else
{
SkipCustomModifiers(br);
CustomModifiers.Skip(br);
bool pinned = false;
if (br.PeekByte() == ELEMENT_TYPE_PINNED)
{
br.ReadByte();
pinned = true;
}
SkipCustomModifiers(br);
CustomModifiers.Skip(br);
Type type = ReadTypeOrByRef(module, br, context);
list.Add(new LocalVariableInfo(i, type, pinned));
}
@ -281,9 +278,9 @@ namespace IKVM.Reflection
br.ReadByte();
// LAMESPEC it is allowed (by C++/CLI, ilasm and peverify) to have custom modifiers after the BYREF
// (which makes sense, as it is analogous to pointers)
CustomModifiers mods = ReadCustomModifiers(module, br, context);
CustomModifiers mods = CustomModifiers.Read(module, br, context);
// C++/CLI generates void& local variables, so we need to use ReadTypeOrVoid here
return ReadTypeOrVoid(module, br, context).__MakeByRefType(mods.required, mods.optional);
return ReadTypeOrVoid(module, br, context).__MakeByRefType(mods);
}
else
{
@ -331,8 +328,7 @@ namespace IKVM.Reflection
int rank = type.GetArrayRank();
bb.Write(ELEMENT_TYPE_ARRAY);
// LAMESPEC the Type production (23.2.12) doesn't include CustomMod* for arrays, but the verifier allows it and ildasm also supports it
WriteCustomModifiers(module, bb, ELEMENT_TYPE_CMOD_REQD, type.__GetRequiredCustomModifiers());
WriteCustomModifiers(module, bb, ELEMENT_TYPE_CMOD_OPT, type.__GetOptionalCustomModifiers());
WriteCustomModifiers(module, bb, type.__GetCustomModifiers());
WriteType(module, bb, type.GetElementType());
bb.WriteCompressedInt(rank);
int[] sizes = type.__GetArraySizes();
@ -357,8 +353,7 @@ namespace IKVM.Reflection
{
bb.Write(ELEMENT_TYPE_PTR);
}
WriteCustomModifiers(module, bb, ELEMENT_TYPE_CMOD_REQD, type.__GetRequiredCustomModifiers());
WriteCustomModifiers(module, bb, ELEMENT_TYPE_CMOD_OPT, type.__GetOptionalCustomModifiers());
WriteCustomModifiers(module, bb, type.__GetCustomModifiers());
type = type.GetElementType();
}
Universe u = module.universe;
@ -467,8 +462,7 @@ namespace IKVM.Reflection
private static void WriteGenericSignature(ModuleBuilder module, ByteBuffer bb, Type type)
{
Type[] typeArguments = type.GetGenericArguments();
Type[][] requiredCustomModifiers = type.__GetGenericArgumentsRequiredCustomModifiers();
Type[][] optionalCustomModifiers = type.__GetGenericArgumentsOptionalCustomModifiers();
CustomModifiers[] customModifiers = type.__GetGenericArgumentsCustomModifiers();
if (!type.IsGenericTypeDefinition)
{
type = type.GetGenericTypeDefinition();
@ -486,68 +480,21 @@ namespace IKVM.Reflection
bb.WriteCompressedInt(typeArguments.Length);
for (int i = 0; i < typeArguments.Length; i++)
{
WriteCustomModifiers(module, bb, ELEMENT_TYPE_CMOD_REQD, requiredCustomModifiers[i]);
WriteCustomModifiers(module, bb, ELEMENT_TYPE_CMOD_OPT, optionalCustomModifiers[i]);
WriteCustomModifiers(module, bb, customModifiers[i]);
WriteType(module, bb, typeArguments[i]);
}
}
protected static void WriteCustomModifiers(ModuleBuilder module, ByteBuffer bb, byte mod, Type[] modifiers)
protected static void WriteCustomModifiers(ModuleBuilder module, ByteBuffer bb, CustomModifiers modifiers)
{
if (modifiers != null)
foreach (CustomModifiers.Entry entry in modifiers)
{
foreach (Type type in modifiers)
{
bb.Write(mod);
bb.WriteTypeDefOrRefEncoded(module.GetTypeTokenForMemberRef(type));
}
bb.Write(entry.IsRequired ? ELEMENT_TYPE_CMOD_REQD : ELEMENT_TYPE_CMOD_OPT);
bb.WriteTypeDefOrRefEncoded(module.GetTypeTokenForMemberRef(entry.Type));
}
}
protected static bool IsCustomModifier(byte b)
{
return b == ELEMENT_TYPE_CMOD_OPT || b == ELEMENT_TYPE_CMOD_REQD;
}
struct CustomModifiers
{
internal Type[] required;
internal Type[] optional;
}
private static CustomModifiers ReadCustomModifiers(ModuleReader module, ByteReader br, IGenericContext context)
{
CustomModifiers mods = new CustomModifiers();
byte b = br.PeekByte();
if (IsCustomModifier(b))
{
List<Type> required = new List<Type>();
List<Type> optional = new List<Type>();
while (IsCustomModifier(b))
{
bool req = br.ReadByte() == ELEMENT_TYPE_CMOD_REQD;
Type type = ReadTypeDefOrRefEncoded(module, br, context);
(req ? required : optional).Add(type);
b = br.PeekByte();
}
mods.required = required.ToArray();
mods.optional = optional.ToArray();
}
return mods;
}
protected static void SkipCustomModifiers(ByteReader br)
{
byte b = br.PeekByte();
while (IsCustomModifier(b))
{
br.ReadByte();
br.ReadCompressedInt();
b = br.PeekByte();
}
}
private static Type ReadTypeDefOrRefEncoded(ModuleReader module, ByteReader br, IGenericContext context)
internal static Type ReadTypeDefOrRefEncoded(ModuleReader module, ByteReader br, IGenericContext context)
{
int encoded = br.ReadCompressedInt();
switch (encoded & 3)
@ -563,37 +510,6 @@ namespace IKVM.Reflection
}
}
protected static void ReadCustomModifiers(ModuleReader module, ByteReader br, IGenericContext context, out Type[] requiredCustomModifiers, out Type[] optionalCustomModifiers)
{
byte b = br.PeekByte();
if (IsCustomModifier(b))
{
List<Type> required = new List<Type>();
List<Type> optional = new List<Type>();
while (IsCustomModifier(b))
{
br.ReadByte();
Type type = ReadTypeDefOrRefEncoded(module, br, context);
if (b == ELEMENT_TYPE_CMOD_REQD)
{
required.Add(type);
}
else
{
optional.Add(type);
}
b = br.PeekByte();
}
requiredCustomModifiers = required.ToArray();
optionalCustomModifiers = optional.ToArray();
}
else
{
requiredCustomModifiers = null;
optionalCustomModifiers = null;
}
}
// unmanaged calling convention
internal static void WriteStandAloneMethodSig(ModuleBuilder module, ByteBuffer bb, CallingConvention callingConvention, Type returnType, Type[] parameterTypes)
{
@ -671,8 +587,8 @@ namespace IKVM.Reflection
}
internal static void WritePropertySig(ModuleBuilder module, ByteBuffer bb, CallingConventions callingConvention,
Type returnType, Type[] returnTypeRequiredCustomModifiers, Type[] returnTypeOptionalCustomModifiers,
Type[] parameterTypes, Type[][] parameterTypeRequiredCustomModifiers, Type[][] parameterTypeOptionalCustomModifiers)
Type returnType, CustomModifiers returnTypeCustomModifiers,
Type[] parameterTypes, CustomModifiers[] parameterTypeCustomModifiers)
{
byte flags = PROPERTY;
if ((callingConvention & CallingConventions.HasThis) != 0)
@ -689,20 +605,15 @@ namespace IKVM.Reflection
}
bb.Write(flags);
bb.WriteCompressedInt(parameterTypes == null ? 0 : parameterTypes.Length);
WriteCustomModifiers(module, bb, ELEMENT_TYPE_CMOD_REQD, returnTypeRequiredCustomModifiers);
WriteCustomModifiers(module, bb, ELEMENT_TYPE_CMOD_OPT, returnTypeOptionalCustomModifiers);
WriteCustomModifiers(module, bb, returnTypeCustomModifiers);
WriteType(module, bb, returnType);
if (parameterTypes != null)
{
for (int i = 0; i < parameterTypes.Length; i++)
{
if (parameterTypeRequiredCustomModifiers != null)
if (parameterTypeCustomModifiers != null)
{
WriteCustomModifiers(module, bb, ELEMENT_TYPE_CMOD_REQD, parameterTypeRequiredCustomModifiers[i]);
}
if (parameterTypeOptionalCustomModifiers != null)
{
WriteCustomModifiers(module, bb, ELEMENT_TYPE_CMOD_OPT, parameterTypeOptionalCustomModifiers[i]);
WriteCustomModifiers(module, bb, parameterTypeCustomModifiers[i]);
}
WriteType(module, bb, parameterTypes[i]);
}
@ -729,7 +640,7 @@ namespace IKVM.Reflection
{
br.ReadByte();
int paramCount = br.ReadCompressedInt();
SkipCustomModifiers(br);
CustomModifiers.Skip(br);
ReadRetType(module, br, null);
for (int i = 0; i < paramCount; i++)
{
@ -739,12 +650,12 @@ namespace IKVM.Reflection
Type[] types = new Type[paramCount - i];
for (int j = 0; j < types.Length; j++)
{
SkipCustomModifiers(br);
CustomModifiers.Skip(br);
types[j] = ReadType(module, br, null);
}
return types;
}
SkipCustomModifiers(br);
CustomModifiers.Skip(br);
ReadType(module, br, null);
}
return Type.EmptyTypes;
@ -763,42 +674,5 @@ namespace IKVM.Reflection
}
return expanded;
}
protected static Type[][] BindTypeParameters(IGenericBinder binder, Type[][] types)
{
if (types == null)
{
return null;
}
Type[][] expanded = new Type[types.Length][];
for (int i = 0; i < types.Length; i++)
{
expanded[i] = BindTypeParameters(binder, types[i]);
}
return expanded;
}
protected static Type[][][] BindTypeParameters(IGenericBinder binder, Type[][][] types)
{
if (types == null)
{
return null;
}
Type[][][] expanded = new Type[types.Length][][];
for (int i = 0; i < types.Length; i++)
{
expanded[i] = BindTypeParameters(binder, types[i]);
}
return expanded;
}
protected static Type[] BindTypeParameters(IGenericBinder binder, Type[][][] types, int index, int optOrReq)
{
if (types == null || types[index] == null)
{
return null;
}
return BindTypeParameters(binder, types[index][optOrReq]);
}
}
}

Просмотреть файл

@ -146,14 +146,21 @@ namespace IKVM.Reflection
return Empty<PropertyInfo>.Array;
}
public virtual Type[] __GetRequiredCustomModifiers()
public virtual CustomModifiers __GetCustomModifiers()
{
return Type.EmptyTypes;
return new CustomModifiers();
}
public virtual Type[] __GetOptionalCustomModifiers()
[Obsolete("Please use __GetCustomModifiers() instead.")]
public Type[] __GetRequiredCustomModifiers()
{
return Type.EmptyTypes;
return __GetCustomModifiers().GetRequired();
}
[Obsolete("Please use __GetCustomModifiers() instead.")]
public Type[] __GetOptionalCustomModifiers()
{
return __GetCustomModifiers().GetOptional();
}
public virtual bool HasElementType
@ -284,14 +291,33 @@ namespace IKVM.Reflection
return Type.EmptyTypes;
}
public virtual Type[][] __GetGenericArgumentsRequiredCustomModifiers()
public virtual CustomModifiers[] __GetGenericArgumentsCustomModifiers()
{
return Empty<Type[]>.Array;
return Empty<CustomModifiers>.Array;
}
public virtual Type[][] __GetGenericArgumentsOptionalCustomModifiers()
[Obsolete("Please use __GetGenericArgumentsCustomModifiers() instead")]
public Type[][] __GetGenericArgumentsRequiredCustomModifiers()
{
return Empty<Type[]>.Array;
CustomModifiers[] customModifiers = __GetGenericArgumentsCustomModifiers();
Type[][] array = new Type[customModifiers.Length][];
for (int i = 0; i < array.Length; i++)
{
array[i] = customModifiers[i].GetRequired();
}
return array;
}
[Obsolete("Please use __GetGenericArgumentsCustomModifiers() instead")]
public Type[][] __GetGenericArgumentsOptionalCustomModifiers()
{
CustomModifiers[] customModifiers = __GetGenericArgumentsCustomModifiers();
Type[][] array = new Type[customModifiers.Length][];
for (int i = 0; i < array.Length; i++)
{
array[i] = customModifiers[i].GetOptional();
}
return array;
}
public virtual Type GetGenericTypeDefinition()
@ -1226,61 +1252,110 @@ namespace IKVM.Reflection
public Type MakeArrayType()
{
return ArrayType.Make(this, null, null);
return ArrayType.Make(this, new CustomModifiers());
}
public Type __MakeArrayType(CustomModifiers customModifiers)
{
return ArrayType.Make(this, customModifiers);
}
[Obsolete("Please use __MakeArrayType(CustomModifiers) instead.")]
public Type __MakeArrayType(Type[] requiredCustomModifiers, Type[] optionalCustomModifiers)
{
return ArrayType.Make(this, Util.Copy(requiredCustomModifiers), Util.Copy(optionalCustomModifiers));
return __MakeArrayType(CustomModifiers.FromReqOpt(requiredCustomModifiers, optionalCustomModifiers));
}
public Type MakeArrayType(int rank)
{
return MultiArrayType.Make(this, rank, Empty<int>.Array, new int[rank], null, null);
return __MakeArrayType(rank, new CustomModifiers());
}
public Type __MakeArrayType(int rank, CustomModifiers customModifiers)
{
return MultiArrayType.Make(this, rank, Empty<int>.Array, new int[rank], customModifiers);
}
[Obsolete("Please use __MakeArrayType(int, CustomModifiers) instead.")]
public Type __MakeArrayType(int rank, Type[] requiredCustomModifiers, Type[] optionalCustomModifiers)
{
return MultiArrayType.Make(this, rank, Empty<int>.Array, new int[rank], Util.Copy(requiredCustomModifiers), Util.Copy(optionalCustomModifiers));
return __MakeArrayType(rank, CustomModifiers.FromReqOpt(requiredCustomModifiers, optionalCustomModifiers));
}
public Type __MakeArrayType(int rank, int[] sizes, int[] lobounds, CustomModifiers customModifiers)
{
return MultiArrayType.Make(this, rank, sizes ?? Empty<int>.Array, lobounds ?? Empty<int>.Array, customModifiers);
}
[Obsolete("Please use __MakeArrayType(int, int[], int[], CustomModifiers) instead.")]
public Type __MakeArrayType(int rank, int[] sizes, int[] lobounds, Type[] requiredCustomModifiers, Type[] optionalCustomModifiers)
{
return MultiArrayType.Make(this, rank, sizes ?? Empty<int>.Array, lobounds ?? Empty<int>.Array, Util.Copy(requiredCustomModifiers), Util.Copy(optionalCustomModifiers));
return __MakeArrayType(rank, sizes, lobounds, CustomModifiers.FromReqOpt(requiredCustomModifiers, optionalCustomModifiers));
}
public Type MakeByRefType()
{
return ByRefType.Make(this, null, null);
return ByRefType.Make(this, new CustomModifiers());
}
public Type __MakeByRefType(CustomModifiers customModifiers)
{
return ByRefType.Make(this, customModifiers);
}
[Obsolete("Please use __MakeByRefType(CustomModifiers) instead.")]
public Type __MakeByRefType(Type[] requiredCustomModifiers, Type[] optionalCustomModifiers)
{
return ByRefType.Make(this, Util.Copy(requiredCustomModifiers), Util.Copy(optionalCustomModifiers));
return __MakeByRefType(CustomModifiers.FromReqOpt(requiredCustomModifiers, optionalCustomModifiers));
}
public Type MakePointerType()
{
return PointerType.Make(this, null, null);
return PointerType.Make(this, new CustomModifiers());
}
public Type __MakePointerType(CustomModifiers customModifiers)
{
return PointerType.Make(this, customModifiers);
}
[Obsolete("Please use __MakeByRefType(CustomModifiers) instead.")]
public Type __MakePointerType(Type[] requiredCustomModifiers, Type[] optionalCustomModifiers)
{
return PointerType.Make(this, Util.Copy(requiredCustomModifiers), Util.Copy(optionalCustomModifiers));
return __MakePointerType(CustomModifiers.FromReqOpt(requiredCustomModifiers, optionalCustomModifiers));
}
public Type MakeGenericType(params Type[] typeArguments)
{
return __MakeGenericType(typeArguments, null, null);
return __MakeGenericType(typeArguments, null);
}
public Type __MakeGenericType(Type[] typeArguments, CustomModifiers[] customModifiers)
{
if (!this.__IsMissing && !this.IsGenericTypeDefinition)
{
throw new InvalidOperationException();
}
return GenericTypeInstance.Make(this, Util.Copy(typeArguments), customModifiers == null ? null : (CustomModifiers[])customModifiers.Clone());
}
[Obsolete("Please use __MakeGenericType(Type[], CustomModifiers[]) instead.")]
public Type __MakeGenericType(Type[] typeArguments, Type[][] requiredCustomModifiers, Type[][] optionalCustomModifiers)
{
if (!this.__IsMissing && !this.IsGenericTypeDefinition)
{
throw new InvalidOperationException();
}
return GenericTypeInstance.Make(this, Util.Copy(typeArguments), Util.Copy(requiredCustomModifiers), Util.Copy(optionalCustomModifiers));
CustomModifiers[] mods = null;
if (requiredCustomModifiers != null || optionalCustomModifiers != null)
{
mods = new CustomModifiers[typeArguments.Length];
for (int i = 0; i < mods.Length; i++)
{
mods[i] = CustomModifiers.FromReqOpt(Util.NullSafeElementAt(requiredCustomModifiers, i), Util.NullSafeElementAt(optionalCustomModifiers, i));
}
}
return GenericTypeInstance.Make(this, Util.Copy(typeArguments), mods);
}
public static System.Type __GetSystemType(TypeCode typeCode)
@ -1582,7 +1657,7 @@ namespace IKVM.Reflection
{
Type[] args = GetGenericArguments();
Type.InplaceBindTypeParameters(binder, args);
return GenericTypeInstance.Make(this, args, null, null);
return GenericTypeInstance.Make(this, args, null);
}
else
{
@ -1590,7 +1665,7 @@ namespace IKVM.Reflection
}
}
internal static void InplaceBindTypeParameters(IGenericBinder binder, Type[] types)
private static void InplaceBindTypeParameters(IGenericBinder binder, Type[] types)
{
for (int i = 0; i < types.Length; i++)
{
@ -1678,19 +1753,24 @@ namespace IKVM.Reflection
internal ConstructorInfo GetPseudoCustomAttributeConstructor(params Type[] parameterTypes)
{
Universe u = this.Module.universe;
MethodSignature methodSig = MethodSignature.MakeFromBuilder(u.System_Void, parameterTypes, null, CallingConventions.Standard | CallingConventions.HasThis, 0);
MethodSignature methodSig = MethodSignature.MakeFromBuilder(u.System_Void, parameterTypes, new PackedCustomModifiers(), CallingConventions.Standard | CallingConventions.HasThis, 0);
MethodBase mb =
FindMethod(".ctor", methodSig) ??
u.GetMissingMethodOrThrow(this, ".ctor", methodSig);
return (ConstructorInfo)mb;
}
public MethodBase __CreateMissingMethod(string name, CallingConventions callingConvention, Type returnType, Type[] returnTypeRequiredCustomModifiers, Type[] returnTypeOptionalCustomModifiers, Type[] parameterTypes, Type[][] parameterTypeRequiredCustomModifiers, Type[][] parameterTypeOptionalCustomModifiers)
public MethodBase __CreateMissingMethod(string name, CallingConventions callingConvention, Type returnType, CustomModifiers returnTypeCustomModifiers, Type[] parameterTypes, CustomModifiers[] parameterTypeCustomModifiers)
{
return CreateMissingMethod(name, callingConvention, returnType, parameterTypes, PackedCustomModifiers.CreateFromExternal(returnTypeCustomModifiers, parameterTypeCustomModifiers, parameterTypes.Length));
}
private MethodBase CreateMissingMethod(string name, CallingConventions callingConvention, Type returnType, Type[] parameterTypes, PackedCustomModifiers customModifiers)
{
MethodSignature sig = new MethodSignature(
returnType ?? this.Module.universe.System_Void,
Util.Copy(parameterTypes),
PackedCustomModifiers.CreateFromExternal(returnTypeOptionalCustomModifiers, returnTypeRequiredCustomModifiers, parameterTypeOptionalCustomModifiers, parameterTypeRequiredCustomModifiers, parameterTypes.Length),
customModifiers,
callingConvention,
0);
MethodInfo method = new MissingMethod(this, name, sig);
@ -1701,9 +1781,21 @@ namespace IKVM.Reflection
return method;
}
[Obsolete("Please use __CreateMissingMethod(string, CallingConventions, Type, CustomModifiers, Type[], CustomModifiers[]) instead")]
public MethodBase __CreateMissingMethod(string name, CallingConventions callingConvention, Type returnType, Type[] returnTypeRequiredCustomModifiers, Type[] returnTypeOptionalCustomModifiers, Type[] parameterTypes, Type[][] parameterTypeRequiredCustomModifiers, Type[][] parameterTypeOptionalCustomModifiers)
{
return CreateMissingMethod(name, callingConvention, returnType, parameterTypes, PackedCustomModifiers.CreateFromExternal(returnTypeOptionalCustomModifiers, returnTypeRequiredCustomModifiers, parameterTypeOptionalCustomModifiers, parameterTypeRequiredCustomModifiers, parameterTypes.Length));
}
public FieldInfo __CreateMissingField(string name, Type fieldType, CustomModifiers customModifiers)
{
return new MissingField(this, name, FieldSignature.Create(fieldType, customModifiers));
}
[Obsolete("Please use __CreateMissingField(string, Type, CustomModifiers) instead")]
public FieldInfo __CreateMissingField(string name, Type fieldType, Type[] requiredCustomModifiers, Type[] optionalCustomModifiers)
{
return new MissingField(this, name, FieldSignature.Create(fieldType, optionalCustomModifiers, requiredCustomModifiers));
return __CreateMissingField(name, fieldType, CustomModifiers.FromReqOpt(requiredCustomModifiers, optionalCustomModifiers));
}
internal virtual Type SetMetadataTokenForMissing(int token)
@ -1733,32 +1825,24 @@ namespace IKVM.Reflection
{
protected readonly Type elementType;
private int token;
private readonly Type[] requiredCustomModifiers;
private readonly Type[] optionalCustomModifiers;
private readonly CustomModifiers mods;
protected ElementHolderType(Type elementType, Type[] requiredCustomModifiers, Type[] optionalCustomModifiers)
protected ElementHolderType(Type elementType, CustomModifiers mods)
{
this.elementType = elementType;
this.requiredCustomModifiers = requiredCustomModifiers;
this.optionalCustomModifiers = optionalCustomModifiers;
this.mods = mods;
}
protected bool EqualsHelper(ElementHolderType other)
{
return other != null
&& other.elementType.Equals(elementType)
&& Util.ArrayEquals(other.requiredCustomModifiers, requiredCustomModifiers)
&& Util.ArrayEquals(other.optionalCustomModifiers, optionalCustomModifiers);
&& other.mods.Equals(mods);
}
public override Type[] __GetRequiredCustomModifiers()
public override CustomModifiers __GetCustomModifiers()
{
return Util.Copy(requiredCustomModifiers);
}
public override Type[] __GetOptionalCustomModifiers()
{
return Util.Copy(optionalCustomModifiers);
return mods;
}
public sealed override string Name
@ -1834,15 +1918,13 @@ namespace IKVM.Reflection
internal sealed override Type BindTypeParameters(IGenericBinder binder)
{
Type type = elementType.BindTypeParameters(binder);
Type[] req = BindArray(requiredCustomModifiers, binder);
Type[] opt = BindArray(optionalCustomModifiers, binder);
CustomModifiers mods = this.mods.Bind(binder);
if (ReferenceEquals(type, elementType)
&& ReferenceEquals(req, requiredCustomModifiers)
&& ReferenceEquals(opt, optionalCustomModifiers))
&& mods.Equals(this.mods))
{
return this;
}
return Wrap(type, req, opt);
return Wrap(type, mods);
}
internal override void CheckBaked()
@ -1850,28 +1932,6 @@ namespace IKVM.Reflection
elementType.CheckBaked();
}
private static Type[] BindArray(Type[] array, IGenericBinder binder)
{
if (array ==null || array.Length == 0)
{
return array;
}
Type[] result = array;
for (int i = 0; i < array.Length; i++)
{
Type type = array[i].BindTypeParameters(binder);
if (!ReferenceEquals(type, array[i]))
{
if (result == array)
{
result = (Type[])array.Clone();
}
result[i] = type;
}
}
return result;
}
internal sealed override IList<CustomAttributeData> GetCustomAttributesData(Type attributeType)
{
return CustomAttributeData.EmptyList;
@ -1879,18 +1939,18 @@ namespace IKVM.Reflection
internal abstract string GetSuffix();
protected abstract Type Wrap(Type type, Type[] requiredCustomModifiers, Type[] optionalCustomModifiers);
protected abstract Type Wrap(Type type, CustomModifiers mods);
}
sealed class ArrayType : ElementHolderType
{
internal static Type Make(Type type, Type[] requiredCustomModifiers, Type[] optionalCustomModifiers)
internal static Type Make(Type type, CustomModifiers mods)
{
return type.Module.CanonicalizeType(new ArrayType(type, requiredCustomModifiers, optionalCustomModifiers));
return type.Module.CanonicalizeType(new ArrayType(type, mods));
}
private ArrayType(Type type, Type[] requiredCustomModifiers, Type[] optionalCustomModifiers)
: base(type, requiredCustomModifiers, optionalCustomModifiers)
private ArrayType(Type type, CustomModifiers mods)
: base(type, mods)
{
}
@ -1960,9 +2020,9 @@ namespace IKVM.Reflection
return "[]";
}
protected override Type Wrap(Type type, Type[] requiredCustomModifiers, Type[] optionalCustomModifiers)
protected override Type Wrap(Type type, CustomModifiers mods)
{
return Make(type, requiredCustomModifiers, optionalCustomModifiers);
return Make(type, mods);
}
}
@ -1972,13 +2032,13 @@ namespace IKVM.Reflection
private readonly int[] sizes;
private readonly int[] lobounds;
internal static Type Make(Type type, int rank, int[] sizes, int[] lobounds, Type[] requiredCustomModifiers, Type[] optionalCustomModifiers)
internal static Type Make(Type type, int rank, int[] sizes, int[] lobounds, CustomModifiers mods)
{
return type.Module.CanonicalizeType(new MultiArrayType(type, rank, sizes, lobounds, requiredCustomModifiers, optionalCustomModifiers));
return type.Module.CanonicalizeType(new MultiArrayType(type, rank, sizes, lobounds, mods));
}
private MultiArrayType(Type type, int rank, int[] sizes, int[] lobounds, Type[] requiredCustomModifiers, Type[] optionalCustomModifiers)
: base(type, requiredCustomModifiers, optionalCustomModifiers)
private MultiArrayType(Type type, int rank, int[] sizes, int[] lobounds, CustomModifiers mods)
: base(type, mods)
{
this.rank = rank;
this.sizes = sizes;
@ -2080,9 +2140,9 @@ namespace IKVM.Reflection
}
}
protected override Type Wrap(Type type, Type[] requiredCustomModifiers, Type[] optionalCustomModifiers)
protected override Type Wrap(Type type, CustomModifiers mods)
{
return Make(type, rank, sizes, lobounds, requiredCustomModifiers, optionalCustomModifiers);
return Make(type, rank, sizes, lobounds, mods);
}
}
@ -2166,14 +2226,9 @@ namespace IKVM.Reflection
get { return null; }
}
public override Type[] GetOptionalCustomModifiers()
public override CustomModifiers __GetCustomModifiers()
{
return Empty<Type>.Array;
}
public override Type[] GetRequiredCustomModifiers()
{
return Empty<Type>.Array;
return new CustomModifiers();
}
public override MemberInfo Member
@ -2195,13 +2250,13 @@ namespace IKVM.Reflection
sealed class ByRefType : ElementHolderType
{
internal static Type Make(Type type, Type[] requiredCustomModifiers, Type[] optionalCustomModifiers)
internal static Type Make(Type type, CustomModifiers mods)
{
return type.Module.CanonicalizeType(new ByRefType(type, requiredCustomModifiers, optionalCustomModifiers));
return type.Module.CanonicalizeType(new ByRefType(type, mods));
}
private ByRefType(Type type, Type[] requiredCustomModifiers, Type[] optionalCustomModifiers)
: base(type, requiredCustomModifiers, optionalCustomModifiers)
private ByRefType(Type type, CustomModifiers mods)
: base(type, mods)
{
}
@ -2235,21 +2290,21 @@ namespace IKVM.Reflection
return "&";
}
protected override Type Wrap(Type type, Type[] requiredCustomModifiers, Type[] optionalCustomModifiers)
protected override Type Wrap(Type type, CustomModifiers mods)
{
return Make(type, requiredCustomModifiers, optionalCustomModifiers);
return Make(type, mods);
}
}
sealed class PointerType : ElementHolderType
{
internal static Type Make(Type type, Type[] requiredCustomModifiers, Type[] optionalCustomModifiers)
internal static Type Make(Type type, CustomModifiers mods)
{
return type.Module.CanonicalizeType(new PointerType(type, requiredCustomModifiers, optionalCustomModifiers));
return type.Module.CanonicalizeType(new PointerType(type, mods));
}
private PointerType(Type type, Type[] requiredCustomModifiers, Type[] optionalCustomModifiers)
: base(type, requiredCustomModifiers, optionalCustomModifiers)
private PointerType(Type type, CustomModifiers mods)
: base(type, mods)
{
}
@ -2283,9 +2338,9 @@ namespace IKVM.Reflection
return "*";
}
protected override Type Wrap(Type type, Type[] requiredCustomModifiers, Type[] optionalCustomModifiers)
protected override Type Wrap(Type type, CustomModifiers mods)
{
return Make(type, requiredCustomModifiers, optionalCustomModifiers);
return Make(type, mods);
}
}
@ -2293,12 +2348,11 @@ namespace IKVM.Reflection
{
private readonly Type type;
private readonly Type[] args;
private readonly Type[][] requiredCustomModifiers;
private readonly Type[][] optionalCustomModifiers;
private readonly CustomModifiers[] mods;
private Type baseType;
private int token;
internal static Type Make(Type type, Type[] typeArguments, Type[][] requiredCustomModifiers, Type[][] optionalCustomModifiers)
internal static Type Make(Type type, Type[] typeArguments, CustomModifiers[] mods)
{
bool identity = true;
if (type is TypeBuilder || type is BakedType || type.__IsMissing)
@ -2312,8 +2366,7 @@ namespace IKVM.Reflection
for (int i = 0; i < typeArguments.Length; i++)
{
if (typeArguments[i] != type.GetGenericTypeArgument(i)
|| !IsEmpty(requiredCustomModifiers, i)
|| !IsEmpty(optionalCustomModifiers, i))
|| !IsEmpty(mods, i))
{
identity = false;
break;
@ -2326,31 +2379,29 @@ namespace IKVM.Reflection
}
else
{
return type.Module.CanonicalizeType(new GenericTypeInstance(type, typeArguments, requiredCustomModifiers, optionalCustomModifiers));
return type.Module.CanonicalizeType(new GenericTypeInstance(type, typeArguments, mods));
}
}
private static bool IsEmpty(Type[][] mods, int i)
private static bool IsEmpty(CustomModifiers[] mods, int i)
{
// we need to be extra careful, because mods doesn't not need to be in canonical format
// (Signature.ReadGenericInst() calls Make() directly, without copying the modifier arrays)
return mods == null || mods[i] == null || mods[i].Length == 0;
return mods == null || mods[i].IsEmpty;
}
private GenericTypeInstance(Type type, Type[] args, Type[][] requiredCustomModifiers, Type[][] optionalCustomModifiers)
private GenericTypeInstance(Type type, Type[] args, CustomModifiers[] mods)
{
this.type = type;
this.args = args;
this.requiredCustomModifiers = requiredCustomModifiers;
this.optionalCustomModifiers = optionalCustomModifiers;
this.mods = mods;
}
public override bool Equals(object o)
{
GenericTypeInstance gt = o as GenericTypeInstance;
return gt != null && gt.type.Equals(type) && Util.ArrayEquals(gt.args, args)
&& Util.ArrayEquals(gt.requiredCustomModifiers, requiredCustomModifiers)
&& Util.ArrayEquals(gt.optionalCustomModifiers, optionalCustomModifiers);
&& Util.ArrayEquals(gt.mods, mods);
}
public override int GetHashCode()
@ -2571,14 +2622,9 @@ namespace IKVM.Reflection
return Util.Copy(args);
}
public override Type[][] __GetGenericArgumentsRequiredCustomModifiers()
public override CustomModifiers[] __GetGenericArgumentsCustomModifiers()
{
return Util.Copy(requiredCustomModifiers ?? new Type[args.Length][]);
}
public override Type[][] __GetGenericArgumentsOptionalCustomModifiers()
{
return Util.Copy(optionalCustomModifiers ?? new Type[args.Length][]);
return mods != null ? (CustomModifiers[])mods.Clone() : new CustomModifiers[args.Length];
}
internal override Type GetGenericTypeArgument(int index)
@ -2644,7 +2690,7 @@ namespace IKVM.Reflection
{
xargs[i] = args[i].BindTypeParameters(binder);
}
return Make(type, xargs, null, null);
return Make(type, xargs, null);
}
}
return this;

Просмотреть файл

@ -163,62 +163,6 @@ namespace IKVM.Reflection
return false;
}
internal static bool ArrayEquals(Type[][] t1, Type[][] t2)
{
if (t1 == t2)
{
return true;
}
if (t1 == null)
{
return t2.Length == 0;
}
else if (t2 == null)
{
return t1.Length == 0;
}
if (t1.Length == t2.Length)
{
for (int i = 0; i < t1.Length; i++)
{
if (!ArrayEquals(t1[i], t2[i]))
{
return false;
}
}
return true;
}
return false;
}
internal static bool ArrayEquals(Type[][][] t1, Type[][][] t2)
{
if (t1 == t2)
{
return true;
}
if (t1 == null)
{
return t2.Length == 0;
}
else if (t2 == null)
{
return t1.Length == 0;
}
if (t1.Length == t2.Length)
{
for (int i = 0; i < t1.Length; i++)
{
if (!ArrayEquals(t1[i], t2[i]))
{
return false;
}
}
return true;
}
return false;
}
internal static bool TypeEquals(Type t1, Type t2)
{
if (t1 == t2)
@ -250,30 +194,47 @@ namespace IKVM.Reflection
return h;
}
internal static int GetHashCode(Type[][] types)
internal static bool ArrayEquals(CustomModifiers[] m1, CustomModifiers[] m2)
{
if (m1 == null || m2 == null)
{
return m1 == m2;
}
if (m1.Length != m2.Length)
{
return false;
}
for (int i = 0; i < m1.Length; i++)
{
if (!m1[i].Equals(m2[i]))
{
return false;
}
}
return true;
}
internal static int GetHashCode(CustomModifiers[] mods)
{
int h = 0;
if (types != null)
if (mods != null)
{
foreach (Type[] array in types)
foreach (CustomModifiers mod in mods)
{
h ^= GetHashCode(array);
h ^= mod.GetHashCode();
}
}
return h;
}
internal static int GetHashCode(Type[][][] types)
internal static T NullSafeElementAt<T>(T[] array, int index)
{
int h = 0;
if (types != null)
{
foreach (Type[][] array in types)
{
h ^= GetHashCode(array);
}
}
return h;
return array == null ? default(T) : array[index];
}
internal static int NullSafeLength<T>(T[] array)
{
return array == null ? 0 : array.Length;
}
}

Просмотреть файл

@ -28,6 +28,7 @@
<include name="CustomAttributeData.cs" />
<include name="CustomAttributeNamedArgument.cs" />
<include name="CustomAttributeTypedArgument.cs" />
<include name="CustomModifiers.cs" />
<include name="Enums.cs" />
<include name="EventInfo.cs" />
<include name="ExceptionHandlingClause.cs" />
@ -61,6 +62,7 @@
<include name="Emit\AssemblyBuilder.cs" />
<include name="Emit\ConstructorBuilder.cs" />
<include name="Emit\CustomAttributeBuilder.cs" />
<include name="Emit\CustomModifiersBuilder.cs" />
<include name="Emit\EnumBuilder.cs" />
<include name="Emit\Enums.cs" />
<include name="Emit\EventBuilder.cs" />