This question originated from Simplify Feature Set Topic. We want to learn more about what are the current drawbacks and how we can improve.
I only see the setback of this datatype on data manipulation. As it require conversion if any validation is required (for eg: string to numeric to process on numeric values).
Mostly, it provides no advantage over the primitive datatypes, so you always have to change it to something else, since it is the standard variable type for many activities.
Why would you want to use a Generic Value for processing text when String is much more powerful. Why use Generic Value when Decimal is better for numbers. Now, if you gave us implicitly typed variables (var keyword), that would be something useful.
What would be the functional difference between implicitly typed variables and Generic Value?
Chiefly, the ability to properly use .Net’s LINQ feature. As it is now, you cannot use LINQ statements that return an anonymous type. So for example when working with DataTables we cannot take advantage of LINQ and must rely on DataTable.Select.
Working with DataTables is indeed a hefty job today. There is separate work done on this and @Cosmin_Ion_Nicolae can provide more detail. I think we could open a similar thread to discuss this. I like @ericmyrs comment around not being able to take advantage of LINQ. Adding a var keyword would most likely help.
We plan to add some methods to GenericValue - these wont solve the above problem but i would like your opinion:
- ToUpper, ToLower
- ToInt (would call Floor() for doubles, and return 0/1 for booleans)
- ToString (“true”/“false” for booleans)
At runtime, int, double and boolean values would be automatically converted to string before methods like length, contains etc would be applied.
What do you think about this change?
I still don’t understand the use case for GenericValue.
Why are you trying to make a type that will only reveal an error on runtime? Even js fans started to like typescript strictly because it made runtime errors into compiler errors. Why go the other direction and add abstractions over things like a string?