1 #region Copyright notice and license 2 // Protocol Buffers - Google's data interchange format 3 // Copyright 2015 Google Inc. All rights reserved. 4 // 5 // Use of this source code is governed by a BSD-style 6 // license that can be found in the LICENSE file or at 7 // https://developers.google.com/open-source/licenses/bsd 8 #endregion 9 10 using System; 11 using System.Collections; 12 using System.Reflection; 13 14 namespace Google.Protobuf.Reflection 15 { 16 /// <summary> 17 /// Accessor for map fields. 18 /// </summary> 19 internal sealed class MapFieldAccessor : FieldAccessorBase 20 { MapFieldAccessor(PropertyInfo property, FieldDescriptor descriptor)21 internal MapFieldAccessor(PropertyInfo property, FieldDescriptor descriptor) : base(property, descriptor) 22 { 23 } 24 Clear(IMessage message)25 public override void Clear(IMessage message) 26 { 27 IDictionary list = (IDictionary) GetValue(message); 28 list.Clear(); 29 } 30 HasValue(IMessage message)31 public override bool HasValue(IMessage message) 32 { 33 throw new InvalidOperationException("HasValue is not implemented for map fields"); 34 } 35 SetValue(IMessage message, object value)36 public override void SetValue(IMessage message, object value) 37 { 38 throw new InvalidOperationException("SetValue is not implemented for map fields"); 39 } 40 } 41 } 42