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
public sealed class KeepTime : IDisposable { | |
private Stopwatch _stopwatch; | |
public KeepTime() { | |
Debug.WriteLine(String.Format("Start {0}", | |
DateTime.Now.ToShortTimeString())); | |
_stopwatch = Stopwatch.StartNew(); | |
} | |
public void Dispose() { | |
_stopwatch.Stop(); | |
Debug.WriteLine(String.Format("Stop {0} ({1}ミリ秒)", |
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
#region ==== Abstract Class : ViewModelBase | |
/// <summary> | |
/// ViewModelの抽象基底クラス | |
/// INotifyPropertyChanged, IDataErrorInfo を実装、 | |
/// その他 ViewModel用のヘルパークラス等を提供する | |
/// </summary> | |
public abstract class ViewModelBase : INotifyPropertyChanged, IDataErrorInfo | |
{ | |
// 省略 |
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
string text = "マルチバイト文字"; | |
int size = 10; // 10バイト | |
Encoding e = System.Text.Encoding.GetEncoding("Shift_JIS"); | |
string result = new String(text.TakeWhile((c, i) => e.GetByteCount(text.Substring(0, i + 1)) <= size).ToArray()); |
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
using System.ComponentModel; | |
public static class MyTryParse | |
{ | |
public static bool TryParse<T>(string input, ref T result) | |
{ | |
try | |
{ | |
var converter = TypeDescriptor.GetConverter(typeof(T)); | |
if(converter != null) |
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
using System; | |
using System.Collections.ObjectModel; | |
/// <summary> | |
/// 配列の拡張メソッドを管理するクラス | |
/// </summary> | |
public static class ArrayExtensions | |
{ | |
/// <summary> | |
/// 指定した配列をラップする読み取り専用のラッパーを作成します |
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
readonly Action<string, Action> _measurement = ((desc, execute) => | |
{ | |
var sw = new Stopwatch(); | |
sw.Start(); | |
execute(); | |
sw.Stop(); | |
Console.WriteLine("{0}:{1}", desc, sw.Elapsed); | |
}); | |
var rand = new Random(); |
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
public int ImportCsvData(string fullPath, string targetTableName, SqlConnection conn) | |
{ | |
int affected = 0; | |
System.IO.FileInfo fi = new System.IO.FileInfo(fullPath); | |
using (System.Data.Odbc.OdbcConnection odbcconn = new System.Data.Odbc.OdbcConnection(@"DRIVER={Microsoft Text Driver (*.txt; *.csv)};DefaultDir=" + fi.DirectoryName)) | |
{ | |
odbcconn.Open(); | |
System.Data.Odbc.OdbcCommand cmd = odbcconn.CreateCommand(); |
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
public class Company : IFormattable | |
{ | |
// プロパティは省略。 | |
public string ToString(string format, IFormatProvider formatProvider) | |
{ | |
if (format == null || format == "G" || format == "f") { | |
return CompnayName; | |
} | |
if (format == "s") { |
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
var cultures = new[] { "ja-jp", "zh-cn", "en-us", "en-gb", "fr-fr", "de-de", "pt-br", "tr-tr", "he-il" }; | |
var price = 9800; | |
foreach (var c in cultures) | |
{ | |
var culture = new CultureInfo(c); | |
var plus = price.ToString("c", culture); | |
var minus = (-price).ToString("c", culture); | |
Console.WriteLine("{0,-11} / {1,-12} ({2})", plus, minus, culture.DisplayName); | |
} |
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
public static Task<IEnumerable<T>> ExecuteAsync<T>(this DataServiceQuery<T> q) | |
{ | |
return Task.Factory.FromAsync<IEnumerable<T>>(q.BeginExecute, q.EndExecute, null); | |
} | |
var tasks = Common.GetQueries(context, keys) | |
.Select(x => x.ExecuteAsync() | |
.ContinueWith(t => { lock (w) Common.Output(t.Result, w); }) | |
).ToArray(); // ToArray を付けて、ここで全タスクを先に起動してしまう。 | |
Task.WaitAll(tasks.ToArray()); |
OlderNewer