A
A
Alexey Smirnov2017-10-15 00:26:34
.NET
Alexey Smirnov, 2017-10-15 00:26:34

How to pass a piece of code to a method of another class (C#)?

Hello.
I have some class with a method.
Inside this method is the following line:

resultedText[0] = deserializedText[1].history[3].NUMER.ToString();

In the above line, I manually change only the following part of the code: the rest of the code in this line and in the entire class is unchanged. I would like to be able to change the above part of the code ( ) while in another class, and pass the already modified piece of code to the class. PS I don't know if it's even possible to implement this.
[1].history[3].NUMER
[1].history[3].NUMER

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
eRKa, 2017-10-15
@ERAFY

I would suggest using T4 .
It will be a .tt file, in which you can describe the code generation logic. In fact, it will take the file you need from the project as text and generate what you want from it. Before starting the project, you simply run the T4 file.
On one of our projects, we generate model code based on our metadata in this way.

C
cicatrix, 2017-10-15
@cicatrix

What code? Software?
Judging by the indexes, you have a tree-like data structure (graph). In the main class, it is necessary to read data into it (there is, by the way, the TreeNode system class for this).
Then you can open the root element of the tree (or some of the branches) as a property for changes in another class.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question