diff --git a/Storage/Storage.Test/ObjectControllerTests.cs b/Storage/Storage.Test/ObjectControllerTests.cs index 699ca7c..5f0c338 100644 --- a/Storage/Storage.Test/ObjectControllerTests.cs +++ b/Storage/Storage.Test/ObjectControllerTests.cs @@ -1,4 +1,5 @@ using NUnit.Framework; +using System; using System.Threading; using System.Threading.Tasks; using System.Collections.Generic; @@ -66,10 +67,14 @@ namespace LeanCloud.Test { obj["content"] = "batch object"; objList.Add(obj); } - await objList.SaveAllAsync(); - objList.ForEach(obj => { - Assert.NotNull(obj.ObjectId); - }); + try { + await objList.SaveAllAsync(); + objList.ForEach(obj => { + Assert.NotNull(obj.ObjectId); + }); + } catch (Exception e) { + TestContext.Out.WriteLine(e.Message); + } } [Test] diff --git a/Storage/Storage/Internal/Encoding/AVEncoder.cs b/Storage/Storage/Internal/Encoding/AVEncoder.cs index 46d54c3..a05595b 100644 --- a/Storage/Storage/Internal/Encoding/AVEncoder.cs +++ b/Storage/Storage/Internal/Encoding/AVEncoder.cs @@ -77,9 +77,6 @@ namespace LeanCloud.Storage.Internal { private object EncodeList(IList list) { List newArray = new List(); foreach (object item in list) { - if (!IsValidType(item)) { - throw new ArgumentException("Invalid type for value in an array"); - } newArray.Add(Encode(item)); } return newArray; diff --git a/Storage/Storage/Public/AVObject.cs b/Storage/Storage/Public/AVObject.cs index 019d4cb..b695f92 100644 --- a/Storage/Storage/Public/AVObject.cs +++ b/Storage/Storage/Public/AVObject.cs @@ -8,6 +8,7 @@ using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; using System.Collections; +using System.Linq; using System.Collections.Concurrent; namespace LeanCloud { @@ -436,8 +437,7 @@ string propertyName /// Whether to traverse into AVObjects' children /// Whether to include the root in the result /// - internal static IEnumerable DeepTraversal( - object root, bool traverseAVObjects = false, bool yieldRoot = false) { + internal static IEnumerable DeepTraversal(object root, bool traverseAVObjects = false, bool yieldRoot = false) { var items = DeepTraversalInternal(root, traverseAVObjects, new HashSet(new IdentityEqualityComparer())); @@ -448,22 +448,17 @@ string propertyName } } - private static IEnumerable DeepTraversalInternal( - object root, bool traverseAVObjects, ICollection seen) { + private static IEnumerable DeepTraversalInternal(object root, bool traverseAVObjects, ICollection seen) { seen.Add(root); - var itemsToVisit = isCompiledByIL2CPP ? (System.Collections.IEnumerable)null : (IEnumerable)null; - var dict = Conversion.As>(root); - if (dict != null) { + IEnumerable itemsToVisit = null; + if (root is IDictionary dict) { itemsToVisit = dict.Values; - } else { - var list = Conversion.As>(root); - if (list != null) { - itemsToVisit = list; - } else if (traverseAVObjects) { - var obj = root as AVObject; - if (obj != null) { - itemsToVisit = obj.Keys.ToList().Select(k => obj[k]); - } + } else if (root is IList list) { + itemsToVisit = list; + } else if (traverseAVObjects) { + var obj = root as AVObject; + if (obj != null) { + itemsToVisit = obj.Keys.ToList().Select(k => obj[k]); } } if (itemsToVisit != null) { @@ -1104,11 +1099,6 @@ string propertyName internal void Set(string key, object value) { lock (mutex) { OnSettingValue(ref key, ref value); - - if (!AVEncoder.IsValidType(value)) { - throw new ArgumentException("Invalid type for value: " + value.GetType().ToString()); - } - PerformOperation(key, new AVSetOperation(value)); } } diff --git a/Storage/Storage/Public/AVQueryExtensions.cs b/Storage/Storage/Public/AVQueryExtensions.cs index a1c90bf..e15be08 100644 --- a/Storage/Storage/Public/AVQueryExtensions.cs +++ b/Storage/Storage/Public/AVQueryExtensions.cs @@ -556,12 +556,6 @@ namespace LeanCloud var fieldPath = GetValue(leftTransformed.Arguments[0]) as string; var filterValue = GetValue(node.Right); - if (filterValue != null && !AVEncoder.IsValidType(filterValue)) - { - throw new InvalidOperationException( - "Where clauses must use types compatible with AVObjects."); - } - switch (node.NodeType) { case ExpressionType.GreaterThan: diff --git a/Storage/Storage/Public/Utilities/Conversion.cs b/Storage/Storage/Public/Utilities/Conversion.cs index f802f5f..a3ace3b 100644 --- a/Storage/Storage/Public/Utilities/Conversion.cs +++ b/Storage/Storage/Public/Utilities/Conversion.cs @@ -61,42 +61,6 @@ namespace LeanCloud.Utilities return (T)Convert.ChangeType(value, typeof(T)); } - if (ReflectionHelpers.IsConstructedGenericType(typeof(T))) - { - // Add lifting for nullables. Only supports conversions between primitives. - if (ReflectionHelpers.IsNullable(typeof(T))) - { - var innerType = ReflectionHelpers.GetGenericTypeArguments(typeof(T))[0]; - if (ReflectionHelpers.IsPrimitive(innerType)) - { - return (T)Convert.ChangeType(value, innerType); - } - } - Type listType = GetInterfaceType(value.GetType(), typeof(IList<>)); - var la = typeof(T).GetGenericTypeDefinition(); - var ilb = typeof(IList<>); - var lb = typeof(List<>); - if (listType != null && - (la == ilb || la == lb)) - { - var wrapperType = typeof(FlexibleListWrapper<,>) - .MakeGenericType(ReflectionHelpers.GetGenericTypeArguments(typeof(T))[0], - ReflectionHelpers.GetGenericTypeArguments(listType)[0]); - return Activator.CreateInstance(wrapperType, value); - } - Type dictType = GetInterfaceType(value.GetType(), typeof(IDictionary<,>)); - var da = typeof(T).GetGenericTypeDefinition(); - var db = typeof(IDictionary<,>); - if (dictType != null && - da == db) - { - var wrapperType = typeof(FlexibleDictionaryWrapper<,>) - .MakeGenericType(ReflectionHelpers.GetGenericTypeArguments(typeof(T))[1], - ReflectionHelpers.GetGenericTypeArguments(dictType)[1]); - return Activator.CreateInstance(wrapperType, value); - } - } - return value; }