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.Reflection; 11 12 namespace Google.Protobuf.Compatibility 13 { 14 /// <summary> 15 /// Extension methods for <see cref="PropertyInfo"/>, effectively providing 16 /// the familiar members from previous desktop framework versions while 17 /// targeting the newer releases, .NET Core etc. 18 /// </summary> 19 internal static class PropertyInfoExtensions 20 { 21 /// <summary> 22 /// Returns the public getter of a property, or null if there is no such getter 23 /// (either because it's read-only, or the getter isn't public). 24 /// </summary> GetGetMethod(this PropertyInfo target)25 internal static MethodInfo GetGetMethod(this PropertyInfo target) 26 { 27 var method = target.GetMethod; 28 return method != null && method.IsPublic ? method : null; 29 } 30 31 /// <summary> 32 /// Returns the public setter of a property, or null if there is no such setter 33 /// (either because it's write-only, or the setter isn't public). 34 /// </summary> GetSetMethod(this PropertyInfo target)35 internal static MethodInfo GetSetMethod(this PropertyInfo target) 36 { 37 var method = target.SetMethod; 38 return method != null && method.IsPublic ? method : null; 39 } 40 } 41 } 42