I have an spreadsheet type application I am creating, but I ran into some problems with polymorphism. When all of the expressions need to be calculated, I compile it in CodeDom so I can evaluate the expressions. The whole spreadsheet is actually an object with rows and cells, so I pass that into the compiler, run it in my program, and have it calculate the results. Then I display those results in the spreadsheet.

---- The problem is this -----

If I have the expression "R1C1 + 5" in a cell, in code it is actually "Code.Row[1].Cells[1].getResult() + 5". The problem is, R1C1 can either be a cell containing a string, or a cell containing a double. So if R1C1 contains a number, I want getResult() to return a double. If it isn't a number, I want it to return a string (in this scenario it would result in a compile error, so assume R1C1 contains a number.)

Is there anyway that I can store the result in the Cell object and return either a double or a string at runtime depending on what type the result is? I've tried using the primitive type 'object,' but I end up losing precision and the calculations are wrong. Any solution to this problem would be greatly appreciated. Thanks.

0