创建打开并将文件的内容加载到新 ITextBuffer的 ITextDocument 。
命名空间: Microsoft.VisualStudio.Text
程序集: Microsoft.VisualStudio.Text.Data(在 Microsoft.VisualStudio.Text.Data.dll 中)
语法
声明
Function CreateAndLoadTextDocument ( _
filePath As String, _
contentType As IContentType, _
attemptUtf8Detection As Boolean, _
<OutAttribute> ByRef characterSubstitutionsOccurred As Boolean _
) As ITextDocument
ITextDocument CreateAndLoadTextDocument(
string filePath,
IContentType contentType,
bool attemptUtf8Detection,
out bool characterSubstitutionsOccurred
)
ITextDocument^ CreateAndLoadTextDocument(
String^ filePath,
IContentType^ contentType,
bool attemptUtf8Detection,
[OutAttribute] bool% characterSubstitutionsOccurred
)
abstract CreateAndLoadTextDocument :
filePath:string *
contentType:IContentType *
attemptUtf8Detection:bool *
characterSubstitutionsOccurred:bool byref -> ITextDocument
function CreateAndLoadTextDocument(
filePath : String,
contentType : IContentType,
attemptUtf8Detection : boolean,
characterSubstitutionsOccurred : boolean
) : ITextDocument
参数
filePath
类型:String要加载的文件的完整路径。
contentType
类型:Microsoft.VisualStudio.Utilities.IContentType
attemptUtf8Detection
类型:Boolean是否尝试将文档加载为 UTF-8 文件。
characterSubstitutionsOccurred
类型:Boolean%[out] 如果无法使用给定编码直接转换某些文件字节,则设置为 true。
返回值
类型:Microsoft.VisualStudio.Text.ITextDocument
ITextDocument 。
异常
异常 | 条件 |
---|---|
ArgumentNullException | filePath 或 contentType 为 nullnull 引用(在 Visual Basic 中为 Nothing)。 |
备注
此方法的 Visual Studio 实现检测文件编码如下所示:
如果有字节顺序标记,请使用相应的编码。
否则,请通过与 contentType 参数的 IEncodingDetector 对象来循环,直到一个方返回一个非 null Encoding 值和使用编码。
如果未检测编码,因此, attemptUtf8Detection 设置了标志,因此,可以向流解码为 UTF8,但不是 ASCII,则使用 UTF8。
否则,请使用系统默认编码。
.NET Framework 安全性
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关详细信息,请参阅通过部分受信任的代码使用库。