-WinRT build
This commit is contained in:
@@ -33,13 +33,13 @@ using NUnit.Framework;
|
|||||||
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
||||||
using TestFixture = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestClassAttribute;
|
using TestFixture = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestClassAttribute;
|
||||||
using Test = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestMethodAttribute;
|
using Test = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestMethodAttribute;
|
||||||
|
#endif
|
||||||
using Windows.Data.Json;
|
using Windows.Data.Json;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace Newtonsoft.Json.Tests.Converters
|
namespace Newtonsoft.Json.Tests.Converters
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,7 +5,13 @@ using System.Text;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using Newtonsoft.Json.Linq.JsonPath;
|
using Newtonsoft.Json.Linq.JsonPath;
|
||||||
|
#if !NETFX_CORE
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
#else
|
||||||
|
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
||||||
|
using TestFixture = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestClassAttribute;
|
||||||
|
using Test = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestMethodAttribute;
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace Newtonsoft.Json.Tests.Linq.JsonPath
|
namespace Newtonsoft.Json.Tests.Linq.JsonPath
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -142,9 +142,11 @@
|
|||||||
<Compile Include="Linq\JArrayTests.cs" />
|
<Compile Include="Linq\JArrayTests.cs" />
|
||||||
<Compile Include="Linq\JConstructorTests.cs" />
|
<Compile Include="Linq\JConstructorTests.cs" />
|
||||||
<Compile Include="Linq\JObjectTests.cs" />
|
<Compile Include="Linq\JObjectTests.cs" />
|
||||||
<Compile Include="Linq\JPathTests.cs" />
|
|
||||||
<Compile Include="Linq\JPropertyTests.cs" />
|
<Compile Include="Linq\JPropertyTests.cs" />
|
||||||
<Compile Include="Linq\JRawTests.cs" />
|
<Compile Include="Linq\JRawTests.cs" />
|
||||||
|
<Compile Include="Linq\JsonPath\JPathExecuteTests.cs" />
|
||||||
|
<Compile Include="Linq\JsonPath\JPathParseTests.cs" />
|
||||||
|
<Compile Include="Linq\JsonPath\QueryExpressionTests.cs" />
|
||||||
<Compile Include="Linq\JTokenEqualityComparerTests.cs" />
|
<Compile Include="Linq\JTokenEqualityComparerTests.cs" />
|
||||||
<Compile Include="Linq\JTokenReaderTest.cs" />
|
<Compile Include="Linq\JTokenReaderTest.cs" />
|
||||||
<Compile Include="Linq\JTokenTests.cs" />
|
<Compile Include="Linq\JTokenTests.cs" />
|
||||||
@@ -177,7 +179,6 @@
|
|||||||
<Compile Include="Serialization\TraceWriterTests.cs" />
|
<Compile Include="Serialization\TraceWriterTests.cs" />
|
||||||
<Compile Include="Serialization\TypeNameHandlingTests.cs" />
|
<Compile Include="Serialization\TypeNameHandlingTests.cs" />
|
||||||
<Compile Include="Serialization\WebApiIntegrationTests.cs" />
|
<Compile Include="Serialization\WebApiIntegrationTests.cs" />
|
||||||
<Compile Include="SilverlightTests.cs" />
|
|
||||||
<Compile Include="TestFixtureBase.cs" />
|
<Compile Include="TestFixtureBase.cs" />
|
||||||
<Compile Include="TestObjects\AbstractGenericBase.cs" />
|
<Compile Include="TestObjects\AbstractGenericBase.cs" />
|
||||||
<Compile Include="TestObjects\ArgumentConverterPrecedenceClassConverter.cs" />
|
<Compile Include="TestObjects\ArgumentConverterPrecedenceClassConverter.cs" />
|
||||||
|
|||||||
@@ -9471,28 +9471,6 @@ Parameter name: value",
|
|||||||
]", json);
|
]", json);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Foo2
|
|
||||||
{
|
|
||||||
public string Name { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
[Ignore]
|
|
||||||
public void SerializeMultipleObjectsFromStream()
|
|
||||||
{
|
|
||||||
StringReader sr = new StringReader(@"{ ""name"": ""bar"" }{ ""name"": ""baz"" }");
|
|
||||||
|
|
||||||
var reader1 = new JsonTextReader(sr);
|
|
||||||
var serializer1 = new JsonSerializer { };
|
|
||||||
var foo1 = serializer1.Deserialize<Foo2>(reader1);
|
|
||||||
Assert.AreEqual("bar", foo1.Name);
|
|
||||||
|
|
||||||
var reader2 = new JsonTextReader(sr);
|
|
||||||
var serializer2 = new JsonSerializer { };
|
|
||||||
var foo2 = serializer2.Deserialize<Foo2>(reader2);
|
|
||||||
Assert.AreEqual("baz", foo2.Name);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if !(PORTABLE || PORTABLE40 || NETFX_CORE)
|
#if !(PORTABLE || PORTABLE40 || NETFX_CORE)
|
||||||
[Test]
|
[Test]
|
||||||
public void SerializeDictionaryWithStructKey()
|
public void SerializeDictionaryWithStructKey()
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ using System;
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Data.Odbc;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Newtonsoft.Json.Serialization;
|
using Newtonsoft.Json.Serialization;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
@@ -145,7 +145,12 @@ namespace Newtonsoft.Json.Converters
|
|||||||
|
|
||||||
// all fsharp objects have CompilationMappingAttribute
|
// all fsharp objects have CompilationMappingAttribute
|
||||||
// get the fsharp assembly from the attribute and initialize latebound methods
|
// get the fsharp assembly from the attribute and initialize latebound methods
|
||||||
object[] attributes = objectType.GetCustomAttributes(true);
|
object[] attributes;
|
||||||
|
#if !(NETFX_CORE || PORTABLE)
|
||||||
|
attributes = objectType.GetCustomAttributes(true);
|
||||||
|
#else
|
||||||
|
attributes = objectType.GetTypeInfo().GetCustomAttributes(true).ToArray();
|
||||||
|
#endif
|
||||||
bool isFSharpType = false;
|
bool isFSharpType = false;
|
||||||
foreach (object attribute in attributes)
|
foreach (object attribute in attributes)
|
||||||
{
|
{
|
||||||
@@ -171,7 +176,7 @@ namespace Newtonsoft.Json.Converters
|
|||||||
{
|
{
|
||||||
_initialized = true;
|
_initialized = true;
|
||||||
|
|
||||||
Assembly fsharpCoreAssembly = attributeType.Assembly;
|
Assembly fsharpCoreAssembly = attributeType.Assembly();
|
||||||
Type fsharpType = fsharpCoreAssembly.GetType("Microsoft.FSharp.Reflection.FSharpType");
|
Type fsharpType = fsharpCoreAssembly.GetType("Microsoft.FSharp.Reflection.FSharpType");
|
||||||
|
|
||||||
MethodInfo isUnionMethodInfo = fsharpType.GetMethod("IsUnion", BindingFlags.Public | BindingFlags.Static);
|
MethodInfo isUnionMethodInfo = fsharpType.GetMethod("IsUnion", BindingFlags.Public | BindingFlags.Static);
|
||||||
|
|||||||
@@ -127,6 +127,7 @@
|
|||||||
<Compile Include="Converters\DataSetConverter.cs" />
|
<Compile Include="Converters\DataSetConverter.cs" />
|
||||||
<Compile Include="Converters\DataTableConverter.cs" />
|
<Compile Include="Converters\DataTableConverter.cs" />
|
||||||
<Compile Include="Converters\DateTimeConverterBase.cs" />
|
<Compile Include="Converters\DateTimeConverterBase.cs" />
|
||||||
|
<Compile Include="Converters\DiscriminatedUnionConverter.cs" />
|
||||||
<Compile Include="Converters\EntityKeyMemberConverter.cs" />
|
<Compile Include="Converters\EntityKeyMemberConverter.cs" />
|
||||||
<Compile Include="Converters\ExpandoObjectConverter.cs" />
|
<Compile Include="Converters\ExpandoObjectConverter.cs" />
|
||||||
<Compile Include="Converters\IsoDateTimeConverter.cs" />
|
<Compile Include="Converters\IsoDateTimeConverter.cs" />
|
||||||
@@ -178,11 +179,19 @@
|
|||||||
<Compile Include="Linq\JContainer.cs" />
|
<Compile Include="Linq\JContainer.cs" />
|
||||||
<Compile Include="Linq\JEnumerable.cs" />
|
<Compile Include="Linq\JEnumerable.cs" />
|
||||||
<Compile Include="Linq\JObject.cs" />
|
<Compile Include="Linq\JObject.cs" />
|
||||||
<Compile Include="Linq\JPath.cs" />
|
|
||||||
<Compile Include="Linq\JProperty.cs" />
|
<Compile Include="Linq\JProperty.cs" />
|
||||||
<Compile Include="Linq\JPropertyDescriptor.cs" />
|
<Compile Include="Linq\JPropertyDescriptor.cs" />
|
||||||
<Compile Include="Linq\JPropertyKeyedCollection.cs" />
|
<Compile Include="Linq\JPropertyKeyedCollection.cs" />
|
||||||
<Compile Include="Linq\JRaw.cs" />
|
<Compile Include="Linq\JRaw.cs" />
|
||||||
|
<Compile Include="Linq\JsonPath\ArrayIndexFilter.cs" />
|
||||||
|
<Compile Include="Linq\JsonPath\ArrayMultipleIndexFilter.cs" />
|
||||||
|
<Compile Include="Linq\JsonPath\ArraySliceFilter.cs" />
|
||||||
|
<Compile Include="Linq\JsonPath\FieldFilter.cs" />
|
||||||
|
<Compile Include="Linq\JsonPath\JPath.cs" />
|
||||||
|
<Compile Include="Linq\JsonPath\PathFilter.cs" />
|
||||||
|
<Compile Include="Linq\JsonPath\QueryExpression.cs" />
|
||||||
|
<Compile Include="Linq\JsonPath\QueryFilter.cs" />
|
||||||
|
<Compile Include="Linq\JsonPath\ScanFilter.cs" />
|
||||||
<Compile Include="Linq\JToken.cs" />
|
<Compile Include="Linq\JToken.cs" />
|
||||||
<Compile Include="Linq\JTokenEqualityComparer.cs" />
|
<Compile Include="Linq\JTokenEqualityComparer.cs" />
|
||||||
<Compile Include="Linq\JTokenReader.cs" />
|
<Compile Include="Linq\JTokenReader.cs" />
|
||||||
|
|||||||
@@ -55,30 +55,30 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if NETFX_CORE || PORTABLE
|
#if NETFX_CORE || PORTABLE
|
||||||
[Flags]
|
[Flags]
|
||||||
internal enum BindingFlags
|
internal enum BindingFlags
|
||||||
{
|
{
|
||||||
Default = 0,
|
Default = 0,
|
||||||
IgnoreCase = 1,
|
IgnoreCase = 1,
|
||||||
DeclaredOnly = 2,
|
DeclaredOnly = 2,
|
||||||
Instance = 4,
|
Instance = 4,
|
||||||
Static = 8,
|
Static = 8,
|
||||||
Public = 16,
|
Public = 16,
|
||||||
NonPublic = 32,
|
NonPublic = 32,
|
||||||
FlattenHierarchy = 64,
|
FlattenHierarchy = 64,
|
||||||
InvokeMethod = 256,
|
InvokeMethod = 256,
|
||||||
CreateInstance = 512,
|
CreateInstance = 512,
|
||||||
GetField = 1024,
|
GetField = 1024,
|
||||||
SetField = 2048,
|
SetField = 2048,
|
||||||
GetProperty = 4096,
|
GetProperty = 4096,
|
||||||
SetProperty = 8192,
|
SetProperty = 8192,
|
||||||
PutDispProperty = 16384,
|
PutDispProperty = 16384,
|
||||||
ExactBinding = 65536,
|
ExactBinding = 65536,
|
||||||
PutRefDispProperty = 32768,
|
PutRefDispProperty = 32768,
|
||||||
SuppressChangeType = 131072,
|
SuppressChangeType = 131072,
|
||||||
OptionalParamBinding = 262144,
|
OptionalParamBinding = 262144,
|
||||||
IgnoreReturn = 16777216
|
IgnoreReturn = 16777216
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
internal static class ReflectionUtils
|
internal static class ReflectionUtils
|
||||||
@@ -154,7 +154,7 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
fullyQualifiedTypeName = t.AssemblyQualifiedName;
|
fullyQualifiedTypeName = t.AssemblyQualifiedName;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
fullyQualifiedTypeName = t.AssemblyQualifiedName;
|
fullyQualifiedTypeName = t.AssemblyQualifiedName;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
switch (assemblyFormat)
|
switch (assemblyFormat)
|
||||||
@@ -690,25 +690,25 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
throw new Exception("Cannot get attributes from '{0}'.".FormatWith(CultureInfo.InvariantCulture, provider));
|
throw new Exception("Cannot get attributes from '{0}'.".FormatWith(CultureInfo.InvariantCulture, provider));
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
public static T[] GetAttributes<T>(object provider, bool inherit) where T : Attribute
|
public static T[] GetAttributes<T>(object provider, bool inherit) where T : Attribute
|
||||||
{
|
{
|
||||||
if (provider is Type)
|
if (provider is Type)
|
||||||
return ((Type)provider).GetTypeInfo().GetCustomAttributes<T>(inherit).ToArray();
|
return ((Type) provider).GetTypeInfo().GetCustomAttributes<T>(inherit).ToArray();
|
||||||
|
|
||||||
if (provider is Assembly)
|
if (provider is Assembly)
|
||||||
return ((Assembly)provider).GetCustomAttributes<T>().ToArray();
|
return ((Assembly) provider).GetCustomAttributes<T>().ToArray();
|
||||||
|
|
||||||
if (provider is MemberInfo)
|
if (provider is MemberInfo)
|
||||||
return ((MemberInfo)provider).GetCustomAttributes<T>(inherit).ToArray();
|
return ((MemberInfo) provider).GetCustomAttributes<T>(inherit).ToArray();
|
||||||
|
|
||||||
if (provider is Module)
|
if (provider is Module)
|
||||||
return ((Module)provider).GetCustomAttributes<T>().ToArray();
|
return ((Module) provider).GetCustomAttributes<T>().ToArray();
|
||||||
|
|
||||||
if (provider is ParameterInfo)
|
if (provider is ParameterInfo)
|
||||||
return ((ParameterInfo)provider).GetCustomAttributes<T>(inherit).ToArray();
|
return ((ParameterInfo) provider).GetCustomAttributes<T>(inherit).ToArray();
|
||||||
|
|
||||||
throw new Exception("Cannot get attributes from '{0}'.".FormatWith(CultureInfo.InvariantCulture, provider));
|
throw new Exception("Cannot get attributes from '{0}'.".FormatWith(CultureInfo.InvariantCulture, provider));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
public static void SplitFullyQualifiedTypeName(string fullyQualifiedTypeName, out string typeName, out string assemblyName)
|
public static void SplitFullyQualifiedTypeName(string fullyQualifiedTypeName, out string typeName, out string assemblyName)
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ using System.Reflection;
|
|||||||
using Newtonsoft.Json.Utilities.LinqBridge;
|
using Newtonsoft.Json.Utilities.LinqBridge;
|
||||||
#else
|
#else
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace Newtonsoft.Json.Utilities
|
namespace Newtonsoft.Json.Utilities
|
||||||
@@ -38,45 +37,45 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
internal static class TypeExtensions
|
internal static class TypeExtensions
|
||||||
{
|
{
|
||||||
#if NETFX_CORE || PORTABLE
|
#if NETFX_CORE || PORTABLE
|
||||||
private static BindingFlags DefaultFlags = BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance;
|
private static BindingFlags DefaultFlags = BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance;
|
||||||
|
|
||||||
public static MethodInfo GetGetMethod(this PropertyInfo propertyInfo)
|
public static MethodInfo GetGetMethod(this PropertyInfo propertyInfo)
|
||||||
{
|
{
|
||||||
return propertyInfo.GetGetMethod(false);
|
return propertyInfo.GetGetMethod(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MethodInfo GetGetMethod(this PropertyInfo propertyInfo, bool nonPublic)
|
public static MethodInfo GetGetMethod(this PropertyInfo propertyInfo, bool nonPublic)
|
||||||
{
|
{
|
||||||
MethodInfo getMethod = propertyInfo.GetMethod;
|
MethodInfo getMethod = propertyInfo.GetMethod;
|
||||||
if (getMethod != null && (getMethod.IsPublic || nonPublic))
|
if (getMethod != null && (getMethod.IsPublic || nonPublic))
|
||||||
return getMethod;
|
return getMethod;
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MethodInfo GetSetMethod(this PropertyInfo propertyInfo)
|
public static MethodInfo GetSetMethod(this PropertyInfo propertyInfo)
|
||||||
{
|
{
|
||||||
return propertyInfo.GetSetMethod(false);
|
return propertyInfo.GetSetMethod(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MethodInfo GetSetMethod(this PropertyInfo propertyInfo, bool nonPublic)
|
public static MethodInfo GetSetMethod(this PropertyInfo propertyInfo, bool nonPublic)
|
||||||
{
|
{
|
||||||
MethodInfo setMethod = propertyInfo.SetMethod;
|
MethodInfo setMethod = propertyInfo.SetMethod;
|
||||||
if (setMethod != null && (setMethod.IsPublic || nonPublic))
|
if (setMethod != null && (setMethod.IsPublic || nonPublic))
|
||||||
return setMethod;
|
return setMethod;
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsSubclassOf(this Type type, Type c)
|
public static bool IsSubclassOf(this Type type, Type c)
|
||||||
{
|
{
|
||||||
return type.GetTypeInfo().IsSubclassOf(c);
|
return type.GetTypeInfo().IsSubclassOf(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsAssignableFrom(this Type type, Type c)
|
public static bool IsAssignableFrom(this Type type, Type c)
|
||||||
{
|
{
|
||||||
return type.GetTypeInfo().IsAssignableFrom(c.GetTypeInfo());
|
return type.GetTypeInfo().IsAssignableFrom(c.GetTypeInfo());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
public static MethodInfo Method(this Delegate d)
|
public static MethodInfo Method(this Delegate d)
|
||||||
@@ -84,7 +83,7 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
#if !(NETFX_CORE || PORTABLE)
|
#if !(NETFX_CORE || PORTABLE)
|
||||||
return d.Method;
|
return d.Method;
|
||||||
#else
|
#else
|
||||||
return d.GetMethodInfo();
|
return d.GetMethodInfo();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,7 +110,7 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
#if !(NETFX_CORE || PORTABLE)
|
#if !(NETFX_CORE || PORTABLE)
|
||||||
return type.ContainsGenericParameters;
|
return type.ContainsGenericParameters;
|
||||||
#else
|
#else
|
||||||
return type.GetTypeInfo().ContainsGenericParameters;
|
return type.GetTypeInfo().ContainsGenericParameters;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,7 +119,7 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
#if !(NETFX_CORE || PORTABLE)
|
#if !(NETFX_CORE || PORTABLE)
|
||||||
return type.IsInterface;
|
return type.IsInterface;
|
||||||
#else
|
#else
|
||||||
return type.GetTypeInfo().IsInterface;
|
return type.GetTypeInfo().IsInterface;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,7 +128,7 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
#if !(NETFX_CORE || PORTABLE)
|
#if !(NETFX_CORE || PORTABLE)
|
||||||
return type.IsGenericType;
|
return type.IsGenericType;
|
||||||
#else
|
#else
|
||||||
return type.GetTypeInfo().IsGenericType;
|
return type.GetTypeInfo().IsGenericType;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,7 +137,7 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
#if !(NETFX_CORE || PORTABLE)
|
#if !(NETFX_CORE || PORTABLE)
|
||||||
return type.IsGenericTypeDefinition;
|
return type.IsGenericTypeDefinition;
|
||||||
#else
|
#else
|
||||||
return type.GetTypeInfo().IsGenericTypeDefinition;
|
return type.GetTypeInfo().IsGenericTypeDefinition;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,7 +146,16 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
#if !(NETFX_CORE || PORTABLE)
|
#if !(NETFX_CORE || PORTABLE)
|
||||||
return type.BaseType;
|
return type.BaseType;
|
||||||
#else
|
#else
|
||||||
return type.GetTypeInfo().BaseType;
|
return type.GetTypeInfo().BaseType;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Assembly Assembly(this Type type)
|
||||||
|
{
|
||||||
|
#if !(NETFX_CORE || PORTABLE)
|
||||||
|
return type.Assembly;
|
||||||
|
#else
|
||||||
|
return type.GetTypeInfo().Assembly;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,7 +164,7 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
#if !(NETFX_CORE || PORTABLE)
|
#if !(NETFX_CORE || PORTABLE)
|
||||||
return type.IsEnum;
|
return type.IsEnum;
|
||||||
#else
|
#else
|
||||||
return type.GetTypeInfo().IsEnum;
|
return type.GetTypeInfo().IsEnum;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,7 +173,7 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
#if !(NETFX_CORE || PORTABLE)
|
#if !(NETFX_CORE || PORTABLE)
|
||||||
return type.IsClass;
|
return type.IsClass;
|
||||||
#else
|
#else
|
||||||
return type.GetTypeInfo().IsClass;
|
return type.GetTypeInfo().IsClass;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,7 +182,7 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
#if !(NETFX_CORE || PORTABLE)
|
#if !(NETFX_CORE || PORTABLE)
|
||||||
return type.IsSealed;
|
return type.IsSealed;
|
||||||
#else
|
#else
|
||||||
return type.GetTypeInfo().IsSealed;
|
return type.GetTypeInfo().IsSealed;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -214,293 +222,293 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (NETFX_CORE || PORTABLE)
|
#if (NETFX_CORE || PORTABLE)
|
||||||
public static MethodInfo GetBaseDefinition(this MethodInfo method)
|
public static MethodInfo GetBaseDefinition(this MethodInfo method)
|
||||||
{
|
{
|
||||||
return method.GetRuntimeBaseDefinition();
|
return method.GetRuntimeBaseDefinition();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (NETFX_CORE || PORTABLE)
|
#if (NETFX_CORE || PORTABLE)
|
||||||
public static bool IsDefined(this Type type, Type attributeType, bool inherit)
|
public static bool IsDefined(this Type type, Type attributeType, bool inherit)
|
||||||
{
|
|
||||||
return type.GetTypeInfo().CustomAttributes.Any(a => a.AttributeType == attributeType);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static MethodInfo GetMethod(this Type type, string name)
|
|
||||||
{
|
|
||||||
return type.GetMethod(name, DefaultFlags);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static MethodInfo GetMethod(this Type type, string name, BindingFlags bindingFlags)
|
|
||||||
{
|
|
||||||
return type.GetTypeInfo().GetDeclaredMethod(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static MethodInfo GetMethod(this Type type, IList<Type> parameterTypes)
|
|
||||||
{
|
|
||||||
return type.GetMethod(null, parameterTypes);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static MethodInfo GetMethod(this Type type, string name, IList<Type> parameterTypes)
|
|
||||||
{
|
|
||||||
return type.GetMethod(name, DefaultFlags, null, parameterTypes, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static MethodInfo GetMethod(this Type type, string name, BindingFlags bindingFlags, object placeHolder1, IList<Type> parameterTypes, object placeHolder2)
|
|
||||||
{
|
|
||||||
return type.GetTypeInfo().DeclaredMethods.Where(m =>
|
|
||||||
{
|
|
||||||
if (name != null && m.Name != name)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!TestAccessibility(m, bindingFlags))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return m.GetParameters().Select(p => p.ParameterType).SequenceEqual(parameterTypes);
|
|
||||||
}).SingleOrDefault();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static PropertyInfo GetProperty(this Type type, string name, BindingFlags bindingFlags, object placeholder1, Type propertyType, IList<Type> indexParameters, object placeholder2)
|
|
||||||
{
|
|
||||||
return type.GetTypeInfo().DeclaredProperties.Where(p =>
|
|
||||||
{
|
|
||||||
if (name != null && name != p.Name)
|
|
||||||
return false;
|
|
||||||
if (propertyType != null && propertyType != p.PropertyType)
|
|
||||||
return false;
|
|
||||||
if (indexParameters != null)
|
|
||||||
{
|
{
|
||||||
if (!p.GetIndexParameters().Select(ip => ip.ParameterType).SequenceEqual(indexParameters))
|
return type.GetTypeInfo().CustomAttributes.Any(a => a.AttributeType == attributeType);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MethodInfo GetMethod(this Type type, string name)
|
||||||
|
{
|
||||||
|
return type.GetMethod(name, DefaultFlags);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MethodInfo GetMethod(this Type type, string name, BindingFlags bindingFlags)
|
||||||
|
{
|
||||||
|
return type.GetTypeInfo().GetDeclaredMethod(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MethodInfo GetMethod(this Type type, IList<Type> parameterTypes)
|
||||||
|
{
|
||||||
|
return type.GetMethod(null, parameterTypes);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MethodInfo GetMethod(this Type type, string name, IList<Type> parameterTypes)
|
||||||
|
{
|
||||||
|
return type.GetMethod(name, DefaultFlags, null, parameterTypes, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MethodInfo GetMethod(this Type type, string name, BindingFlags bindingFlags, object placeHolder1, IList<Type> parameterTypes, object placeHolder2)
|
||||||
|
{
|
||||||
|
return type.GetTypeInfo().DeclaredMethods.Where(m =>
|
||||||
|
{
|
||||||
|
if (name != null && m.Name != name)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!TestAccessibility(m, bindingFlags))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return m.GetParameters().Select(p => p.ParameterType).SequenceEqual(parameterTypes);
|
||||||
|
}).SingleOrDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PropertyInfo GetProperty(this Type type, string name, BindingFlags bindingFlags, object placeholder1, Type propertyType, IList<Type> indexParameters, object placeholder2)
|
||||||
|
{
|
||||||
|
return type.GetTypeInfo().DeclaredProperties.Where(p =>
|
||||||
|
{
|
||||||
|
if (name != null && name != p.Name)
|
||||||
|
return false;
|
||||||
|
if (propertyType != null && propertyType != p.PropertyType)
|
||||||
|
return false;
|
||||||
|
if (indexParameters != null)
|
||||||
|
{
|
||||||
|
if (!p.GetIndexParameters().Select(ip => ip.ParameterType).SequenceEqual(indexParameters))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}).SingleOrDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IEnumerable<MemberInfo> GetMember(this Type type, string name, MemberTypes memberType, BindingFlags bindingFlags)
|
||||||
|
{
|
||||||
|
return type.GetTypeInfo().GetMembersRecursive().Where(m =>
|
||||||
|
{
|
||||||
|
if (name != null && name != m.Name)
|
||||||
|
return false;
|
||||||
|
if (m.MemberType() != memberType)
|
||||||
|
return false;
|
||||||
|
if (!TestAccessibility(m, bindingFlags))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IEnumerable<ConstructorInfo> GetConstructors(this Type type)
|
||||||
|
{
|
||||||
|
return type.GetConstructors(DefaultFlags);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IEnumerable<ConstructorInfo> GetConstructors(this Type type, BindingFlags bindingFlags)
|
||||||
|
{
|
||||||
|
return type.GetConstructors(bindingFlags, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IEnumerable<ConstructorInfo> GetConstructors(this Type type, BindingFlags bindingFlags, IList<Type> parameterTypes)
|
||||||
|
{
|
||||||
|
return type.GetTypeInfo().DeclaredConstructors.Where(c =>
|
||||||
|
{
|
||||||
|
if (!TestAccessibility(c, bindingFlags))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (parameterTypes != null && !c.GetParameters().Select(p => p.ParameterType).SequenceEqual(parameterTypes))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ConstructorInfo GetConstructor(this Type type, IList<Type> parameterTypes)
|
||||||
|
{
|
||||||
|
return type.GetConstructor(DefaultFlags, null, parameterTypes, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ConstructorInfo GetConstructor(this Type type, BindingFlags bindingFlags, object placeholder1, IList<Type> parameterTypes, object placeholder2)
|
||||||
|
{
|
||||||
|
return type.GetConstructors(bindingFlags, parameterTypes).SingleOrDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MemberInfo[] GetMember(this Type type, string member)
|
||||||
|
{
|
||||||
|
return type.GetMember(member, DefaultFlags);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MemberInfo[] GetMember(this Type type, string member, BindingFlags bindingFlags)
|
||||||
|
{
|
||||||
|
return type.GetTypeInfo().GetMembersRecursive().Where(m => m.Name == member && TestAccessibility(m, bindingFlags)).ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MemberInfo GetField(this Type type, string member)
|
||||||
|
{
|
||||||
|
return type.GetField(member, DefaultFlags);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MemberInfo GetField(this Type type, string member, BindingFlags bindingFlags)
|
||||||
|
{
|
||||||
|
return type.GetTypeInfo().GetDeclaredField(member);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IEnumerable<PropertyInfo> GetProperties(this Type type, BindingFlags bindingFlags)
|
||||||
|
{
|
||||||
|
IList<PropertyInfo> properties = (bindingFlags.HasFlag(BindingFlags.DeclaredOnly))
|
||||||
|
? type.GetTypeInfo().DeclaredProperties.ToList()
|
||||||
|
: type.GetTypeInfo().GetPropertiesRecursive();
|
||||||
|
|
||||||
|
return properties.Where(p => TestAccessibility(p, bindingFlags));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IList<MemberInfo> GetMembersRecursive(this TypeInfo type)
|
||||||
|
{
|
||||||
|
TypeInfo t = type;
|
||||||
|
IList<MemberInfo> members = new List<MemberInfo>();
|
||||||
|
while (t != null)
|
||||||
|
{
|
||||||
|
foreach (var member in t.DeclaredMembers)
|
||||||
|
{
|
||||||
|
if (!members.Any(p => p.Name == member.Name))
|
||||||
|
members.Add(member);
|
||||||
|
}
|
||||||
|
t = (t.BaseType != null) ? t.BaseType.GetTypeInfo() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return members;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IList<PropertyInfo> GetPropertiesRecursive(this TypeInfo type)
|
||||||
|
{
|
||||||
|
TypeInfo t = type;
|
||||||
|
IList<PropertyInfo> properties = new List<PropertyInfo>();
|
||||||
|
while (t != null)
|
||||||
|
{
|
||||||
|
foreach (var member in t.DeclaredProperties)
|
||||||
|
{
|
||||||
|
if (!properties.Any(p => p.Name == member.Name))
|
||||||
|
properties.Add(member);
|
||||||
|
}
|
||||||
|
t = (t.BaseType != null) ? t.BaseType.GetTypeInfo() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IList<FieldInfo> GetFieldsRecursive(this TypeInfo type)
|
||||||
|
{
|
||||||
|
TypeInfo t = type;
|
||||||
|
IList<FieldInfo> fields = new List<FieldInfo>();
|
||||||
|
while (t != null)
|
||||||
|
{
|
||||||
|
foreach (var member in t.DeclaredFields)
|
||||||
|
{
|
||||||
|
if (!fields.Any(p => p.Name == member.Name))
|
||||||
|
fields.Add(member);
|
||||||
|
}
|
||||||
|
t = (t.BaseType != null) ? t.BaseType.GetTypeInfo() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return fields;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IEnumerable<MethodInfo> GetMethods(this Type type, BindingFlags bindingFlags)
|
||||||
|
{
|
||||||
|
return type.GetTypeInfo().DeclaredMethods;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PropertyInfo GetProperty(this Type type, string name)
|
||||||
|
{
|
||||||
|
return type.GetProperty(name, DefaultFlags);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PropertyInfo GetProperty(this Type type, string name, BindingFlags bindingFlags)
|
||||||
|
{
|
||||||
|
return type.GetTypeInfo().GetDeclaredProperty(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IEnumerable<FieldInfo> GetFields(this Type type)
|
||||||
|
{
|
||||||
|
return type.GetFields(DefaultFlags);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IEnumerable<FieldInfo> GetFields(this Type type, BindingFlags bindingFlags)
|
||||||
|
{
|
||||||
|
IList<FieldInfo> fields = (bindingFlags.HasFlag(BindingFlags.DeclaredOnly))
|
||||||
|
? type.GetTypeInfo().DeclaredFields.ToList()
|
||||||
|
: type.GetTypeInfo().GetFieldsRecursive();
|
||||||
|
|
||||||
|
return fields.Where(f => TestAccessibility(f, bindingFlags)).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool TestAccessibility(PropertyInfo member, BindingFlags bindingFlags)
|
||||||
|
{
|
||||||
|
if (member.GetMethod != null && TestAccessibility(member.GetMethod, bindingFlags))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (member.SetMethod != null && TestAccessibility(member.SetMethod, bindingFlags))
|
||||||
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
private static bool TestAccessibility(MemberInfo member, BindingFlags bindingFlags)
|
||||||
}).SingleOrDefault();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IEnumerable<MemberInfo> GetMember(this Type type, string name, MemberTypes memberType, BindingFlags bindingFlags)
|
|
||||||
{
|
|
||||||
return type.GetTypeInfo().GetMembersRecursive().Where(m =>
|
|
||||||
{
|
|
||||||
if (name != null && name != m.Name)
|
|
||||||
return false;
|
|
||||||
if (m.MemberType() != memberType)
|
|
||||||
return false;
|
|
||||||
if (!TestAccessibility(m, bindingFlags))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IEnumerable<ConstructorInfo> GetConstructors(this Type type)
|
|
||||||
{
|
|
||||||
return type.GetConstructors(DefaultFlags);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IEnumerable<ConstructorInfo> GetConstructors(this Type type, BindingFlags bindingFlags)
|
|
||||||
{
|
|
||||||
return type.GetConstructors(bindingFlags, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static IEnumerable<ConstructorInfo> GetConstructors(this Type type, BindingFlags bindingFlags, IList<Type> parameterTypes)
|
|
||||||
{
|
|
||||||
return type.GetTypeInfo().DeclaredConstructors.Where(c =>
|
|
||||||
{
|
|
||||||
if (!TestAccessibility(c, bindingFlags))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (parameterTypes != null && !c.GetParameters().Select(p => p.ParameterType).SequenceEqual(parameterTypes))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ConstructorInfo GetConstructor(this Type type, IList<Type> parameterTypes)
|
|
||||||
{
|
|
||||||
return type.GetConstructor(DefaultFlags, null, parameterTypes, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ConstructorInfo GetConstructor(this Type type, BindingFlags bindingFlags, object placeholder1, IList<Type> parameterTypes, object placeholder2)
|
|
||||||
{
|
|
||||||
return type.GetConstructors(bindingFlags, parameterTypes).SingleOrDefault();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static MemberInfo[] GetMember(this Type type, string member)
|
|
||||||
{
|
|
||||||
return type.GetMember(member, DefaultFlags);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static MemberInfo[] GetMember(this Type type, string member, BindingFlags bindingFlags)
|
|
||||||
{
|
|
||||||
return type.GetTypeInfo().GetMembersRecursive().Where(m => m.Name == member && TestAccessibility(m, bindingFlags)).ToArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static MemberInfo GetField(this Type type, string member)
|
|
||||||
{
|
|
||||||
return type.GetField(member, DefaultFlags);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static MemberInfo GetField(this Type type, string member, BindingFlags bindingFlags)
|
|
||||||
{
|
|
||||||
return type.GetTypeInfo().GetDeclaredField(member);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IEnumerable<PropertyInfo> GetProperties(this Type type, BindingFlags bindingFlags)
|
|
||||||
{
|
|
||||||
IList<PropertyInfo> properties = (bindingFlags.HasFlag(BindingFlags.DeclaredOnly))
|
|
||||||
? type.GetTypeInfo().DeclaredProperties.ToList()
|
|
||||||
: type.GetTypeInfo().GetPropertiesRecursive();
|
|
||||||
|
|
||||||
return properties.Where(p => TestAccessibility(p, bindingFlags));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static IList<MemberInfo> GetMembersRecursive(this TypeInfo type)
|
|
||||||
{
|
|
||||||
TypeInfo t = type;
|
|
||||||
IList<MemberInfo> members = new List<MemberInfo>();
|
|
||||||
while (t != null)
|
|
||||||
{
|
|
||||||
foreach (var member in t.DeclaredMembers)
|
|
||||||
{
|
{
|
||||||
if (!members.Any(p => p.Name == member.Name))
|
if (member is FieldInfo)
|
||||||
members.Add(member);
|
{
|
||||||
|
return TestAccessibility((FieldInfo) member, bindingFlags);
|
||||||
|
}
|
||||||
|
else if (member is MethodBase)
|
||||||
|
{
|
||||||
|
return TestAccessibility((MethodBase) member, bindingFlags);
|
||||||
|
}
|
||||||
|
else if (member is PropertyInfo)
|
||||||
|
{
|
||||||
|
return TestAccessibility((PropertyInfo) member, bindingFlags);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Exception("Unexpected member type.");
|
||||||
}
|
}
|
||||||
t = (t.BaseType != null) ? t.BaseType.GetTypeInfo() : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return members;
|
private static bool TestAccessibility(FieldInfo member, BindingFlags bindingFlags)
|
||||||
}
|
|
||||||
|
|
||||||
private static IList<PropertyInfo> GetPropertiesRecursive(this TypeInfo type)
|
|
||||||
{
|
|
||||||
TypeInfo t = type;
|
|
||||||
IList<PropertyInfo> properties = new List<PropertyInfo>();
|
|
||||||
while (t != null)
|
|
||||||
{
|
|
||||||
foreach (var member in t.DeclaredProperties)
|
|
||||||
{
|
{
|
||||||
if (!properties.Any(p => p.Name == member.Name))
|
bool visibility = (member.IsPublic && bindingFlags.HasFlag(BindingFlags.Public)) ||
|
||||||
properties.Add(member);
|
(!member.IsPublic && bindingFlags.HasFlag(BindingFlags.NonPublic));
|
||||||
|
|
||||||
|
bool instance = (member.IsStatic && bindingFlags.HasFlag(BindingFlags.Static)) ||
|
||||||
|
(!member.IsStatic && bindingFlags.HasFlag(BindingFlags.Instance));
|
||||||
|
|
||||||
|
return visibility && instance;
|
||||||
}
|
}
|
||||||
t = (t.BaseType != null) ? t.BaseType.GetTypeInfo() : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return properties;
|
private static bool TestAccessibility(MethodBase member, BindingFlags bindingFlags)
|
||||||
}
|
|
||||||
|
|
||||||
private static IList<FieldInfo> GetFieldsRecursive(this TypeInfo type)
|
|
||||||
{
|
|
||||||
TypeInfo t = type;
|
|
||||||
IList<FieldInfo> fields = new List<FieldInfo>();
|
|
||||||
while (t != null)
|
|
||||||
{
|
|
||||||
foreach (var member in t.DeclaredFields)
|
|
||||||
{
|
{
|
||||||
if (!fields.Any(p => p.Name == member.Name))
|
bool visibility = (member.IsPublic && bindingFlags.HasFlag(BindingFlags.Public)) ||
|
||||||
fields.Add(member);
|
(!member.IsPublic && bindingFlags.HasFlag(BindingFlags.NonPublic));
|
||||||
|
|
||||||
|
bool instance = (member.IsStatic && bindingFlags.HasFlag(BindingFlags.Static)) ||
|
||||||
|
(!member.IsStatic && bindingFlags.HasFlag(BindingFlags.Instance));
|
||||||
|
|
||||||
|
return visibility && instance;
|
||||||
}
|
}
|
||||||
t = (t.BaseType != null) ? t.BaseType.GetTypeInfo() : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return fields;
|
public static Type[] GetGenericArguments(this Type type)
|
||||||
}
|
{
|
||||||
|
return type.GetTypeInfo().GenericTypeArguments;
|
||||||
|
}
|
||||||
|
|
||||||
public static IEnumerable<MethodInfo> GetMethods(this Type type, BindingFlags bindingFlags)
|
public static IEnumerable<Type> GetInterfaces(this Type type)
|
||||||
{
|
{
|
||||||
return type.GetTypeInfo().DeclaredMethods;
|
return type.GetTypeInfo().ImplementedInterfaces;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PropertyInfo GetProperty(this Type type, string name)
|
public static IEnumerable<MethodInfo> GetMethods(this Type type)
|
||||||
{
|
{
|
||||||
return type.GetProperty(name, DefaultFlags);
|
return type.GetTypeInfo().DeclaredMethods;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PropertyInfo GetProperty(this Type type, string name, BindingFlags bindingFlags)
|
|
||||||
{
|
|
||||||
return type.GetTypeInfo().GetDeclaredProperty(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IEnumerable<FieldInfo> GetFields(this Type type)
|
|
||||||
{
|
|
||||||
return type.GetFields(DefaultFlags);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IEnumerable<FieldInfo> GetFields(this Type type, BindingFlags bindingFlags)
|
|
||||||
{
|
|
||||||
IList<FieldInfo> fields = (bindingFlags.HasFlag(BindingFlags.DeclaredOnly))
|
|
||||||
? type.GetTypeInfo().DeclaredFields.ToList()
|
|
||||||
: type.GetTypeInfo().GetFieldsRecursive();
|
|
||||||
|
|
||||||
return fields.Where(f => TestAccessibility(f, bindingFlags)).ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static bool TestAccessibility(PropertyInfo member, BindingFlags bindingFlags)
|
|
||||||
{
|
|
||||||
if (member.GetMethod != null && TestAccessibility(member.GetMethod, bindingFlags))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
if (member.SetMethod != null && TestAccessibility(member.SetMethod, bindingFlags))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static bool TestAccessibility(MemberInfo member, BindingFlags bindingFlags)
|
|
||||||
{
|
|
||||||
if (member is FieldInfo)
|
|
||||||
{
|
|
||||||
return TestAccessibility((FieldInfo)member, bindingFlags);
|
|
||||||
}
|
|
||||||
else if (member is MethodBase)
|
|
||||||
{
|
|
||||||
return TestAccessibility((MethodBase)member, bindingFlags);
|
|
||||||
}
|
|
||||||
else if (member is PropertyInfo)
|
|
||||||
{
|
|
||||||
return TestAccessibility((PropertyInfo)member, bindingFlags);
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new Exception("Unexpected member type.");
|
|
||||||
}
|
|
||||||
|
|
||||||
private static bool TestAccessibility(FieldInfo member, BindingFlags bindingFlags)
|
|
||||||
{
|
|
||||||
bool visibility = (member.IsPublic && bindingFlags.HasFlag(BindingFlags.Public)) ||
|
|
||||||
(!member.IsPublic && bindingFlags.HasFlag(BindingFlags.NonPublic));
|
|
||||||
|
|
||||||
bool instance = (member.IsStatic && bindingFlags.HasFlag(BindingFlags.Static)) ||
|
|
||||||
(!member.IsStatic && bindingFlags.HasFlag(BindingFlags.Instance));
|
|
||||||
|
|
||||||
return visibility && instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static bool TestAccessibility(MethodBase member, BindingFlags bindingFlags)
|
|
||||||
{
|
|
||||||
bool visibility = (member.IsPublic && bindingFlags.HasFlag(BindingFlags.Public)) ||
|
|
||||||
(!member.IsPublic && bindingFlags.HasFlag(BindingFlags.NonPublic));
|
|
||||||
|
|
||||||
bool instance = (member.IsStatic && bindingFlags.HasFlag(BindingFlags.Static)) ||
|
|
||||||
(!member.IsStatic && bindingFlags.HasFlag(BindingFlags.Instance));
|
|
||||||
|
|
||||||
return visibility && instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Type[] GetGenericArguments(this Type type)
|
|
||||||
{
|
|
||||||
return type.GetTypeInfo().GenericTypeArguments;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IEnumerable<Type> GetInterfaces(this Type type)
|
|
||||||
{
|
|
||||||
return type.GetTypeInfo().ImplementedInterfaces;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IEnumerable<MethodInfo> GetMethods(this Type type)
|
|
||||||
{
|
|
||||||
return type.GetTypeInfo().DeclaredMethods;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
public static bool IsAbstract(this Type type)
|
public static bool IsAbstract(this Type type)
|
||||||
@@ -508,7 +516,7 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
#if !(NETFX_CORE || PORTABLE)
|
#if !(NETFX_CORE || PORTABLE)
|
||||||
return type.IsAbstract;
|
return type.IsAbstract;
|
||||||
#else
|
#else
|
||||||
return type.GetTypeInfo().IsAbstract;
|
return type.GetTypeInfo().IsAbstract;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -517,7 +525,7 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
#if !(NETFX_CORE || PORTABLE)
|
#if !(NETFX_CORE || PORTABLE)
|
||||||
return type.IsVisible;
|
return type.IsVisible;
|
||||||
#else
|
#else
|
||||||
return type.GetTypeInfo().IsVisible;
|
return type.GetTypeInfo().IsVisible;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -526,7 +534,7 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
#if !(NETFX_CORE || PORTABLE)
|
#if !(NETFX_CORE || PORTABLE)
|
||||||
return type.IsValueType;
|
return type.IsValueType;
|
||||||
#else
|
#else
|
||||||
return type.GetTypeInfo().IsValueType;
|
return type.GetTypeInfo().IsValueType;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -609,8 +617,8 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
allTypes.Add(target);
|
allTypes.Add(target);
|
||||||
|
|
||||||
return from type in allTypes
|
return from type in allTypes
|
||||||
from method in type.GetMethods()
|
from method in type.GetMethods()
|
||||||
select method;
|
select method;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user