Skip to content

Instantly share code, notes, and snippets.

@biac
biac / 参加者.cs
Created June 11, 2012 07:38
Kujian - 参加者.cs
public class 参加者
{
private const string OriginalData = @"…略(約40人分)…";
public string Name { get; set; }
public string ImageUrl { get; set; }
public static IList<参加者> Create()
{
XName img = XName.Get("img");
@biac
biac / Demo1Page.xaml.cs
Created April 15, 2012 06:03
Demo1Page.ToKatakanaButton_Click_1() / ToHiraganaButton_Click_1()
private void ToKatakanaButton_Click_1(object sender, RoutedEventArgs e)
{
this.TextArea.Text = NativeMethods.StringConvertToKatakana(this.TextArea.Text);
}
private void ToHiraganaButton_Click_1(object sender, RoutedEventArgs e)
{
this.TextArea.Text = NativeMethods.StringConvertToHiragana(this.TextArea.Text);
}
@biac
biac / Demo1Page.xaml.cs
Created April 15, 2012 05:46
Demo1Page.SaveTxtAutoButton_Click_1()
private async void SaveTxtAutoButton_Click_1(object sender, RoutedEventArgs e)
{
var thisButton = sender as Button;
thisButton.IsEnabled = false;
// "My Document" に "AutoSaved.txt" という名前で勝手に保存
StorageFolder myDoc = KnownFolders.DocumentsLibrary; // ←System.UnauthorizedAccessException が発生!!
// Package.appxmanifest に次の設定が必要:
@biac
biac / Demo1Page.xaml.cs
Created April 15, 2012 04:38
Demo1Page.SaveTxtButton_Click_1()
private async void SaveTxtButton_Click_1(object sender, RoutedEventArgs e)
{
var thisButton = sender as Button;
thisButton.IsEnabled = false;
// FileSavePicker を用意する
var picker = new FileSavePicker ();
picker.CommitButtonText = "テキストファイルを保存する";
picker.DefaultFileExtension = ".txt";
@biac
biac / Demo1Page.xaml.cs
Created April 15, 2012 03:16
Demo1Page.OpenTxtButton_Click_1()
private async void OpenTxtButton_Click_1(object sender, RoutedEventArgs e)
{
var thisButton = sender as Button;
thisButton.IsEnabled = false;
// FileOpenPicker を用意する
var picker = new FileOpenPicker();
picker.CommitButtonText = "テキストファイルを開く";
picker.FileTypeFilter.Add(".txt"); // 1つは必須!!
@biac
biac / gist:2133554
Created March 20, 2012 09:48
MSTest と NUnit のテストメソッドをひとつのテストクラスに押し込んでみたw #vs11 beta
using FizzBuzzModel;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NUnit.Framework;
using MS = Microsoft.VisualStudio.TestTools.UnitTesting;
using NU = NUnit.Framework;
namespace FizzBuzzModelTests
{
@biac
biac / gist:2117818
Created March 19, 2012 16:19
Metro スタイルアプリで、DataContextへViewModelをバインドさせている
// XAML
<Page
x:Class="FizzBuzzMetro.FizzBuzzPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:FizzBuzzMetro"
xmlns:vm="using:FizzBuzzModel"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
@biac
biac / gist:1750914
Created February 6, 2012 09:01
C# の || と |
static void Main(string[] args) {
if (expr1() || expr2())
Console.WriteLine("|| - short circuit");
if (expr1() | expr2())
Console.WriteLine("| - both evaluated");
Console.ReadKey();
}
@biac
biac / gist:1741281
Created February 5, 2012 00:05
.NET TIPS 正規表現を使って部分文字列を取得するには?[C#]
// 元記事 http://www.atmarkit.co.jp/fdotnet/dotnettips/579regexmatch/regexmatch.html
// その中の「HTMLからアンカー要素を抜き出すサンプル・プログラム」が残念だったので、いぢくってみる f(^^;
static void Main(string[] args) {
string anchor = "<a href=\"(?<url>.*?)\".*?>(?<text>.*?)</a>";
// @ITのトップページを取得
using (WebClient wc = new WebClient()) {
string html = wc.DownloadString("http://www.atmarkit.co.jp/");
@biac
biac / SaveAsync.cs
Created January 27, 2012 14:24
#win8 #metro でユーザーごとのデータを保存/復元する
// 抜き書きしたので、間違ってたらゴメン f(^^;
// try ~ catch も削ったし。
private static async Task SaveImplAsync(UserDataRepository clonedData)
{
//UserDataRepository clonedData;
//↑ここに、ユーザーごとのデータが入ってると思いねえ。
// ※非同期でセーブするんだから、ナマ禁止! スナップショットをコピーしたのを使う。
// Get the output stream for the SessionState file.