Class PropertyInfoDecoratorExtensions
- Namespace
- Cuemon.Reflection
- Assembly
- Cuemon.Core.dll
Extension methods for the PropertyInfo class hidden behind the IDecorator<T> interface.
public static class PropertyInfoDecoratorExtensions
- Inheritance
-
PropertyInfoDecoratorExtensions
Examples
PropertyInfoDecoratorExtensions provides extension methods on Decorator.Enclose for detecting auto-implemented properties and override behavior via IsAutoProperty and IsOverridden. This example retrieves PropertyInfo for Product.Code (auto-property), Product.Label (expression-bodied), and FeaturedProduct.Summary (overridden in a derived class), then calls IsAutoProperty on the first two and IsOverridden on the third. Console output shows True for the auto-property, False for the expression-bodied property, and True for the overridden property, confirming correct identification of property characteristics.
using System;
using System.Reflection;
using Cuemon;
using Cuemon.Reflection;
namespace MyApp.Examples;
public static class PropertyInfoDecoratorExtensionsExample
{
public static void Demonstrate()
{
PropertyInfo code = typeof(Product).GetProperty(nameof(Product.Code))!;
PropertyInfo label = typeof(Product).GetProperty(nameof(Product.Label))!;
PropertyInfo summary = typeof(FeaturedProduct).GetProperty(nameof(Product.Summary))!;
Console.WriteLine(Decorator.Enclose(code).IsAutoProperty());
Console.WriteLine(Decorator.Enclose(label).IsAutoProperty());
Console.WriteLine(Decorator.Enclose(summary).IsOverridden());
}
}
public class Product
{
public string Code { get; set; } = string.Empty;
public string Label => $"Product:{Code}";
public virtual string Summary => "standard";
}
public sealed class FeaturedProduct : Product
{
public override string Summary => "featured";
}
Methods
IsAutoProperty(IDecorator<PropertyInfo>)
Determines whether the underlying PropertyInfo of the decorator is considered an automatic property implementation.
public static bool IsAutoProperty(this IDecorator<PropertyInfo> decorator)
Parameters
decoratorIDecorator<PropertyInfo>The IDecorator<T> to extend.
Returns
- bool
trueif the underlying PropertyInfo of thedecoratoris considered an automatic property implementation; otherwise,false.
Exceptions
- ArgumentNullException
decoratorcannot be null.
IsOverridden(IDecorator<PropertyInfo>)
Determines whether the underlying PropertyInfo of the decorator has been overridden.
public static bool IsOverridden(this IDecorator<PropertyInfo> decorator)
Parameters
decoratorIDecorator<PropertyInfo>The IDecorator<T> to extend.
Returns
- bool
trueif the underlying PropertyInfo of thedecoratorhas been overridden; otherwise,false.
Exceptions
- ArgumentNullException
decoratorcannot be null.