View Span.cs
using System;
using System.Collections.Generic;
namespace SpanOfT_Dev
{
public class Program
{
private static void Main(string[] args)
{
int[] arr = { 1, 2, 3, 4, 5 };
View Span.cs
using System;
using System.Collections.Generic;
namespace SpanOfT_Dev
{
public class Program
{
private static void Main(string[] args)
{
int[] arr = { 1, 2, 3, 4, 5 };
View Span.cs
using System;
namespace SpanOfT_Dev
{
public class Program
{
private static void Main(string[] args)
{
int[] arr = { 0, 1, 2, 3, 4, 5 };
Span<int> span = arr.AsSpan();
View Span.cs
int[] arr = { 0, 1, 2, 3, 4, 5 };
Span<int> span = arr.AsSpan();
foreach (var number in span)
{
Console.WriteLine(number);
}
View CategoriesController.cs
[HttpPost]
[ValidateAntiForgeryToken]
[AuthorizeResource(typeof(InsertCategoryRequirement))]
public async Task<IActionResult> Create([Bind("Id,Name,UserId")] Category category)
{
ViewData["UserId"] = new SelectList(_context.Users, "Id", "Id", category.UserId);
// If ModelState isn't valid, return to view immediately
if (!ModelState.IsValid)
{
View AuthorizeResourceAttribute.cs
public class AuthorizeResourceAttribute : TypeFilterAttribute
{
public AuthorizeResourceAttribute(Type requirementType)
: base(typeof(AuthorizeResourceFilter))
{
Arguments = new object[] { requirementType };
}
private class AuthorizeResourceFilter : IAsyncActionFilter
{
View CategoriesController.cs
public class CategoriesController : Controller
{
private readonly ApplicationDbContext _context;
private readonly IAuthorizationService _authorizationService;
public CategoriesController(ApplicationDbContext context, IAuthorizationService authorizationService)
{
_context = context;
_authorizationService = authorizationService;
}
View CategoriesController.cs
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create([Bind("Id,Name,UserId")] Category category)
{
var authorizationResult = await _authorizationService.AuthorizeAsync(User, category, new InsertCategoryRequirement());
if (!authorizationResult.Succeeded) // If user has no access show him 403
{
return new ForbidResult();
}
View InsertCategoryRequirement.cs
public class InsertCategoryHandler : AuthorizationHandler<InsertCategoryRequirement, Category>, IAuthorizationRequirement
{
private readonly ISecurityService _securityService;
public InsertCategoryHandler(ISecurityService securityService) => _securityService = securityService;
protected override async Task HandleRequirementAsync(AuthorizationHandlerContext context,
InsertCategoryRequirement requirement, Category category)
{