views:

120

answers:

2

I am creating a C# class as per:

http://msdn.microsoft.com/en-us/library/x6h10s6x.aspx

however I want my own 'return' rather than the return default(int); it automatically generates. I know I can insert my own text using an EditPoint i.e

 editPoint.Insert("return records.AsEnumerable<" + tableNameAsSingular + ">();");

but it still tries to stick in its own 'return' too

A: 

In CodeDOM, there is something like CodeMethodReturnStatement. There may be something similar in VS code generation extensibility.

BlueMonkMN
+1  A: 

A workaround can be to delete of the default content of the method:

TextPoint startPoint = method.GetStartPoint(vsCMPart.vsCMPartBody);
TextPoint endPoint = method.GetEndPoint(vsCMPart.vsCMPartBody);

var editPoint = startPoint.CreateEditPoint();
editPoint.Delete(endPoint);

This code should erase the default content of the method.

Elisha
Fantastic, thank you. I should ask another question but... Do you know the best way to add using statements with EnvDte?
Phill Duffy
You can add it as text :var editPoint = applicationObject.ActiveDocument.GetTextDocument().CreateEditPoint(TextDocument.StartPoint);editPoint.Insert("using System;");
Elisha