add a code line to a class programmatically

Hi

Is it possible to add a code line to an existing class file via coding when a user click on a button.

I.e.

Add: int i = 4;

in my class file, numbers.cs in the void Numbers() method.

void Numbers()
{
   int a= 1;
   int b = 2;
   
   //added here the next line of code programmatically
   int i = 4;

}

This is just an example class and not my actual class. Just need to know if the concept is possible and viable.

Thanks

sunettew1

Is it possible to add a code line to an existing class file via coding when a user click on a button.

Via reflection and code emit. What will be the purpose?

I have a framework that I want to add code to when new projects gets added to a solution by other developers and they setup their object hierachy in the front end.

Thanks

sunettew1

I have a framework that I want to add code to when new projects gets added to a solution

Do you mean a VS Package?

Leave a Reply