M
Mark Rae
Hi,
In v1.1 I used to simulate nullable datatypes with structs. e.g.
public struct NullableString
{
private readonly String pstrValue;
private readonly bool blnHasValue;
public NullableString(String strValue)
{
this.pstrValue = strValue;
this.blnHasValue = true;
}
public String Value {get{return this.pstrValue;}}
public bool HasValue {get{return blnHasValue;}}
};
However, now that we have these natively in v2, I'm trying to use them as
part of my database abstraction layer. I have a class which begins:
public class CSale
{
private String? pstrTransactionID;
public String? strTransactionID {get{return
pstrTransactionID;}set{pstrTransactionID = value;}}
private DateTime? pdtmPayment;
public DateTime? dtmPayment{get{return pdtmPayment;}set{pdtmPayment =
value;}}
private int? pintItems;
public int? intItems {get{return pintItems;}set{pintItems = value;}}
private decimal? pcurFee;
public decimal? curFee{get{return pcurFee;}set{pcurFee = value;}}
// etc
}
However, this doesn't compile. Instead, the compiler generates the following
error:
The type 'string' must be a non-nullable value type in order to use it as
parameter 'T' in the generic type or method 'System.Nullable<T>'
IntelliSense still works, though, i.e. if I type a period after
strTransactionID, it drops down the list of properties and methods e.g.
HasValue, Value etc.
If I comment out the two lines relating to the String parameter, the class
compiles OK.
Any assistance gratefully received.
Mark
In v1.1 I used to simulate nullable datatypes with structs. e.g.
public struct NullableString
{
private readonly String pstrValue;
private readonly bool blnHasValue;
public NullableString(String strValue)
{
this.pstrValue = strValue;
this.blnHasValue = true;
}
public String Value {get{return this.pstrValue;}}
public bool HasValue {get{return blnHasValue;}}
};
However, now that we have these natively in v2, I'm trying to use them as
part of my database abstraction layer. I have a class which begins:
public class CSale
{
private String? pstrTransactionID;
public String? strTransactionID {get{return
pstrTransactionID;}set{pstrTransactionID = value;}}
private DateTime? pdtmPayment;
public DateTime? dtmPayment{get{return pdtmPayment;}set{pdtmPayment =
value;}}
private int? pintItems;
public int? intItems {get{return pintItems;}set{pintItems = value;}}
private decimal? pcurFee;
public decimal? curFee{get{return pcurFee;}set{pcurFee = value;}}
// etc
}
However, this doesn't compile. Instead, the compiler generates the following
error:
The type 'string' must be a non-nullable value type in order to use it as
parameter 'T' in the generic type or method 'System.Nullable<T>'
IntelliSense still works, though, i.e. if I type a period after
strTransactionID, it drops down the list of properties and methods e.g.
HasValue, Value etc.
If I comment out the two lines relating to the String parameter, the class
compiles OK.
Any assistance gratefully received.
Mark