Get datatype from values passed as string

前端 未结 5 704
滥情空心
滥情空心 2021-02-04 12:16

I am writing a framework that will connect to many different data source types and return values from these sources. The easy ones are SQL, Access and Oracle. The tougher ones a

5条回答
  •  遇见更好的自我
    2021-02-04 12:34

    Would it be easier to store it in a generic datatype with .ToInt16(), .ToInt32(), .ToBool(), etc.? If you write an app expecting int and it gets boolean it will fail, so it would be better to let the programmer explicit convert to the expected datatype.

    The problem with your approach is that you don't know if a row containing 0 as the first item will contain -100000 as item number 100. This means you can't do a successfull conversion until all rows has been TryParsed by all the different datatypes. Very expensive operation!

    If anything I'd use precompiled regular expressions and/or custom logic to process the data. For instance iterating all rows to find highest/lowest number, occurence of string, etc.

提交回复
热议问题