Dictionary の初期化

Dictionary リテラルの夢は儚く散った・・・訂正。散ってはいなかった - ぐるぐる~

こんな風に書けますよ (・∀・)

var dict = new Dictionary<string, int>
{ 
    { "Hoge", 1 }, 
    { "Fuga", 2 }, 
    { "Piyo", 3 } 
};

方法 : コレクション初期化子を使用してディクショナリを初期化する (C# プログラミング ガイド)

CompositeControl

ポイント

  • VS のデザイナ上でも正常に動作させるために、複合コントロールの生成時に内部コントロールの生成も行う
    • デザイナのことを考えなければ CreateChildControls メソッドで生成しても問題無い
      • その場合、内部コントロールにアクセスするプロパティでは毎回 EnsureChildControls を呼び出す必要がある
  • 既定では複合コントロールは span タグで囲まれるが、TagKey プロパティをオーバーライドすれば別のタグに変更可能
    • このタグに、ID や CssClass 等のプロパティ値が適用される


MyList.cs

using System;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

namespace Sample.Controls
{
    [ParseChildren(true, "Items")]
    [PersistChildren(false)]
    public class MyList : CompositeControl
    {
        private HtmlGenericControl _legend = new HtmlGenericControl("legend");
        private RadioButtonList _radioButtonList = new RadioButtonList();


        [MergableProperty(false)]
        [PersistenceMode(PersistenceMode.InnerDefaultProperty)]
        public ListItemCollection Items
        {
            get
            {
                return this._radioButtonList.Items;
            }
        }

        public string Caption
        {
            get
            {
                return this._legend.InnerText;
            }
            set
            {
                this._legend.InnerText = value;
            }
        }


        protected override HtmlTextWriterTag TagKey
        {
            get
            {
                return HtmlTextWriterTag.Fieldset;
            }
        }

        protected override void CreateChildControls()
        {
            this.Controls.Add(this._legend);
            this.Controls.Add(this._radioButtonList);
        }
    }
}


Default.aspx (1)

<%@ Register Assembly="Sample" Namespace="Sample.Controls" TagPrefix="my" %>

Default.aspx (2)

<my:MyList runat="server" ID="_myList1" Caption="My List 1">
    <asp:ListItem Text="ほげ" Value="Hoge" />
    <asp:ListItem Text="ふが" Value="Fuga" />
    <asp:ListItem Text="ぴよ" Value="Piyo" />
</my:MyList>

デザイン時の CompositeControl の挙動

なんかおかしい。
↓の Items プロパティでは、内部コントロールを返すために EnsureChildControls メソッドを実行しているのだけれど、そうするとデザイン時に正しく処理がされないようで RadioButtonList 内の各項目が表示されない。なぜか、CreateChildControls が2回呼ばれているみたい。
実行時には問題無し。
プロパティの中で EnsureChildControls メソッドを呼ばないようにして、RadioButtonList の生成をコンストラクタとかで済ますようにすれば回避できるが…。

MyList.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.ComponentModel;

namespace Sample.Controls
{
    [ParseChildren(true, "Items")]
    [PersistChildren(false)]
    public class MyList : CompositeControl
    {
        private RadioButtonList _radioButtonList;


        [MergableProperty(false)]
        [PersistenceMode(PersistenceMode.InnerDefaultProperty)]
        public ListItemCollection Items
        {
            get
            {
                this.EnsureChildControls();
                return this._radioButtonList.Items;
            }
        }

        protected override void CreateChildControls()
        {
            HtmlGenericControl _fieldset = new HtmlGenericControl("fieldset")
            {
                Controls =
                {
                    (this._radioButtonList = new RadioButtonList())
                }
            };
            this.Controls.Add(this._fieldset);
        }
    }
}

Default.aspx (1)

<%@ Register Assembly="Sample" Namespace="Sample.Controls" TagPrefix="my" %>

Default.aspx (2)

<my:MyList runat="server" ID="_myList1">
    <asp:ListItem Text="ほげ" Value="Hoge" />
    <asp:ListItem Text="ふが" Value="Fuga" />
    <asp:ListItem Text="ぴよ" Value="Piyo" />
</my:MyList>

管理コンソールの表エディタで Date 型の値を入力する方法

Oracle Enterprise Management コンソールの表エディタで Date 型の値を入力する場合、

dd-Mon-yyyy HH:MI:SS AM

という書式に従って入力しなければならない。しかも日本語環境では、Mon と AM の部分を日本語で入力しなければならない。
例えば 2009/06/16 16:00:00 ならば

16-6月-2009 04:00:00 午後

となる。

なお、データ入力中に表エディタの下部にある [SQLを表示] ボタンをクリックすれば、発行される SQL 文を表示できるので、ここで to_date 関数の第二引数に指定されている書式を確認することができる。

最近

久々にニコ動を見てるんだけど、これすごくイイネ!
D


オリジナル
D


そしてよっぺいww自重しろwww
D


よっぺいと言ったらやっぱコレだ
D


よっぺいはこれもよい
D


なんかよっぺいだらけになっちゃったけど、よっぺいと花たんどっち選ぶ?って聞かれたら迷わず花たんは俺の嫁です。

ユーザーコントロールにコレクションのプロパティを持たせる

MyList.ascx

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MyList.ascx.cs" Inherits="Sample.MyList" %>

<fieldset class="MyListControl">
    <legend><%= this.Caption %></legend>
    <ul>
<% 
    foreach (var item in this.Items)
    {
%>
        <li>Item: <%= item.Text %></li>
<%
    }
%>
    </ul>
</fieldset>


MyList.ascx.cs

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Sample
{
    [ParseChildren(true)]
    [PersistChildren(false)]
    public partial class MyList : System.Web.UI.UserControl
    {
        public string Caption
        {
            get;
            set;
        }

        [MergableProperty(false)]
        [PersistenceMode(PersistenceMode.InnerProperty)]
        public List<MyListItem> Items
        {
            get;
            set;
        }
    }

    public class MyListItem
    {
        public string Text
        {
            get;
            set;
        }
    }
}


aspx (1)

<%@ Register tagprefix="my" src="MyList.ascx" tagname="MyList" %>
<%@ Register tagprefix="my" Assembly="Sample" Namespace="Sample" %>


aspx (2)

<my:MyList runat="server" Caption="List 1">
    <Items>
        <my:MyListItem Text="Item 1" />
        <my:MyListItem Text="Item 2" />
        <my:MyListItem Text="Item 3" />
    </Items>
</my:MyList>