MemberReflection Class
Definition
- Namespace
- Cuemon.Reflection
- Assemblies
- Cuemon.Core.dll
Provides a robust way specifying binding constraints for reflection based member searching.
public class MemberReflection
- Inheritance
-
objectMemberReflection
Examples
The following example demonstrates how to use
using System;
using System.Reflection;
using Cuemon.Reflection; // for MemberReflection, MemberReflectionOptions
namespace MyApp.Examples;
public class MemberReflectionExample
{
public void Demonstrate()
{
// Create flags to find only public instance members (excluding inherited)
BindingFlags flags = new MemberReflection(
excludePrivate: true,
excludeStatic: true,
excludeInheritancePath: true);
Console.WriteLine(flags);
// Output: Instance, Public, DeclaredOnly
// Use the static CreateFlags factory method
BindingFlags allFlags = MemberReflection.CreateFlags();
Console.WriteLine(allFlags);
// Output: Instance, Static, Public, NonPublic
// Configure via MemberReflectionOptions
BindingFlags customFlags = MemberReflection.CreateFlags(o =>
{
o.ExcludePrivate = true;
o.ExcludeStatic = true;
});
// Use with reflection
var members = typeof(string).GetMembers(customFlags);
Console.WriteLine(members.Length); // Number of public instance members on string
}
}
Constructors
| Name | Description |
|---|---|
| MemberReflection(Action<MemberReflectionOptions>) | Initializes a new instance of the MemberReflection class. |
| MemberReflection(bool, bool, bool, bool) | Initializes a new instance of the MemberReflection class. |
Fields
| Name | Description |
|---|---|
| Everything | Defines a binding constraint that allows searching all members of a given type. |
Properties
| Name | Description |
|---|---|
| Flags | Gets the binding constraint of this instance. |
Methods
| Name | Description |
|---|---|
| CreateFlags(Action<MemberReflectionOptions>) | Creates the binding constraint needed for reflection using the optional |
Operators
| Name | Description |
|---|---|
| implicit operator BindingFlags(MemberReflection) | Performs an implicit conversion from MemberReflection to BindingFlags. |