/*
- 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
{
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)
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
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)
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)
}
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]);
}
}
return parameterTypes[parameter];
}
- internal Type[] GetOptionalCustomModifiers(int parameter)
+ internal CustomModifiers GetParameterCustomModifiers(int parameter)
{
- return parameterOptionalCustomModifiers == null ? Type.EmptyTypes : parameterOptionalCustomModifiers[parameter];
+ return customModifiers.GetParameterCustomModifiers(parameter);
}
- internal Type[] GetRequiredCustomModifiers(int parameter)
+ internal CallingConventions CallingConvention
{
- return parameterRequiredCustomModifiers == null ? Type.EmptyTypes : parameterRequiredCustomModifiers[parameter];
+ get { return callingConvention; }
}
- internal CallingConventions CallingConvention
+ internal bool MatchParameterTypes(Type[] types)
{
- get { return callingConvention; }
+ return Util.ArrayEquals(types, parameterTypes);
}
internal static PropertySignature ReadSig(ModuleReader module, ByteReader br, IGenericContext context)
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));
}
}
}