0

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

Phill Duffy
  • 2,805
  • 3
  • 33
  • 45

2 Answers2

1

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
  • 23,310
  • 6
  • 60
  • 75
  • Fantastic, thank you. I should ask another question but... Do you know the best way to add using statements with EnvDte? – Phill Duffy Oct 12 '09 at 11:40
  • You can add it as text : var editPoint = applicationObject.ActiveDocument.GetTextDocument().CreateEditPoint(TextDocument.StartPoint); editPoint.Insert("using System;"); – Elisha Oct 18 '09 at 11:11
0

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

BlueMonkMN
  • 25,079
  • 9
  • 80
  • 146