-
-
Notifications
You must be signed in to change notification settings - Fork 261
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
using System.Collections.Generic; | ||
using System.Globalization; | ||
using System.Linq; | ||
using Parse.Utilities; | ||
|
||
namespace Parse.Internal { | ||
/// <summary> | ||
|
@@ -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> || | ||
Conversion.ConvertTo<IList<object>>(value) is IList<object>; | ||
} | ||
|
||
public object Encode(object value) { | ||
|
@@ -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>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use the public API ( |
||
if (dict != null) { | ||
var json = new Dictionary<string, object>(); | ||
foreach (var pair in dict) { | ||
|
@@ -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>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use the public API |
||
if (list != null) { | ||
return EncodeList(list); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.Linq; | ||
using Parse.Utilities; | ||
|
||
namespace Parse.Internal { | ||
class ParseAddOperation : IParseFieldOperation { | ||
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use the public API |
||
return oldList.Concat(objects).ToList(); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.Linq; | ||
using Parse.Utilities; | ||
|
||
namespace Parse.Internal { | ||
class ParseAddUniqueOperation : IParseFieldOperation { | ||
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
} | ||
|
@@ -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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Parse.Utilities; | ||
|
||
#if IOS | ||
using PreserveAttribute = Foundation.PreserveAttribute; | ||
|
@@ -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)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use the public API |
||
} | ||
|
||
public bool ContainsKey(string key) { | ||
|
@@ -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() { | ||
|
@@ -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); | ||
} | ||
|
||
|
@@ -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)); | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Parse.Utilities; | ||
|
||
#if IOS | ||
using PreserveAttribute = Foundation.PreserveAttribute; | ||
|
@@ -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)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use the public API There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
} | ||
|
||
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) { | ||
|
@@ -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); | ||
} | ||
|
||
|
@@ -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)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
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?