Document.Saved 屬性
如果物件自上次儲存或開啟之後就沒有被修改過,會傳回 true。
命名空間: EnvDTE
組件: EnvDTE (在 EnvDTE.dll 中)
語法
'宣告
Property Saved As Boolean
bool Saved { get; set; }
property bool Saved {
bool get ();
void set (bool value);
}
abstract Saved : bool with get, set
function get Saved () : boolean
function set Saved (value : boolean)
屬性值
類型:Boolean
布林值,如果物件自上次儲存或開啟之後就沒有被修改過,則表示為 true (預設),否則為 false。
備註
Saved 屬性取代 Visual Studio 6.0 版裡的 IsDirty 屬性,但傳回值與 IsDirty 相反。
範例
public void CodeExample(DTE2 dte, AddIn addin)
{
try
{ // Before running, create two text files named "TextFile1.txt"
// and "TextFile2.txt", include them in your solution,
// and then open them. Notice changes when code executes.
Document doc, doc2;
string msg = "";
string msg2 = "";
if (dte.Documents.Count > 0)
{
doc = dte.Documents.Item("TextFile1.txt");
// Find specified text.
if (doc.MarkText("text to find", 0))
{
msg += "(1) The text was found!\n"; //MessageBox.Show("The text was found");
// Delete the bookmark created by MarkText.
doc.ClearBookmarks();
}
if (doc.ReplaceText("text to find", "was replaced by this", 0))
msg += "(2) It [was replaced by this].\n";
if (doc.Undo())
msg += "(3) The ReplaceText method has been undone.\n";
if (doc.Redo())
msg += "(4) The ReplaceText method had been redone.\n";
// This will bring the other document to the foreground.
doc2 = doc.Collection.Item("TextFile2.txt");
doc2.Activate();
// Have these documents been saved?
foreach (Document dc in dte.Documents)
{
if (dc.Saved) msg += dc.Name + " has been saved.\n";
}
MessageBox.Show(msg, "Example Output");
// Access the application object.
msg2 += doc2.DTE.Name + " is the application object.\n";
// Show the Guid for the document.
msg2 += doc2.Kind + " is the Guid for this document.\n";
// Show the language used to author the code.
msg2 += doc2.Language + " is the language used in this document.\n";
// Show the document's name.
msg2 += doc2.Name + " is the name of this document.\n";
// Get the projectitem associated with this document.
msg2 += doc2.ProjectItem.Name + " is the ProjectItem associated with this document.\n";
// Show the document type.
msg2 += doc2.Type + " is the type of document.\n";
foreach (Window win in doc2.Windows)
{
msg2 += win.Caption + " is a window.\n";
}
MessageBox.Show(msg2, "Example Output");
}
else MessageBox.Show("Sample not setup properly.");
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
.NET Framework 安全性
- 完全信任立即呼叫者。這個成員無法供部分信任的程式碼使用。如需詳細資訊,請參閱從部分受信任程式碼使用程式庫。