編輯

共用方式為


PersistenceParticipant.CollectValues Method

Definition

A host invokes this method on a custom persistence participant to collect read-write values and write-only values, to be persisted.

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))

Parameters

readWriteValues
IDictionary<XName,Object>

The read-write values to be persisted.

writeOnlyValues
IDictionary<XName,Object>

The write-only values to be persisted.

Examples

The following code sample demonstrates using CollectValues in a class that derives from PersistenceParticipant. This example is from the Persistence Participants sample.

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;
        }
    }
}

Remarks

The host packages read-write values in the first dictionary as InstanceValue objects of an InstanceData collection, and packages write-only values in the second dictionary as InstanceValue objects with Optional and WriteOnly flags set. For more information, see InstanceValueOptions.

Important

Each value provided by implementations of CollectValues across all persistence participants within one persistence episode must have a unique XName.

Applies to