Strings.StrConvで全角に変換しようとする文字列にサロゲートペア文字が含まれていると"??"に変換されてしまいます。
Debug.WriteLine("𠀋=" + Strings.StrConv("𠀋", VbStrConv.Wide)); // 𠀋=??と表示される
「.NET Frameworkは文字列を内部的にUnicodeしており、標準機能のStrConvを使用しているからヨシ!」と思っていると失敗するので注意が必要です。
参考
Strings.StrConvで全角に変換しようとする文字列にサロゲートペア文字が含まれていると"??"に変換されてしまいます。
Debug.WriteLine("𠀋=" + Strings.StrConv("𠀋", VbStrConv.Wide)); // 𠀋=??と表示される
「.NET Frameworkは文字列を内部的にUnicodeしており、標準機能のStrConvを使用しているからヨシ!」と思っていると失敗するので注意が必要です。
参考
int x = null; // コンパイルエラー
Dim x As Integer = Nothing ' x = 0
Public Shared Sub Main()
Dim n As Integer = Nothing
' コンパイルエラー(VBNC30020)
' If n Is Nothing Then
' Console.WriteLine("n is Nothing")
' End If
If n = Nothing Then
Console.WriteLine("n equals Nothing")
End If
If IsNothing(n) Then
Console.WriteLine("isNothing n")
End If
If n = 0 Then
Console.WriteLine("n equals zero")
End If
End Sub
' 実行結果
' n equals Nothing
' n equals zero
<cc1:FileDownloadButton ID="FileDownloadButton1" runat="server"
Text="Download"
OnDownloading="FileDownloadButton1_Downloading"
OnDownloaded="FileDownloadButton1_Downloaded"/>
protected void FileDownloadButton1_Downloading(object sender, EventArgs e)
{
// Tempファイルを作成する
var path = Path.GetTempFileName();
var file = new FileInfo(path);
// Tempファイルへデータを出力する
using (var s = file.OpenWrite())
using (var w = new StreamWriter(s))
{
w.WriteLine("Hello");
w.Flush();
}
// FileDownloadButtonのFileプロパティへTempファイルをセットする
FileDownloadButton1.File = file;
}
protected void FileDownloadButton1_Downloaded(object sender, EventArgs e)
{
// Tempファイルを削除する
FileDownloadButton1.File.Delete();
}
var sb = new StringBuilder()
.Append("select *").Append(Environment.NewLine)
.Append(" from Table1").Append(Environment.NewLine)
.Append(" where Column1 = @Value1").Append(Environment.NewLine);
var sw = new StringWriter();
sw.WriteLine("select *");
sw.WriteLine(" from Table1");
sw.WriteLine(" where Column1 = @Value1");
class Class1
{
private readonly DbProviderFactory factory;
private readonly string connectionString;
public Class1(DbProviderFactory factory, string connectionString)
{
this.factory = factory;
this.connectionString = connectionString;
}
public List<object> Method1()
{
using (var conn = factory.CreateConnection())
using (var command = factory.CreateCommand())
{
conn.ConnectionString = connectionString;
conn.Open();
command.Connection = conn;
command.CommandText = "select * from Table1 where ID = @ID";
var param = factory.CreateParameter();
param.ParameterName = "ID";
param.Value = "ID1";
command.Parameters.Add(param);
var reader = command.ExecuteReader();
var result = new List<object>();
while (reader.Read())
{
var arr = new object[reader.FieldCount];
reader.GetValues(arr);
result.Add(arr);
}
return result;
}
}
class MyPage : Page {
protected void Page_PreRender(object sender, EventArgs e) {
var args = "xxx"; // 例えば、詳細情報を表示するためのプライマリキー
var js = ClientScript.GetPostBackEventReference(this, args);
Table1.Rows[0].Cells[0].Attributes.Add("onclick", js);
}
}
// 上のクラスへIPostBackEventHandlerを実装
class MyPage : Page, IPostBackEventHandler {
...
public void RaisePostBackEvent(string eventArgs) {
// 例えばセッションへeventArgsをセットして詳細ページへ遷移する
Session.Add("key", eventArgs);
var detail = ResolveUrl("~/MyDetailPage.aspx");
Server.Transfer(detail);
}
}
var path = VirtualPathUtility.Combine(HttpRuntime.AppDomainVirtualPath,
"Web.config");
var conf = WebConfigurationManager.OpenWebConfiguration(path);
class NetworkConfigurationSection : ConfigurationSection
{
[ConfigurationProperty("LocalHost")]
public NetworkConfigElement LocalHost
{
get { return base["LocalHost"] as NetworkConfigElement; }
set { base["LocalHost"] = value; }
}
[ConfigurationProperty("Networks")]
public NetworkConfigElementCollection Networks
{
get { return base["Networks"] as NetworkConfigElementCollection; }
}
}
class NetworkConfigElement : ConfigurationElement
{
[ConfigurationProperty("IPAddress")]
public string IPAddress
{
get { return base["IPAddress"] as string; }
set { base["IPAddress"] = value; }
}
}
class NetworkConfigElementCollection : ConfigurationElementCollection
{
protected override ConfigurationElement CreateNewElement()
{
return new NetworkConfigElement();
}
protected override object GetElementKey(ConfigurationElement element)
{
NetworkConfigElement elm = element as NetworkConfigElement;
if (null == elm) return null;
return elm.IPAddress;
}
}
byte[] data = null;
using (var memory = new MemoryStream()) {
using (var gzip = new GZipStream(memory, CompressionMode.Compress)) {
int input = 0;
byte[] buffer = new byte[1];
while (-1 != (input = Console.Read())) {
buffer[0] = Convert.ToByte(input);
gzip.Write(buffer, 0, buffer.Length);
}
}
data = memory.ToArray();
}
var clientHandler = new HttpClientHandler(); clientHandler.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
using(var client = new HttpClient(clientHandler))
using(var content = new ByteArrayContent(data))
{
content.Headers.ContentEncoding.Add("gzip");
using(var message = client.PostAsync(url, content).Result)
{
Console.WriteLine(message.Content.ReadAsStringAsync().Result);
}
}
# -*- coding: shift-jis -*-
import clr
import unittest
clr.AddReferenceToFileAndPath('Class1.dll')
from TwoCardPokerLib import Hand
class HandTest(unittest.TestCase):
def test_royal_flush_wins_pair_aces(self):
h1 = Hand('Ac', 'Kc')
h2 = Hand('Ad', 'As')
self.assertEquals(1, h1.Compare(h2))
def test_straight_flush_diamonds_eq_straight_flush_hearts(self):
h1 = Hand('Td', '9d')
h2 = Hand('Th', '9h')
self.assertEquals(0, h1.Compare(h2))
@unittest.skip('')
def test_straight_loses_ace_high(self):
h1 = Hand('Ah', '2c')
h2 = Hand('As', '9c')
self.assertEquals(1, h1.Compare(h2))
def test_flush_9_6_high_loses_flush_9_7(self):
h1 = Hand('9h', '6h')
h2 = Hand('9d', '7d')
self.assertEquals(-1, h1.Compare(h2))
def test_king_high_loses_ace_high(self):
h1 = Hand('Kc', 'Jh')
h2 = Hand('As', '5d')
self.assertEquals(-1, h1.Compare(h2))
C:\>ipy.exe -m unittest -v testhand
test_flush_9_6_high_loses_flush_9_7 (testhand.HandTest) ... FAIL
test_king_high_loses_ace_high (testhand.HandTest) ... ok
test_royal_flush_wins_pair_aces (testhand.HandTest) ... ok
test_straight_flush_diamonds_eq_straight_flush_hearts (testhand.HandTest) ... ok
test_straight_loses_ace_high (testhand.HandTest) ... skipped ''
======================================================================
FAIL: test_flush_9_6_high_loses_flush_9_7 (testhand.HandTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "c:\testhand.py", line 29, in test_flush_9_6_high_loses_flush_9_7
self.assertEquals(-1, h1.Compare(h2))
AssertionError: -1 != 0
----------------------------------------------------------------------
Ran 5 tests in 0.164s
FAILED (failures=1, skipped=1)
<configuration>
<system.diagnostics>
<trace autoflush="true">
<listeners>
<clear />
<add name="file"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="TEXT-WRITER.log">
<!-- Warning以上を出力 -->
<filter type="System.Diagnostics.EventTypeFilter"
initializeData="Warning" />
</add>
</listeners>
</trace>
</system.diagnostics>
</configuration>
TraceTest Warning: 0 : TraceWarning TraceTest Error: 0 : TraceError
<configuration>
<system.diagnostics>
<trace autoflush="true">
<listeners>
<clear />
<!-- テキストファイル -->
<add name="file"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="TEXT-WRITER.log"
traceOutputOptions="Callstack, DateTime, LogicalOperationStack, ProcessId, ThreadId, Timestamp" />
</listeners>
</trace>
</system.diagnostics>
</configuration>
TraceTest.exe Information: 0 : TraceInformation
ProcessId=5700
LogicalOperationStack=
ThreadId=1
DateTime=2014-02-02T12:47:28.3398027Z
Timestamp=6032477769
Callstack= 場所 System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
場所 System.Environment.get_StackTrace()
場所 System.Diagnostics.TraceEventCache.get_Callstack()
場所 System.Diagnostics.TraceListener.WriteFooter(TraceEventCache eventCache)
場所 System.Diagnostics.TraceListener.TraceEvent(TraceEventCache eventCache, String source, TraceEventType eventType, Int32 id, String message)
場所 System.Diagnostics.TraceInternal.TraceEvent(TraceEventType eventType, Int32 id, String format, Object[] args)
場所 TraceTest.TraceTest.Main(String[] args)
namespace TraceTest
{
using System.Diagnostics;
public class TraceTest {
public static void Main(string[] args) {
Trace.TraceInformation("TraceInformation");
Trace.TraceWarning("TraceWarning");
Trace.TraceError("TraceError");
}
}
}
<configuration>
<system.diagnostics>
<trace autoflush="true">
<listeners>
<clear />
<!-- 標準出力 -->
<add name="console"
type="System.Diagnostics.ConsoleTraceListener" />
<!-- 区切りリスト -->
<add name="delimited-list"
type="System.Diagnostics.DelimitedListTraceListener"
initializeData="DELIMITED-LIST.log" />
<!-- イベントログ -->
<add name="eventlog"
type="System.Diagnostics.EventLogTraceListener"
initializeData="Application" />
<!-- テキストファイル -->
<add name="file"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="TEXT-WRITER.log" />
<!-- XML形式 -->
<add name="xml-writer"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData="XML-WRITER.log" />
</listeners>
</trace>
</system.diagnostics>
</configuration>
参考