Modifying sourcecode with an addin.
This is the code I am trying to use:
CodeElements elementList = project.ProjectItems.Item("Event_Handling").ProjectItems.Item("Event_Loop.cs").FileCodeModel.CodeElements;
//the last element is most likely the namespace so get that.
CodeElement lastElement = elementList.Item(elementList.Count-1);
CodeElements methods = lastElement.Children.Item(0).Children;
TextSelection ts = (TextSelection)project.ProjectItems.Item("Event_Handling").ProjectItems.Item("Event_Loop.cs").Document.Selection;
ts.TopPoint = methods.Item("two").GetStartPoint(vsCMPart.vsCMPartBody);
ts.BottomPoint = methods.Item("two").GetEndPoint(vsCMPart.vsCMPartBody);
ts.Text = "hello world 1";
This is the code that it is trying to operate on:
using System;
using System.Collections.Generic;
using System.Text;
namespace CaptureEventsSpike.Event_Handling
{
class Event_Loop
{
public void one()
{
}
public void two()
{
}
public void three()
{
}
}
}
Thanks for any help in advance. I am open to anyway of doing this. I am only using the technique above as its the only way that I can vaguely see of doing it. Using the code object model is good if I can. That is why i dont want to use the replace text function. Also the replace text function would not work for inserting code over an empty string.

