Skip to content

Commit

Permalink
Merge branch 'pr/n127_steinbitglis'
Browse files Browse the repository at this point in the history
  • Loading branch information
aaubry committed May 19, 2015
2 parents 5714cf4 + 2eaa062 commit e37bfff
Show file tree
Hide file tree
Showing 13 changed files with 94 additions and 99 deletions.
22 changes: 21 additions & 1 deletion YamlDotNet.sln
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.30723.0
VisualStudioVersion = 12.0.31101.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{69EE9636-55BA-49C2-827E-D5684221C345}"
ProjectSection(SolutionItems) = preProject
Expand Down Expand Up @@ -34,15 +34,19 @@ EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug-UnitySubset-v35|Any CPU = Debug-UnitySubset-v35|Any CPU
PerformanceTests|Any CPU = PerformanceTests|Any CPU
Release-Portable-Signed|Any CPU = Release-Portable-Signed|Any CPU
Release-Portable-Unsigned|Any CPU = Release-Portable-Unsigned|Any CPU
Release-Signed|Any CPU = Release-Signed|Any CPU
Release-UnitySubset-v35|Any CPU = Release-UnitySubset-v35|Any CPU
Release-Unsigned|Any CPU = Release-Unsigned|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{BF32DE1B-6276-4341-B212-F8862ADBBA7A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BF32DE1B-6276-4341-B212-F8862ADBBA7A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BF32DE1B-6276-4341-B212-F8862ADBBA7A}.Debug-UnitySubset-v35|Any CPU.ActiveCfg = Debug-UnitySubset-v35|Any CPU
{BF32DE1B-6276-4341-B212-F8862ADBBA7A}.Debug-UnitySubset-v35|Any CPU.Build.0 = Debug-UnitySubset-v35|Any CPU
{BF32DE1B-6276-4341-B212-F8862ADBBA7A}.PerformanceTests|Any CPU.ActiveCfg = Release-Portable-Unsigned|Any CPU
{BF32DE1B-6276-4341-B212-F8862ADBBA7A}.PerformanceTests|Any CPU.Build.0 = Release-Portable-Unsigned|Any CPU
{BF32DE1B-6276-4341-B212-F8862ADBBA7A}.Release-Portable-Signed|Any CPU.ActiveCfg = Release-Portable-Signed|Any CPU
Expand All @@ -51,58 +55,74 @@ Global
{BF32DE1B-6276-4341-B212-F8862ADBBA7A}.Release-Portable-Unsigned|Any CPU.Build.0 = Release-Portable-Unsigned|Any CPU
{BF32DE1B-6276-4341-B212-F8862ADBBA7A}.Release-Signed|Any CPU.ActiveCfg = Release-Signed|Any CPU
{BF32DE1B-6276-4341-B212-F8862ADBBA7A}.Release-Signed|Any CPU.Build.0 = Release-Signed|Any CPU
{BF32DE1B-6276-4341-B212-F8862ADBBA7A}.Release-UnitySubset-v35|Any CPU.ActiveCfg = Release-UnitySubset-v35|Any CPU
{BF32DE1B-6276-4341-B212-F8862ADBBA7A}.Release-UnitySubset-v35|Any CPU.Build.0 = Release-UnitySubset-v35|Any CPU
{BF32DE1B-6276-4341-B212-F8862ADBBA7A}.Release-Unsigned|Any CPU.ActiveCfg = Release-Unsigned|Any CPU
{BF32DE1B-6276-4341-B212-F8862ADBBA7A}.Release-Unsigned|Any CPU.Build.0 = Release-Unsigned|Any CPU
{A9F67018-0240-4D16-A4EA-BCB780D0AF05}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A9F67018-0240-4D16-A4EA-BCB780D0AF05}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A9F67018-0240-4D16-A4EA-BCB780D0AF05}.Debug-UnitySubset-v35|Any CPU.ActiveCfg = Debug|Any CPU
{A9F67018-0240-4D16-A4EA-BCB780D0AF05}.PerformanceTests|Any CPU.ActiveCfg = Release|Any CPU
{A9F67018-0240-4D16-A4EA-BCB780D0AF05}.Release-Portable-Signed|Any CPU.ActiveCfg = Release-Portable|Any CPU
{A9F67018-0240-4D16-A4EA-BCB780D0AF05}.Release-Portable-Unsigned|Any CPU.ActiveCfg = Release-Portable|Any CPU
{A9F67018-0240-4D16-A4EA-BCB780D0AF05}.Release-Portable-Unsigned|Any CPU.Build.0 = Release-Portable|Any CPU
{A9F67018-0240-4D16-A4EA-BCB780D0AF05}.Release-Signed|Any CPU.ActiveCfg = Release|Any CPU
{A9F67018-0240-4D16-A4EA-BCB780D0AF05}.Release-UnitySubset-v35|Any CPU.ActiveCfg = Release|Any CPU
{A9F67018-0240-4D16-A4EA-BCB780D0AF05}.Release-Unsigned|Any CPU.ActiveCfg = Release|Any CPU
{A9F67018-0240-4D16-A4EA-BCB780D0AF05}.Release-Unsigned|Any CPU.Build.0 = Release|Any CPU
{773B71D6-FEE5-4E4D-8717-5C5EF58D6F17}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{773B71D6-FEE5-4E4D-8717-5C5EF58D6F17}.Debug-UnitySubset-v35|Any CPU.ActiveCfg = Debug|Any CPU
{773B71D6-FEE5-4E4D-8717-5C5EF58D6F17}.PerformanceTests|Any CPU.ActiveCfg = Release|Any CPU
{773B71D6-FEE5-4E4D-8717-5C5EF58D6F17}.PerformanceTests|Any CPU.Build.0 = Release|Any CPU
{773B71D6-FEE5-4E4D-8717-5C5EF58D6F17}.Release-Portable-Signed|Any CPU.ActiveCfg = Release|Any CPU
{773B71D6-FEE5-4E4D-8717-5C5EF58D6F17}.Release-Portable-Unsigned|Any CPU.ActiveCfg = Release|Any CPU
{773B71D6-FEE5-4E4D-8717-5C5EF58D6F17}.Release-Signed|Any CPU.ActiveCfg = Release|Any CPU
{773B71D6-FEE5-4E4D-8717-5C5EF58D6F17}.Release-UnitySubset-v35|Any CPU.ActiveCfg = Release|Any CPU
{773B71D6-FEE5-4E4D-8717-5C5EF58D6F17}.Release-Unsigned|Any CPU.ActiveCfg = Release|Any CPU
{A5C7D77C-0F08-4647-8376-3719BD6DEBD9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A5C7D77C-0F08-4647-8376-3719BD6DEBD9}.Debug-UnitySubset-v35|Any CPU.ActiveCfg = Debug|Any CPU
{A5C7D77C-0F08-4647-8376-3719BD6DEBD9}.PerformanceTests|Any CPU.ActiveCfg = Release|Any CPU
{A5C7D77C-0F08-4647-8376-3719BD6DEBD9}.PerformanceTests|Any CPU.Build.0 = Release|Any CPU
{A5C7D77C-0F08-4647-8376-3719BD6DEBD9}.Release-Portable-Signed|Any CPU.ActiveCfg = Release|Any CPU
{A5C7D77C-0F08-4647-8376-3719BD6DEBD9}.Release-Portable-Unsigned|Any CPU.ActiveCfg = Release|Any CPU
{A5C7D77C-0F08-4647-8376-3719BD6DEBD9}.Release-Signed|Any CPU.ActiveCfg = Release|Any CPU
{A5C7D77C-0F08-4647-8376-3719BD6DEBD9}.Release-UnitySubset-v35|Any CPU.ActiveCfg = Release|Any CPU
{A5C7D77C-0F08-4647-8376-3719BD6DEBD9}.Release-Unsigned|Any CPU.ActiveCfg = Release|Any CPU
{0FB497EA-A116-406A-AE8C-A24933D8CB21}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0FB497EA-A116-406A-AE8C-A24933D8CB21}.Debug-UnitySubset-v35|Any CPU.ActiveCfg = Debug|Any CPU
{0FB497EA-A116-406A-AE8C-A24933D8CB21}.PerformanceTests|Any CPU.ActiveCfg = Release|Any CPU
{0FB497EA-A116-406A-AE8C-A24933D8CB21}.PerformanceTests|Any CPU.Build.0 = Release|Any CPU
{0FB497EA-A116-406A-AE8C-A24933D8CB21}.Release-Portable-Signed|Any CPU.ActiveCfg = Release|Any CPU
{0FB497EA-A116-406A-AE8C-A24933D8CB21}.Release-Portable-Unsigned|Any CPU.ActiveCfg = Release|Any CPU
{0FB497EA-A116-406A-AE8C-A24933D8CB21}.Release-Signed|Any CPU.ActiveCfg = Release|Any CPU
{0FB497EA-A116-406A-AE8C-A24933D8CB21}.Release-UnitySubset-v35|Any CPU.ActiveCfg = Release|Any CPU
{0FB497EA-A116-406A-AE8C-A24933D8CB21}.Release-Unsigned|Any CPU.ActiveCfg = Release|Any CPU
{C6E0B465-8422-4D6B-85CE-C59724A28E1F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C6E0B465-8422-4D6B-85CE-C59724A28E1F}.Debug-UnitySubset-v35|Any CPU.ActiveCfg = Debug|Any CPU
{C6E0B465-8422-4D6B-85CE-C59724A28E1F}.PerformanceTests|Any CPU.ActiveCfg = Release|Any CPU
{C6E0B465-8422-4D6B-85CE-C59724A28E1F}.PerformanceTests|Any CPU.Build.0 = Release|Any CPU
{C6E0B465-8422-4D6B-85CE-C59724A28E1F}.Release-Portable-Signed|Any CPU.ActiveCfg = Release|Any CPU
{C6E0B465-8422-4D6B-85CE-C59724A28E1F}.Release-Portable-Unsigned|Any CPU.ActiveCfg = Release|Any CPU
{C6E0B465-8422-4D6B-85CE-C59724A28E1F}.Release-Signed|Any CPU.ActiveCfg = Release|Any CPU
{C6E0B465-8422-4D6B-85CE-C59724A28E1F}.Release-UnitySubset-v35|Any CPU.ActiveCfg = Release|Any CPU
{C6E0B465-8422-4D6B-85CE-C59724A28E1F}.Release-Unsigned|Any CPU.ActiveCfg = Release|Any CPU
{BE49A287-5F47-4E3B-90EB-97B51451934C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BE49A287-5F47-4E3B-90EB-97B51451934C}.Debug-UnitySubset-v35|Any CPU.ActiveCfg = Debug|Any CPU
{BE49A287-5F47-4E3B-90EB-97B51451934C}.PerformanceTests|Any CPU.ActiveCfg = Release|Any CPU
{BE49A287-5F47-4E3B-90EB-97B51451934C}.PerformanceTests|Any CPU.Build.0 = Release|Any CPU
{BE49A287-5F47-4E3B-90EB-97B51451934C}.Release-Portable-Signed|Any CPU.ActiveCfg = Release|Any CPU
{BE49A287-5F47-4E3B-90EB-97B51451934C}.Release-Portable-Unsigned|Any CPU.ActiveCfg = Release|Any CPU
{BE49A287-5F47-4E3B-90EB-97B51451934C}.Release-Signed|Any CPU.ActiveCfg = Release|Any CPU
{BE49A287-5F47-4E3B-90EB-97B51451934C}.Release-UnitySubset-v35|Any CPU.ActiveCfg = Release|Any CPU
{BE49A287-5F47-4E3B-90EB-97B51451934C}.Release-Unsigned|Any CPU.ActiveCfg = Release|Any CPU
{91A1F4BC-65C0-42E6-B5FD-320A2D59AF71}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{91A1F4BC-65C0-42E6-B5FD-320A2D59AF71}.Debug-UnitySubset-v35|Any CPU.ActiveCfg = Debug|Any CPU
{91A1F4BC-65C0-42E6-B5FD-320A2D59AF71}.PerformanceTests|Any CPU.ActiveCfg = Release|Any CPU
{91A1F4BC-65C0-42E6-B5FD-320A2D59AF71}.PerformanceTests|Any CPU.Build.0 = Release|Any CPU
{91A1F4BC-65C0-42E6-B5FD-320A2D59AF71}.Release-Portable-Signed|Any CPU.ActiveCfg = Release|Any CPU
{91A1F4BC-65C0-42E6-B5FD-320A2D59AF71}.Release-Portable-Unsigned|Any CPU.ActiveCfg = Release|Any CPU
{91A1F4BC-65C0-42E6-B5FD-320A2D59AF71}.Release-Signed|Any CPU.ActiveCfg = Release|Any CPU
{91A1F4BC-65C0-42E6-B5FD-320A2D59AF71}.Release-UnitySubset-v35|Any CPU.ActiveCfg = Release|Any CPU
{91A1F4BC-65C0-42E6-B5FD-320A2D59AF71}.Release-Unsigned|Any CPU.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
Expand Down
4 changes: 2 additions & 2 deletions YamlDotNet/Core/AnchorNotFoundException.cs
Expand Up @@ -64,7 +64,7 @@ public AnchorNotFoundException(string message, Exception inner)
{
}

#if !PORTABLE
#if !(PORTABLE || UNITY)
/// <summary>
/// Initializes a new instance of the <see cref="AnchorNotFoundException"/> class.
/// </summary>
Expand All @@ -78,4 +78,4 @@ protected AnchorNotFoundException(SerializationInfo info, StreamingContext conte
}
#endif
}
}
}
4 changes: 2 additions & 2 deletions YamlDotNet/Core/DuplicateAnchorException.cs
Expand Up @@ -64,7 +64,7 @@ public DuplicateAnchorException(string message, Exception inner)
{
}

#if !PORTABLE
#if !(PORTABLE || UNITY)
/// <summary>
/// Initializes a new instance of the <see cref="DuplicateAnchorException"/> class.
/// </summary>
Expand All @@ -78,4 +78,4 @@ protected DuplicateAnchorException(SerializationInfo info, StreamingContext cont
}
#endif
}
}
}
4 changes: 2 additions & 2 deletions YamlDotNet/Core/ForwardAnchorNotSupportedException.cs
Expand Up @@ -65,7 +65,7 @@ public ForwardAnchorNotSupportedException(string message, Exception inner)
{
}

#if !PORTABLE
#if !(PORTABLE || UNITY)
/// <summary>
/// Initializes a new instance of the <see cref="AnchorNotFoundException"/> class.
/// </summary>
Expand All @@ -79,4 +79,4 @@ protected ForwardAnchorNotSupportedException(SerializationInfo info, StreamingCo
}
#endif
}
}
}
2 changes: 1 addition & 1 deletion YamlDotNet/Core/SemanticErrorException.cs
Expand Up @@ -64,7 +64,7 @@ public SemanticErrorException(string message, Exception inner)
{
}

#if !PORTABLE
#if !(PORTABLE || UNITY)
/// <summary>
/// Initializes a new instance of the <see cref="SemanticErrorException"/> class.
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions YamlDotNet/Core/SyntaxErrorException.cs
Expand Up @@ -64,7 +64,7 @@ public SyntaxErrorException(string message, Exception inner)
{
}

#if !PORTABLE
#if !(PORTABLE || UNITY)
/// <summary>
/// Initializes a new instance of the <see cref="SyntaxErrorException"/> class.
/// </summary>
Expand All @@ -78,4 +78,4 @@ protected SyntaxErrorException(SerializationInfo info, StreamingContext context)
}
#endif
}
}
}
2 changes: 1 addition & 1 deletion YamlDotNet/Core/YamlException.cs
Expand Up @@ -84,7 +84,7 @@ public YamlException(string message, Exception inner)
{
}

#if !PORTABLE
#if !(PORTABLE || UNITY)
/// <summary>
/// Initializes a new instance of the <see cref="YamlException"/> class.
/// </summary>
Expand Down
43 changes: 32 additions & 11 deletions YamlDotNet/Helpers/Portability.cs
Expand Up @@ -28,6 +28,18 @@

namespace YamlDotNet
{
#if (PORTABLE || UNITY)
internal static class StandardRegexOptions
{
public const RegexOptions Compiled = RegexOptions.None;
}
#else
internal static class StandardRegexOptions
{
public const RegexOptions Compiled = RegexOptions.Compiled;
}
#endif

#if PORTABLE
/// <summary>
/// Mock SerializableAttribute to avoid having to add #if all over the place
Expand Down Expand Up @@ -83,7 +95,8 @@ public static bool IsAssignableFrom(this Type type, TypeInfo source)

public static TypeCode GetTypeCode(this Type type)
{
if (type.IsEnum())
bool isEnum = type.IsEnum();
if (isEnum)
{
type = Enum.GetUnderlyingType(type);
}
Expand Down Expand Up @@ -229,11 +242,6 @@ internal enum TypeCode
String = 18,
}

internal static class StandardRegexOptions
{
public const RegexOptions Compiled = RegexOptions.None;
}

internal abstract class DBNull
{
private DBNull() {}
Expand Down Expand Up @@ -328,11 +336,6 @@ public static Exception Unwrap(this TargetInvocationException ex)
return result;
}
}

internal static class StandardRegexOptions
{
public const RegexOptions Compiled = RegexOptions.Compiled;
}

internal sealed class CultureInfoAdapter : CultureInfo
{
Expand All @@ -351,4 +354,22 @@ public override object GetFormat(Type formatType)
}

#endif

#if UNITY
internal static class PropertyInfoExtensions
{
public static object ReadValue(this PropertyInfo property, object target)
{
return property.GetGetMethod().Invoke(target, null);
}
}
#else
internal static class PropertyInfoExtensions
{
public static object ReadValue(this PropertyInfo property, object target)
{
return property.GetValue(target, null);
}
}
#endif
}
3 changes: 3 additions & 0 deletions YamlDotNet/Properties/AssemblyInfo.cs
Expand Up @@ -19,6 +19,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#if !UNITY
using System.Reflection;
using System.Runtime.InteropServices;
using System;
Expand Down Expand Up @@ -61,4 +62,6 @@
[assembly: CLSCompliant(true)]
#if !SIGNED
[assembly: InternalsVisibleTo("YamlDotNet.Test")]
#endif

#endif
Expand Up @@ -48,8 +48,6 @@ bool INodeDeserializer.Deserialize(EventReader reader, Type expectedType, Func<E
var list = (IList)_objectFactory.Create(expectedType);
while (!reader.Accept<SequenceEnd>())
{
var current = reader.Parser.Current;

var item = nestedObjectDeserializer(reader, typeof(object));
var promise = item as IValuePromise;
if (promise == null)
Expand Down
Expand Up @@ -90,7 +90,7 @@ public void Write(object target, object value)

public IObjectDescriptor Read(object target)
{
var propertyValue = _propertyInfo.GetValue(target, null);
var propertyValue = _propertyInfo.ReadValue(target);
var actualType = TypeOverride ?? _typeResolver.Resolve(Type, propertyValue);
return new ObjectDescriptor(propertyValue, actualType, Type, ScalarStyle);
}
Expand Down
76 changes: 2 additions & 74 deletions YamlDotNet/Serialization/Utilities/TypeConverter.cs
Expand Up @@ -36,7 +36,7 @@ namespace YamlDotNet.Serialization.Utilities
/// </summary>
public static class TypeConverter
{
#if !PORTABLE
#if !(PORTABLE || UNITY)
/// <summary>
/// Registers a <see cref="System.ComponentModel.TypeConverter"/> dynamically.
/// </summary>
Expand Down Expand Up @@ -251,77 +251,5 @@ public static object ChangeType(object value, Type destinationType, CultureInfo
// Default to the Convert class
return Convert.ChangeType(value, destinationType, CultureInfo.InvariantCulture);
}

/// <summary>
/// Tries to parse the specified value.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="value">The value.</param>
/// <returns></returns>
public static T? TryParse<T>(string value) where T : struct
{
switch (typeof(T).GetTypeCode())
{
case TypeCode.Boolean:
return (T?)(object)TryParse<bool>(value, bool.TryParse);

case TypeCode.Byte:
return (T?)(object)TryParse<byte>(value, byte.TryParse);

case TypeCode.DateTime:
return (T?)(object)TryParse<DateTime>(value, DateTime.TryParse);

case TypeCode.Decimal:
return (T?)(object)TryParse<decimal>(value, decimal.TryParse);

case TypeCode.Double:
return (T?)(object)TryParse<double>(value, double.TryParse);

case TypeCode.Int16:
return (T?)(object)TryParse<short>(value, short.TryParse);

case TypeCode.Int32:
return (T?)(object)TryParse<int>(value, int.TryParse);

case TypeCode.Int64:
return (T?)(object)TryParse<long>(value, long.TryParse);

case TypeCode.SByte:
return (T?)(object)TryParse<sbyte>(value, sbyte.TryParse);

case TypeCode.Single:
return (T?)(object)TryParse<float>(value, float.TryParse);

case TypeCode.UInt16:
return (T?)(object)TryParse<ushort>(value, ushort.TryParse);

case TypeCode.UInt32:
return (T?)(object)TryParse<uint>(value, uint.TryParse);

case TypeCode.UInt64:
return (T?)(object)TryParse<ulong>(value, ulong.TryParse);

default:
throw new NotSupportedException(string.Format("Cannot parse type '{0}'.", typeof(T).FullName));
}
}

/// <summary>
/// Tries to parse the specified value.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="value">The value to be parsed.</param>
/// <param name="parse">The parse function.</param>
/// <returns></returns>
public static T? TryParse<T>(string value, TryParseDelegate<T> parse) where T : struct
{
T result;
return parse(value, out result) ? (T?)result : null;
}

/// <summary>
/// Defines a method that is used to tentatively parse a string.
/// </summary>
public delegate bool TryParseDelegate<T>(string value, out T result);
}
}
}

0 comments on commit e37bfff

Please sign in to comment.