Skip to content

Commit 4241566

Browse files
committed
Style cleanup
1 parent 6a9b802 commit 4241566

36 files changed

+745
-519
lines changed

Assets/FullSerializer/Source/Converters/Unity/UnityEvent_Converter.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,22 @@
55

66
namespace FullSerializer {
77
partial class fsConverterRegistrar {
8-
// Disable the converter for the time being. Unity's JsonUtility API cannot be called from
9-
// within a C# ISerializationCallbackReceiver callback.
8+
// Disable the converter for the time being. Unity's JsonUtility API
9+
// cannot be called from within a C# ISerializationCallbackReceiver
10+
// callback.
1011

11-
// public static Internal.Converters.UnityEvent_Converter Register_UnityEvent_Converter;
12+
// public static Internal.Converters.UnityEvent_Converter
13+
// Register_UnityEvent_Converter;
1214
}
1315
}
1416

1517
namespace FullSerializer.Internal.Converters {
16-
// The standard FS reflection converter has started causing Unity to crash when processing
17-
// UnityEvent. We can send the serialization through JsonUtility which appears to work correctly
18-
// instead.
18+
// The standard FS reflection converter has started causing Unity to crash
19+
// when processing UnityEvent. We can send the serialization through
20+
// JsonUtility which appears to work correctly instead.
1921
//
20-
// We have to support legacy serialization formats so importing works as expected.
22+
// We have to support legacy serialization formats so importing works as
23+
// expected.
2124
public class UnityEvent_Converter : fsConverter {
2225
public override bool CanProcess(Type type) {
2326
return typeof(UnityEvent).Resolve().IsAssignableFrom(type) && type.IsGenericType == false;

Assets/FullSerializer/Source/Converters/fsArrayConverter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ public override bool RequestInheritanceSupport(Type storageType) {
1616
}
1717

1818
public override fsResult TrySerialize(object instance, out fsData serialized, Type storageType) {
19-
// note: IList[index] is **significantly** faster than Array.Get, so make sure we use
20-
// that instead.
19+
// note: IList[index] is **significantly** faster than Array.Get, so
20+
// make sure we use that instead.
2121

2222
IList arr = (Array)instance;
2323
Type elementType = storageType.GetElementType();

Assets/FullSerializer/Source/Converters/fsDateConverter.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ namespace FullSerializer.Internal {
66
/// Supports serialization for DateTime, DateTimeOffset, and TimeSpan.
77
/// </summary>
88
public class fsDateConverter : fsConverter {
9-
// The format strings that we use when serializing DateTime and DateTimeOffset types.
9+
// The format strings that we use when serializing DateTime and
10+
// DateTimeOffset types.
1011
private const string DefaultDateTimeFormatString = @"o";
1112
private const string DateTimeOffsetFormatString = @"o";
1213

@@ -57,12 +58,14 @@ public override fsResult TryDeserialize(fsData data, ref object instance, Type s
5758
return fsResult.Success;
5859
}
5960

60-
// DateTime.TryParse can fail for some valid DateTime instances. Try to use Convert.ToDateTime.
61+
// DateTime.TryParse can fail for some valid DateTime instances.
62+
// Try to use Convert.ToDateTime.
6163
if (fsGlobalConfig.AllowInternalExceptions) {
6264
try {
6365
instance = Convert.ToDateTime(data.AsString);
6466
return fsResult.Success;
65-
} catch (Exception e) {
67+
}
68+
catch (Exception e) {
6669
return fsResult.Fail("Unable to parse " + data.AsString + " into a DateTime; got exception " + e);
6770
}
6871
}

Assets/FullSerializer/Source/Converters/fsDictionaryConverter.cs

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
using System.Reflection;
55

66
namespace FullSerializer.Internal {
7-
// While the generic IEnumerable converter can handle dictionaries, we process them separately here because
8-
// we support a few more advanced use-cases with dictionaries, such as inline strings. Further, dictionary
9-
// processing in general is a bit more advanced because a few of the collection implementations are buggy.
7+
// While the generic IEnumerable converter can handle dictionaries, we
8+
// process them separately here because we support a few more advanced
9+
// use-cases with dictionaries, such as inline strings. Further, dictionary
10+
// processing in general is a bit more advanced because a few of the
11+
// collection implementations are buggy.
1012
public class fsDictionaryConverter : fsConverter {
1113
public override bool CanProcess(Type type) {
1214
return typeof(IDictionary).IsAssignableFrom(type);
@@ -70,7 +72,8 @@ public override fsResult TrySerialize(object instance_, out fsData serialized, T
7072
Type keyStorageType, valueStorageType;
7173
GetKeyValueTypes(instance.GetType(), out keyStorageType, out valueStorageType);
7274

73-
// No other way to iterate dictionaries and still have access to the key/value info
75+
// No other way to iterate dictionaries and still have access to the
76+
// key/value info
7477
IDictionaryEnumerator enumerator = instance.GetEnumerator();
7578

7679
bool allStringKeys = true;
@@ -116,23 +119,28 @@ public override fsResult TrySerialize(object instance_, out fsData serialized, T
116119
}
117120

118121
private fsResult AddItemToDictionary(IDictionary dictionary, object key, object value) {
119-
// Because we're operating through the IDictionary interface by default (and not the
120-
// generic one), we normally send items through IDictionary.Add(object, object). This
121-
// works fine in the general case, except that the add method verifies that it's
122-
// parameter types are proper types. However, mono is buggy and these type checks do
123-
// not consider null a subtype of the parameter types, and exceptions get thrown. So,
124-
// we have to special case adding null items via the generic functions (which do not
125-
// do the null check), which is slow and messy.
122+
// Because we're operating through the IDictionary interface by
123+
// default (and not the generic one), we normally send items through
124+
// IDictionary.Add(object, object). This works fine in the general
125+
// case, except that the add method verifies that it's parameter
126+
// types are proper types. However, mono is buggy and these type
127+
// checks do not consider null a subtype of the parameter types, and
128+
// exceptions get thrown. So, we have to special case adding null
129+
// items via the generic functions (which do not do the null check),
130+
// which is slow and messy.
126131
//
127-
// An example of a collection that fails deserialization without this method is
128-
// `new SortedList<int, string> { { 0, null } }`. (SortedDictionary is fine because
129-
// it properly handles null values).
132+
// An example of a collection that fails deserialization without this
133+
// method is `new SortedList<int, string> { { 0, null } }`.
134+
// (SortedDictionary is fine because it properly handles null
135+
// values).
130136
if (key == null || value == null) {
131-
// Life would be much easier if we had MakeGenericType available, but we don't. So
132-
// we're going to find the correct generic KeyValuePair type via a bit of trickery.
133-
// All dictionaries extend ICollection<KeyValuePair<TKey, TValue>>, so we just
134-
// fetch the ICollection<> type with the proper generic arguments, and then we take
135-
// the KeyValuePair<> generic argument, and whola! we have our proper generic type.
137+
// Life would be much easier if we had MakeGenericType available,
138+
// but we don't. So we're going to find the correct generic
139+
// KeyValuePair type via a bit of trickery. All dictionaries
140+
// extend ICollection<KeyValuePair<TKey, TValue>>, so we just
141+
// fetch the ICollection<> type with the proper generic
142+
// arguments, and then we take the KeyValuePair<> generic
143+
// argument, and whola! we have our proper generic type.
136144

137145
var collectionType = fsReflectionUtility.GetInterface(dictionary.GetType(), typeof(ICollection<>));
138146
if (collectionType == null) {
@@ -146,23 +154,24 @@ private fsResult AddItemToDictionary(IDictionary dictionary, object key, object
146154
return fsResult.Success;
147155
}
148156

149-
// We use the inline set methods instead of dictionary.Add; dictionary.Add will throw an exception
150-
// if the key already exists.
157+
// We use the inline set methods instead of dictionary.Add;
158+
// dictionary.Add will throw an exception if the key already exists.
151159
dictionary[key] = value;
152160
return fsResult.Success;
153161
}
154162

155163
private static void GetKeyValueTypes(Type dictionaryType, out Type keyStorageType, out Type valueStorageType) {
156-
// All dictionaries extend IDictionary<TKey, TValue>, so we just fetch the generic arguments from it
164+
// All dictionaries extend IDictionary<TKey, TValue>, so we just
165+
// fetch the generic arguments from it
157166
var interfaceType = fsReflectionUtility.GetInterface(dictionaryType, typeof(IDictionary<,>));
158167
if (interfaceType != null) {
159168
var genericArgs = interfaceType.GetGenericArguments();
160169
keyStorageType = genericArgs[0];
161170
valueStorageType = genericArgs[1];
162171
}
163-
164172
else {
165-
// Fetching IDictionary<,> failed... we have to encode full type information :(
173+
// Fetching IDictionary<,> failed... we have to encode full type
174+
// information :(
166175
keyStorageType = typeof(object);
167176
valueStorageType = typeof(object);
168177
}

Assets/FullSerializer/Source/Converters/fsEnumConverter.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ public override bool RequestInheritanceSupport(Type storageType) {
2020
}
2121

2222
public override object CreateInstance(fsData data, Type storageType) {
23-
// In .NET compact, Enum.ToObject(Type, Object) is defined but the overloads like
24-
// Enum.ToObject(Type, int) are not -- so we get around this by boxing the value.
23+
// In .NET compact, Enum.ToObject(Type, Object) is defined but the
24+
// overloads like Enum.ToObject(Type, int) are not -- so we get
25+
// around this by boxing the value.
2526
return Enum.ToObject(storageType, (object)0);
2627
}
2728

@@ -61,8 +62,8 @@ public override fsResult TryDeserialize(fsData data, ref object instance, Type s
6162
for (int i = 0; i < enumValues.Length; ++i) {
6263
string enumValue = enumValues[i];
6364

64-
// Verify that the enum name exists; Enum.TryParse is only available in .NET 4.0
65-
// and above :(.
65+
// Verify that the enum name exists; Enum.TryParse is only
66+
// available in .NET 4.0 and above :(.
6667
if (ArrayContains(Enum.GetNames(storageType), enumValue) == false) {
6768
return fsResult.Fail("Cannot find enum name " + enumValue + " on type " + storageType);
6869
}
@@ -74,12 +75,12 @@ public override fsResult TryDeserialize(fsData data, ref object instance, Type s
7475
instance = Enum.ToObject(storageType, (object)instanceValue);
7576
return fsResult.Success;
7677
}
77-
7878
else if (data.IsInt64) {
7979
int enumValue = (int)data.AsInt64;
8080

81-
// In .NET compact, Enum.ToObject(Type, Object) is defined but the overloads like
82-
// Enum.ToObject(Type, int) are not -- so we get around this by boxing the value.
81+
// In .NET compact, Enum.ToObject(Type, Object) is defined but
82+
// the overloads like Enum.ToObject(Type, int) are not -- so we
83+
// get around this by boxing the value.
8384
instance = Enum.ToObject(storageType, (object)enumValue);
8485

8586
return fsResult.Success;
@@ -89,7 +90,8 @@ public override fsResult TryDeserialize(fsData data, ref object instance, Type s
8990
}
9091

9192
/// <summary>
92-
/// Returns true if the given value is contained within the specified array.
93+
/// Returns true if the given value is contained within the specified
94+
/// array.
9395
/// </summary>
9496
private static bool ArrayContains<T>(T[] values, T value) {
9597
// note: We don't use LINQ because this function will *not* allocate

Assets/FullSerializer/Source/Converters/fsForwardConverter.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22

33
namespace FullSerializer {
44
/// <summary>
5-
/// This allows you to forward serialization of an object to one of its members. For example,
5+
/// This allows you to forward serialization of an object to one of its
6+
/// members. For example,
67
///
78
/// [fsForward("Values")]
89
/// struct Wrapper {
9-
/// public int[] Values;
10+
/// public int[] Values;
1011
/// }
1112
///
12-
/// Then `Wrapper` will be serialized into a JSON array of integers. It will be as if `Wrapper`
13-
/// doesn't exist.
13+
/// Then `Wrapper` will be serialized into a JSON array of integers. It will
14+
/// be as if `Wrapper` doesn't exist.
1415
/// </summary>
1516
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.Struct)]
1617
public sealed class fsForwardAttribute : Attribute {
@@ -20,9 +21,12 @@ public sealed class fsForwardAttribute : Attribute {
2021
public string MemberName;
2122

2223
/// <summary>
23-
/// Forward object serialization to an instance member. See class comment.
24+
/// Forward object serialization to an instance member. See class
25+
/// comment.
2426
/// </summary>
25-
/// <param name="memberName">The name of the member that we should serialize this object as.</param>
27+
/// <param name="memberName">
28+
/// The name of the member that we should serialize this object as.
29+
/// </param>
2630
public fsForwardAttribute(string memberName) {
2731
MemberName = memberName;
2832
}

Assets/FullSerializer/Source/Converters/fsIEnumerableConverter.cs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
namespace FullSerializer.Internal {
77
/// <summary>
8-
/// Provides serialization support for anything which extends from `IEnumerable` and has an `Add` method.
8+
/// Provides serialization support for anything which extends from
9+
/// `IEnumerable` and has an `Add` method.
910
/// </summary>
1011
public class fsIEnumerableConverter : fsConverter {
1112
public override bool CanProcess(Type type) {
@@ -29,16 +30,18 @@ public override fsResult TrySerialize(object instance_, out fsData serialized, T
2930
foreach (object item in instance) {
3031
fsData itemData;
3132

32-
// note: We don't fail the entire deserialization even if the item failed
33+
// note: We don't fail the entire deserialization even if the
34+
// item failed
3335
var itemResult = Serializer.TrySerialize(elementType, item, out itemData);
3436
result.AddMessages(itemResult);
3537
if (itemResult.Failed) continue;
3638

3739
serializedList.Add(itemData);
3840
}
3941

40-
// Stacks iterate from back to front, which means when we deserialize we will deserialize
41-
// the items in the wrong order, so the stack will get reversed.
42+
// Stacks iterate from back to front, which means when we deserialize
43+
// we will deserialize the items in the wrong order, so the stack
44+
// will get reversed.
4245
if (IsStack(instance.GetType())) {
4346
serializedList.Reverse();
4447
}
@@ -57,8 +60,8 @@ public override fsResult TryDeserialize(fsData data, ref object instance_, Type
5760

5861
if ((result += CheckType(data, fsDataType.Array)).Failed) return result;
5962

60-
// For general strategy, instance may already have items in it. We will try to deserialize into
61-
// the existing element.
63+
// For general strategy, instance may already have items in it. We
64+
// will try to deserialize into the existing element.
6265
var elementStorageType = GetElementType(storageType);
6366
var addMethod = GetAddMethod(storageType);
6467
var getMethod = storageType.GetFlattenedMethod("get_Item");
@@ -74,7 +77,8 @@ public override fsResult TryDeserialize(fsData data, ref object instance_, Type
7477
itemInstance = getMethod.Invoke(instance, new object[] { i });
7578
}
7679

77-
// note: We don't fail the entire deserialization even if the item failed
80+
// note: We don't fail the entire deserialization even if the
81+
// item failed
7882
var itemResult = Serializer.TryDeserialize(itemData, elementStorageType, ref itemInstance);
7983
result.AddMessages(itemResult);
8084
if (itemResult.Failed) continue;
@@ -125,10 +129,11 @@ private static int TryGetExistingSize(Type type, object instance) {
125129
}
126130

127131
private static MethodInfo GetAddMethod(Type type) {
128-
// There is a really good chance the type will extend ICollection{}, which will contain
129-
// the add method we want. Just doing type.GetFlattenedMethod() may return the incorrect one --
130-
// for example, with dictionaries, it'll return Add(TKey, TValue), and we want
131-
// Add(KeyValuePair<TKey, TValue>).
132+
// There is a really good chance the type will extend ICollection{},
133+
// which will contain the add method we want. Just doing
134+
// type.GetFlattenedMethod() may return the incorrect one -- for
135+
// example, with dictionaries, it'll return Add(TKey, TValue), and we
136+
// want Add(KeyValuePair<TKey, TValue>).
132137
Type collectionInterface = fsReflectionUtility.GetInterface(type, typeof(ICollection<>));
133138
if (collectionInterface != null) {
134139
MethodInfo add = collectionInterface.GetDeclaredMethod("Add");

Assets/FullSerializer/Source/Converters/fsNullableConverter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace FullSerializer.Internal {
44
/// <summary>
5-
/// The reflected converter will properly serialize nullable types. However, we do it here
6-
/// instead as we can emit less serialization data.
5+
/// The reflected converter will properly serialize nullable types. However,
6+
/// we do it here instead as we can emit less serialization data.
77
/// </summary>
88
public class fsNullableConverter : fsConverter {
99
public override bool CanProcess(Type type) {

Assets/FullSerializer/Source/Converters/fsPrimitiveConverter.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,13 @@ public override fsResult TrySerialize(object instance, out fsData serialized, Ty
5858
}
5959

6060
if (UseDouble(instanceType)) {
61-
// Casting from float to double introduces floating point jitter, ie, 0.1 becomes 0.100000001490116.
62-
// Casting to decimal as an intermediate step removes the jitter. Not sure why.
61+
// Casting from float to double introduces floating point jitter,
62+
// ie, 0.1 becomes 0.100000001490116. Casting to decimal as an
63+
// intermediate step removes the jitter. Not sure why.
6364
if (instance.GetType() == typeof(float) &&
64-
// Decimal can't store float.MinValue/float.MaxValue/float.PositiveInfinity/float.NegativeInfinity/float.NaN - an exception gets thrown in that scenario.
65+
// Decimal can't store
66+
// float.MinValue/float.MaxValue/float.PositiveInfinity/float.NegativeInfinity/float.NaN
67+
// - an exception gets thrown in that scenario.
6568
(float)instance != float.MinValue &&
6669
(float)instance != float.MaxValue &&
6770
!float.IsInfinity((float)instance) &&
@@ -121,5 +124,4 @@ public override fsResult TryDeserialize(fsData storage, ref object instance, Typ
121124
return fsResult.Fail(GetType().Name + ": Bad data; expected bool, number, string, but got " + storage);
122125
}
123126
}
124-
}
125-
127+
}

0 commit comments

Comments
 (0)