Skip to content

Made ParseClient.ConvertTo() a public API. #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Parse/Internal/Cloud/Controller/ParseCloudCodeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Parse.Utilities;

namespace Parse.Internal {
internal class ParseCloudCodeController : IParseCloudCodeController {
Expand All @@ -27,7 +28,7 @@ public Task<T> CallFunctionAsync<T>(String name,
if (!decoded.ContainsKey("result")) {
return default(T);
}
return (T)ParseClient.ConvertTo<T>(decoded["result"]);
return (T)Conversion.ConvertTo<T>(decoded["result"]);
});
}
}
Expand Down
5 changes: 3 additions & 2 deletions Parse/Internal/Encoding/ParseDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using System.Collections.Generic;
using System.Globalization;
using Parse.Utilities;

namespace Parse.Internal {
internal class ParseDecoder {
Expand Down Expand Up @@ -59,8 +60,8 @@ public object Decode(object data) {
}

if (typeString == "GeoPoint") {
return new ParseGeoPoint((double)ParseClient.ConvertTo<double>(dict["latitude"]),
(double)ParseClient.ConvertTo<double>(dict["longitude"]));
return new ParseGeoPoint((double)Conversion.ConvertTo<double>(dict["latitude"]),
(double)Conversion.ConvertTo<double>(dict["longitude"]));
}

if (typeString == "Object") {
Expand Down
9 changes: 5 additions & 4 deletions Parse/Internal/Encoding/ParseEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using Parse.Utilities;

namespace Parse.Internal {
/// <summary>
Expand All @@ -23,8 +24,8 @@ value is ParseGeoPoint ||
value is ParseRelationBase ||
value is DateTime ||
value is byte[] ||
ParseClient.ConvertTo<IDictionary<string, object>>(value) is IDictionary<string, object> ||
ParseClient.ConvertTo<IList<object>>(value) is IList<object>;
Conversion.ConvertTo<IDictionary<string, object>>(value) is IDictionary<string, object> ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure we can, but use the public API?

Conversion.ConvertTo<IList<object>>(value) is IList<object>;
}

public object Encode(object value) {
Expand Down Expand Up @@ -55,7 +56,7 @@ public object Encode(object value) {
return jsonConvertible.ToJSON();
}

var dict = ParseClient.ConvertTo<IDictionary<string, object>>(value) as IDictionary<string, object>;
var dict = Conversion.ConvertTo<IDictionary<string, object>>(value) as IDictionary<string, object>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the public API (As<>)

if (dict != null) {
var json = new Dictionary<string, object>();
foreach (var pair in dict) {
Expand All @@ -64,7 +65,7 @@ public object Encode(object value) {
return json;
}

var list = ParseClient.ConvertTo<IList<object>>(value) as IList<object>;
var list = Conversion.ConvertTo<IList<object>>(value) as IList<object>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the public API

if (list != null) {
return EncodeList(list);
}
Expand Down
3 changes: 2 additions & 1 deletion Parse/Internal/Object/Controller/ParseObjectController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Parse.Utilities;

namespace Parse.Internal {
internal class ParseObjectController : IParseObjectController {
Expand Down Expand Up @@ -163,7 +164,7 @@ private IList<Task<IDictionary<string, object>>> ExecuteBatchRequest(IList<Parse
return;
}

var resultsArray = ParseClient.As<IList<object>>(t.Result.Item2["results"]);
var resultsArray = Conversion.As<IList<object>>(t.Result.Item2["results"]);
int resultLength = resultsArray.Count;
if (resultLength != batchSize) {
foreach (var tcs in tcss) {
Expand Down
5 changes: 3 additions & 2 deletions Parse/Internal/Operation/ParseAddOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Parse.Utilities;

namespace Parse.Internal {
class ParseAddOperation : IParseFieldOperation {
Expand All @@ -28,7 +29,7 @@ public IParseFieldOperation MergeWithPrevious(IParseFieldOperation previous) {
}
if (previous is ParseSetOperation) {
var setOp = (ParseSetOperation)previous;
var oldList = (IList<object>)ParseClient.ConvertTo<IList<object>>(setOp.Value);
var oldList = (IList<object>)Conversion.ConvertTo<IList<object>>(setOp.Value);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the public API

return new ParseSetOperation(oldList.Concat(objects).ToList());
}
if (previous is ParseAddOperation) {
Expand All @@ -41,7 +42,7 @@ public object Apply(object oldValue, string key) {
if (oldValue == null) {
return objects.ToList();
}
var oldList = (IList<object>)ParseClient.ConvertTo<IList<object>>(oldValue);
var oldList = (IList<object>)Conversion.ConvertTo<IList<object>>(oldValue);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the public API

return oldList.Concat(objects).ToList();
}

Expand Down
5 changes: 3 additions & 2 deletions Parse/Internal/Operation/ParseAddUniqueOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Parse.Utilities;

namespace Parse.Internal {
class ParseAddUniqueOperation : IParseFieldOperation {
Expand All @@ -28,7 +29,7 @@ public IParseFieldOperation MergeWithPrevious(IParseFieldOperation previous) {
}
if (previous is ParseSetOperation) {
var setOp = (ParseSetOperation)previous;
var oldList = (IList<object>)ParseClient.ConvertTo<IList<object>>(setOp.Value);
var oldList = (IList<object>)Conversion.ConvertTo<IList<object>>(setOp.Value);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the public API

var result = this.Apply(oldList, null);
return new ParseSetOperation(result);
}
Expand All @@ -43,7 +44,7 @@ public object Apply(object oldValue, string key) {
if (oldValue == null) {
return objects.ToList();
}
var newList = ((IList<object>)ParseClient.ConvertTo<IList<object>>(oldValue)).ToList();
var newList = ((IList<object>)Conversion.ConvertTo<IList<object>>(oldValue)).ToList();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the public API

var comparer = ParseFieldOperations.ParseObjectComparer;
foreach (var objToAdd in objects) {
if (objToAdd is ParseObject) {
Expand Down
6 changes: 4 additions & 2 deletions Parse/Internal/Operation/ParseRemoveOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using System.Collections.ObjectModel;
using System.Linq;

using Parse.Utilities;

namespace Parse.Internal {
class ParseRemoveOperation : IParseFieldOperation {
private ReadOnlyCollection<object> objects;
Expand All @@ -28,7 +30,7 @@ public IParseFieldOperation MergeWithPrevious(IParseFieldOperation previous) {
}
if (previous is ParseSetOperation) {
var setOp = (ParseSetOperation)previous;
var oldList = (IList<object>)ParseClient.ConvertTo<IList<object>>(setOp.Value);
var oldList = Conversion.As<IList<object>>(setOp.Value);
return new ParseSetOperation(this.Apply(oldList, null));
}
if (previous is ParseRemoveOperation) {
Expand All @@ -42,7 +44,7 @@ public object Apply(object oldValue,string key) {
if (oldValue == null) {
return new List<object>();
}
var oldList = (IList<object>)ParseClient.ConvertTo<IList<object>>(oldValue);
var oldList = Conversion.As<IList<object>>(oldValue);
return oldList.Except(objects, ParseFieldOperations.ParseObjectComparer).ToList();
}

Expand Down
21 changes: 11 additions & 10 deletions Parse/Internal/Utilities/FlexibleDictionaryWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using System.Collections.Generic;
using System.Linq;
using Parse.Utilities;

#if IOS
using PreserveAttribute = Foundation.PreserveAttribute;
Expand All @@ -27,7 +28,7 @@ public FlexibleDictionaryWrapper(IDictionary<string, TIn> toWrap) {
}

public void Add(string key, TOut value) {
toWrap.Add(key, (TIn)ParseClient.ConvertTo<TIn>(value));
toWrap.Add(key, (TIn)Conversion.ConvertTo<TIn>(value));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the public API

}

public bool ContainsKey(string key) {
Expand All @@ -45,29 +46,29 @@ public bool Remove(string key) {
public bool TryGetValue(string key, out TOut value) {
TIn outValue;
bool result = toWrap.TryGetValue(key, out outValue);
value = (TOut)ParseClient.ConvertTo<TOut>(outValue);
value = (TOut)Conversion.ConvertTo<TOut>(outValue);
return result;
}

public ICollection<TOut> Values {
get {
return toWrap.Values
.Select(item => (TOut)ParseClient.ConvertTo<TOut>(item)).ToList();
.Select(item => (TOut)Conversion.ConvertTo<TOut>(item)).ToList();
}
}

public TOut this[string key] {
get {
return (TOut)ParseClient.ConvertTo<TOut>(toWrap[key]);
return (TOut)Conversion.ConvertTo<TOut>(toWrap[key]);
}
set {
toWrap[key] = (TIn)ParseClient.ConvertTo<TIn>(value);
toWrap[key] = (TIn)Conversion.ConvertTo<TIn>(value);
}
}

public void Add(KeyValuePair<string, TOut> item) {
toWrap.Add(new KeyValuePair<string, TIn>(item.Key,
(TIn)ParseClient.ConvertTo<TIn>(item.Value)));
(TIn)Conversion.ConvertTo<TIn>(item.Value)));
}

public void Clear() {
Expand All @@ -76,13 +77,13 @@ public void Clear() {

public bool Contains(KeyValuePair<string, TOut> item) {
return toWrap.Contains(new KeyValuePair<string, TIn>(item.Key,
(TIn)ParseClient.ConvertTo<TIn>(item.Value)));
(TIn)Conversion.ConvertTo<TIn>(item.Value)));
}

public void CopyTo(KeyValuePair<string, TOut>[] array, int arrayIndex) {
var converted = from pair in toWrap
select new KeyValuePair<string, TOut>(pair.Key,
(TOut)ParseClient.ConvertTo<TOut>(pair.Value));
(TOut)Conversion.ConvertTo<TOut>(pair.Value));
converted.ToList().CopyTo(array, arrayIndex);
}

Expand All @@ -96,13 +97,13 @@ public bool IsReadOnly {

public bool Remove(KeyValuePair<string, TOut> item) {
return toWrap.Remove(new KeyValuePair<string, TIn>(item.Key,
(TIn)ParseClient.ConvertTo<TIn>(item.Value)));
(TIn)Conversion.ConvertTo<TIn>(item.Value)));
}

public IEnumerator<KeyValuePair<string, TOut>> GetEnumerator() {
foreach (var pair in toWrap) {
yield return new KeyValuePair<string, TOut>(pair.Key,
(TOut)ParseClient.ConvertTo<TOut>(pair.Value));
(TOut)Conversion.ConvertTo<TOut>(pair.Value));
}
}

Expand Down
19 changes: 10 additions & 9 deletions Parse/Internal/Utilities/FlexibleListWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Parse.Utilities;

#if IOS
using PreserveAttribute = Foundation.PreserveAttribute;
Expand All @@ -28,11 +29,11 @@ public FlexibleListWrapper(IList<TIn> toWrap) {
}

public int IndexOf(TOut item) {
return toWrap.IndexOf((TIn)ParseClient.ConvertTo<TIn>(item));
return toWrap.IndexOf((TIn)Conversion.ConvertTo<TIn>(item));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the public API

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, important that the exception given here is useful. If we silently fail here we change behavior significantly, as IndexOf(null) is valid. Also, we literally cannot call As because we support value types here.

}

public void Insert(int index, TOut item) {
toWrap.Insert(index, (TIn)ParseClient.ConvertTo<TIn>(item));
toWrap.Insert(index, (TIn)Conversion.ConvertTo<TIn>(item));
}

public void RemoveAt(int index) {
Expand All @@ -41,27 +42,27 @@ public void RemoveAt(int index) {

public TOut this[int index] {
get {
return (TOut)ParseClient.ConvertTo<TOut>(toWrap[index]);
return (TOut)Conversion.ConvertTo<TOut>(toWrap[index]);
}
set {
toWrap[index] = (TIn)ParseClient.ConvertTo<TIn>(value);
toWrap[index] = (TIn)Conversion.ConvertTo<TIn>(value);
}
}

public void Add(TOut item) {
toWrap.Add((TIn)ParseClient.ConvertTo<TIn>(item));
toWrap.Add((TIn)Conversion.ConvertTo<TIn>(item));
}

public void Clear() {
toWrap.Clear();
}

public bool Contains(TOut item) {
return toWrap.Contains((TIn)ParseClient.ConvertTo<TIn>(item));
return toWrap.Contains((TIn)Conversion.ConvertTo<TIn>(item));
}

public void CopyTo(TOut[] array, int arrayIndex) {
toWrap.Select(item => (TOut)ParseClient.ConvertTo<TOut>(item))
toWrap.Select(item => (TOut)Conversion.ConvertTo<TOut>(item))
.ToList().CopyTo(array, arrayIndex);
}

Expand All @@ -74,12 +75,12 @@ public bool IsReadOnly {
}

public bool Remove(TOut item) {
return toWrap.Remove((TIn)ParseClient.ConvertTo<TIn>(item));
return toWrap.Remove((TIn)Conversion.ConvertTo<TIn>(item));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the public API

}

public IEnumerator<TOut> GetEnumerator() {
foreach (var item in (IEnumerable)toWrap) {
yield return (TOut)ParseClient.ConvertTo<TOut>(item);
yield return (TOut)Conversion.ConvertTo<TOut>(item);
}
}

Expand Down
Loading