G
Guest
Hi all !
Here is a tricky one, only for gurus !
I would like to associate a presence information with a base type.
In C language, we added a boolean presence field with each optional field :
typedef struct
{
unsigned char myFieldIsPresent;
unsigned short myField;
} SExample;
Let's move to .NET. I would like to merge these two entities in a single one.
First try, I can create a generic class :
class MyType<T>
{
public bool IsPresent
{
get { ... }
set { ... }
}
public T Value
{
get { ... }
set { ... }
}
}
Quite fine, but I must use the Value property to access the value !
MyType<ushort> myField = new MyType<ushort>;
myField.Value = 12;
The Graal would be the following :
MysteriousType myField = new MysteriousType;
myField = 12;
myField.IsPresent = true;
Anybody feeling inspired ?
Anyway, thank you very much...
Thomas
Here is a tricky one, only for gurus !
I would like to associate a presence information with a base type.
In C language, we added a boolean presence field with each optional field :
typedef struct
{
unsigned char myFieldIsPresent;
unsigned short myField;
} SExample;
Let's move to .NET. I would like to merge these two entities in a single one.
First try, I can create a generic class :
class MyType<T>
{
public bool IsPresent
{
get { ... }
set { ... }
}
public T Value
{
get { ... }
set { ... }
}
}
Quite fine, but I must use the Value property to access the value !
MyType<ushort> myField = new MyType<ushort>;
myField.Value = 12;
The Graal would be the following :
MysteriousType myField = new MysteriousType;
myField = 12;
myField.IsPresent = true;
Anybody feeling inspired ?
Anyway, thank you very much...
Thomas