mee
mee

Reputation: 851

Reading a text file and perform the conditional statements manually

I have a text file - a template file, which has all the imports, parameters, constants, class name, methods etc. I need to read it manually and wherever needed, need to replace the corresponding value from excel file. In this within the method we have if, else statements too. Where i need to read the statement, if the condition statisfies, enter the loop and proceed further. The corresponding else part needs to be ignored. Any idea\suggestions on how this can be done? the if else needs to be executed manually.

Sample code Example:

if(0==0) {
    if(1==0) {
        value=0;
    } else {
        value=1;
    }
    return value;
} else {
    return 0;
}

So in this case, if the first if part returns, I need to skip the last else. Im counting the condition satisfaction by counting the braces.

Upvotes: 0

Views: 312

Answers (2)

theB
theB

Reputation: 6738

If IronPython/Ruby aren't desirable options, you may want to look at Roslyn. If that's not an option there's always the System.Reflection.Emit namespace.

Upvotes: 1

BendEg
BendEg

Reputation: 21088

For those purpose i like to use IronPython. It is a language based on the Dynamic Language Runtime (DLR). This should give you a nice tool to do what you want. More information can be found here: Home of IronPython

To complete the answer, also IronRuby should be a solution for you. But with this i have no experiance...

EDIT

Even with the newest .net framework and Roslyn you have a big amount of possibilities to do what you want. Just read a litte bit about c#-scripting with roslyn.

Upvotes: 1

Related Questions