"Alexey Lavnikov" wrote:
That means, I have to write C# parser myself?
Unless you manage to find an existing implementatation, yes. The problem
with a "CSharpToCodeDom" parser is the vastly different expression space of
C# and CodeDom. Some C# expressions are nearly impossible to recreate in
CodeDom. An example:
[C#]
obj as IDisposable
[/C#]
A possible equivalent would be
[C#]
obj is IDisposable ? (IDisposable)obj : (IDisposable)null;
[/C#]
Of course, the expression (boolean ? expr1 : expr2) also has no equivalent.
You'd have to introduce a method.
[CodeDom]
internal T As<T>(object value)
{
if (value != null &&
typeof(T).IsAssignableFrom(value.GetType())
return (T)value;
else
return null;
}
internal T Or<T>(bool condition,
T trueExpression, T falseExpression)
{
if (condition)
return trueExpression;
else
return falseExpression;
}
....
// equivalent to: obj as IDisposable
As<IDisposable>(obj)
// equivalent to: boolean ? expr1 : expr2
Or(boolean, expr1, expr2)
[/CodeDom]
I've no idea how to replicate the checked statement. Other expressions are
just cumbersome to replicate, e.g. is, foreach, using, lock.
Mark
PS: I've found one implementation of ICodeParser:
Microsoft.VisualStudio.Designer.CodeDom.VsCodeDomP arser in the assembly
Microsoft.VisualStudio. My guess is that the Form Designer uses that.