-Changed MetadataTypeAttribute to use GetCustomeAttributes to support .NET 4.0 PCL
This commit is contained in:
+2
-6
@@ -173,8 +173,7 @@ function CoreClrTests($build)
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
Set-Location "$sourceDir\Newtonsoft.Json.Tests"
|
Set-Location "$sourceDir\Newtonsoft.Json.Tests"
|
||||||
$logPath = "$workingDir\$name.txt"
|
k --configuration Release test -parallel none | Tee-Object -file "$workingDir\$name.txt"
|
||||||
k --configuration Release test -parallel none | Tee-Object -file $logPath
|
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
@@ -196,10 +195,7 @@ function WinRTTests($build)
|
|||||||
|
|
||||||
Write-Host -ForegroundColor Green "Running MSTest tests " $name
|
Write-Host -ForegroundColor Green "Running MSTest tests " $name
|
||||||
Write-Host
|
Write-Host
|
||||||
exec { &($testCmd) $outDir\$name\AppPackages\$($name)_1.0.0.0_AnyCPU_Debug_Test\$($name)_1.0.0.0_AnyCPU_Debug.appx /InIsolation /Logger:trx | Out-Default } "Error running $name tests"
|
exec { &($testCmd) $outDir\$name\AppPackages\$($name)_1.0.0.0_AnyCPU_Debug_Test\$($name)_1.0.0.0_AnyCPU_Debug.appx /InIsolation | Tee-Object -file "$workingDir\$name.txt" } "Error running $name tests"
|
||||||
|
|
||||||
robocopy $baseDir\TestResults $workingDir /NP | Out-Default
|
|
||||||
del $baseDir\TestResults -Recurse -Force
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function NUnitTests($build)
|
function NUnitTests($build)
|
||||||
|
|||||||
@@ -2527,7 +2527,7 @@ keyword such as type of business.""
|
|||||||
Assert.AreEqual("titleId", n.FidOrder[n.FidOrder.Count - 1]);
|
Assert.AreEqual("titleId", n.FidOrder[n.FidOrder.Count - 1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !(NET20 || NETFX_CORE || ASPNETCORE50 || PORTABLE40)
|
#if !(NET20 || NETFX_CORE || ASPNETCORE50)
|
||||||
[MetadataType(typeof(OptInClassMetadata))]
|
[MetadataType(typeof(OptInClassMetadata))]
|
||||||
public class OptInClass
|
public class OptInClass
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -59,8 +59,9 @@ namespace Newtonsoft.Json.Serialization
|
|||||||
private static readonly ThreadSafeStore<Type, Func<object[], JsonConverter>> JsonConverterCreatorCache =
|
private static readonly ThreadSafeStore<Type, Func<object[], JsonConverter>> JsonConverterCreatorCache =
|
||||||
new ThreadSafeStore<Type, Func<object[], JsonConverter>>(GetJsonConverterCreator);
|
new ThreadSafeStore<Type, Func<object[], JsonConverter>>(GetJsonConverterCreator);
|
||||||
|
|
||||||
#if !(NET20 || PORTABLE40 || NETFX_CORE)
|
#if !(NET20 || NETFX_CORE)
|
||||||
private static readonly ThreadSafeStore<Type, Type> AssociatedMetadataTypesCache = new ThreadSafeStore<Type, Type>(GetAssociateMetadataTypeFromAttribute);
|
private static readonly ThreadSafeStore<Type, Type> AssociatedMetadataTypesCache = new ThreadSafeStore<Type, Type>(GetAssociateMetadataTypeFromAttribute);
|
||||||
|
private static ReflectionObject _metadataTypeAttributeReflectionObject;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
public static T GetCachedAttribute<T>(object attributeProvider) where T : Attribute
|
public static T GetCachedAttribute<T>(object attributeProvider) where T : Attribute
|
||||||
@@ -220,7 +221,7 @@ namespace Newtonsoft.Json.Serialization
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !(NET20 || PORTABLE40 || NETFX_CORE)
|
#if !(NET20 || NETFX_CORE)
|
||||||
private static Type GetAssociatedMetadataType(Type type)
|
private static Type GetAssociatedMetadataType(Type type)
|
||||||
{
|
{
|
||||||
return AssociatedMetadataTypesCache.Get(type);
|
return AssociatedMetadataTypesCache.Get(type);
|
||||||
@@ -228,26 +229,26 @@ namespace Newtonsoft.Json.Serialization
|
|||||||
|
|
||||||
private static Type GetAssociateMetadataTypeFromAttribute(Type type)
|
private static Type GetAssociateMetadataTypeFromAttribute(Type type)
|
||||||
{
|
{
|
||||||
IList<CustomAttributeData> customAttributes = ReflectionUtils.GetCustomAttributeData(type);
|
object[] customAttributes;
|
||||||
|
#if !PORTABLE
|
||||||
foreach (CustomAttributeData customAttributeData in customAttributes)
|
customAttributes = type.GetCustomAttributes(false);
|
||||||
{
|
|
||||||
Type attributeType;
|
|
||||||
|
|
||||||
#if (NET20 || NET35 || NET40)
|
|
||||||
attributeType = customAttributeData.Constructor.DeclaringType;
|
|
||||||
#else
|
#else
|
||||||
attributeType = customAttributeData.AttributeType;
|
customAttributes = type.GetTypeInfo().GetCustomAttributes(false).Cast<object>().ToArray();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (attributeType != null
|
foreach (var attribute in customAttributes)
|
||||||
&& string.Equals(attributeType.Name, "MetadataTypeAttribute", StringComparison.Ordinal)
|
{
|
||||||
&& attributeType.Assembly().GetName().Name == "System.ComponentModel.DataAnnotations")
|
Type attributeType = attribute.GetType();
|
||||||
{
|
|
||||||
// MetadataTypeAttribute constructor takes one argument, the type we're looking for
|
|
||||||
CustomAttributeTypedArgument o = customAttributeData.ConstructorArguments[0];
|
|
||||||
|
|
||||||
return (Type)o.Value;
|
if (string.Equals(attributeType.Name, "MetadataTypeAttribute", StringComparison.Ordinal)
|
||||||
|
&& attributeType.Assembly().FullName.StartsWith("System.ComponentModel.DataAnnotations", StringComparison.Ordinal))
|
||||||
|
{
|
||||||
|
const string metadataClassTypeName = "MetadataClassType";
|
||||||
|
|
||||||
|
if (_metadataTypeAttributeReflectionObject == null)
|
||||||
|
_metadataTypeAttributeReflectionObject = ReflectionObject.Create(attributeType, metadataClassTypeName);
|
||||||
|
|
||||||
|
return (Type)_metadataTypeAttributeReflectionObject.GetValue(attribute, metadataClassTypeName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -259,7 +260,7 @@ namespace Newtonsoft.Json.Serialization
|
|||||||
{
|
{
|
||||||
T attribute;
|
T attribute;
|
||||||
|
|
||||||
#if !(NET20 || PORTABLE40 || NETFX_CORE)
|
#if !(NET20 || NETFX_CORE)
|
||||||
Type metadataType = GetAssociatedMetadataType(type);
|
Type metadataType = GetAssociatedMetadataType(type);
|
||||||
if (metadataType != null)
|
if (metadataType != null)
|
||||||
{
|
{
|
||||||
@@ -287,7 +288,7 @@ namespace Newtonsoft.Json.Serialization
|
|||||||
{
|
{
|
||||||
T attribute;
|
T attribute;
|
||||||
|
|
||||||
#if !(NET20 || PORTABLE40 || NETFX_CORE)
|
#if !(NET20 || NETFX_CORE)
|
||||||
Type metadataType = GetAssociatedMetadataType(memberInfo.DeclaringType);
|
Type metadataType = GetAssociatedMetadataType(memberInfo.DeclaringType);
|
||||||
if (metadataType != null)
|
if (metadataType != null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -732,17 +732,6 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !PORTABLE40
|
|
||||||
public static IList<CustomAttributeData> GetCustomAttributeData(Type t)
|
|
||||||
{
|
|
||||||
#if !(NETFX_CORE || ASPNETCORE50 || PORTABLE)
|
|
||||||
return CustomAttributeData.GetCustomAttributes(t);
|
|
||||||
#else
|
|
||||||
return t.GetTypeInfo().CustomAttributes.ToList();
|
|
||||||
#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)
|
||||||
{
|
{
|
||||||
int? assemblyDelimiterIndex = GetAssemblyDelimiterIndex(fullyQualifiedTypeName);
|
int? assemblyDelimiterIndex = GetAssemblyDelimiterIndex(fullyQualifiedTypeName);
|
||||||
|
|||||||
Reference in New Issue
Block a user