< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Channels.MessageProperties
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Channels/MessageProperties.cs
Line coverage
50%
Covered lines: 182
Uncovered lines: 182
Coverable lines: 364
Total lines: 1013
Line coverage: 50%
Branch coverage
42%
Covered branches: 118
Total branches: 276
Branch coverage: 42.7%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Channels/MessageProperties.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System;
 5using System.Collections;
 6using System.Collections.Generic;
 7using CoreWCF.Runtime;
 8using CoreWCF.Security;
 9
 10namespace CoreWCF.Channels
 11{
 12    public sealed class MessageProperties : IDictionary<string, object>, IDisposable
 13    {
 14        private Property[] _properties;
 15        private int _propertyCount;
 16        private MessageEncoder _encoder;
 17        private Uri _via;
 18        private object _allowOutputBatching;
 19        private SecurityMessageProperty _security;
 20        private bool _disposed;
 21        private const int InitialPropertyCount = 2;
 22        private const int MaxRecycledArrayLength = 8;
 23        private const string ViaKey = "Via";
 24        private const string AllowOutputBatchingKey = "AllowOutputBatching";
 25        private const string SecurityKey = "Security";
 26        private const string EncoderKey = "Encoder";
 27        private const int NotFoundIndex = -1;
 28        private const int ViaIndex = -2;
 29        private const int AllowOutputBatchingIndex = -3;
 30        private const int SecurityIndex = -4;
 31        private const int EncoderIndex = -5;
 532        private static readonly object s_trueBool = true;
 533        private static readonly object s_falseBool = false;
 34
 591035        public MessageProperties()
 36        {
 591037        }
 38
 639        public MessageProperties(MessageProperties properties)
 40        {
 641            CopyProperties(properties);
 642        }
 43
 26844        internal MessageProperties(KeyValuePair<string, object>[] array)
 45        {
 26846            if (array == null)
 47            {
 048                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(array));
 49            }
 50
 26851            CopyProperties(array);
 26852        }
 53
 54        private void ThrowDisposed()
 55        {
 056            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ObjectDisposedException(string.Empty, SR.Forma
 57        }
 58
 59        public object this[string name]
 60        {
 61            get
 62            {
 14663                if (_disposed)
 64                {
 065                    ThrowDisposed();
 66                }
 67
 68
 14669                if (!TryGetValue(name, out object value))
 70                {
 071                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.Format(SR.Message
 72                }
 73
 14674                return value;
 75            }
 76            set
 77            {
 191778                if (_disposed)
 79                {
 080                    ThrowDisposed();
 81                }
 82
 191783                UpdateProperty(name, value, false);
 191784            }
 85        }
 86
 87        internal bool CanRecycle
 88        {
 89            get
 90            {
 62191                return _properties == null || _properties.Length <= MaxRecycledArrayLength;
 92            }
 93        }
 94
 95        public int Count
 96        {
 97            get
 98            {
 62599                if (_disposed)
 100                {
 0101                    ThrowDisposed();
 102                }
 103
 625104                return _propertyCount;
 105            }
 106        }
 107
 108        public MessageEncoder Encoder
 109        {
 110            get
 111            {
 41112                if (_disposed)
 113                {
 0114                    ThrowDisposed();
 115                }
 116
 41117                return _encoder;
 118            }
 119            set
 120            {
 5361121                if (_disposed)
 122                {
 0123                    ThrowDisposed();
 124                }
 125
 5361126                AdjustPropertyCount((object)_encoder == null, (object)value == null);
 5361127                _encoder = value;
 5361128            }
 129        }
 130
 131        public bool AllowOutputBatching
 132        {
 133            get
 134            {
 117135                if (_disposed)
 136                {
 0137                    ThrowDisposed();
 138                }
 139
 117140                return (object)_allowOutputBatching == s_trueBool;
 141            }
 142            set
 143            {
 703144                if (_disposed)
 145                {
 0146                    ThrowDisposed();
 147                }
 148
 703149                AdjustPropertyCount((object)_allowOutputBatching == null, false);
 150
 703151                if (value)
 152                {
 0153                    _allowOutputBatching = s_trueBool;
 154                }
 155                else
 156                {
 703157                    _allowOutputBatching = s_falseBool;
 158                }
 703159            }
 160        }
 161
 162        public bool IsFixedSize
 163        {
 164            get
 165            {
 0166                if (_disposed)
 167                {
 0168                    ThrowDisposed();
 169                }
 170
 0171                return false;
 172            }
 173        }
 174
 175        public bool IsReadOnly
 176        {
 177            get
 178            {
 0179                if (_disposed)
 180                {
 0181                    ThrowDisposed();
 182                }
 183
 0184                return false;
 185            }
 186        }
 187
 188        public ICollection<string> Keys
 189        {
 190            get
 191            {
 0192                if (_disposed)
 193                {
 0194                    ThrowDisposed();
 195                }
 196
 0197                List<string> keys = new List<string>();
 198
 0199                if ((object)_via != null)
 200                {
 0201                    keys.Add(ViaKey);
 202                }
 203
 0204                if ((object)_allowOutputBatching != null)
 205                {
 0206                    keys.Add(AllowOutputBatchingKey);
 207                }
 208
 0209                if ((object)_security != null)
 210                {
 0211                    keys.Add(SecurityKey);
 212                }
 213
 0214                if ((object)_encoder != null)
 215                {
 0216                    keys.Add(EncoderKey);
 217                }
 218
 0219                if (_properties != null)
 220                {
 0221                    for (int i = 0; i < _properties.Length; i++)
 222                    {
 0223                        string propertyName = _properties[i].Name;
 224
 0225                        if (propertyName == null)
 226                        {
 227                            break;
 228                        }
 229
 0230                        keys.Add(propertyName);
 231                    }
 232                }
 233
 0234                return keys;
 235            }
 236        }
 237
 238        public SecurityMessageProperty Security
 239        {
 240            get
 241            {
 2884242                if (_disposed)
 243                {
 0244                    ThrowDisposed();
 245                }
 246
 2884247                return _security;
 248            }
 249            set
 250            {
 821251                if (_disposed)
 252                {
 0253                    ThrowDisposed();
 254                }
 255
 821256                AdjustPropertyCount((object)_security == null, (object)value == null);
 821257                _security = value;
 821258            }
 259        }
 260
 261        public ICollection<object> Values
 262        {
 263            get
 264            {
 0265                if (_disposed)
 266                {
 0267                    ThrowDisposed();
 268                }
 269
 0270                List<object> values = new List<object>();
 271
 0272                if ((object)_via != null)
 273                {
 0274                    values.Add(_via);
 275                }
 276
 0277                if ((object)_allowOutputBatching != null)
 278                {
 0279                    values.Add(_allowOutputBatching);
 280                }
 281
 0282                if ((object)_security != null)
 283                {
 0284                    values.Add(_security);
 285                }
 286
 0287                if ((object)_encoder != null)
 288                {
 0289                    values.Add(_encoder);
 290                }
 0291                if (_properties != null)
 292                {
 0293                    for (int i = 0; i < _properties.Length; i++)
 294                    {
 0295                        if (_properties[i].Name == null)
 296                        {
 297                            break;
 298                        }
 299
 0300                        values.Add(_properties[i].Value);
 301                    }
 302                }
 303
 0304                return values;
 305            }
 306        }
 307
 308        public Uri Via
 309        {
 310            get
 311            {
 567312                if (_disposed)
 313                {
 0314                    ThrowDisposed();
 315                }
 316
 567317                return _via;
 318            }
 319            set
 320            {
 855321                if (_disposed)
 322                {
 0323                    ThrowDisposed();
 324                }
 325
 855326                AdjustPropertyCount((object)_via == null, (object)value == null);
 855327                _via = value;
 855328            }
 329        }
 330
 331        public void Add(string name, object property)
 332        {
 3087333            if (_disposed)
 334            {
 0335                ThrowDisposed();
 336            }
 337
 3087338            if (property == null)
 339            {
 0340                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(property));
 341            }
 342
 3087343            UpdateProperty(name, property, true);
 3087344        }
 345
 346        private void AdjustPropertyCount(bool oldValueIsNull, bool newValueIsNull)
 347        {
 7740348            if (newValueIsNull)
 349            {
 773350                if (!oldValueIsNull)
 351                {
 0352                    _propertyCount--;
 353                }
 354            }
 355            else
 356            {
 6967357                if (oldValueIsNull)
 358                {
 6819359                    _propertyCount++;
 360                }
 361            }
 7740362        }
 363
 364        public void Clear()
 365        {
 621366            if (_disposed)
 367            {
 0368                ThrowDisposed();
 369            }
 370
 621371            if (_properties != null)
 372            {
 4642373                for (int i = 0; i < _properties.Length; i++)
 374                {
 2292375                    if (_properties[i].Name == null)
 376                    {
 377                        break;
 378                    }
 379
 1704380                    _properties[i] = new Property();
 381                }
 382            }
 383
 621384            _via = null;
 621385            _allowOutputBatching = null;
 621386            _security = null;
 621387            _encoder = null;
 621388            _propertyCount = 0;
 621389        }
 390
 391        public void CopyProperties(MessageProperties properties)
 392        {
 393            // CopyProperties behavior should be equivalent to the behavior
 394            // of MergeProperties except that Merge supports property values that
 395            // implement the IMergeEnabledMessageProperty.  Any changes to CopyProperties
 396            // should be reflected in MergeProperties as well.
 6397            if (properties == null)
 398            {
 0399                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(properties));
 400            }
 401
 6402            if (_disposed)
 403            {
 0404                ThrowDisposed();
 405            }
 406
 6407            if (properties._properties != null)
 408            {
 0409                for (int i = 0; i < properties._properties.Length; i++)
 410                {
 0411                    if (properties._properties[i].Name == null)
 412                    {
 413                        break;
 414                    }
 415
 0416                    Property property = properties._properties[i];
 417
 418                    // this[string] will call CreateCopyOfPropertyValue, so we don't need to repeat that here
 0419                    this[property.Name] = property.Value;
 420                }
 421            }
 422
 6423            Via = properties.Via;
 6424            AllowOutputBatching = properties.AllowOutputBatching;
 6425            Security = (properties.Security != null) ? (SecurityMessageProperty)properties.Security.CreateCopy() : null;
 6426            Encoder = properties.Encoder;
 6427        }
 428
 429        internal void MergeProperties(MessageProperties properties)
 430        {
 431            // MergeProperties behavior should be equivalent to the behavior
 432            // of CopyProperties except that Merge supports property values that
 433            // implement the IMergeEnabledMessageProperty.  Any changes to CopyProperties
 434            // should be reflected in MergeProperties as well.
 35435            if (properties == null)
 436            {
 0437                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(properties));
 438            }
 439
 35440            if (_disposed)
 441            {
 0442                ThrowDisposed();
 443            }
 444
 35445            if (properties._properties != null)
 446            {
 136447                for (int i = 0; i < properties._properties.Length; i++)
 448                {
 68449                    if (properties._properties[i].Name == null)
 450                    {
 451                        break;
 452                    }
 453
 34454                    Property property = properties._properties[i];
 455
 456                    // Used with Http transport
 457                    //IMergeEnabledMessageProperty currentValue;
 458                    //if (!this.TryGetValue<IMergeEnabledMessageProperty>(property.Name, out currentValue) ||
 459                    //    !currentValue.TryMergeWithProperty(property.Value))
 460                    //{
 461                    // Merge wasn't possible so copy
 462                    // this[string] will call CreateCopyOfPropertyValue, so we don't need to repeat that here
 34463                    this[property.Name] = property.Value;
 464                    //}
 465                }
 466            }
 467
 35468            Via = properties.Via;
 35469            AllowOutputBatching = properties.AllowOutputBatching;
 35470            Security = (properties.Security != null) ? (SecurityMessageProperty)properties.Security.CreateCopy() : null;
 35471            Encoder = properties.Encoder;
 35472        }
 473
 474        internal void CopyProperties(KeyValuePair<string, object>[] array)
 475        {
 624476            if (_disposed)
 477            {
 0478                ThrowDisposed();
 479            }
 480
 1606481            for (int i = 0; i < array.Length; i++)
 482            {
 179483                KeyValuePair<string, object> property = array[i];
 484
 485                // this[string] will call CreateCopyOfPropertyValue, so we don't need to repeat that here
 179486                this[property.Key] = property.Value;
 487            }
 624488        }
 489
 490        public bool ContainsKey(string name)
 491        {
 206492            if (_disposed)
 493            {
 0494                ThrowDisposed();
 495            }
 496
 206497            if (name == null)
 498            {
 0499                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(name));
 500            }
 501
 206502            int index = FindProperty(name);
 503            switch (index)
 504            {
 505                case ViaIndex:
 0506                    return (object)_via != null;
 507                case AllowOutputBatchingIndex:
 0508                    return (object)_allowOutputBatching != null;
 509                case SecurityIndex:
 0510                    return (object)_security != null;
 511                case EncoderIndex:
 0512                    return (object)_encoder != null;
 513                case NotFoundIndex:
 95514                    return false;
 515                default:
 111516                    return true;
 517            }
 518        }
 519
 520        private object CreateCopyOfPropertyValue(object propertyValue)
 521        {
 4827522            if (!(propertyValue is IMessageProperty messageProperty))
 523            {
 3962524                return propertyValue;
 525            }
 526
 865527            object copy = messageProperty.CreateCopy();
 865528            if (copy == null)
 529            {
 0530                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.MessagePropertyReturn
 531            }
 532
 865533            return copy;
 534        }
 535
 536        public void Dispose()
 537        {
 3260538            if (_disposed)
 539            {
 0540                return;
 541            }
 542
 3260543            _disposed = true;
 544
 3260545            if (_properties != null)
 546            {
 13492547                for (int i = 0; i < _properties.Length; i++)
 548                {
 5974549                    if (_properties[i].Name == null)
 550                    {
 551                        break;
 552                    }
 553
 4300554                    _properties[i].Dispose();
 555                }
 556            }
 557
 3260558            if (_security != null)
 559            {
 107560                _security.Dispose();
 561            }
 3260562        }
 563
 564        private int FindProperty(string name)
 565        {
 9015566            if (name == ViaKey)
 567            {
 0568                return ViaIndex;
 569            }
 9015570            else if (name == AllowOutputBatchingKey)
 571            {
 0572                return AllowOutputBatchingIndex;
 573            }
 9015574            else if (name == EncoderKey)
 575            {
 178576                return EncoderIndex;
 577            }
 8837578            else if (name == SecurityKey)
 579            {
 0580                return SecurityIndex;
 581            }
 582
 8837583            if (_properties != null)
 584            {
 24452585                for (int i = 0; i < _properties.Length; i++)
 586                {
 11769587                    string propertyName = _properties[i].Name;
 588
 11769589                    if (propertyName == null)
 590                    {
 591                        break;
 592                    }
 593
 8940594                    if (propertyName == name)
 595                    {
 2355596                        return i;
 597                    }
 598                }
 599            }
 600
 6482601            return NotFoundIndex;
 602        }
 603
 604        internal void Recycle()
 605        {
 621606            _disposed = false;
 621607            Clear();
 621608        }
 609
 610        public bool Remove(string name)
 611        {
 20612            if (_disposed)
 613            {
 0614                ThrowDisposed();
 615            }
 616
 20617            int originalPropertyCount = _propertyCount;
 20618            UpdateProperty(name, null, false);
 20619            return originalPropertyCount != _propertyCount;
 620        }
 621
 622        public bool TryGetValue(string name, out object value)
 623        {
 3785624            if (_disposed)
 625            {
 0626                ThrowDisposed();
 627            }
 628
 3785629            if (name == null)
 630            {
 0631                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(name));
 632            }
 633
 3785634            int index = FindProperty(name);
 635            switch (index)
 636            {
 637                case ViaIndex:
 0638                    value = _via;
 0639                    break;
 640                case AllowOutputBatchingIndex:
 0641                    value = _allowOutputBatching;
 0642                    break;
 643                case SecurityIndex:
 0644                    value = _security;
 0645                    break;
 646                case EncoderIndex:
 0647                    value = _encoder;
 0648                    break;
 649                case NotFoundIndex:
 1541650                    value = null;
 1541651                    break;
 652                default:
 2244653                    value = _properties[index].Value;
 654                    break;
 655            }
 656
 3785657            return value != null;
 658        }
 659
 660        public bool TryGetValue<TProperty>(string name, out TProperty property)
 661        {
 14662            if (TryGetValue(name, out object o))
 663            {
 14664                if (!(o is TProperty))
 665                {
 0666                    property = default;
 0667                    return false;
 668                }
 669
 14670                property = (TProperty)o;
 14671                return true;
 672            }
 673            else
 674            {
 0675                property = default;
 0676                return false;
 677            }
 678        }
 679
 680        internal TProperty GetValue<TProperty>(string name) where TProperty : class
 681        {
 0682            return GetValue<TProperty>(name, false);
 683        }
 684
 685        internal TProperty GetValue<TProperty>(string name, bool ensureTypeMatch) where TProperty : class
 686        {
 0687            if (!TryGetValue(name, out object obj))
 688            {
 0689                return null;
 690            }
 691
 0692            return ensureTypeMatch ? (TProperty)obj : obj as TProperty;
 693        }
 694
 695        private void UpdateProperty(string name, object value, bool mustNotExist)
 696        {
 5024697            if (name == null)
 698            {
 0699                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(name));
 700            }
 701
 5024702            int index = FindProperty(name);
 5024703            if (index != NotFoundIndex)
 704            {
 178705                if (mustNotExist)
 706                {
 707                    bool exists;
 708                    switch (index)
 709                    {
 710                        case ViaIndex:
 0711                            exists = (object)_via != null;
 0712                            break;
 713                        case AllowOutputBatchingIndex:
 0714                            exists = (object)_allowOutputBatching != null;
 0715                            break;
 716                        case SecurityIndex:
 0717                            exists = (object)_security != null;
 0718                            break;
 719                        case EncoderIndex:
 0720                            exists = (object)_encoder != null;
 0721                            break;
 722                        default:
 0723                            exists = true;
 724                            break;
 725                    }
 0726                    if (exists)
 727                    {
 0728                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.Format(SR.Dup
 729                    }
 730                }
 731
 178732                if (index >= 0)
 733                {
 0734                    if (value == null)
 735                    {
 0736                        _properties[index].Dispose();
 737                        int shiftIndex;
 0738                        for (shiftIndex = index + 1; shiftIndex < _properties.Length; shiftIndex++)
 739                        {
 0740                            if (_properties[shiftIndex].Name == null)
 741                            {
 742                                break;
 743                            }
 744
 0745                            _properties[shiftIndex - 1] = _properties[shiftIndex];
 746                        }
 0747                        _properties[shiftIndex - 1] = new Property();
 0748                        _propertyCount--;
 749                    }
 750                    else
 751                    {
 0752                        _properties[index].Value = CreateCopyOfPropertyValue(value);
 753                    }
 754                }
 755                else
 756                {
 757                    switch (index)
 758                    {
 759                        case ViaIndex:
 0760                            Via = (Uri)value;
 0761                            break;
 762                        case AllowOutputBatchingIndex:
 0763                            AllowOutputBatching = (bool)value;
 0764                            break;
 765                        case SecurityIndex:
 0766                            if (Security != null)
 0767                                Security.Dispose();
 0768                            Security = (SecurityMessageProperty)CreateCopyOfPropertyValue(value);
 0769                            break;
 770                        case EncoderIndex:
 178771                            Encoder = (MessageEncoder)value;
 178772                            break;
 773                        default:
 774                            Fx.Assert("");
 0775                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException());
 776                    }
 777                }
 778            }
 4846779            else if (value != null)
 780            {
 781                int newIndex;
 782
 4826783                if (_properties == null)
 784                {
 2454785                    _properties = new Property[InitialPropertyCount];
 2454786                    newIndex = 0;
 787                }
 788                else
 789                {
 10946790                    for (newIndex = 0; newIndex < _properties.Length; newIndex++)
 791                    {
 5064792                        if (_properties[newIndex].Name == null)
 793                        {
 794                            break;
 795                        }
 796                    }
 797
 2372798                    if (newIndex == _properties.Length)
 799                    {
 409800                        Property[] newProperties = new Property[_properties.Length * 2];
 409801                        Array.Copy(_properties, newProperties, _properties.Length);
 409802                        _properties = newProperties;
 803                    }
 804                }
 805
 4826806                object newValue = CreateCopyOfPropertyValue(value);
 4826807                _properties[newIndex] = new Property(name, newValue);
 4826808                _propertyCount++;
 809            }
 4846810        }
 811
 812        void ICollection<KeyValuePair<string, object>>.CopyTo(KeyValuePair<string, object>[] array, int index)
 813        {
 624814            if (_disposed)
 815            {
 0816                ThrowDisposed();
 817            }
 818
 624819            if (array == null)
 820            {
 0821                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(array));
 822            }
 823
 624824            if (array.Length < _propertyCount)
 825            {
 0826                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.MessagePropertiesArra
 827            }
 828
 624829            if (index < 0 || index > array.Length - _propertyCount)
 830            {
 0831                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(index),
 0832                                                    SR.Format(SR.ValueMustBeInRange, 0, array.Length - _propertyCount)))
 833            }
 834
 624835            if (_via != null)
 836            {
 0837                array[index++] = new KeyValuePair<string, object>(ViaKey, _via);
 838            }
 839
 624840            if (_allowOutputBatching != null)
 841            {
 0842                array[index++] = new KeyValuePair<string, object>(AllowOutputBatchingKey, _allowOutputBatching);
 843            }
 844
 624845            if (_security != null)
 0846                array[index++] = new KeyValuePair<string, object>(SecurityKey, _security.CreateCopy());
 847
 624848            if (_encoder != null)
 849            {
 178850                array[index++] = new KeyValuePair<string, object>(EncoderKey, _encoder);
 851            }
 852
 624853            if (_properties != null)
 854            {
 4855                for (int i = 0; i < _properties.Length; i++)
 856                {
 2857                    string propertyName = _properties[i].Name;
 858
 2859                    if (propertyName == null)
 860                    {
 861                        break;
 862                    }
 863
 1864                    array[index++] = new KeyValuePair<string, object>(propertyName, CreateCopyOfPropertyValue(_propertie
 865                }
 866            }
 624867        }
 868
 869        void ICollection<KeyValuePair<string, object>>.Add(KeyValuePair<string, object> pair)
 870        {
 0871            if (_disposed)
 872            {
 0873                ThrowDisposed();
 874            }
 875
 0876            if (pair.Value == null)
 877            {
 0878                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("pair.Value");
 879            }
 880
 0881            UpdateProperty(pair.Key, pair.Value, true);
 0882        }
 883
 884        bool ICollection<KeyValuePair<string, object>>.Contains(KeyValuePair<string, object> pair)
 885        {
 0886            if (_disposed)
 887            {
 0888                ThrowDisposed();
 889            }
 890
 0891            if (pair.Value == null)
 892            {
 0893                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("pair.Value");
 894            }
 895
 0896            if (pair.Key == null)
 897            {
 0898                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("pair.Key");
 899            }
 900
 0901            if (!TryGetValue(pair.Key, out object value))
 902            {
 0903                return false;
 904            }
 0905            return value.Equals(pair.Value);
 906        }
 907
 908        IEnumerator IEnumerable.GetEnumerator()
 909        {
 0910            if (_disposed)
 911            {
 0912                ThrowDisposed();
 913            }
 914
 0915            return ((IEnumerable<KeyValuePair<string, object>>)this).GetEnumerator();
 916        }
 917
 918        IEnumerator<KeyValuePair<string, object>> IEnumerable<KeyValuePair<string, object>>.GetEnumerator()
 919        {
 0920            if (_disposed)
 921            {
 0922                ThrowDisposed();
 923            }
 924
 0925            List<KeyValuePair<string, object>> pairs = new List<KeyValuePair<string, object>>(_propertyCount);
 926
 0927            if (_via != null)
 928            {
 0929                pairs.Add(new KeyValuePair<string, object>(ViaKey, _via));
 930            }
 931
 0932            if (_allowOutputBatching != null)
 933            {
 0934                pairs.Add(new KeyValuePair<string, object>(AllowOutputBatchingKey, _allowOutputBatching));
 935            }
 936
 0937            if (_security != null)
 0938                pairs.Add(new KeyValuePair<string, object>(SecurityKey, _security));
 939
 0940            if (_encoder != null)
 941            {
 0942                pairs.Add(new KeyValuePair<string, object>(EncoderKey, _encoder));
 943            }
 944
 0945            if (_properties != null)
 946            {
 0947                for (int i = 0; i < _properties.Length; i++)
 948                {
 0949                    string propertyName = _properties[i].Name;
 950
 0951                    if (propertyName == null)
 952                    {
 953                        break;
 954                    }
 955
 0956                    pairs.Add(new KeyValuePair<string, object>(propertyName, _properties[i].Value));
 957                }
 958            }
 959
 0960            return pairs.GetEnumerator();
 961        }
 962
 963        bool ICollection<KeyValuePair<string, object>>.Remove(KeyValuePair<string, object> pair)
 964        {
 0965            if (_disposed)
 966            {
 0967                ThrowDisposed();
 968            }
 969
 0970            if (pair.Value == null)
 971            {
 0972                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("pair.Value");
 973            }
 974
 0975            if (pair.Key == null)
 976            {
 0977                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("pair.Key");
 978            }
 979
 0980            if (!TryGetValue(pair.Key, out object value))
 981            {
 0982                return false;
 983            }
 0984            if (!value.Equals(pair.Value))
 985            {
 0986                return false;
 987            }
 0988            Remove(pair.Key);
 0989            return true;
 990        }
 991
 992        private struct Property : IDisposable
 993        {
 994            public Property(string name, object value)
 995            {
 4826996                Name = name;
 4826997                Value = value;
 4826998            }
 999
 252031000            public string Name { get; }
 1001
 114051002            public object Value { get; set; }
 1003
 1004            public void Dispose()
 1005            {
 43001006                if (Value is IDisposable disposable)
 1007                {
 01008                    disposable.Dispose();
 1009                }
 43001010            }
 1011        }
 1012    }
 1013}

Methods/Properties

.cctor()
.ctor()
.ctor(CoreWCF.Channels.MessageProperties)
.ctor(System.Collections.Generic.KeyValuePair`2<System.String,System.Object>[])
ThrowDisposed()
Item(System.String)
Item(System.String,System.Object)
CanRecycle()
Count()
Encoder()
Encoder(CoreWCF.Channels.MessageEncoder)
AllowOutputBatching()
AllowOutputBatching(System.Boolean)
IsFixedSize()
IsReadOnly()
Keys()
Security()
Security(CoreWCF.Security.SecurityMessageProperty)
Values()
Via()
Via(System.Uri)
Add(System.String,System.Object)
AdjustPropertyCount(System.Boolean,System.Boolean)
Clear()
CopyProperties(CoreWCF.Channels.MessageProperties)
MergeProperties(CoreWCF.Channels.MessageProperties)
CopyProperties(System.Collections.Generic.KeyValuePair`2<System.String,System.Object>[])
ContainsKey(System.String)
CreateCopyOfPropertyValue(System.Object)
Dispose()
FindProperty(System.String)
Recycle()
Remove(System.String)
TryGetValue(System.String,System.Object&)
TryGetValue(System.String,TProperty&)
GetValue(System.String)
GetValue(System.String,System.Boolean)
UpdateProperty(System.String,System.Object,System.Boolean)
System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<System.String,System.Object>>.CopyTo(System.Collections.Generic.KeyValuePair`2<System.String,System.Object>[],System.Int32)
System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<System.String,System.Object>>.Add(System.Collections.Generic.KeyValuePair`2<System.String,System.Object>)
System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<System.String,System.Object>>.Contains(System.Collections.Generic.KeyValuePair`2<System.String,System.Object>)
System.Collections.IEnumerable.GetEnumerator()
System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<System.String,System.Object>>.GetEnumerator()
System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<System.String,System.Object>>.Remove(System.Collections.Generic.KeyValuePair`2<System.String,System.Object>)
.ctor(System.String,System.Object)
Name()
Value()
Dispose()