Microsoft.Extensions.Primitives
9.0.0-rc.1.24431.7
Prefix Reserved
See the version list below for details.
dotnet add package Microsoft.Extensions.Primitives --version 9.0.0-rc.1.24431.7
NuGet\Install-Package Microsoft.Extensions.Primitives -Version 9.0.0-rc.1.24431.7
<PackageReference Include="Microsoft.Extensions.Primitives" Version="9.0.0-rc.1.24431.7" />
paket add Microsoft.Extensions.Primitives --version 9.0.0-rc.1.24431.7
#r "nuget: Microsoft.Extensions.Primitives, 9.0.0-rc.1.24431.7"
// Install Microsoft.Extensions.Primitives as a Cake Addin #addin nuget:?package=Microsoft.Extensions.Primitives&version=9.0.0-rc.1.24431.7&prerelease // Install Microsoft.Extensions.Primitives as a Cake Tool #tool nuget:?package=Microsoft.Extensions.Primitives&version=9.0.0-rc.1.24431.7&prerelease
About
Microsoft.Extensions.Primitives
contains isolated types that are used in many places within console or ASP.NET Core applications using framework extensions.
Key Features
- IChangeToken: An interface that represents a token that can notify when a change occurs. This can be used to trigger actions or invalidate caches when something changes. For example, the configuration and file providers libraries use this interface to reload settings or files when they are modified.
- StringValues: A struct that represents a single string or an array of strings. This can be used to efficiently store and manipulate multiple values that are logically a single value. For example, the HTTP headers and query strings libraries use this struct to handle multiple values for the same key.
- StringSegment: A struct that represents a substring of another string. This can be used to avoid allocating new strings when performing operations on parts of a string. For example, the configuration and logging libraries use this struct to parse and format strings.
How to Use
IChangeToken with configuration example
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Primitives;
using System;
class Program
{
static void Main(string[] args)
{
// Create a configuration builder
var configurationBuilder = new ConfigurationBuilder()
.SetBasePath(Environment.CurrentDirectory)
// appsettings.json expected to have the following contents:
// {
// "SomeKey": "SomeValue"
// }
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
// Build the configuration
IConfiguration configuration = configurationBuilder.Build();
// Create a change token for the configuration
IChangeToken changeToken = configuration.GetReloadToken();
// Attach a change callback
IDisposable changeTokenRegistration = changeToken.RegisterChangeCallback(state =>
{
Console.WriteLine("Configuration changed!");
IConfigurationRoot root = (IConfigurationRoot)state;
var someValue = root["SomeKey"]; // Access the updated configuration value
Console.WriteLine($"New value of SomeKey: {someValue}");
}, configuration);
// go and update the value of the key SomeKey in appsettings.json.
// The change callback will be invoked when the file is saved.
Console.WriteLine("Listening for configuration changes. Press any key to exit.");
Console.ReadKey();
// Clean up the change token registration when no longer needed
changeTokenRegistration.Dispose();
}
}
StringValues example
using System;
using Microsoft.Extensions.Primitives;
namespace StringValuesSample
{
class Program
{
static void Main(string[] args)
{
// Create a StringValues object from a single string or an array of strings
StringValues single = "Hello";
StringValues multiple = new string[] { "Hello", "World" };
// Use the implicit conversion to string or the ToString method to get the values
Console.WriteLine($"Single: {single}"); // Single: Hello
Console.WriteLine($"Multiple: {multiple}"); // Multiple: Hello,World
// Use the indexer, the Count property, and the IsNullOrEmpty method to access the values
Console.WriteLine($"Multiple[1]: {multiple[1]}"); // Multiple[1]: World
Console.WriteLine($"Single.Count: {single.Count}"); // Single.Count: 1
Console.WriteLine($"Multiple.IsNullOrEmpty: {StringValues.IsNullOrEmpty(multiple)}"); // Multiple.IsNullOrEmpty: False
// Use the Equals method or the == operator to compare two StringValues objects
Console.WriteLine($"single == \"Hello\": {single == "Hello"}"); // single == "Hello": True
Console.WriteLine($"multiple == \"Hello\": {multiple == "Hello"}"); // multiple == "Hello": False
}
}
}
Main Types
The main types provided by this library are:
IChangeToken
StringValues
StringSegment
Additional Documentation
Related Packages
Feedback & Contributing
Microsoft.Extensions.Primitives 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. |
.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 was computed. |
.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. |
-
.NETFramework 4.6.2
- System.Memory (>= 4.5.5)
- System.Runtime.CompilerServices.Unsafe (>= 6.0.0)
-
.NETStandard 2.0
- System.Memory (>= 4.5.5)
- System.Runtime.CompilerServices.Unsafe (>= 6.0.0)
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages (663)
Showing the top 5 NuGet packages that depend on Microsoft.Extensions.Primitives:
Package | Downloads |
---|---|
Microsoft.Extensions.Options
Provides a strongly typed way of specifying and accessing settings using dependency injection. |
|
Microsoft.Extensions.Configuration.Abstractions
Provides abstractions of key-value pair based configuration. Interfaces defined in this package are implemented by classes in Microsoft.Extensions.Configuration and other configuration packages. |
|
Microsoft.Extensions.Configuration
Implementation of key-value pair based configuration for Microsoft.Extensions.Configuration. Includes the memory configuration provider. |
|
Microsoft.Extensions.FileProviders.Abstractions
Abstractions of files and directories. Commonly Used Types: Microsoft.Extensions.FileProviders.IDirectoryContents Microsoft.Extensions.FileProviders.IFileInfo Microsoft.Extensions.FileProviders.IFileProvider |
|
Microsoft.Extensions.FileProviders.Physical
File provider for physical files for Microsoft.Extensions.FileProviders. |
GitHub repositories (176)
Showing the top 5 popular GitHub repositories that depend on Microsoft.Extensions.Primitives:
Repository | Stars |
---|---|
dotnet/AspNetCore.Docs
Documentation for ASP.NET Core
|
|
chocolatey/choco
Chocolatey - the package manager for Windows
|
|
JeffreySu/WeiXinMPSDK
微信全平台 .NET SDK, Senparc.Weixin for C#,支持 .NET Framework 及 .NET Core、.NET 8.0。已支持微信公众号、小程序、小游戏、微信支付、企业微信/企业号、开放平台、JSSDK、微信周边等全平台。 WeChat SDK for C#.
|
|
microsoft/ailab
Experience, Learn and Code the latest breakthrough innovations with Microsoft AI
|
|
aspnet/Mvc
[Archived] ASP.NET Core MVC is a model view controller framework for building dynamic web sites with clean separation of concerns, including the merged MVC, Web API, and Web Pages w/ Razor. Project moved to https://github.com/aspnet/AspNetCore
|
Version | Downloads | Last updated | |
---|---|---|---|
9.0.0 | 1,025,698 | 11/12/2024 | |
9.0.0-rc.2.24473.5 | 313,230 | 10/8/2024 | |
9.0.0-rc.1.24431.7 | 270,286 | 9/10/2024 | |
9.0.0-preview.7.24405.7 | 165,706 | 8/13/2024 | |
9.0.0-preview.6.24327.7 | 241,082 | 7/9/2024 | |
9.0.0-preview.5.24306.7 | 191,177 | 6/11/2024 | |
9.0.0-preview.4.24266.19 | 144,751 | 5/21/2024 | |
9.0.0-preview.3.24172.9 | 325,778 | 4/11/2024 | |
9.0.0-preview.2.24128.5 | 215,124 | 3/12/2024 | |
9.0.0-preview.1.24080.9 | 215,420 | 2/13/2024 | |
8.0.0 | 204,139,631 | 11/14/2023 | |
8.0.0-rc.2.23479.6 | 2,335,533 | 10/10/2023 | |
8.0.0-rc.1.23419.4 | 1,270,687 | 9/12/2023 | |
8.0.0-preview.7.23375.6 | 716,236 | 8/8/2023 | |
8.0.0-preview.6.23329.7 | 497,896 | 7/11/2023 | |
8.0.0-preview.5.23280.8 | 354,243 | 6/13/2023 | |
8.0.0-preview.4.23259.5 | 595,655 | 5/16/2023 | |
8.0.0-preview.3.23174.8 | 591,515 | 4/11/2023 | |
8.0.0-preview.2.23128.3 | 509,690 | 3/14/2023 | |
8.0.0-preview.1.23110.8 | 405,675 | 2/21/2023 | |
7.0.0 | 288,529,191 | 11/7/2022 | |
7.0.0-rc.2.22472.3 | 1,550,567 | 10/11/2022 | |
7.0.0-rc.1.22426.10 | 611,402 | 9/14/2022 | |
7.0.0-preview.7.22375.6 | 467,458 | 8/9/2022 | |
7.0.0-preview.6.22324.4 | 373,866 | 7/12/2022 | |
7.0.0-preview.5.22301.12 | 249,652 | 6/14/2022 | |
7.0.0-preview.4.22229.4 | 569,869 | 5/10/2022 | |
7.0.0-preview.3.22175.4 | 234,991 | 4/13/2022 | |
7.0.0-preview.2.22152.2 | 374,958 | 3/14/2022 | |
7.0.0-preview.1.22076.8 | 255,270 | 2/17/2022 | |
6.0.1 | 94,838 | 11/12/2024 | |
6.0.0 | 638,140,988 | 11/8/2021 | |
6.0.0-rc.2.21480.5 | 2,070,427 | 10/12/2021 | |
6.0.0-rc.1.21451.13 | 785,796 | 9/14/2021 | |
6.0.0-preview.7.21377.19 | 901,217 | 8/10/2021 | |
6.0.0-preview.6.21352.12 | 451,197 | 7/14/2021 | |
6.0.0-preview.5.21301.5 | 419,752 | 6/15/2021 | |
6.0.0-preview.4.21253.7 | 1,751,936 | 5/24/2021 | |
6.0.0-preview.3.21201.4 | 843,570 | 4/8/2021 | |
6.0.0-preview.2.21154.6 | 301,681 | 3/11/2021 | |
6.0.0-preview.1.21102.12 | 758,889 | 2/12/2021 | |
5.0.1 | 51,316,843 | 4/6/2021 | |
5.0.0 | 544,044,831 | 11/9/2020 | |
5.0.0-rc.2.20475.5 | 1,175,893 | 10/13/2020 | |
5.0.0-rc.1.20451.14 | 978,938 | 9/14/2020 | |
5.0.0-preview.8.20407.11 | 713,123 | 8/25/2020 | |
5.0.0-preview.7.20364.11 | 548,274 | 7/21/2020 | |
5.0.0-preview.6.20305.6 | 259,938 | 6/25/2020 | |
5.0.0-preview.5.20278.1 | 403,366 | 6/10/2020 | |
5.0.0-preview.4.20251.6 | 447,174 | 5/18/2020 | |
5.0.0-preview.3.20215.2 | 337,023 | 4/23/2020 | |
5.0.0-preview.2.20160.3 | 452,169 | 4/2/2020 | |
5.0.0-preview.1.20120.4 | 237,573 | 3/16/2020 | |
3.1.32 | 23,787,806 | 12/13/2022 | |
3.1.31 | 3,169,557 | 11/8/2022 | |
3.1.30 | 3,646,234 | 10/11/2022 | |
3.1.29 | 2,898,408 | 9/13/2022 | |
3.1.28 | 6,622,995 | 8/9/2022 | |
3.1.27 | 2,562,608 | 7/12/2022 | |
3.1.26 | 2,203,755 | 6/14/2022 | |
3.1.25 | 4,060,044 | 5/10/2022 | |
3.1.24 | 13,591,699 | 4/11/2022 | |
3.1.23 | 6,043,608 | 3/8/2022 | |
3.1.22 | 24,589,123 | 12/14/2021 | |
3.1.21 | 13,340,036 | 11/7/2021 | |
3.1.20 | 7,071,616 | 10/11/2021 | |
3.1.19 | 6,751,095 | 9/14/2021 | |
3.1.18 | 66,265,663 | 8/10/2021 | |
3.1.17 | 9,219,721 | 7/13/2021 | |
3.1.16 | 16,366,341 | 6/8/2021 | |
3.1.15 | 10,810,759 | 5/11/2021 | |
3.1.14 | 22,297,967 | 4/6/2021 | |
3.1.13 | 19,119,927 | 3/9/2021 | |
3.1.12 | 14,915,624 | 2/9/2021 | |
3.1.11 | 23,647,627 | 1/12/2021 | |
3.1.10 | 36,629,177 | 11/9/2020 | |
3.1.9 | 86,446,427 | 10/13/2020 | |
3.1.8 | 255,128,784 | 9/8/2020 | |
3.1.7 | 47,666,410 | 8/11/2020 | |
3.1.6 | 53,640,004 | 7/14/2020 | |
3.1.5 | 57,480,639 | 6/9/2020 | |
3.1.4 | 70,442,426 | 5/12/2020 | |
3.1.3 | 128,963,768 | 3/24/2020 | |
3.1.2 | 90,423,511 | 2/18/2020 | |
3.1.1 | 53,009,392 | 1/14/2020 | |
3.1.0 | 298,906,129 | 12/3/2019 | |
3.1.0-preview3.19553.2 | 1,995,058 | 11/13/2019 | |
3.1.0-preview2.19525.4 | 247,330 | 11/1/2019 | |
3.1.0-preview1.19506.1 | 1,333,774 | 10/15/2019 | |
3.0.3 | 71,621,059 | 2/18/2020 | |
3.0.2 | 1,259,658 | 1/14/2020 | |
3.0.1 | 8,705,724 | 11/18/2019 | |
3.0.0 | 213,168,563 | 9/23/2019 | |
3.0.0-rc1.19456.10 | 198,036 | 9/16/2019 | |
3.0.0-preview9.19423.4 | 1,797,979 | 9/4/2019 | |
3.0.0-preview8.19405.4 | 656,486 | 8/13/2019 | |
3.0.0-preview7.19362.4 | 378,463 | 7/23/2019 | |
3.0.0-preview6.19304.6 | 931,202 | 6/12/2019 | |
3.0.0-preview5.19227.9 | 895,800 | 5/6/2019 | |
3.0.0-preview4.19216.2 | 102,633 | 4/18/2019 | |
3.0.0-preview3.19153.1 | 459,386 | 3/6/2019 | |
3.0.0-preview.19074.2 | 263,307 | 1/29/2019 | |
3.0.0-preview.18572.1 | 206,429 | 12/4/2018 | |
2.2.0 | 749,295,659 | 12/3/2018 | |
2.2.0-preview3-35497 | 814,861 | 10/17/2018 | |
2.2.0-preview2-35157 | 679,811 | 9/12/2018 | |
2.2.0-preview1-35029 | 374,998 | 8/22/2018 | |
2.1.6 | 7,974,835 | 11/13/2018 | |
2.1.1 | 474,672,651 | 6/18/2018 | |
2.1.0 | 553,265,917 | 5/29/2018 | |
2.1.0-rc1-final | 766,409 | 5/6/2018 | |
2.1.0-preview2-final | 1,115,709 | 4/10/2018 | |
2.1.0-preview1-final | 2,219,222 | 2/26/2018 | |
2.0.0 | 659,314,099 | 8/11/2017 | |
2.0.0-preview2-final | 819,409 | 6/28/2017 | |
2.0.0-preview1-final | 827,173 | 5/10/2017 | |
1.1.1 | 81,111,747 | 5/9/2017 | |
1.1.0 | 56,199,093 | 11/16/2016 | |
1.1.0-preview1-final | 289,314 | 10/24/2016 | |
1.0.1 | 145,548,346 | 12/12/2016 | |
1.0.0 | 296,761,826 | 6/27/2016 | |
1.0.0-rc2-final | 2,350,556 | 5/16/2016 | |
1.0.0-rc1-final | 1,051,169 | 11/18/2015 |