Table of Contents

Class MethodBaseOptions

Namespace
Cuemon.Reflection
Assembly
Cuemon.Core.dll

Configuration options for MethodBase.

public class MethodBaseOptions : IParameterObject
Inheritance
MethodBaseOptions
Implements

Examples

MethodBaseOptions stores method lookup rules including binding flags, string comparison mode, and expected parameter types for use during reflection-based method resolution. This example configures options with BindingFlags.Instance | BindingFlags.Public, StringComparison.OrdinalIgnoreCase, and typeof(decimal) parameter types, then passes them to a custom ResolveMethod helper that searches the PricingEngine class for a method matching the name and parameter signature. Console output shows the resolved method name (ApplyDiscount) or "not found", the binding flags, and the expected parameter type names (Decimal, Decimal).

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

namespace MyApp.Examples;

public static class MethodBaseOptionsExample
{
    public static void Demonstrate()
    {
        var options = new MethodBaseOptions
        {
            Flags = BindingFlags.Instance | BindingFlags.Public,
            Comparison = StringComparison.OrdinalIgnoreCase,
            Types = new[] { typeof(decimal), typeof(decimal) }
        };

        MethodInfo method = ResolveMethod(typeof(PricingEngine), "applydiscount", options);

        Console.WriteLine(method == null ? "not found" : method.Name);
        Console.WriteLine(options.Flags);
        Console.WriteLine(string.Join(", ", options.Types.Select(type => type.Name)));
    }

    private static MethodInfo ResolveMethod(Type source, string name, MethodBaseOptions options)
    {
        return source.GetMethods(options.Flags).FirstOrDefault(method =>
            method.Name.Equals(name, options.Comparison) &&
            method.GetParameters().Select(parameter => parameter.ParameterType)
                .SequenceEqual(options.Types ?? Array.Empty<Type>()));
    }
}

public sealed class PricingEngine
{
    public decimal ApplyDiscount(decimal subtotal, decimal discount)
    {
        return subtotal - discount;
    }
}

Constructors

MethodBaseOptions()

Initializes a new instance of the MethodBaseOptions class.

public MethodBaseOptions()

Properties

Comparison

Gets or sets the StringComparison rules to use when resolving a member name.

public StringComparison Comparison { get; set; }

Property Value

StringComparison

The StringComparison rules to use when resolving a member name.

Flags

Gets or sets the BindingFlags that specifies how the member search is conducted.

public BindingFlags Flags { get; set; }

Property Value

BindingFlags

The BindingFlags that specifies how the member search is conducted.

Types

Gets or sets the types representing the number, order, and type of the parameters for the member to resolve.

public Type[] Types { get; set; }

Property Value

Type[]

The types representing the number, order, and type of the parameters for the member to resolve.

See Also