Type ParameterType (int pos);
Type [] Types { get; }
int Count { get; }
+ Type ExtensionMethodType { get; }
bool HasParams { get; }
string ParameterName (int pos);
string ParameterDesc (int pos);
+
Parameter.Modifier ParameterModifier (int pos);
string GetSignatureForError ();
+
+#if MS_COMPATIBLE
+ ParameterData InflateTypes (Type[] genArguments, Type[] argTypes);
+#endif
}
public class ReflectionParameters : ParameterData {
ParameterInfo [] pi;
Type [] types;
- int params_idx = -1;
+ int params_idx = int.MaxValue;
bool is_varargs;
+ bool is_extension;
ParameterData gpd;
public ReflectionParameters (MethodBase mb)
types = new Type [count];
for (int i = 0; i < count; i++)
- types [i] = pi [i].ParameterType;
+ types [i] = TypeManager.TypeToCoreType (pi [i].ParameterType);
// TODO: This (if) should be done one level higher to correctly use
// out caching facilities.
if (!pi [i].ParameterType.IsArray)
continue;
- object [] attrs = pi [i].GetCustomAttributes (TypeManager.param_array_type, true);
- if (attrs.Length == 1) {
+ if (pi [i].IsDefined (TypeManager.param_array_type, false)) {
params_idx = i;
- return;
+ break;
}
}
+
+ if (TypeManager.extension_attribute_type != null && mb.IsStatic &&
+ (mb.DeclaringType.Attributes & Class.StaticClassAttribute) == Class.StaticClassAttribute &&
+ mb.IsDefined (TypeManager.extension_attribute_type, false))
+ is_extension = true;
}
public override bool Equals (object obj)
return sb.ToString ();
}
+#if MS_COMPATIBLE
+ public ParameterData InflateTypes (Type[] genArguments, Type[] argTypes)
+ {
+ ReflectionParameters p = (ReflectionParameters)MemberwiseClone ();
+
+ for (int i = 0; i < types.Length; ++i) {
+ if (types[i].IsGenericParameter) {
+ for (int ii = 0; ii < genArguments.Length; ++ii) {
+ if (types[i] != genArguments[ii])
+ continue;
+
+ p.types[i] = argTypes[ii];
+ break;
+ }
+ continue;
+ }
+
+ if (types[i].IsGenericType) {
+ Type[] gen_arguments_open = types[i].GetGenericTypeDefinition ().GetGenericArguments ();
+ Type[] gen_arguments = types[i].GetGenericArguments ();
+ for (int ii = 0; ii < gen_arguments_open.Length; ++ii) {
+ if (gen_arguments [ii].IsGenericParameter) {
+ for (int iii = 0; iii < genArguments.Length; ++iii) {
+ if (gen_arguments [ii] != genArguments [iii])
+ continue;
+
+ gen_arguments_open [ii] = argTypes [iii];
+ break;
+ }
+ } else {
+ gen_arguments_open [ii] = gen_arguments [ii];
+ }
+ }
+
+ p.types[i] = types[i].GetGenericTypeDefinition ().MakeGenericType (gen_arguments_open);
+ }
+ }
+ return p;
+ }
+#endif
+
public Type ParameterType (int pos)
{
if (is_varargs && pos >= pi.Length)
return TypeManager.runtime_argument_handle_type;
- return pi [pos].ParameterType;
+ return types [pos];
}
public string ParameterName (int pos)
if (params_idx == pos)
sb.Append ("params ");
+ if (pos == 0 && ExtensionMethodType != null)
+ sb.Append ("this ");
+
sb.Append (TypeManager.CSharpName (partype).Replace ("&", ""));
return sb.ToString ();
public Parameter.Modifier ParameterModifier (int pos)
{
- if (pos == params_idx)
+ if (pos >= params_idx)
return Parameter.Modifier.PARAMS;
- else if (is_varargs && pos >= pi.Length)
+ if (is_varargs && pos >= pi.Length)
return Parameter.Modifier.ARGLIST;
if (gpd != null)
return gpd.ParameterModifier (pos);
- Type t = pi [pos].ParameterType;
+ Type t = types [pos];
if (t.IsByRef){
if ((pi [pos].Attributes & (ParameterAttributes.Out|ParameterAttributes.In)) == ParameterAttributes.Out)
return Parameter.Modifier.OUT;
get { return is_varargs ? pi.Length + 1 : pi.Length; }
}
+ public Type ExtensionMethodType {
+ get {
+ if (!is_extension)
+ return null;
+
+ return types [0];
+ }
+ }
+
public bool HasParams {
- get { return params_idx != -1; }
+ get { return params_idx != int.MaxValue; }
}
public Type[] Types {
/// </summary>
public class SeekableStreamReader
{
- public SeekableStreamReader (StreamReader reader)
+ const int AverageReadLength = 1024;
+ TextReader reader;
+ Stream stream;
+ Encoding encoding;
+
+ char[] buffer;
+ int buffer_start; // in chars
+ int char_count; // count buffer[] valid characters
+ int pos; // index into buffer[]
+
+ public SeekableStreamReader (Stream stream, Encoding encoding)
{
- this.reader = reader;
+ this.stream = stream;
+ this.encoding = encoding;
+
+ this.reader = new StreamReader (stream, encoding, true);
this.buffer = new char [AverageReadLength * 3];
// Let the StreamWriter autodetect the encoder
reader.Peek ();
}
- public SeekableStreamReader (Stream stream, Encoding encoding)
- : this (new StreamReader (stream, encoding, true))
- { }
-
- StreamReader reader;
-
- private const int AverageReadLength = 1024;
-
- char[] buffer;
- int buffer_start; // in chars
- int char_count; // count buffer[] valid characters
- int pos; // index into buffer[]
-
/// <remarks>
/// This value corresponds to the current position in a stream of characters.
/// The StreamReader hides its manipulation of the underlying byte stream and all
get { return buffer_start + pos; }
set {
- if (value < buffer_start || value > buffer_start + char_count)
- throw new InternalErrorException ("can't seek that far back: " + (pos - value));
+ if (value > buffer_start + char_count)
+ throw new InternalErrorException ("can't seek that far forward: " + (pos - value));
+
+ if (value < buffer_start){
+ // Reinitialize.
+ stream.Position = 0;
+ reader = new StreamReader (stream, encoding, true);
+ buffer_start = 0;
+ char_count = 0;
+ pos = 0;
+ Peek ();
+
+ while (value > buffer_start + char_count){
+ pos = char_count+1;
+ Peek ();
+ }
+ pos = value - buffer_start;
+ }
+
pos = value - buffer_start;
}
}
}
}
}
+
+ class PartialMethodDefinitionInfo : MethodInfo
+ {
+ MethodOrOperator mc;
+ MethodAttributes attrs;
+
+ public PartialMethodDefinitionInfo (MethodOrOperator mc)
+ {
+ this.mc = mc;
+ if ((mc.ModFlags & Modifiers.STATIC) != 0)
+ attrs = MethodAttributes.Static;
+ }
+
+ public override MethodInfo GetBaseDefinition ()
+ {
+ throw new NotImplementedException ();
+ }
+
+ public override ICustomAttributeProvider ReturnTypeCustomAttributes
+ {
+ get { throw new NotImplementedException (); }
+ }
+
+ public override MethodAttributes Attributes
+ {
+ get { return attrs; }
+ }
+
+ public override MethodImplAttributes GetMethodImplementationFlags ()
+ {
+ throw new NotImplementedException ();
+ }
+
+ public override ParameterInfo [] GetParameters ()
+ {
+ throw new NotImplementedException ();
+ }
+
+ public override object Invoke (object obj, BindingFlags invokeAttr, Binder binder, object [] parameters, CultureInfo culture)
+ {
+ throw new NotImplementedException ();
+ }
+
+ public override RuntimeMethodHandle MethodHandle
+ {
+ get { throw new NotImplementedException (); }
+ }
+
+ public override Type DeclaringType
+ {
+ get { return mc.Parent.TypeBuilder; }
+ }
+
+ public override object [] GetCustomAttributes (Type attributeType, bool inherit)
+ {
+ throw new NotImplementedException ();
+ }
+
+ public override object [] GetCustomAttributes (bool inherit)
+ {
+ throw new NotImplementedException ();
+ }
+
+ public override Type ReturnType {
+ get {
+ return mc.MemberType;
+ }
+ }
+
+ public override bool IsDefined (Type attributeType, bool inherit)
+ {
+ throw new NotImplementedException ();
+ }
+
+ public override string Name
+ {
+ get { return mc.Name; }
+ }
+
+ public override Type ReflectedType
+ {
+ get { throw new NotImplementedException (); }
+ }
+ }
+
}