[Mono-dev] FindMembers() for TypeBuilder excluding overriden ones

Raja R Harinath rharinath at novell.com
Mon Nov 14 02:27:11 EST 2005


Hi,

Atsushi Eno <atsushi at ximian.com> writes:

> Raja R Harinath wrote:
>
>> Atsushi Eno <atsushi at ximian.com> writes:
>>
>>> In mcs(.exe) I want to get a MemberInfo array which has a certain
>>> name and does not contain overriden base members i.e. something
>>> like Type.FindMembers() with Type.FilterName (TypeBuilder.GetMethods()
>>> returns base ones, and it should be fine).
>>>
>>> (For example, suppose I'm building System.Xml.dll, I don't want
>>> XmlReader.Read() while we have XmlTextReader.Read() for XmlTextReader.)
>>>
>>> Is there any preferable way I can go, or do I have to create such one?
>>> It would be useful to fix one /doc bug; #76690.
>> I'm assuming that DeclaredOnly is too strict a filter.  It's somewhat
>
> Yes, DeclaredOnly is not what I need (I still need XmlTextReader.Read()
> on MyDerivedXmlTextReader where if I have no overriden one).
>
>> non-trivial.  If you use Expression.MemberLookup or
>> TypeManager.MemberLookup instead of Type.FindMembers, you can use
>>    mi.DeclaringType != t && mi.IsVirtual && !TypeManager.IsOverride
>> (mi)
>> to filter out base virtual methods.  However, to ensure that it
>> actually
>> is overriden, you have to compare the signatures, and/or use
>> GetBaseDefinition().
>
> Seems like TypeManager.FindMembers() handles that mess, and your test
> above nicely works :-)

Hmm, are you sure?  What about a case like this:

  class X { virtual void foo (); }
  class Y { }

Using the above filter on methods of 'Y' will throw away 'foo', if I'm
not mistaken.

- Hari



More information about the Mono-devel-list mailing list