C# EncodingをComboBoxなどで表示選択出来るクラス

#使用例
ComboBox.SelectedIndexChangedにmethodを登録して
そこで処理をすれば良いと思います。

```
private System.Windows.Forms.ComboBox encodings;
private System.Windows.Forms.BindingSource encodingBindingSource;

HogeEncodingList encodinglist = null;

public Test () {
  InitializeComponent ();
  encodinglist = new HogeEncodingList ();
}

private void Test_Load (Object sender, EventArgs e) {
  encodinglist.HogeCreateList ();
  encodings.DataSource = encodingBindingSource;
  encodingBindingSource.DataSource = encodinglist;
}
```

#BindingSource使わない場合
```
private void Test_Load (Object sender, EventArgs e) {
  encodinglist.HogeCreateList ();
  encodings.DataSource = encodinglist;
}
```

#本体
```
using System;
using System.Text;
using System.Collections.Generic;
using System.ComponentModel;

namespace Test {
  public class HogeEncoding : IEquatable<HogeEncoding>, IComparable<HogeEncoding> {
    public String Name;
    public EncodingInfo EncodingInfo;
    public Boolean BOM;
    public String BOMName;

    static public Boolean HogeHasBOM (Encoding enc) {
      return enc.GetPreamble ().Length == 0 ? false : true;
    }

    static public Boolean HogeHasBOM (EncodingInfo info) {
      return info.GetEncoding ().GetPreamble ().Length == 0 ? false : true;
    }

    static public Encoding HogeGetEncodings (Encoding enc, Boolean BOM) {
      switch (enc.CodePage) {
        case 1200: // utf-16
          return new UnicodeEncoding (false, BOM, true);
        case 1201: // utf-16 Big-Endian
          return new UnicodeEncoding (true, BOM, true);
        case 12000: // utf-32
          return new UTF32Encoding (false, BOM, true);
        case 12001: // utf-32 Big-Endian
          return new UTF32Encoding (true, BOM, true);
        case 65001: // utf-8
          return new UTF8Encoding (BOM, true);
        case 65000: // utf-7
          return new UTF7Encoding (true);
      }
      return enc;
    }

    static public Encoding HogeGetEncoding (HogeEncoding e, Boolean BOM) {
      return HogeGetEncoding (e.EncodingInfo.GetEncoding (), BOM);
    }

    static private Encoding HogeGetEncoding (Object p, Boolean bOM) {
      throw new NotImplementedException ();
    }

    public Boolean Equals (HogeEncoding o) {
      throw new NotImplementedException ();
    }

    public int CompareTo (HogeEncoding o) {
      return BOMName.CompareTo (o.BOMName);
    }

    public override String ToString () {
      return BOMName;
    }
  }

  public class HogeEncodingList : BindingList<HogeEncoding>, INotifyPropertyChanged {
    public event PropertyChangedEventHandler PropertyChanged = null;
    private void NotifyPropertyChanged (String propertyName = "") {
      if (PropertyChanged != null)
        PropertyChanged (this, new PropertyChangedEventArgs (propertyName));
    }

    public void HogeCreateList () {
      SortedSet<HogeEncoding> set = new SortedSet<HogeEncoding> ();
      foreach (EncodingInfo info in Encoding.GetEncodings ()) {
        Boolean bom = HogeEncoding.HogeHasBOM (info.GetEncoding ());
        HogeEncoding e = new HogeEncoding ();
        {
          e.EncodingInfo = info;
          e.Name = info.Name;
          e.BOM = bom;
          e.BOMName = info.Name + @" " + (bom ? @"HAS-BOM" : @"NO-BOM") + @" (" + info.CodePage + @")";
        }
        set.Add (e);
      }
      foreach (HogeEncoding o in set)
        Add (o);
    }

    public HogeEncoding GetHogeEncodingFromEncodingInfo (EncodingInfo info) {
      if (info != null) {
        foreach (HogeEncoding s in this)
          if (s.Name.Equals (info.Name))
            return s;
      }
      throw new ArgumentException (info.Name);
    }

    public HogeEncoding GetHogeEncodingFromEncoding (Encoding enc) {
      if (enc != null) {
        foreach (HogeEncoding s in this)
          if (s.EncodingInfo.GetEncoding ().Equals (enc))
            return s;
      }
      throw new ArgumentException (enc.EncodingName);
    }

    public HogeEncoding GetHogeEncodingFromCodePage (int codepage) {
      foreach (HogeEncoding s in this) {
        if (s.EncodingInfo.GetEncoding ().CodePage.Equals (codepage))
          return s;
      }
      throw new ArgumentException (codepage.ToString ());
    }

    public HogeEncoding GetHogeEncodingFromName (String name) {
      foreach (HogeEncoding s in this) {
        if (s.Name.Equals (name))
          return s;
      }
      throw new ArgumentException (name);
    }

    public HogeEncoding GetHogeEncodingFromBOMName (String bom) {
      foreach (HogeEncoding s in this) {
        if (s.BOMName.Equals (bom))
          return s;
      }
      throw new ArgumentException (bom);
    }

    public Boolean Equals (HogeEncoding o) {
      throw new NotImplementedException ();
    }

    public Int32 CompareTo (HogeEncoding o) {
      throw new NotImplementedException ();
    }
  }
}
```