using System;
using System.Reflection;
namespace A
{
interface IObjectWithId<TId>
{
TId Id { get; }
}
interface IEntityBase : IObjectWithId<object>
{
new object Id { get; }
}
abstract class BusinessObject<TId> : IObjectWithId<TId>
{
public abstract TId Id { get; }
}
class EntityBase : BusinessObject<object>, IEntityBase
{
public override object Id { get { return null; } }
}
public static class Program
{
public static void Main()
{
Console.WriteLine(typeof(EntityBase).GetProperty("Id", BindingFlags.Instance | BindingFlags.Public));
}
}
}
Я получаю следующее:
System.Reflection.AmbiguousMatchException was unhandled
Message="Ambiguous match found."
Source="mscorlib"
StackTrace:
at System.RuntimeType.GetPropertyImpl(String name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers)
at System.Type.GetProperty(String name, BindingFlags bindingAttr)
at A.Program.Main() in C:\Home\work\A\Program.cs:line 26
InnerException:
Microsoft Visual Studio 2008
Версия 9.0.30729.1 SP
Microsoft.NET Framework
Версия 3.5 SP1
EDIT:
Как ни странно, похоже, что другие люди не могут воспроизвести его. Хотя он каждый раз падает на мою машину. Я узнал, что этот код:
Console.WriteLine(typeof(EntityBase).GetProperty("Id", BindingFlags.Instance | BindingFlags.Public, null, typeof(object), Type.EmptyTypes, null));
Работает нормально, хотя оно должно быть одинаковым.