OLD | NEW |
1 #region Copyright notice and license | 1 #region Copyright notice and license |
2 // Protocol Buffers - Google's data interchange format | 2 // Protocol Buffers - Google's data interchange format |
3 // Copyright 2015 Google Inc. All rights reserved. | 3 // Copyright 2015 Google Inc. All rights reserved. |
4 // https://developers.google.com/protocol-buffers/ | 4 // https://developers.google.com/protocol-buffers/ |
5 // | 5 // |
6 // Redistribution and use in source and binary forms, with or without | 6 // Redistribution and use in source and binary forms, with or without |
7 // modification, are permitted provided that the following conditions are | 7 // modification, are permitted provided that the following conditions are |
8 // met: | 8 // met: |
9 // | 9 // |
10 // * Redistributions of source code must retain the above copyright | 10 // * Redistributions of source code must retain the above copyright |
(...skipping 15 matching lines...) Expand all Loading... |
26 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 26 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
27 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 27 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
28 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 28 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
29 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 29 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
30 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 30 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
31 #endregion | 31 #endregion |
32 | 32 |
33 using System; | 33 using System; |
34 using System.Reflection; | 34 using System.Reflection; |
35 | 35 |
36 #if !DOTNET35 | |
37 namespace Google.Protobuf.Compatibility | 36 namespace Google.Protobuf.Compatibility |
38 { | 37 { |
39 /// <summary> | 38 /// <summary> |
40 /// Provides extension methods on Type that just proxy to TypeInfo. | 39 /// Provides extension methods on Type that just proxy to TypeInfo. |
41 /// These are used to support the new type system from .NET 4.5, without | 40 /// These are used to support the new type system from .NET 4.5, without |
42 /// having calls to GetTypeInfo all over the place. While the methods here a
re meant to be | 41 /// having calls to GetTypeInfo all over the place. While the methods here a
re meant to be |
43 /// broadly compatible with the desktop framework, there are some subtle dif
ferences in behaviour - but | 42 /// broadly compatible with the desktop framework, there are some subtle dif
ferences in behaviour - but |
44 /// they're not expected to affect our use cases. While the class is interna
l, that should be fine: we can | 43 /// they're not expected to affect our use cases. While the class is interna
l, that should be fine: we can |
45 /// evaluate each new use appropriately. | 44 /// evaluate each new use appropriately. |
46 /// </summary> | 45 /// </summary> |
47 internal static class TypeExtensions | 46 internal static class TypeExtensions |
48 { | 47 { |
49 /// <summary> | 48 /// <summary> |
| 49 /// Returns true if the target type is a value type, including a nullabl
e value type or an enum, or false |
| 50 /// if it's a reference type (class, delegate, interface - including Sys
tem.ValueType and System.Enum). |
| 51 /// </summary> |
| 52 internal static bool IsValueType(this Type target) |
| 53 { |
| 54 return target.GetTypeInfo().IsValueType; |
| 55 } |
| 56 |
| 57 /// <summary> |
50 /// See https://msdn.microsoft.com/en-us/library/system.type.isassignabl
efrom | 58 /// See https://msdn.microsoft.com/en-us/library/system.type.isassignabl
efrom |
51 /// </summary> | 59 /// </summary> |
52 internal static bool IsAssignableFrom(this Type target, Type c) | 60 internal static bool IsAssignableFrom(this Type target, Type c) |
53 { | 61 { |
54 return target.GetTypeInfo().IsAssignableFrom(c.GetTypeInfo()); | 62 return target.GetTypeInfo().IsAssignableFrom(c.GetTypeInfo()); |
55 } | 63 } |
56 | 64 |
57 /// <summary> | 65 /// <summary> |
58 /// Returns a representation of the public property associated with the
given name in the given type, | 66 /// Returns a representation of the public property associated with the
given name in the given type, |
59 /// including inherited properties or null if there is no such public pr
operty. | 67 /// including inherited properties or null if there is no such public pr
operty. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 if (ret != null && ret.IsPublic) | 104 if (ret != null && ret.IsPublic) |
97 { | 105 { |
98 return ret; | 106 return ret; |
99 } | 107 } |
100 target = typeInfo.BaseType; | 108 target = typeInfo.BaseType; |
101 } | 109 } |
102 return null; | 110 return null; |
103 } | 111 } |
104 } | 112 } |
105 } | 113 } |
106 #endif | |
OLD | NEW |