In an existing application, code is generated to perform the cast, as shown below: (types are also generated classes, I provide an example with just objectand string)
object o;
string s = (string)o;
When o has a type int, it flings InvalidCastException. So I want to change the code to:
object o;
string s = o as string;
and check back later if there is any string s.
To perform code generation is used System.CodeDom. Listing is generated using the class CodeCastExpression.
I cannot find a way to generate a way variable as type... Can someone help me? Thank!
source
share