当前位置: 首页>>代码示例>>C#>>正文


C# IDictionary.ReadOnlyCopy方法代码示例

本文整理汇总了C#中IDictionary.ReadOnlyCopy方法的典型用法代码示例。如果您正苦于以下问题:C# IDictionary.ReadOnlyCopy方法的具体用法?C# IDictionary.ReadOnlyCopy怎么用?C# IDictionary.ReadOnlyCopy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IDictionary的用法示例。


在下文中一共展示了IDictionary.ReadOnlyCopy方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ReadInstanceKeyMetadata

        public void ReadInstanceKeyMetadata(Guid key, IDictionary<XName, InstanceValue> metadata, bool complete)
        {
            if (key == Guid.Empty)
            {
                throw Fx.Exception.Argument("key", SRCore.InvalidKeyArgument);
            }
            ThrowIfNoInstance();
            ThrowIfNotActive("ReadInstanceKeyMetadata");

            InstanceKeyView keyView;
            if (!InstanceView.InstanceKeys.TryGetValue(key, out keyView))
            {
                if (InstanceView.InstanceKeysConsistency == InstanceValueConsistency.None)
                {
                    throw Fx.Exception.AsError(new InvalidOperationException(SRCore.KeyNotAssociated));
                }

                Dictionary<Guid, InstanceKeyView> copy = new Dictionary<Guid, InstanceKeyView>(InstanceView.InstanceKeys);
                keyView = new InstanceKeyView(key);
                if (complete)
                {
                    keyView.InstanceKeyMetadata = metadata.ReadOnlyCopy(false);
                    keyView.InstanceKeyMetadataConsistency = InstanceValueConsistency.None;
                }
                else
                {
                    keyView.InstanceKeyMetadata = metadata.ReadOnlyMergeInto(null, false);
                    keyView.InstanceKeyMetadataConsistency = InstanceValueConsistency.Partial;
                }
                if (!InstanceView.IsBoundToLock && InstanceView.InstanceState != InstanceState.Completed)
                {
                    keyView.InstanceKeyMetadataConsistency |= InstanceValueConsistency.InDoubt;
                }
                copy[keyView.InstanceKey] = keyView;
                InstanceView.InstanceKeys = new ReadOnlyDictionaryInternal<Guid, InstanceKeyView>(copy);
            }
            else
            {
                if (keyView.InstanceKeyMetadataConsistency == InstanceValueConsistency.None)
                {
                    return;
                }

                if (complete)
                {
                    keyView.InstanceKeyMetadata = metadata.ReadOnlyCopy(false);
                    keyView.InstanceKeyMetadataConsistency = InstanceView.IsBoundToLock || InstanceView.InstanceState == InstanceState.Completed ? InstanceValueConsistency.None : InstanceValueConsistency.InDoubt;
                }
                else
                {
                    if ((InstanceView.IsBoundToLock || InstanceView.InstanceState == InstanceState.Completed) && (keyView.InstanceKeyMetadataConsistency & InstanceValueConsistency.InDoubt) != 0)
                    {
                        // In this case, prefer throwing out old data and keeping only authoritative data.
                        keyView.InstanceKeyMetadata = metadata.ReadOnlyMergeInto(null, false);
                        keyView.InstanceKeyMetadataConsistency = InstanceValueConsistency.Partial;
                    }
                    else
                    {
                        keyView.InstanceKeyMetadata = metadata.ReadOnlyMergeInto(keyView.InstanceKeyMetadata, false);
                        keyView.InstanceKeyMetadataConsistency |= InstanceValueConsistency.Partial;
                    }
                }
            }
        }
开发者ID:uQr,项目名称:referencesource,代码行数:64,代码来源:InstancePersistenceContext.cs

示例2: ReadInstanceOwnerMetadata

        public void ReadInstanceOwnerMetadata(IDictionary<XName, InstanceValue> metadata, bool complete)
        {
            ThrowIfNoOwner();
            ThrowIfNotActive("ReadInstanceOwnerMetadata");

            if (InstanceView.InstanceOwnerMetadataConsistency == InstanceValueConsistency.None)
            {
                return;
            }

            if (complete)
            {
                InstanceView.InstanceOwnerMetadata = metadata.ReadOnlyCopy(false);
                InstanceView.InstanceOwnerMetadataConsistency = InstanceValueConsistency.InDoubt;
            }
            else
            {
                InstanceView.InstanceOwnerMetadata = metadata.ReadOnlyMergeInto(InstanceView.InstanceOwnerMetadata, false);
                InstanceView.InstanceOwnerMetadataConsistency |= InstanceValueConsistency.Partial;
            }
        }
开发者ID:uQr,项目名称:referencesource,代码行数:21,代码来源:InstancePersistenceContext.cs

示例3: LoadedInstance

        public void LoadedInstance(InstanceState state, IDictionary<XName, InstanceValue> instanceData, IDictionary<XName, InstanceValue> instanceMetadata, IDictionary<Guid, IDictionary<XName, InstanceValue>> associatedInstanceKeyMetadata, IDictionary<Guid, IDictionary<XName, InstanceValue>> completedInstanceKeyMetadata)
        {
            if (state == InstanceState.Uninitialized)
            {
                if (instanceData != null && instanceData.Count > 0)
                {
                    throw Fx.Exception.AsError(new InvalidOperationException(SRCore.UninitializedCannotHaveData));
                }
            }
            else if (state == InstanceState.Completed)
            {
                if (associatedInstanceKeyMetadata != null && associatedInstanceKeyMetadata.Count > 0)
                {
                    throw Fx.Exception.AsError(new InvalidOperationException(SRCore.CompletedMustNotHaveAssociatedKeys));
                }
            }
            else if (state != InstanceState.Initialized)
            {
                throw Fx.Exception.Argument("state", SRCore.InvalidInstanceState);
            }
            ThrowIfNoInstance();
            ThrowIfNotActive("PersistedInstance");

            InstanceValueConsistency consistency = InstanceView.IsBoundToLock || state == InstanceState.Completed ? InstanceValueConsistency.None : InstanceValueConsistency.InDoubt;

            ReadOnlyDictionaryInternal<XName, InstanceValue> instanceDataCopy = instanceData.ReadOnlyCopy(false);
            ReadOnlyDictionaryInternal<XName, InstanceValue> instanceMetadataCopy = instanceMetadata.ReadOnlyCopy(false);

            Dictionary<Guid, InstanceKeyView> keysCopy = null;
            int totalKeys = (associatedInstanceKeyMetadata != null ? associatedInstanceKeyMetadata.Count : 0) + (completedInstanceKeyMetadata != null ? completedInstanceKeyMetadata.Count : 0);
            if (totalKeys > 0)
            {
                keysCopy = new Dictionary<Guid, InstanceKeyView>(totalKeys);
            }
            if (associatedInstanceKeyMetadata != null && associatedInstanceKeyMetadata.Count > 0)
            {
                foreach (KeyValuePair<Guid, IDictionary<XName, InstanceValue>> keyMetadata in associatedInstanceKeyMetadata)
                {
                    InstanceKeyView view = new InstanceKeyView(keyMetadata.Key);
                    view.InstanceKeyState = InstanceKeyState.Associated;
                    view.InstanceKeyMetadata = keyMetadata.Value.ReadOnlyCopy(false);
                    view.InstanceKeyMetadataConsistency = InstanceView.IsBoundToLock ? InstanceValueConsistency.None : InstanceValueConsistency.InDoubt;
                    keysCopy.Add(view.InstanceKey, view);
                }
            }

            if (completedInstanceKeyMetadata != null && completedInstanceKeyMetadata.Count > 0)
            {
                foreach (KeyValuePair<Guid, IDictionary<XName, InstanceValue>> keyMetadata in completedInstanceKeyMetadata)
                {
                    InstanceKeyView view = new InstanceKeyView(keyMetadata.Key);
                    view.InstanceKeyState = InstanceKeyState.Completed;
                    view.InstanceKeyMetadata = keyMetadata.Value.ReadOnlyCopy(false);
                    view.InstanceKeyMetadataConsistency = consistency;
                    keysCopy.Add(view.InstanceKey, view);
                }
            }

            InstanceView.InstanceState = state;

            InstanceView.InstanceData = instanceDataCopy;
            InstanceView.InstanceDataConsistency = consistency;

            InstanceView.InstanceMetadata = instanceMetadataCopy;
            InstanceView.InstanceMetadataConsistency = consistency;

            InstanceView.InstanceKeys = keysCopy == null ? null : new ReadOnlyDictionaryInternal<Guid, InstanceKeyView>(keysCopy);
            InstanceView.InstanceKeysConsistency = consistency;
        }
开发者ID:uQr,项目名称:referencesource,代码行数:69,代码来源:InstancePersistenceContext.cs

示例4: ReadInstanceMetadata

        public void ReadInstanceMetadata(IDictionary<XName, InstanceValue> metadata, bool complete)
        {
            ThrowIfNoInstance();
            ThrowIfNotActive("ReadInstanceMetadata");

            if (InstanceView.InstanceMetadataConsistency == InstanceValueConsistency.None)
            {
                return;
            }

            if (complete)
            {
                InstanceView.InstanceMetadata = metadata.ReadOnlyCopy(false);
                InstanceView.InstanceMetadataConsistency = InstanceView.IsBoundToLock || InstanceView.InstanceState == InstanceState.Completed ? InstanceValueConsistency.None : InstanceValueConsistency.InDoubt;
            }
            else
            {
                if ((InstanceView.IsBoundToLock || InstanceView.InstanceState == InstanceState.Completed) && (InstanceView.InstanceMetadataConsistency & InstanceValueConsistency.InDoubt) != 0)
                {
                    // In this case, prefer throwing out old data and keeping only authoritative data.
                    InstanceView.InstanceMetadata = metadata.ReadOnlyMergeInto(null, false);
                    InstanceView.InstanceMetadataConsistency = InstanceValueConsistency.Partial;
                }
                else
                {
                    InstanceView.InstanceMetadata = metadata.ReadOnlyMergeInto(InstanceView.InstanceMetadata, false);
                    InstanceView.InstanceMetadataConsistency |= InstanceValueConsistency.Partial;
                }
            }
        }
开发者ID:uQr,项目名称:referencesource,代码行数:30,代码来源:InstancePersistenceContext.cs

示例5: PersistedInstance

        public void PersistedInstance(IDictionary<XName, InstanceValue> data)
        {
            ThrowIfNotLocked();
            ThrowIfCompleted();
            ThrowIfNotTransactional("PersistedInstance");

            InstanceView.InstanceData = data.ReadOnlyCopy(true);
            InstanceView.InstanceDataConsistency = InstanceValueConsistency.None;
            InstanceView.InstanceState = InstanceState.Initialized;
        }
开发者ID:uQr,项目名称:referencesource,代码行数:10,代码来源:InstancePersistenceContext.cs

示例6: ReadInstanceOwnerMetadata

 public void ReadInstanceOwnerMetadata(IDictionary<XName, InstanceValue> metadata, bool complete)
 {
     this.ThrowIfNoOwner();
     this.ThrowIfNotActive("ReadInstanceOwnerMetadata");
     if (this.InstanceView.InstanceOwnerMetadataConsistency != InstanceValueConsistency.None)
     {
         if (complete)
         {
             this.InstanceView.InstanceOwnerMetadata = metadata.ReadOnlyCopy(false);
             this.InstanceView.InstanceOwnerMetadataConsistency = InstanceValueConsistency.InDoubt;
         }
         else
         {
             this.InstanceView.InstanceOwnerMetadata = metadata.ReadOnlyMergeInto(this.InstanceView.InstanceOwnerMetadata, false);
             System.Runtime.DurableInstancing.InstanceView instanceView = this.InstanceView;
             instanceView.InstanceOwnerMetadataConsistency |= InstanceValueConsistency.Partial;
         }
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:19,代码来源:InstancePersistenceContext.cs

示例7: ReadInstanceMetadata

 public void ReadInstanceMetadata(IDictionary<XName, InstanceValue> metadata, bool complete)
 {
     this.ThrowIfNoInstance();
     this.ThrowIfNotActive("ReadInstanceMetadata");
     if (this.InstanceView.InstanceMetadataConsistency != InstanceValueConsistency.None)
     {
         if (complete)
         {
             this.InstanceView.InstanceMetadata = metadata.ReadOnlyCopy(false);
             this.InstanceView.InstanceMetadataConsistency = (this.InstanceView.IsBoundToLock || (this.InstanceView.InstanceState == InstanceState.Completed)) ? InstanceValueConsistency.None : InstanceValueConsistency.InDoubt;
         }
         else if ((this.InstanceView.IsBoundToLock || (this.InstanceView.InstanceState == InstanceState.Completed)) && ((this.InstanceView.InstanceMetadataConsistency & InstanceValueConsistency.InDoubt) != InstanceValueConsistency.None))
         {
             this.InstanceView.InstanceMetadata = metadata.ReadOnlyMergeInto(null, false);
             this.InstanceView.InstanceMetadataConsistency = InstanceValueConsistency.Partial;
         }
         else
         {
             this.InstanceView.InstanceMetadata = metadata.ReadOnlyMergeInto(this.InstanceView.InstanceMetadata, false);
             System.Runtime.DurableInstancing.InstanceView instanceView = this.InstanceView;
             instanceView.InstanceMetadataConsistency |= InstanceValueConsistency.Partial;
         }
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:24,代码来源:InstancePersistenceContext.cs

示例8: ReadInstanceKeyMetadata

 public void ReadInstanceKeyMetadata(Guid key, IDictionary<XName, InstanceValue> metadata, bool complete)
 {
     InstanceKeyView view;
     if (key == Guid.Empty)
     {
         throw Fx.Exception.Argument("key", SRCore.InvalidKeyArgument);
     }
     this.ThrowIfNoInstance();
     this.ThrowIfNotActive("ReadInstanceKeyMetadata");
     if (!this.InstanceView.InstanceKeys.TryGetValue(key, out view))
     {
         if (this.InstanceView.InstanceKeysConsistency == InstanceValueConsistency.None)
         {
             throw Fx.Exception.AsError(new InvalidOperationException(SRCore.KeyNotAssociated));
         }
         Dictionary<Guid, InstanceKeyView> dictionary = new Dictionary<Guid, InstanceKeyView>(this.InstanceView.InstanceKeys);
         view = new InstanceKeyView(key);
         if (complete)
         {
             view.InstanceKeyMetadata = metadata.ReadOnlyCopy(false);
             view.InstanceKeyMetadataConsistency = InstanceValueConsistency.None;
         }
         else
         {
             view.InstanceKeyMetadata = metadata.ReadOnlyMergeInto(null, false);
             view.InstanceKeyMetadataConsistency = InstanceValueConsistency.Partial;
         }
         if (!this.InstanceView.IsBoundToLock && (this.InstanceView.InstanceState != InstanceState.Completed))
         {
             view.InstanceKeyMetadataConsistency |= InstanceValueConsistency.InDoubt;
         }
         dictionary[view.InstanceKey] = view;
         this.InstanceView.InstanceKeys = new ReadOnlyDictionary<Guid, InstanceKeyView>(dictionary, false);
     }
     else if (view.InstanceKeyMetadataConsistency != InstanceValueConsistency.None)
     {
         if (complete)
         {
             view.InstanceKeyMetadata = metadata.ReadOnlyCopy(false);
             view.InstanceKeyMetadataConsistency = (this.InstanceView.IsBoundToLock || (this.InstanceView.InstanceState == InstanceState.Completed)) ? InstanceValueConsistency.None : InstanceValueConsistency.InDoubt;
         }
         else if ((this.InstanceView.IsBoundToLock || (this.InstanceView.InstanceState == InstanceState.Completed)) && ((view.InstanceKeyMetadataConsistency & InstanceValueConsistency.InDoubt) != InstanceValueConsistency.None))
         {
             view.InstanceKeyMetadata = metadata.ReadOnlyMergeInto(null, false);
             view.InstanceKeyMetadataConsistency = InstanceValueConsistency.Partial;
         }
         else
         {
             view.InstanceKeyMetadata = metadata.ReadOnlyMergeInto(view.InstanceKeyMetadata, false);
             view.InstanceKeyMetadataConsistency |= InstanceValueConsistency.Partial;
         }
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:53,代码来源:InstancePersistenceContext.cs

示例9: LoadedInstance

 public void LoadedInstance(InstanceState state, IDictionary<XName, InstanceValue> instanceData, IDictionary<XName, InstanceValue> instanceMetadata, IDictionary<Guid, IDictionary<XName, InstanceValue>> associatedInstanceKeyMetadata, IDictionary<Guid, IDictionary<XName, InstanceValue>> completedInstanceKeyMetadata)
 {
     if (state == InstanceState.Uninitialized)
     {
         if ((instanceData != null) && (instanceData.Count > 0))
         {
             throw Fx.Exception.AsError(new InvalidOperationException(SRCore.UninitializedCannotHaveData));
         }
     }
     else if (state == InstanceState.Completed)
     {
         if ((associatedInstanceKeyMetadata != null) && (associatedInstanceKeyMetadata.Count > 0))
         {
             throw Fx.Exception.AsError(new InvalidOperationException(SRCore.CompletedMustNotHaveAssociatedKeys));
         }
     }
     else if (state != InstanceState.Initialized)
     {
         throw Fx.Exception.Argument("state", SRCore.InvalidInstanceState);
     }
     this.ThrowIfNoInstance();
     this.ThrowIfNotActive("PersistedInstance");
     InstanceValueConsistency consistency = (this.InstanceView.IsBoundToLock || (state == InstanceState.Completed)) ? InstanceValueConsistency.None : InstanceValueConsistency.InDoubt;
     ReadOnlyDictionary<XName, InstanceValue> dictionary = instanceData.ReadOnlyCopy(false);
     ReadOnlyDictionary<XName, InstanceValue> dictionary2 = instanceMetadata.ReadOnlyCopy(false);
     Dictionary<Guid, InstanceKeyView> dictionary3 = null;
     int capacity = ((associatedInstanceKeyMetadata != null) ? associatedInstanceKeyMetadata.Count : 0) + ((completedInstanceKeyMetadata != null) ? completedInstanceKeyMetadata.Count : 0);
     if (capacity > 0)
     {
         dictionary3 = new Dictionary<Guid, InstanceKeyView>(capacity);
     }
     if ((associatedInstanceKeyMetadata != null) && (associatedInstanceKeyMetadata.Count > 0))
     {
         foreach (KeyValuePair<Guid, IDictionary<XName, InstanceValue>> pair in associatedInstanceKeyMetadata)
         {
             InstanceKeyView view = new InstanceKeyView(pair.Key) {
                 InstanceKeyState = InstanceKeyState.Associated,
                 InstanceKeyMetadata = pair.Value.ReadOnlyCopy(false),
                 InstanceKeyMetadataConsistency = this.InstanceView.IsBoundToLock ? InstanceValueConsistency.None : InstanceValueConsistency.InDoubt
             };
             dictionary3.Add(view.InstanceKey, view);
         }
     }
     if ((completedInstanceKeyMetadata != null) && (completedInstanceKeyMetadata.Count > 0))
     {
         foreach (KeyValuePair<Guid, IDictionary<XName, InstanceValue>> pair2 in completedInstanceKeyMetadata)
         {
             InstanceKeyView view2 = new InstanceKeyView(pair2.Key) {
                 InstanceKeyState = InstanceKeyState.Completed,
                 InstanceKeyMetadata = pair2.Value.ReadOnlyCopy(false),
                 InstanceKeyMetadataConsistency = consistency
             };
             dictionary3.Add(view2.InstanceKey, view2);
         }
     }
     this.InstanceView.InstanceState = state;
     this.InstanceView.InstanceData = dictionary;
     this.InstanceView.InstanceDataConsistency = consistency;
     this.InstanceView.InstanceMetadata = dictionary2;
     this.InstanceView.InstanceMetadataConsistency = consistency;
     this.InstanceView.InstanceKeys = (dictionary3 == null) ? null : new ReadOnlyDictionary<Guid, InstanceKeyView>(dictionary3, false);
     this.InstanceView.InstanceKeysConsistency = consistency;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:63,代码来源:InstancePersistenceContext.cs


注:本文中的IDictionary.ReadOnlyCopy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。