Skip to content

Instantly share code, notes, and snippets.

using System;
namespace ConsoleApp {
class Program {
static void Main(string[] args) {
Console.WriteLine("Hello World!");
}
}
}
@ichiroku11
ichiroku11 / HomeController.cs
Created December 4, 2018 04:01
ASP.NET Core MVCでSerilogを使う
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
namespace WebApp.Controllers {
public class HomeController : Controller {
@ichiroku11
ichiroku11 / Program.cs
Created October 18, 2018 08:32
AutoMapper - コンストラクタを呼び出してマッピング
using System;
using AutoMapper;
namespace ConsoleApp {
// 参考
// http://docs.automapper.org/en/stable/Construction.html
// コピー元
public class SampleSrc {
public int Id { get; set; }
@ichiroku11
ichiroku11 / Program.cs
Last active October 23, 2018 03:00
AutoMapper - 継承したオブジェクトをマッピングする
using System;
using AutoMapper;
namespace ConsoleApp {
// コピー元の親クラス
public abstract class SampleSrcBase {
public int Id { get; set; }
public string Value1 { get; set; }
}
@ichiroku11
ichiroku11 / Program.cs
Last active January 25, 2019 00:01
Enumerable.PrependとEnumerable.Append(https://github.com/ichiroku11/Sample に移動)
using System;
using System.Linq;
namespace ConsoleApp {
class Program {
static void Main(string[] args) {
// シーケンス
var source = new[] { 2, 3, 4 };
// Prepend:シーケンスの先頭に値を追加する
@ichiroku11
ichiroku11 / Program.cs
Created October 2, 2018 06:39
2次元配列
using System;
namespace ConsoleApp {
class Program {
static void Main(string[] args) {
var matrix = new string[,] {
{ "1-1", "1-2", "1-3" },
{ "2-1", "2-2", "2-3" }
};
@ichiroku11
ichiroku11 / AccountController.cs
Last active February 14, 2019 04:36
ASP.NET Core MVC - クッキー認証(https://github.com/ichiroku11/Sample へ)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
@ichiroku11
ichiroku11 / TempDataDictionaryExtensions.cs
Created July 27, 2018 01:56
ASP.NET Core MVC - TempDataにオブジェクト
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Newtonsoft.Json;
namespace WebApp {
public static class TempDataDictionaryExtensions {
// TempDataにオブジェクトを書き込む
@ichiroku11
ichiroku11 / SessionExtensions.cs
Created July 27, 2018 01:55
ASP.NET Core MVC - セッションにオブジェクト
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Newtonsoft.Json;
namespace WebApp {
public static class SessionExtensions {
// セッションにオブジェクトを書き込む
@ichiroku11
ichiroku11 / Startup.cs
Created May 17, 2018 02:15
グローバルフィルタで承認(認証というかアクセス制御というか)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.Authorization;
using Microsoft.AspNetCore.Routing;