小编use*_*803的帖子

typeof(t).GetProperties()当t是从另一个派生的接口时

为什么typeof(t).GetProperties()在t是派生接口时没有找到t的所有公共属性?这是预期的行为还是我遗失了什么?

public interface IBaseOne
    {        int Id { get; }    }

public interface IDerivedOne : IBaseOne
    {        string Name { get; }    }

public class ImplementsIDerivedOne : IDerivedOne
    {
        public int Id { get; private set; }
        public string Name { get; private set; }
    }

public static class TypeOfTests
    {
        public static Type Testing<T>() where T : class,IBaseOne
        {
            return typeof(T);
        }
    }

class Program
{
    static void Main(string[] args)
    {
        Type typeFromIBaseOne = TypeOfTests.Testing<IBaseOne  >() ;
        Type typeFromIDerivedOne …
Run Code Online (Sandbox Code Playgroud)

c# generics reflection

4
推荐指数
1
解决办法
285
查看次数

标签 统计

c# ×1

generics ×1

reflection ×1