c#

SoapによるSerialize

Mohmongar
c#にてSystem.Runtime.Serialization.Formatters.Soapによるserialized /deserialized処理はHashtable型には使えるがDictionary型(ジェネリック)には使えない。単に備忘録。

C#でユーザー定義の例外をクラスとして定義

Mohmongar
public class UserException : Exception { public UserException() { } public UserException(string message) : base(message) { } public UserException(string message, Exception inner) : base(message,inner) { } } try { : Throw new UserException(); : } catch (UserException except) { : }

c#でTryParseをジェネリックで利用

Mohmongar
静的メソッドTryParseをジェネリックで解決できないので、メソッドを呼び出す。 リフレクションを使うのでちょっと無理やりかなぁ。 type parse<type>;(string s) { MethodInfo method = typeof(type).GetMethod("TryParse", new Type[] { typeof(string), typeof(type).MakeByRefType() }); object[] parameters = new object[] { s, null }; if ((bool)method.Invoke(null, parameters)) { return (type)(parameters[1]); } else { return default(type); } }</type> 参考はここ MSDN です。

c#でアルファ合成

Mohmongar
c#で透過Bitmapの合成はGraphicsのCompositingModeをSourceOverで使う。 Bitmap ImageWithAlpha; Bitmap backgroundImage; graphics g = Graphics.fromImage(backgroundImage); g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver; g.DrawImage(ImageWithAlpha, 0, 0);