PersistenceParticipant.CollectValues 方法

定義

主機會在自訂的持續性參與者上叫用這個方法,以收集要保存的讀寫值和唯寫值。

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

重要

在同一個持續性時段中,透過跨所有持續性參與者實作 CollectValues 而提供的每個值都必須擁有唯一的 XName。

適用於