PersistenceParticipant.CollectValues 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
主機會在自訂持久化參與者上呼叫此方法,收集讀寫值與唯寫值,並進行持久化。
protected:
virtual void CollectValues([Runtime::InteropServices::Out] System::Collections::Generic::IDictionary<System::Xml::Linq::XName ^, System::Object ^> ^ % readWriteValues, [Runtime::InteropServices::Out] System::Collections::Generic::IDictionary<System::Xml::Linq::XName ^, System::Object ^> ^ % writeOnlyValues);
protected virtual void CollectValues(out System.Collections.Generic.IDictionary<System.Xml.Linq.XName,object> readWriteValues, out System.Collections.Generic.IDictionary<System.Xml.Linq.XName,object> writeOnlyValues);
abstract member CollectValues : IDictionary * IDictionary -> unit
override this.CollectValues : IDictionary * IDictionary -> unit
Protected Overridable Sub CollectValues (ByRef readWriteValues As IDictionary(Of XName, Object), ByRef writeOnlyValues As IDictionary(Of XName, Object))
參數
- readWriteValues
- IDictionary<XName,Object>
要持久化的讀寫值。
- writeOnlyValues
- IDictionary<XName,Object>
這些只寫值要持續保存。
範例
以下程式碼範例示範如何在由 衍生 PersistenceParticipant的類別中使用 CollectValues。 此範例來自 持久性參與者 樣本。
public class StepCountExtension : PersistenceParticipant
{
static XNamespace stepCountNamespace = XNamespace.Get("urn:schemas-microsoft-com:Microsoft.Samples.WF/WorkflowInstances/properties");
static XName currentCountName = stepCountNamespace.GetName("CurrentCount");
int currentCount;
public int CurrentCount
{
get
{
return this.currentCount;
}
}
internal void IncrementStepCount()
{
this.currentCount += 1;
}
protected override void CollectValues(out IDictionary<XName, object> readWriteValues, out IDictionary<XName, object> writeOnlyValues)
{
readWriteValues = new Dictionary<XName, object>(1) { { currentCountName, this.currentCount } };
writeOnlyValues = null;
}
protected override void PublishValues(IDictionary<XName, object> readWriteValues)
{
object loadedData;
if (readWriteValues.TryGetValue(currentCountName, out loadedData))
{
this.currentCount = (int)loadedData;
}
}
}
備註
主機將第一個字典中的讀寫值打包為InstanceValue集合的InstanceData物件,而第二個字典中則將唯寫值打包為InstanceValue物件,且OptionalWriteOnly標記為 。 如需詳細資訊,請參閱InstanceValueOptions。
Important
在同一持續化事件中,所有持續參與者的實作 CollectValues 所提供的每個值都必須有唯一的 XName。