views:

69

answers:

1

In an application, I have to use a valid identity string as a value of a property. I mean the string should be a valid identity name in C#.

For I want to use the string as a formula without change the source code of the component, I have to convert ANY formula, a string, to a valid identity string and convert it back when needed.Of course, when a formula is a valid identity name, the converting function should return it directly.

For example, the formula is Price*Quantity, and the converted value is Price__char_99__Quantity. For example, the formula is Price, and the converted value is Price.

Maybe there is such a function already there, but I took hours and failed to find it out. I guess in XML functions or string codes convertion, there must be some similar one.

Please give me a hand.

Thank you in advance.

Ying

A: 

I would be easier if you create a new class, Formula, rather than attempt to use a string for your forumla property. The Formula class would hold the original text of the formula as a property, so you would not need to convert. You can then create a List to hold any number of Forumula objects. This would be much easier to do than your current solution.

ShellShock