Table of Contents

MemberReflectionOptions Class

Definition

Configuration options for MemberReflection.

public class MemberReflectionOptions : IParameterObject
Inheritance
MemberReflectionOptions
Implements

Examples

The following example demonstrates how to use when generating a public API inventory for .

using System;
using System.Linq;
using System.Reflection;
using Cuemon;
using Cuemon.Reflection;

namespace MyApp.Examples;

public static class MemberReflectionOptionsExample
{
    public static void Demonstrate()
    {
        BindingFlags publicInstanceFlags = MemberReflection.CreateFlags(options =>
        {
            options.ExcludePrivate = true;
            options.ExcludeStatic = true;
        });

        var publicDateSpanMembers = typeof(DateSpan)
            .GetMembers(publicInstanceFlags)
            .Select(member => member.Name)
            .Distinct()
            .OrderBy(name => name)
            .Take(8);

        Console.WriteLine(string.Join(", ", publicDateSpanMembers));

        BindingFlags declaredOnlyFlags = MemberReflection.CreateFlags(options =>
        {
            options.ExcludePrivate = true;
            options.ExcludeStatic = true;
            options.ExcludeInheritancePath = true;
        });

        Console.WriteLine(typeof(DateSpan).GetMethods(publicInstanceFlags).Length);
        Console.WriteLine(typeof(DateSpan).GetMethods(declaredOnlyFlags).Length);

        var documentedOptions = new MemberReflectionOptions
        {
            ExcludePrivate = true,
            ExcludeStatic = true,
            ExcludeInheritancePath = true
        };

        Console.WriteLine($"{documentedOptions.ExcludePrivate}/{documentedOptions.ExcludeStatic}/{documentedOptions.ExcludeInheritancePath}/{documentedOptions.ExcludePublic}");
    }
}

Constructors

Name Description
MemberReflectionOptions()

Initializes a new instance of the MemberReflectionOptions class.

Properties

Name Description
ExcludeInheritancePath

Gets or sets a value indicating whether derived members of a type's inheritance path are excluded from the binding constraint.

ExcludePrivate

Gets or sets a value indicating whether non-public members are excluded from the binding constraint.

ExcludePublic

Gets or sets a value indicating whether public members are excluded from the binding constraint.

ExcludeStatic

Gets or sets a value indicating whether static members are excluded from the binding constraint.

See Also