本文整理汇总了C#中IVsTextLines.ReplaceLines方法的典型用法代码示例。如果您正苦于以下问题:C# IVsTextLines.ReplaceLines方法的具体用法?C# IVsTextLines.ReplaceLines怎么用?C# IVsTextLines.ReplaceLines使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IVsTextLines
的用法示例。
在下文中一共展示了IVsTextLines.ReplaceLines方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateServiceDefinition
private static void UpdateServiceDefinition(IVsTextLines lines, string roleType, string projectName) {
if (lines == null) {
throw new ArgumentException("lines");
}
int lastLine, lastIndex;
string text;
ErrorHandler.ThrowOnFailure(lines.GetLastLineIndex(out lastLine, out lastIndex));
ErrorHandler.ThrowOnFailure(lines.GetLineText(0, 0, lastLine, lastIndex, out text));
var doc = new XmlDocument();
doc.LoadXml(text);
UpdateServiceDefinition(doc, roleType, projectName);
var encoding = Encoding.UTF8;
var userData = lines as IVsUserData;
if (userData != null) {
var guid = VSConstants.VsTextBufferUserDataGuid.VsBufferEncodingVSTFF_guid;
object data;
int cp;
if (ErrorHandler.Succeeded(userData.GetData(ref guid, out data)) &&
(cp = (data as int? ?? (int)(data as uint? ?? 0)) & (int)__VSTFF.VSTFF_CPMASK) != 0) {
try {
encoding = Encoding.GetEncoding(cp);
} catch (NotSupportedException) {
} catch (ArgumentException) {
}
}
}
var sw = new StringWriterWithEncoding(encoding);
doc.Save(XmlWriter.Create(
sw,
new XmlWriterSettings {
Indent = true,
IndentChars = " ",
NewLineHandling = NewLineHandling.Entitize,
Encoding = encoding
}
));
var sb = sw.GetStringBuilder();
var len = sb.Length;
var pStr = Marshal.StringToCoTaskMemUni(sb.ToString());
try {
ErrorHandler.ThrowOnFailure(lines.ReplaceLines(0, 0, lastLine, lastIndex, pStr, len, new TextSpan[1]));
} finally {
Marshal.FreeCoTaskMem(pStr);
}
}
示例2: CopyFileToBuffer
private static void CopyFileToBuffer(string sourceFilename, IVsTextLines buffer)
{
ArgumentValidation.CheckForEmptyString(sourceFilename, "sourceFileName");
ArgumentValidation.CheckForNullReference(buffer, "buffer");
var spanDst = GetBufferSpan(buffer);
var pContent = IntPtr.Zero;
try
{
var content = RdtManager.Instance.ReadFromFile(sourceFilename);
pContent = Marshal.StringToHGlobalAuto(content);
buffer.ReplaceLines(
spanDst.iStartLine, spanDst.iStartIndex,
spanDst.iEndLine, spanDst.iEndIndex, pContent, content.Length, new[] { new TextSpan() });
}
finally
{
if (pContent != IntPtr.Zero)
{
Marshal.FreeHGlobal(pContent);
}
}
}