This file contains hidden or 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
using Newtonsoft.Json.Linq; | |
using System; | |
using System.Net.Http; | |
using System.Linq; | |
using System.Threading.Tasks; | |
public static class GitHubCommitCounter | |
{ | |
public static async Task Count(string owner, DateTime minDateTime) | |
{ |
This file contains hidden or 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
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.WriteLine(Gender.Female.ToJapanese()); | |
Console.ReadLine(); | |
} | |
} | |
public enum Gender |
This file contains hidden or 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
public static class MockExtensions | |
{ | |
public static IReturnsResult<T> NotifyPropertyChanged<T, TResult>(this Mock<T> mock, Expression<Func<T, TResult>> expression, TResult setupValue) where T : class, INotifyPropertyChanged | |
{ | |
var memberExpression = expression.Body as MemberExpression; | |
if (memberExpression == null) throw new ArgumentException("expression.Body is not MemberExpression"); | |
var returnResult = mock.Setup(expression).Returns(setupValue); | |
mock.Raise(m => m.PropertyChanged += null, new PropertyChangedEventArgs(memberExpression.Member.Name)); |
This file contains hidden or 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
public partial class App : Application | |
{ | |
..... | |
protected override void OnSleep() | |
{ | |
(MainPage.BindingContext as IApplicationLifecycle)?.OnSleep(); | |
} | |
protected override void OnResume() |
This file contains hidden or 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
const string databaseFileName = "sqlite.db3"; | |
// ルートフォルダを取得する | |
IFolder rootFolder = FileSystem.Current.LocalStorage; | |
// ファイルシステム上のDBファイルの存在チェックを行う | |
var result = await rootFolder.CheckExistsAsync(databaseFileName); | |
if (result == ExistenceCheckResult.NotFound) | |
{ | |
// 存在しなかった場合、新たに空のDBファイルを作成する | |
var newFile = await rootFolder.CreateFileAsync(databaseFileName, CreationCollisionOption.ReplaceExisting); | |
// Assemblyに埋め込んだDBファイルをストリームで取得し、空ファイルにコピーする |
This file contains hidden or 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
ViewTypeToViewModelTypeResolver _resolver; | |
protected override void ConfigureViewModelLocator() | |
{ | |
base.ConfigureViewModelLocator(); | |
_resolver = new ViewTypeToViewModelTypeResolver(typeof(MainWindowViewModel).Assembly); // とりあえず適当なVMからAssembly取得して設定しておく | |
ViewModelLocationProvider.SetDefaultViewTypeToViewModelTypeResolver(_resolver.Resolve); | |
} | |
public class ViewTypeToViewModelTypeResolver | |
{ |
This file contains hidden or 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
public static Bitmap ToBitmap(this BitmapSource bitmapSource, PixelFormat pixelFormat) | |
{ | |
int width = bitmapSource.PixelWidth; | |
int height = bitmapSource.PixelHeight; | |
int stride = width * ((bitmapSource.Format.BitsPerPixel + 7) / 8); // 行の長さは色深度によらず8の倍数のため | |
IntPtr intPtr = IntPtr.Zero; | |
try | |
{ | |
intPtr = Marshal.AllocCoTaskMem(height * stride); | |
bitmapSource.CopyPixels(new Int32Rect(0, 0, width, height), intPtr, height * stride, stride); |
This file contains hidden or 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
[DllImport("gdi32.dll", EntryPoint = "DeleteObject")] | |
[return: MarshalAs(UnmanagedType.Bool)] | |
public static extern bool DeleteObject([In] IntPtr hObject); | |
public static ImageSource ToImageSource(this Bitmap bmp) | |
{ | |
var handle = bmp.GetHbitmap(); | |
try | |
{ | |
return Imaging.CreateBitmapSourceFromHBitmap(handle, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); |
This file contains hidden or 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
public static BitmapSource Resize(this BitmapSource source, int resolution) | |
{ | |
var scale = resolution / source.DpiX; | |
// サイズ変更 | |
var transformedBitmap = new TransformedBitmap(); | |
transformedBitmap.BeginInit(); | |
transformedBitmap.Source = source; | |
transformedBitmap.Transform = new ScaleTransform(scale, scale); | |
transformedBitmap.EndInit(); |
This file contains hidden or 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
public static BitmapSource Resize(this BitmapSource source, int resolution) | |
{ | |
var scale = resolution / source.DpiX; | |
// サイズ変更 | |
var transformedBitmap = new TransformedBitmap(); | |
transformedBitmap.BeginInit(); | |
transformedBitmap.Source = source; | |
transformedBitmap.Transform = new ScaleTransform(scale, scale); | |
transformedBitmap.EndInit(); |