static string get_text_range(this IScintillaGateway document, int startPos, int endPos, int bufCapacity) { bool newNppVersion = IsNewNppApiVersion; if (Environment.GetEnvironmentVariable("CSSCRIPT_NPP_NEW_NPP_API") != null) { newNppVersion = Environment.GetEnvironmentVariable("CSSCRIPT_NPP_NEW_NPP_API").ToLower() == "true"; } if (newNppVersion) { using (var tr = new TextRange((IntPtr)startPos, (IntPtr)endPos, bufCapacity)) { document.GetTextRange(tr); return(tr.lpstrText); } } else { using (var tr = new TextRangeLegacy(startPos, endPos, bufCapacity)) { document.GetTextRangeLegacy(tr); return(tr.lpstrText); } } }