# Friday, January 23, 2004

That was in short what was on my requirement list.
I had a few difficulties solving the problem of filling "this" and classes that fill them self in the constructor, but i finally figured it out.


public void Fill(ref object[] objCollection ...)
{
    ...
    System.Type type = objCollection[0].GetType();
    ArrayList arr = new ArrayList();
    ...
    object baseObject;

    // struct or struct[]
    if(type.IsValueType) 
    {
        baseObject = type.Assembly.CreateInstance(type.FullName);
    }
    // this or non serializable class
    else if(arr.Count==0)
    {
        baseObject = objCollection[0];
    }
    // class or class[]
    else if(type.IsSerializable) 
    {
        Stream _stream;
        BinaryFormatter _formatter = new BinaryFormatter();
        try
        {
            _stream = File.Open("Empdata.bin",
             FileMode.Create, FileAccess.Write);
            _formatter.Serialize(_stream, objCollection[0]);
            _stream.Close();

             _stream = File.Open("Empdata.bin",
              FileMode.Open, FileAccess.Read);
             object _desObj = _formatter.Deserialize(_stream);
             baseObject = Convert.ChangeType(_desObj, type);
             _stream.Close();
        }
        catch(Exception e)
        {
            throw new Exception(type.ToString() +
             " could not be serialized.", e);
        }
    }
    else
    {
        throw new NotImplementedException(type.ToString() +
         " is no value type and don't implements the" +
         "ISerializable interface.");
    }
    ...
    arr.Add(baseObject);
    ...
}

C#
Friday, January 23, 2004 10:44:36 PM (W. Europe Standard Time, UTC+01:00)  #    Disclaimer  |  Comments [27]  | 

Michael Fanning blogs about the next version of FxCop.

I added his blog to my blogroll.

Friday, January 23, 2004 9:45:49 PM (W. Europe Standard Time, UTC+01:00)  #    Disclaimer  |  Comments [20]  | 
Friday, January 23, 2004 9:31:37 PM (W. Europe Standard Time, UTC+01:00)  #    Disclaimer  |  Comments [22]  | 
# Tuesday, December 30, 2003
<%@ Page language="C#" %>
<script language="C#" runat="server">
  private void Page_Load(object sender, System.EventArgs e)
  {
    System.Data.OleDb.OleDbConnection _conn =
     new System.Data.OleDb.OleDbConnection();
    _conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
     "Data Source=D:\\WebRoot\\data\\data.mdb";
    System.Data.OleDb.OleDbCommand _cmd = conn.CreateCommand();
    _cmd.CommandType = System.Data.CommandType.Text;
    _cmd.CommandText = "SELECT Name FROM Users WHERE ID=1";
    System.Data.OleDb.OleDbDataAdapter _adapter =
     new System.Data.OleDb.OleDbDataAdapter();
    _adapter.SelectCommand = _cmd;
    System.Data.DataSet _dataset = new System.Data.DataSet();
    _conn.Open();
    _adapter.Fill(dataset, "UserTable");
    _conn.Close();
    if(_dataset.Tables["UserTable"].Rows.Count>0)
    {
      this.TextBox1.Text =
       _dataset.Tables["UserTable"].Rows[0][0].ToString();
    }
  }
</script>
<html>
<body>
<form ID="Form" runat="server">
 <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</form>
</body>
</html>
ASP.NET | C#
Tuesday, December 30, 2003 2:47:51 AM (W. Europe Standard Time, UTC+01:00)  #    Disclaimer  |  Comments [24]  | 
<%@ Page language="C#" %>
<script language="C#" runat="server">
 private void Page_Load(object sender, System.EventArgs e)
 {
   System.Data.OleDb.OleDbConnection _conn =
    new System.Data.OleDb.OleDbConnection();
   _conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
    "DataSource=D:\\WebRoot\\data\\data.mdb";
   System.Data.OleDb.OleDbCommand _cmd = _conn.CreateCommand();
   _cmd.CommandType = System.Data.CommandType.Text;
   _cmd.CommandText = "SELECT Name FROM Users WHERE ID=1";
   _conn.Open();
   System.Data.OleDb.OleDbDataReader _reader = cmd.ExecuteReader();
   if(_reader.Read())
   {
     this.TextBox1.Text = _reader.GetString(0);
   }
   _reader.Close();
   _conn.Close();
}
</script>
<html>
<body>
<form ID="Form" runat="server">
 <asp:TextBox id="TextBox1" runat="server
"></asp:TextBox>
</form
>
</body>
</html
>
ASP.NET | C#
Tuesday, December 30, 2003 2:45:16 AM (W. Europe Standard Time, UTC+01:00)  #    Disclaimer  |  Comments [26]  |