Странная замена
От: DarthSidius  
Дата: 28.04.21 23:40
Оценка:
using System;
using System.Console;
using System.Linq;
using System.Reflection;

[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
public sealed class Atrib1 : Attribute
{
}

[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
public sealed class Atrib2 : Attribute
{
}

class Cls1
{
    [Atrib1]
    public Prop1 : string { get; private set }
    
    [Atrib2]
    public Prop2 : string { get; private set }
    
}

module Program
{
    Main() : void
    {
        def v = typeof(Cls1)
            .GetProperties()
            .Where( pi => pi.GetCustomAttribute.[Atrib1]() != null )
        ;
        foreach( pi in v ) {
            WriteLine(pi)
        }
        _ = ReadLine();
    }
}

Вывод:

System.String Prop1
System.String Prop2

А потому, что компилятор генерирует вот такое:
    [SpecialName]
    public override sealed bool apply(PropertyInfo pi)
    {
      return CustomAttributeExtensions.GetCustomAttribute<Attribute>((MemberInfo) pi) != null;
    }
... << RSDN@Home 1.0.0 alpha 5 rev. 0>>
♠♠♥♠♠♦♥
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.