I am currently parsing boolean into string using this line, but it ain't working all of times, is there any alternative ?
bool.Parse(listItem.Properties["Boolean Property"].ToString()) == false
|
I am currently parsing boolean into string using this line, but it ain't working all of times, is there any alternative ?
|
||||
|
|
This code will read the property as a boolean, though return null if the property is null or not a bool (hence it is put into the nullable bool 'temp'). We then make it a normal bool use the ?? operator - if temp is null, result will be set to 'true'. Otherwise, result is set to whatever value temp has. Using the '.Tostring()' risks a NullReferenceException if the property isn't set... |
|||||
|
http://msdn.microsoft.com/en-us/library/wh2c31dd.aspx hope it helps :) |
|||
|
|