A
Andrzej Kaczmarczyk
Hi
I am experiencing something weird. maybe you could help me.
I have two ineditable classes from outsource libraries: DataColumn and
GridColumn
I have built a wrapper class around DataColumn like this:
public class MyDataColumn {
// wrapped column
protected DataColumn column;
// additional settings
public bool MyFlag;
// hidden constructor
protected MyDataColumn(DataColumn source) {
this.column = source;
this.MyFlag = true;
}
// public converter
public static explicit MyDataColumn(DataColumn source) {
MyDataColumn tmp = source.ExtendedProperties["MyDataColumn"] as
MyDataColumn;
if (tmp == null) {
tmp = new MyDataColumn(source);
source.ExtendedProperties["MyDataColumn"] = tmp;
}
return tmp;
}
}
The purpose of this class is to build a wrapper class and calculate the
extension (MyFlag) upon which store the settings in ExtendedProperties of
the source DataColumn so as long the original DataColumn exists, all calls
to the MyDataColumn will return stored results. With that i can do the
following.
DataColumn column;
// create wrapping
{
MyDataColumn wrappedColumn1 = (MyDataColumn) column;
wrappedColumn1.MyFlag = false;
}
// somewhere else on the same dataColumn
MyDataColumn wrappedColumn2 = (MyDataColumn) column;
if (!wrappedColumn1.MyFlag) {
// <- I am here
}
This had worked excelently until today, when I decided to extend the class
with its child to wrap another class, like this:
public class MyGridColumn : MyDataColumn
{
// another wrapped column
private GridColumn gridColumn;
// more additions
public bool MySecondFlag;
// hidden constructor
protected MyGridColumn(MyDataColumn sourceDataColumn, GridColumn
sourceGridColumn)
: base(sourceDataColumn)
{
this.gridColumn = sourceGridColumn;
this.MySecondFlag = true;
}
// public converter
public static explicit MyGridColumn(GridColumn source) {
MyGridColumn tmp = source.Tag as MyDataColumn; // this class use Tag
objects instead of ExtendedProperties objects array
if (tmp == null) {
DataColumn dataColumn = source.GetDataColumn(); // this method return
the dataColumn used by this gridColumn
tmp = new MyGridColumn(dataColumn, source);
source.Tag = tmp;
}
return tmp;
}
}
Okay, this class' object does basicly the same as above, it wraps around the
GridColumn object, stores itself within it.
However I can't access the inherited property, or to put it otherwise I can,
but they return default values like this:
DataColumn column;
MyDataColumn myColumn = (MyDataColumn) column;
myColumn.MyFlag = false;
GridColumn gridColumn = new gridColumn(column);
MyGridColumn myGridColumn = (MyGridColumn) gridColumn;
myGridColumn.MySecondFlag = false;
the result is that
myColumn.MyFlag = false; // ok
myGridColumn.MyFlag = true; // not ok
myGridColumn.MySecondFlag = false; // ok
if I check via debuger, I can see that values are like above,
if (using debuger) I dig deeper like:
myGridColumn.base.column.Table.Columns[column].ExtendedProperty["MyDataColumn"].MyFlag
I see 'false' which is correct value
if I do the double wrapping instead of inheritance like this:
MyGridColumn {
private MyDataColumn myDataColumn;
private GridColumn gridColumn;
// instead of calling base constructor I do: this.myDataColumn =
(MyDataColumn) gridColumn.GetDataColumn();
}
everything works as expected ie none of the above quirks. but force me to
use longer calls: myGridColumn.myDataColumn.MyFlag instead of
myGridColumn.MyFlag
Can anyone explain this? How to make it work. I have this certain under skin
feeling that I miss something obvious here.
CUIN Kaczy
I am experiencing something weird. maybe you could help me.
I have two ineditable classes from outsource libraries: DataColumn and
GridColumn
I have built a wrapper class around DataColumn like this:
public class MyDataColumn {
// wrapped column
protected DataColumn column;
// additional settings
public bool MyFlag;
// hidden constructor
protected MyDataColumn(DataColumn source) {
this.column = source;
this.MyFlag = true;
}
// public converter
public static explicit MyDataColumn(DataColumn source) {
MyDataColumn tmp = source.ExtendedProperties["MyDataColumn"] as
MyDataColumn;
if (tmp == null) {
tmp = new MyDataColumn(source);
source.ExtendedProperties["MyDataColumn"] = tmp;
}
return tmp;
}
}
The purpose of this class is to build a wrapper class and calculate the
extension (MyFlag) upon which store the settings in ExtendedProperties of
the source DataColumn so as long the original DataColumn exists, all calls
to the MyDataColumn will return stored results. With that i can do the
following.
DataColumn column;
// create wrapping
{
MyDataColumn wrappedColumn1 = (MyDataColumn) column;
wrappedColumn1.MyFlag = false;
}
// somewhere else on the same dataColumn
MyDataColumn wrappedColumn2 = (MyDataColumn) column;
if (!wrappedColumn1.MyFlag) {
// <- I am here
}
This had worked excelently until today, when I decided to extend the class
with its child to wrap another class, like this:
public class MyGridColumn : MyDataColumn
{
// another wrapped column
private GridColumn gridColumn;
// more additions
public bool MySecondFlag;
// hidden constructor
protected MyGridColumn(MyDataColumn sourceDataColumn, GridColumn
sourceGridColumn)
: base(sourceDataColumn)
{
this.gridColumn = sourceGridColumn;
this.MySecondFlag = true;
}
// public converter
public static explicit MyGridColumn(GridColumn source) {
MyGridColumn tmp = source.Tag as MyDataColumn; // this class use Tag
objects instead of ExtendedProperties objects array
if (tmp == null) {
DataColumn dataColumn = source.GetDataColumn(); // this method return
the dataColumn used by this gridColumn
tmp = new MyGridColumn(dataColumn, source);
source.Tag = tmp;
}
return tmp;
}
}
Okay, this class' object does basicly the same as above, it wraps around the
GridColumn object, stores itself within it.
However I can't access the inherited property, or to put it otherwise I can,
but they return default values like this:
DataColumn column;
MyDataColumn myColumn = (MyDataColumn) column;
myColumn.MyFlag = false;
GridColumn gridColumn = new gridColumn(column);
MyGridColumn myGridColumn = (MyGridColumn) gridColumn;
myGridColumn.MySecondFlag = false;
the result is that
myColumn.MyFlag = false; // ok
myGridColumn.MyFlag = true; // not ok
myGridColumn.MySecondFlag = false; // ok
if I check via debuger, I can see that values are like above,
if (using debuger) I dig deeper like:
myGridColumn.base.column.Table.Columns[column].ExtendedProperty["MyDataColumn"].MyFlag
I see 'false' which is correct value
if I do the double wrapping instead of inheritance like this:
MyGridColumn {
private MyDataColumn myDataColumn;
private GridColumn gridColumn;
// instead of calling base constructor I do: this.myDataColumn =
(MyDataColumn) gridColumn.GetDataColumn();
}
everything works as expected ie none of the above quirks. but force me to
use longer calls: myGridColumn.myDataColumn.MyFlag instead of
myGridColumn.MyFlag
Can anyone explain this? How to make it work. I have this certain under skin
feeling that I miss something obvious here.
CUIN Kaczy