-
Notifications
You must be signed in to change notification settings - Fork 25.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add new bind sample /8 * Add new bind sample /8 * Add new bind sample /8 * Add new bind sample /8 * Add new bind sample /8 * Add new bind sample /8 * Add new bind sample /8 * Add new bind sample /8 * Add new bind sample /8 * Add new bind sample /8 * Add new bind sample /8
- Loading branch information
1 parent
cc775be
commit 3aeee53
Showing
18 changed files
with
173 additions
and
104 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
aspnetcore/fundamentals/configuration/index/samples/8.x/ConfigSample/ConfigSample.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 6 additions & 7 deletions
13
aspnetcore/fundamentals/configuration/index/samples/8.x/ConfigSample/Options/ArrayExample.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
namespace ConfigSample.Options | ||
namespace ConfigSample.Options; | ||
|
||
// <snippet> | ||
public class ArrayExample | ||
{ | ||
#region snippet | ||
public class ArrayExample | ||
{ | ||
public string[]? Entries { get; set; } | ||
} | ||
#endregion | ||
public string[]? Entries { get; set; } | ||
} | ||
// </snippet> |
1 change: 1 addition & 0 deletions
1
...nfiguration/index/samples/8.x/ConfigSample/Options/MyConfigServiceCollectionExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...ore/fundamentals/configuration/index/samples/8.x/ConfigSample/Options/NameTitleOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
namespace ConfigSample.Options; | ||
|
||
public abstract class SomethingWithAName | ||
{ | ||
public abstract string? Name { get; set; } | ||
} | ||
|
||
public class NameTitleOptions(int age) : SomethingWithAName | ||
{ | ||
public const string NameTitle = "NameTitle"; | ||
|
||
public override string? Name { get; set; } | ||
public string Title { get; set; } = string.Empty; | ||
|
||
public int Age { get; set; } = age; | ||
} |
17 changes: 8 additions & 9 deletions
17
...core/fundamentals/configuration/index/samples/8.x/ConfigSample/Options/PositionOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
namespace ConfigSample.Options | ||
namespace ConfigSample.Options; | ||
|
||
// <snippet> | ||
public class PositionOptions | ||
{ | ||
#region snippet | ||
public class PositionOptions | ||
{ | ||
public const string Position = "Position"; | ||
public const string Position = "Position"; | ||
|
||
public string Title { get; set; } = String.Empty; | ||
public string Name { get; set; } = String.Empty; | ||
} | ||
#endregion | ||
public string Title { get; set; } = String.Empty; | ||
public string Name { get; set; } = String.Empty; | ||
} | ||
// </snippet> |
44 changes: 21 additions & 23 deletions
44
aspnetcore/fundamentals/configuration/index/samples/8.x/ConfigSample/Pages/Array.cshtml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,35 @@ | ||
using ConfigSample.Options; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.RazorPages; | ||
using Microsoft.Extensions.Configuration; | ||
|
||
namespace ConfigSample | ||
{ | ||
namespace ConfigSample; | ||
|
||
// <snippet> | ||
public class ArrayModel : PageModel | ||
public class ArrayModel : PageModel | ||
{ | ||
private readonly IConfiguration Config; | ||
public ArrayExample? _array { get; private set; } | ||
|
||
public ArrayModel(IConfiguration config) | ||
{ | ||
private readonly IConfiguration Config; | ||
public ArrayExample? _array { get; private set; } | ||
Config = config; | ||
} | ||
|
||
public ArrayModel(IConfiguration config) | ||
public ContentResult OnGet() | ||
{ | ||
_array = Config.GetSection("array").Get<ArrayExample>(); | ||
if (_array == null || _array.Entries != null) | ||
{ | ||
Config = config; | ||
throw new ArgumentNullException(nameof(_array)); | ||
} | ||
string s = String.Empty; | ||
|
||
public ContentResult OnGet() | ||
for (int j = 0; j < _array.Entries!.Length; j++) | ||
{ | ||
_array = Config.GetSection("array").Get<ArrayExample>(); | ||
if (_array == null) | ||
{ | ||
throw new ArgumentNullException(nameof(_array)); | ||
} | ||
string s = String.Empty; | ||
|
||
for (int j = 0; j < _array.Entries.Length; j++) | ||
{ | ||
s += $"Index: {j} Value: {_array.Entries[j]} \n"; | ||
} | ||
|
||
return Content(s); | ||
s += $"Index: {j} Value: {_array.Entries[j]} \n"; | ||
} | ||
|
||
return Content(s); | ||
} | ||
// </snippet> | ||
} | ||
// </snippet> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 20 additions & 17 deletions
37
aspnetcore/fundamentals/configuration/index/samples/8.x/ConfigSample/Pages/Test21.cshtml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,32 @@ | ||
using ConfigSample.Options; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.RazorPages; | ||
using Microsoft.Extensions.Configuration; | ||
|
||
namespace ConfigSample.Pages | ||
{ | ||
namespace ConfigSample.Pages; | ||
|
||
// <snippet> | ||
public class Test21Model : PageModel | ||
public class Test21Model : PageModel | ||
{ | ||
private readonly IConfiguration Configuration; | ||
public PositionOptions? positionOptions { get; private set; } | ||
|
||
public Test21Model(IConfiguration configuration) | ||
{ | ||
private readonly IConfiguration Configuration; | ||
public PositionOptions? positionOptions { get; private set; } | ||
Configuration = configuration; | ||
} | ||
|
||
public Test21Model(IConfiguration configuration) | ||
public ContentResult OnGet() | ||
{ | ||
positionOptions = Configuration.GetSection(PositionOptions.Position) | ||
.Get<PositionOptions>(); | ||
|
||
if (positionOptions == null) | ||
{ | ||
Configuration = configuration; | ||
throw new ArgumentNullException(nameof(positionOptions)); | ||
} | ||
|
||
public ContentResult OnGet() | ||
{ | ||
positionOptions = Configuration.GetSection(PositionOptions.Position) | ||
.Get<PositionOptions>(); | ||
|
||
return Content($"Title: {positionOptions.Title} \n" + | ||
$"Name: {positionOptions.Name}"); | ||
} | ||
return Content($"Title: {positionOptions.Title} \n" + | ||
$"Name: {positionOptions.Name}"); | ||
} | ||
// </snippet> | ||
} | ||
// </snippet> |
4 changes: 4 additions & 0 deletions
4
aspnetcore/fundamentals/configuration/index/samples/8.x/ConfigSample/Pages/Test33.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
@page | ||
@model ConfigSample.Pages.Test33Model | ||
@{ | ||
} |
28 changes: 28 additions & 0 deletions
28
aspnetcore/fundamentals/configuration/index/samples/8.x/ConfigSample/Pages/Test33.cshtml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using ConfigSample.Options; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.RazorPages; | ||
|
||
namespace ConfigSample.Pages; | ||
|
||
// <snippet> | ||
public class Test33Model : PageModel | ||
{ | ||
private readonly IConfiguration Configuration; | ||
|
||
public Test33Model(IConfiguration configuration) | ||
{ | ||
Configuration = configuration; | ||
} | ||
|
||
public ContentResult OnGet() | ||
{ | ||
var nameTitleOptions = new NameTitleOptions(22); | ||
Configuration.GetSection(NameTitleOptions.NameTitle).Bind(nameTitleOptions); | ||
|
||
return Content($"Title: {nameTitleOptions.Title} \n" + | ||
$"Name: {nameTitleOptions.Name} \n" + | ||
$"Age: {nameTitleOptions.Age}" | ||
); | ||
} | ||
} | ||
// </snippet> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 25 additions & 27 deletions
52
...tcore/fundamentals/configuration/index/samples/8.x/ConfigSample/Pages/XML/Index.cshtml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,35 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.RazorPages; | ||
using Microsoft.Extensions.Configuration; | ||
|
||
namespace ConfigSample.Pages.JSON | ||
namespace ConfigSample.Pages.JSON; | ||
|
||
// <snippet> | ||
public class IndexModel : PageModel | ||
{ | ||
#region snippet | ||
public class IndexModel : PageModel | ||
{ | ||
private readonly IConfiguration Configuration; | ||
private readonly IConfiguration Configuration; | ||
|
||
public IndexModel(IConfiguration configuration) | ||
{ | ||
Configuration = configuration; | ||
} | ||
public IndexModel(IConfiguration configuration) | ||
{ | ||
Configuration = configuration; | ||
} | ||
|
||
public ContentResult OnGet() | ||
{ | ||
var key00 = "section:section0:key:key0"; | ||
var key01 = "section:section0:key:key1"; | ||
var key10 = "section:section1:key:key0"; | ||
var key11 = "section:section1:key:key1"; | ||
public ContentResult OnGet() | ||
{ | ||
var key00 = "section:section0:key:key0"; | ||
var key01 = "section:section0:key:key1"; | ||
var key10 = "section:section1:key:key0"; | ||
var key11 = "section:section1:key:key1"; | ||
|
||
var val00 = Configuration[key00]; | ||
var val01 = Configuration[key01]; | ||
var val10 = Configuration[key10]; | ||
var val11 = Configuration[key11]; | ||
var val00 = Configuration[key00]; | ||
var val01 = Configuration[key01]; | ||
var val10 = Configuration[key10]; | ||
var val11 = Configuration[key11]; | ||
|
||
return Content($"{key00} value: {val00} \n" + | ||
$"{key01} value: {val01} \n" + | ||
$"{key10} value: {val10} \n" + | ||
$"{key10} value: {val11} \n" | ||
); | ||
} | ||
return Content($"{key00} value: {val00} \n" + | ||
$"{key01} value: {val01} \n" + | ||
$"{key10} value: {val10} \n" + | ||
$"{key10} value: {val11} \n" | ||
); | ||
} | ||
#endregion | ||
} | ||
// </snippet> |
Oops, something went wrong.