语言

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 具有 Optional 和 WriteOnly 设置标志的对象。 有关详细信息,请参阅 InstanceValueOptions。

Important

一个持久性集中所有持久性参与者实现 CollectValues 提供的每个值都必须具有唯一的 XName。

适用于