Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot

Here if I try to do a typeof(I3).GetProperties() I don't get the Current property (and this is something known, see for example GetProperties() to return all properties for an interface inheritance hierarchyGetProperties() to return all properties for an interface inheritance hierarchy), but I can't simply flatten the interfaces, because then I wouldn't know who is hiding who.

Here if I try to do a typeof(I3).GetProperties() I don't get the Current property (and this is something known, see for example GetProperties() to return all properties for an interface inheritance hierarchy), but I can't simply flatten the interfaces, because then I wouldn't know who is hiding who.

Here if I try to do a typeof(I3).GetProperties() I don't get the Current property (and this is something known, see for example GetProperties() to return all properties for an interface inheritance hierarchy), but I can't simply flatten the interfaces, because then I wouldn't know who is hiding who.

deleted 671 characters in body
Source Link
xanatos
  • 111.1k
  • 13
  • 204
  • 287

Note:

after thinking for another half an hour, the problem for the classesAfter some thought it's clear that there is easily solvable:

public static MethodInfo GetMethod(Type type, string name, Type[] types)
{
    while (type != null)
    {
        var method = type.GetMethod(name, BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly, null, types, null);

        if (method != null)
        {
            return method;
        }

        type = type.BaseType;
    }

    return null;
}

This works because C# (andsomething similar in the .NET) uses single inheritanceMicrosoft.VisualBasic assembly. I simply walk upward (technically this is wrong wrong wrong if I'm importing a VB.NET assembly, because VBsupports late binding.NET uses hide-by-name instead of hide-by-signature It's in Microsoft.VisualBasic.CompilerServices.NewLateBinding, so a method with the same name but different parameters could shadowit doesn't expose the member you are looking for that is present in a base class)late bounded methods. And for interfaces?

Note:

after thinking for another half an hour, the problem for the classes is easily solvable:

public static MethodInfo GetMethod(Type type, string name, Type[] types)
{
    while (type != null)
    {
        var method = type.GetMethod(name, BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly, null, types, null);

        if (method != null)
        {
            return method;
        }

        type = type.BaseType;
    }

    return null;
}

This works because C# (and .NET) uses single inheritance. I simply walk upward (technically this is wrong wrong wrong if I'm importing a VB.NET assembly, because VB.NET uses hide-by-name instead of hide-by-signature, so a method with the same name but different parameters could shadow the member you are looking for that is present in a base class). And for interfaces?

After some thought it's clear that there is something similar in the Microsoft.VisualBasic assembly. VB.NET supports late binding. It's in Microsoft.VisualBasic.CompilerServices.NewLateBinding, but it doesn't expose the late bounded methods.

added 297 characters in body
Source Link
xanatos
  • 111.1k
  • 13
  • 204
  • 287

Clearly if I try typeof(C3).GetProperty("Current") I get an AmbiguousMatchException exception.

This works because C# (and .NET) uses single inheritance. I simply walk upward (technically this is wrong wrong wrong if I'm importing a VB.NET assembly, because VB.NET uses hide-by-name instead of hide-by-signature, so a method with the same name but different parameters could shadow the member you are looking for that is present in a base class). And for interfaces?

Clearly if I try typeof(C3).GetProperty("Current") I get an exception.

This works because C# (and .NET) uses single inheritance. I simply walk upward. And for interfaces?

Clearly if I try typeof(C3).GetProperty("Current") I get an AmbiguousMatchException exception.

This works because C# (and .NET) uses single inheritance. I simply walk upward (technically this is wrong wrong wrong if I'm importing a VB.NET assembly, because VB.NET uses hide-by-name instead of hide-by-signature, so a method with the same name but different parameters could shadow the member you are looking for that is present in a base class). And for interfaces?

added 647 characters in body
Source Link
xanatos
  • 111.1k
  • 13
  • 204
  • 287
Loading
Source Link
xanatos
  • 111.1k
  • 13
  • 204
  • 287
Loading