Skip to content

Commit

Permalink
2004-03-24 Zoltan Varga <vargaz@freemail.hu>
Browse files Browse the repository at this point in the history
	* TypeBuilder.cs (GetMethod): Implement.

svn path=/trunk/mcs/; revision=24520
  • Loading branch information
vargaz committed Mar 24, 2004
1 parent 093adb7 commit 52811a9
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 6 deletions.
2 changes: 2 additions & 0 deletions mcs/class/corlib/System.Reflection.Emit/ChangeLog
@@ -1,5 +1,7 @@
2004-03-24 Zoltan Varga <vargaz@freemail.hu>

* TypeBuilder.cs (GetMethod): Implement.

* CustomAttributeBuilder.cs: Reenable argument checking with MS.NET
compatibility tweaks.

Expand Down
83 changes: 77 additions & 6 deletions mcs/class/corlib/System.Reflection.Emit/TypeBuilder.cs
Expand Up @@ -840,16 +840,35 @@ internal EventInfo[] GetEvents_internal (BindingFlags bindingAttr)
throw not_supported ();
}

public override MethodInfo[] GetMethods (BindingFlags bindingAttr) {
if (methods == null)
private MethodInfo[] GetMethodsByName (string name, BindingFlags bindingAttr, bool ignoreCase, Type reflected_type) {
MethodInfo[] candidates;
if (((bindingAttr & BindingFlags.DeclaredOnly) == 0) && (parent != null)) {
MethodInfo[] parent_methods = parent.GetMethods (bindingAttr);
if (methods == null)
candidates = parent_methods;
else {
candidates = new MethodInfo [methods.Length + parent_methods.Length];
parent_methods.CopyTo (candidates, 0);
methods.CopyTo (candidates, parent_methods.Length);
}
}
else
candidates = methods;

if (candidates == null)
return new MethodInfo [0];

ArrayList l = new ArrayList ();
bool match;
MethodAttributes mattrs;

foreach (MethodInfo c in methods) {
foreach (MethodInfo c in candidates) {
if (c == null)
continue;
if (name != null) {
if (String.Compare (c.Name, name, ignoreCase) != 0)
continue;
}
match = false;
mattrs = c.Attributes;
if ((mattrs & MethodAttributes.MemberAccessMask) == MethodAttributes.Public) {
Expand All @@ -873,15 +892,67 @@ internal EventInfo[] GetEvents_internal (BindingFlags bindingAttr)
continue;
l.Add (c);
}

MethodInfo[] result = new MethodInfo [l.Count];
l.CopyTo (result);
return result;
}

protected override MethodInfo GetMethodImpl( string name, BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers) {
throw not_supported ();
public override MethodInfo[] GetMethods (BindingFlags bindingAttr) {
return GetMethodsByName (null, bindingAttr, false, this);
}


protected override MethodInfo GetMethodImpl (string name, BindingFlags bindingAttr,
Binder binder,
CallingConventions callConvention,
Type[] types, ParameterModifier[] modifiers)
{
if (!is_created)
/* MS.Net throws this exception if the type is unfinished... */
throw not_supported ();

bool ignoreCase = ((bindingAttr & BindingFlags.IgnoreCase) != 0);
MethodInfo[] methods = GetMethodsByName (name, bindingAttr, ignoreCase, this);
MethodInfo found = null;
MethodBase[] match;
int typesLen = (types != null) ? types.Length : 0;
int count = 0;

foreach (MethodInfo m in methods) {
// Under MS.NET, Standard|HasThis matches Standard...
if (callConvention != CallingConventions.Any && ((m.CallingConvention & callConvention) != callConvention))
continue;
found = m;
count++;
}

if (count == 0)
return null;

if (count == 1 && typesLen == 0)
return found;

match = new MethodBase [count];
if (count == 1)
match [0] = found;
else {
count = 0;
foreach (MethodInfo m in methods) {
if (callConvention != CallingConventions.Any && ((m.CallingConvention & callConvention) != callConvention))
continue;
match [count++] = m;
}
}

if (types == null)
return (MethodInfo) Binder.FindMostDerivedMatch (match);

if (binder == null)
binder = Binder.DefaultBinder;

return (MethodInfo)binder.SelectMethod (bindingAttr, match, types, modifiers);
}

public override Type GetNestedType( string name, BindingFlags bindingAttr) {
throw not_supported ();
}
Expand Down

0 comments on commit 52811a9

Please sign in to comment.