M
mark.olszowka
I am writing a generic property table as part of my application
property_name
property_type
property_value
All information is stored in the database as strings.
In my application that maintains this data, I want to ensure that the
user cannot type in a value that cannot be converted to the specified
property_type. There is no list of allowable property types. Any type
or enum that exists in the .Net Framework, or a custom type or enum
derived from the .Net framework is fair game in my application.
I can't seem to figure out how to verify this.
For example:
property_name = "RadiobuttonList.RepeatLayout"
property_type = "System.Web.UI.WebControls.RepeatLayout"
property_value = "Flow"
What code can I write to verify that "Flow" can be converted to the
type specified by the string "System.Web.UI.WebControls.RepeatLayout"?
Here is some of the code that I have tried
Dim strPropertyType As String
Dim strPropertyValue As String
Dim objType As System.Type
strPropertyValue = "Flow"
strPropertyType = "System.Web.UI.WebControls.RepeatLayout"
objType = System.Type.GetType(strPropertyType)
Try
System.Convert.ChangeType(strPropertyValue, objType)
Catch objException As System.Exception
ErrorMessage = "Invalid Property value specified"
End Try
This seems to work for types like String, Int32, etc, but not for Enums
(at least not for System.Web.UI.WebControls.RepeatLayout).
Help!
Remember, at design time, I know NOTHING about the type information I
will be working with.
Thanks
Mark Olszowka
property_name
property_type
property_value
All information is stored in the database as strings.
In my application that maintains this data, I want to ensure that the
user cannot type in a value that cannot be converted to the specified
property_type. There is no list of allowable property types. Any type
or enum that exists in the .Net Framework, or a custom type or enum
derived from the .Net framework is fair game in my application.
I can't seem to figure out how to verify this.
For example:
property_name = "RadiobuttonList.RepeatLayout"
property_type = "System.Web.UI.WebControls.RepeatLayout"
property_value = "Flow"
What code can I write to verify that "Flow" can be converted to the
type specified by the string "System.Web.UI.WebControls.RepeatLayout"?
Here is some of the code that I have tried
Dim strPropertyType As String
Dim strPropertyValue As String
Dim objType As System.Type
strPropertyValue = "Flow"
strPropertyType = "System.Web.UI.WebControls.RepeatLayout"
objType = System.Type.GetType(strPropertyType)
Try
System.Convert.ChangeType(strPropertyValue, objType)
Catch objException As System.Exception
ErrorMessage = "Invalid Property value specified"
End Try
This seems to work for types like String, Int32, etc, but not for Enums
(at least not for System.Web.UI.WebControls.RepeatLayout).
Help!
Remember, at design time, I know NOTHING about the type information I
will be working with.
Thanks
Mark Olszowka