такой иерархии:
interface IReport
{
}
interface IFileStorageBucketNaming
{
static abstract string Bucket { get; }
}
abstract class ReportBase
{
}
class ReportSomeBase<T> : ReportBase, IFileStorageBucketNaming
{
public static String Bucket {get;} = "BucketBase";
}
class Report1 : ReportSomeBase<int>
{
}
Вот как-нибудь можно через типа Report1 получить PropertyInfo на статическое свойство Bucket?
void Foo()
{
var type = typeof(Report1);
var bucketProperty = type.GetProperty(
"Bucket",
System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
string bucketValue = (string)bucketProperty.GetValue(null); // Тут падает...
}
BindingFlags.FlattenHierarchy Specifies that public and protected static members up the hierarchy should be returned. Private static members in inherited classes are not returned. Static members include fields, methods, events, and properties. Nested types are not returned.
о, спасиб) помогло
Обсуждают сегодня