- PR -

System.Singleのコレクションのシリアライズ

1
投稿者投稿内容
れい
ぬし
会議室デビュー日: 2005/11/01
投稿数: 346
投稿日時: 2005-12-13 06:38
Single型の配列かコレクションをプロパティに持つようなコントロールを作っています。
配列ではデザイン時にうまく設定できないようなので、Single型をとるコレクションをCollectionBaseから作りました。
このコレクションをプロパティにもつコントロールをフォームに配置してデザイン表示すると
「ソース配列にある、少なくとも 1 つの要素をターゲット配列の型にキャストできませんでした。」
とエラーが出てきてしまいます。
Double型では同じようにうまくいかないのですが、
Boolean型、Int32型のコレクションでは問題ありません。
プロパティの初期化のコードでエラーがでてるようなんですが、
原因がわかりません。

原因や対策がわかる方がいたら、ぜひ教えてください。
よろしくお願いします。

コード:
  //カスタムコントロール
  public class CustomControl1 : System.Windows.Forms.Control   {
//略
    SingleCollection sc = new SingleCollection();
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
    public SingleCollection Singles {
      get {
        return sc;
      }
    }
  }

  //コレクション
  public class SingleCollection : CollectionBase {
    public Single this[int i] {
      get { return (Single)(base.List[i]);}
      set { base.List[i] = value; }
    }
    public void Add(Single value) { List.Add(value); }
    public void AddRange(Single[] values) {
      for (int i = values.GetLowerBound(0); i <= values.GetUpperBound(0); i++) { List.Add(values[i]);   }
    }
    public void Remove(Single value) { List.Remove(value); }
    public void IndexOf(Single value) {   List.IndexOf(value); }
    public void Insert(int index, Single value) {   List.Insert(index, value); }
    public bool Contains(Single value) { return List.Contains(value); }
    public void CopyTo(Array array, int index) { base.InnerList.CopyTo(array, index); }
  }

  //フォーム
  public class Form1 : System.Windows.Forms.Form
  {
//略
    private void InitializeComponent()
    {
      this.customControl11 = new GraphControl.CustomControl1();
      this.SuspendLayout();
      // 
      // customControl11
      // 
      this.customControl11.Location = new System.Drawing.Point(0, 0);
      this.customControl11.Name = "customControl11";
//この辺でエラーがでているっぽい
      this.customControl11.Singles.AddRange(new System.Single[] {
                                      1F,
                                      2F});
      this.customControl11.Size = new System.Drawing.Size(1, 1);
      this.customControl11.TabIndex = 0;
      this.customControl11.Text = "customControl11";
      // 
      // Form1
      // 
      this.AutoScaleBaseSize = new System.Drawing.Size(5, 12);
      this.ClientSize = new System.Drawing.Size(584, 454);
      this.Controls.Add(this.customControl11);
      this.Name = "Form1";
      this.Text = "Form1";
      this.ResumeLayout(false);
    }
//略
  }



1

スキルアップ/キャリアアップ(JOB@IT)