• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.Reflection;
12 using Google.Protobuf.Compatibility;
13 
14 namespace Google.Protobuf.Reflection
15 {
16     /// <summary>
17     /// Base class for field accessors.
18     /// </summary>
19     internal abstract class FieldAccessorBase : IFieldAccessor
20     {
21         private readonly Func<IMessage, object> getValueDelegate;
22 
FieldAccessorBase(PropertyInfo property, FieldDescriptor descriptor)23         internal FieldAccessorBase(PropertyInfo property, FieldDescriptor descriptor)
24         {
25             Descriptor = descriptor;
26             getValueDelegate = ReflectionUtil.CreateFuncIMessageObject(property.GetGetMethod());
27         }
28 
29         public FieldDescriptor Descriptor { get; }
30 
GetValue(IMessage message)31         public object GetValue(IMessage message)
32         {
33             return getValueDelegate(message);
34         }
35 
HasValue(IMessage message)36         public abstract bool HasValue(IMessage message);
Clear(IMessage message)37         public abstract void Clear(IMessage message);
SetValue(IMessage message, object value)38         public abstract void SetValue(IMessage message, object value);
39     }
40 }
41