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

Atsushi Eno atsushi at ximian.com
Mon Nov 14 03:54:57 EST 2005


Hi,

Raja R Harinath wrote:
> 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.

Oh, apparently I was not sure :P So it seems that I have to iterate
the returned each of the items to check if it is not overriden.

I made another fix that uses Invocation.IsOverride(). I guess it
works this time.

Thanks again.

Atsushi Eno



More information about the Mono-devel-list mailing list