System.Reflection.Context
10.0.2
Prefix Reserved
dotnet add package System.Reflection.Context --version 10.0.2
NuGet\Install-Package System.Reflection.Context -Version 10.0.2
<PackageReference Include="System.Reflection.Context" Version="10.0.2" />
<PackageVersion Include="System.Reflection.Context" Version="10.0.2" />
<PackageReference Include="System.Reflection.Context" />
paket add System.Reflection.Context --version 10.0.2
#r "nuget: System.Reflection.Context, 10.0.2"
#:package System.Reflection.Context@10.0.2
#addin nuget:?package=System.Reflection.Context&version=10.0.2
#tool nuget:?package=System.Reflection.Context&version=10.0.2
About
Provides the CustomReflectionContext class to enable adding or removing custom attributes from reflection objects, or adding dummy properties to those objects, without re-implementing the complete reflection model.
Key Features
- Create a custom reflection context to control how types and members are presented during reflection.
- Easily extend or customize the reflection model to fit specialized application needs.
How to Use
Defining a custom Attribute and implement a CustomReflectionContext to add the attribute to specic methods.
using System.Reflection;
using System.Reflection.Context;
[AttributeUsage(AttributeTargets.Method)]
class CustomAttribute : Attribute
{
}
class CustomContext : CustomReflectionContext
{
// Called whenever the reflection context checks for custom attributes.
protected override IEnumerable<object> GetCustomAttributes(MemberInfo member, IEnumerable<object> declaredAttributes)
{
// Add custom attribute to "ToString" members
if (member.Name == "ToString")
{
yield return new CustomAttribute();
}
// Keep existing attributes as well
foreach (var attr in declaredAttributes)
{
yield return attr;
}
}
}
Inspecting the string type with both the default and custom reflection context.
Type type = typeof(string);
// Representation of the type in the default reflection context
TypeInfo typeInfo = type.GetTypeInfo();
Console.WriteLine("\"To*\" members and their attributes in the default reflection context");
foreach (MemberInfo memberInfo in typeInfo.DeclaredMembers)
{
if (memberInfo.Name.StartsWith("To"))
{
Console.WriteLine(memberInfo.Name);
foreach (Attribute attribute in memberInfo.GetCustomAttributes())
{
Console.WriteLine($" - {attribute.GetType()}");
}
}
}
Console.WriteLine();
// Output:
// "To*" members and their attributes in the default reflection context
// ToCharArray
// ToCharArray
// ToString
// ToString
// ToLower
// ToLower
// ToLowerInvariant
// ToUpper
// ToUpper
// ToUpperInvariant
// Representation of the type in the customized reflection context
CustomContext customContext = new();
TypeInfo customTypeInfo = customContext.MapType(typeInfo);
Console.WriteLine("\"To*\" members and their attributes in the customized reflection context");
foreach (MemberInfo memberInfo in customTypeInfo.DeclaredMembers)
{
if (memberInfo.Name.StartsWith("To"))
{
Console.WriteLine(memberInfo.Name);
foreach (Attribute attribute in memberInfo.GetCustomAttributes())
{
Console.WriteLine($" - {attribute.GetType()}");
}
}
}
// Output:
// "To*" members and their attributes in the customized reflection context
// ToCharArray
// ToCharArray
// ToString
// - CustomAttribute
// ToString
// - CustomAttribute
// ToLower
// ToLower
// ToLowerInvariant
// ToUpper
// ToUpper
// ToUpperInvariant
Main Types
The main type provided by this library is:
System.Reflection.Context.CustomReflectionContext
Additional Documentation
Feedback & Contributing
System.Reflection.Context is released as open source under the MIT license. Bug reports and contributions are welcome at the GitHub repository.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
| .NET Framework | net461 was computed. net462 is compatible. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
-
.NETStandard 2.1
- No dependencies.
-
net10.0
- No dependencies.
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages (13)
Showing the top 5 NuGet packages that depend on System.Reflection.Context:
| Package | Downloads |
|---|---|
|
Microsoft.Windows.Compatibility
This Windows Compatibility Pack provides access to APIs that were previously available only for .NET Framework. It can be used from both .NET as well as .NET Standard. |
|
|
System.ComponentModel.Composition.Registration
This namespace provides classes that constitute the core of the Managed Extensibility Framework, or MEF. Commonly Used Types: System.ComponentModel.Composition.Registration.RegistrationBuilder System.ComponentModel.Composition.Registration.PartBuilder System.ComponentModel.Composition.Registration.PartBuilder<T> System.ComponentModel.Composition.Registration.ParameterImportBuilder System.ComponentModel.Composition.Registration.ImportBuilder System.ComponentModel.Composition.Registration.ExportBuilder |
|
|
Microsoft.NETCore.UniversalWindowsPlatform
Provides a set of packages that can be used when building Universal Windows applications on .NETCore. d67bd83a075b8b10cb95810568073c1a3211f28b When using NuGet 3.x this package requires at least version 3.4. |
|
|
More
The core library for the "More" framework. |
|
|
Gorgon.Core
Contains common core functionality used by the various Gorgon libraries. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated | |
|---|---|---|---|
| 10.0.2 | 3,941 | 1/13/2026 | |
| 10.0.1 | 46,437 | 12/9/2025 | |
| 10.0.0 | 63,993 | 11/11/2025 | |
| 10.0.0-rc.2.25502.107 | 13,098 | 10/14/2025 | |
| 10.0.0-rc.1.25451.107 | 12,300 | 9/9/2025 | |
| 10.0.0-preview.7.25380.108 | 4,279 | 8/12/2025 | |
| 10.0.0-preview.6.25358.103 | 1,458 | 7/15/2025 | |
| 10.0.0-preview.5.25277.114 | 1,021 | 6/6/2025 | |
| 10.0.0-preview.4.25258.110 | 1,944 | 5/12/2025 | |
| 10.0.0-preview.3.25171.5 | 3,547 | 4/10/2025 | |
| 10.0.0-preview.2.25163.2 | 4,169 | 3/18/2025 | |
| 10.0.0-preview.1.25080.5 | 1,478 | 2/25/2025 | |
| 9.0.12 | 1,153 | 1/13/2026 | |
| 9.0.11 | 31,167 | 11/11/2025 | |
| 9.0.10 | 242,696 | 10/14/2025 | |
| 9.0.9 | 91,013 | 9/9/2025 | |
| 9.0.8 | 150,112 | 8/4/2025 | |
| 9.0.7 | 62,346 | 7/8/2025 | |
| 9.0.6 | 246,007 | 6/10/2025 | |
| 9.0.5 | 77,911 | 5/13/2025 | |
| 9.0.4 | 343,658 | 4/8/2025 | |
| 9.0.3 | 90,741 | 3/11/2025 | |
| 9.0.2 | 186,171 | 2/11/2025 | |
| 9.0.1 | 332,495 | 1/14/2025 | |
| 9.0.0 | 444,817 | 11/12/2024 | |
| 9.0.0-rc.2.24473.5 | 32,220 | 10/8/2024 | |
| 9.0.0-rc.1.24431.7 | 8,438 | 9/10/2024 | |
| 9.0.0-preview.7.24405.7 | 6,027 | 8/13/2024 | |
| 9.0.0-preview.6.24327.7 | 14,214 | 7/9/2024 | |
| 9.0.0-preview.5.24306.7 | 5,724 | 6/11/2024 | |
| 9.0.0-preview.4.24266.19 | 2,814 | 5/21/2024 | |
| 9.0.0-preview.3.24172.9 | 7,488 | 4/11/2024 | |
| 9.0.0-preview.2.24128.5 | 997 | 3/12/2024 | |
| 9.0.0-preview.1.24080.9 | 32,524 | 2/13/2024 | |
| 8.0.0 | 9,132,741 | 11/14/2023 | |
| 8.0.0-rc.2.23479.6 | 12,521 | 10/10/2023 | |
| 8.0.0-rc.1.23419.4 | 8,947 | 9/12/2023 | |
| 8.0.0-preview.7.23375.6 | 9,043 | 8/8/2023 | |
| 8.0.0-preview.6.23329.7 | 1,007 | 7/11/2023 | |
| 8.0.0-preview.5.23280.8 | 1,112 | 6/13/2023 | |
| 8.0.0-preview.4.23259.5 | 9,608 | 5/16/2023 | |
| 8.0.0-preview.3.23174.8 | 20,262 | 4/11/2023 | |
| 8.0.0-preview.2.23128.3 | 5,710 | 3/14/2023 | |
| 8.0.0-preview.1.23110.8 | 8,349 | 2/21/2023 | |
| 7.0.0 | 4,770,448 | 11/7/2022 | |
| 7.0.0-rc.2.22472.3 | 9,564 | 10/11/2022 | |
| 7.0.0-rc.1.22426.10 | 62,858 | 9/14/2022 | |
| 7.0.0-preview.7.22375.6 | 10,827 | 8/9/2022 | |
| 7.0.0-preview.6.22324.4 | 1,321 | 7/12/2022 | |
| 7.0.0-preview.5.22301.12 | 1,487 | 6/14/2022 | |
| 7.0.0-preview.4.22229.4 | 11,432 | 5/10/2022 | |
| 7.0.0-preview.3.22175.4 | 2,727 | 4/13/2022 | |
| 7.0.0-preview.2.22152.2 | 11,968 | 3/14/2022 | |
| 7.0.0-preview.1.22076.8 | 2,821 | 2/17/2022 | |
| 6.0.0 | 11,369,928 | 11/8/2021 | |
| 6.0.0-rc.2.21480.5 | 4,825 | 10/12/2021 | |
| 6.0.0-rc.1.21451.13 | 8,162 | 9/14/2021 | |
| 6.0.0-preview.7.21377.19 | 2,894 | 8/10/2021 | |
| 6.0.0-preview.6.21352.12 | 2,078 | 7/14/2021 | |
| 6.0.0-preview.5.21301.5 | 5,506 | 6/15/2021 | |
| 6.0.0-preview.4.21253.7 | 20,959 | 5/24/2021 | |
| 6.0.0-preview.3.21201.4 | 7,665 | 4/8/2021 | |
| 6.0.0-preview.2.21154.6 | 8,189 | 3/11/2021 | |
| 6.0.0-preview.1.21102.12 | 2,674 | 2/12/2021 | |
| 5.0.0 | 23,908,377 | 11/9/2020 | |
| 5.0.0-rc.2.20475.5 | 9,257 | 10/13/2020 | |
| 5.0.0-rc.1.20451.14 | 4,433 | 9/14/2020 | |
| 5.0.0-preview.8.20407.11 | 9,579 | 8/25/2020 | |
| 5.0.0-preview.7.20364.11 | 12,112 | 7/21/2020 | |
| 5.0.0-preview.6.20305.6 | 3,674 | 6/25/2020 | |
| 5.0.0-preview.5.20278.1 | 4,235 | 6/10/2020 | |
| 5.0.0-preview.4.20251.6 | 8,039 | 5/18/2020 | |
| 5.0.0-preview.3.20214.6 | 35,699 | 4/23/2020 | |
| 5.0.0-preview.2.20160.6 | 996 | 4/2/2020 | |
| 5.0.0-preview.1.20120.5 | 1,087 | 3/16/2020 | |
| 4.7.0 | 7,057,238 | 12/3/2019 | |
| 4.7.0-preview3.19551.4 | 2,339 | 11/13/2019 | |
| 4.7.0-preview2.19523.17 | 14,953 | 11/1/2019 | |
| 4.7.0-preview1.19504.10 | 9,703 | 10/15/2019 | |
| 4.6.0 | 1,813,733 | 9/23/2019 | |
| 4.6.0-rc1.19456.4 | 4,974 | 9/16/2019 | |
| 4.6.0-preview9.19421.4 | 2,538 | 9/4/2019 | |
| 4.6.0-preview9.19416.11 | 834 | 9/4/2019 | |
| 4.6.0-preview8.19405.3 | 5,418 | 8/13/2019 | |
| 4.6.0-preview7.19362.9 | 5,475 | 7/23/2019 | |
| 4.6.0-preview6.19303.8 | 888 | 6/12/2019 | |
| 4.6.0-preview6.19264.9 | 844 | 9/4/2019 | |
| 4.6.0-preview5.19224.8 | 863 | 5/6/2019 | |
| 4.6.0-preview4.19212.13 | 867 | 4/18/2019 | |
| 4.6.0-preview3.19128.7 | 882 | 3/6/2019 | |
| 4.6.0-preview.19073.11 | 951 | 1/29/2019 | |
| 4.6.0-preview.18571.3 | 995 | 12/3/2018 | |
| 4.3.0 | 171,717 | 11/15/2016 | |
| 4.3.0-preview1-24530-04 | 1,796 | 10/24/2016 | |
| 4.0.1 | 1,522,391 | 6/27/2016 | |
| 4.0.1-rc2-24027 | 3,772 | 5/16/2016 | |
| 4.0.1-beta-23516 | 2,683 | 11/18/2015 | |
| 4.0.1-beta-23409 | 1,757 | 10/15/2015 | |
| 4.0.1-beta-23225 | 3,618 | 9/2/2015 | |
| 4.0.0 | 2,003,308 | 7/29/2015 |