上传YomovSDK
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Newtonsoft.Json.UnityConverters.Helpers
|
||||
{
|
||||
internal static class EnumerableExtensions
|
||||
{
|
||||
public static IEnumerable<T> WhereNotNullRef<T>(this IEnumerable<T> values)
|
||||
where T : class
|
||||
{
|
||||
foreach (T item in values)
|
||||
{
|
||||
if (item != null)
|
||||
{
|
||||
yield return item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerable<T> WhereNotNullValue<T>(this IEnumerable<T?> values)
|
||||
where T : struct
|
||||
{
|
||||
foreach (T? item in values)
|
||||
{
|
||||
if (item.HasValue)
|
||||
{
|
||||
yield return item.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 57e9831fc3d74a4449704a100f5b9ded
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,117 @@
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Globalization;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
|
||||
namespace Newtonsoft.Json.UnityConverters.Helpers
|
||||
{
|
||||
internal static class JsonHelperExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// This refers to the ctor that lets you specify the line number and
|
||||
/// position that was introduced in Json.NET v12.0.1.
|
||||
/// <see cref="JsonSerializationException.JsonSerializationException(string, string, int, int, Exception)"/>
|
||||
/// <see href="https://github.com/JamesNK/Newtonsoft.Json/blob/12.0.1/Src/Newtonsoft.Json/JsonSerializationException.cs#L110"/>
|
||||
/// </summary>
|
||||
internal static readonly ConstructorInfo _JsonSerializationExceptionPositionalCtor
|
||||
= typeof(JsonSerializationException).GetConstructor(new[] {
|
||||
typeof(string), typeof(string), typeof(int), typeof(int), typeof(Exception)
|
||||
});
|
||||
|
||||
private static JsonSerializationException NewJsonSerializationException(string message, string path, int lineNumber, int linePosition, [AllowNull] Exception innerException)
|
||||
{
|
||||
if (_JsonSerializationExceptionPositionalCtor != null)
|
||||
{
|
||||
return (JsonSerializationException)_JsonSerializationExceptionPositionalCtor.Invoke(new object[] {
|
||||
message, path, lineNumber, linePosition, innerException
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
return new JsonSerializationException(message, innerException);
|
||||
}
|
||||
}
|
||||
|
||||
public static JsonSerializationException CreateSerializationException(this JsonReader reader, string message, [AllowNull] Exception innerException = null)
|
||||
{
|
||||
StringBuilder builder = CreateStringBuilderWithSpaceAfter(message);
|
||||
|
||||
builder.AppendFormat(CultureInfo.InvariantCulture, "Path '{0}'", reader.Path);
|
||||
|
||||
var lineInfo = reader as IJsonLineInfo;
|
||||
int lineNumber = default;
|
||||
int linePosition = default;
|
||||
|
||||
if (lineInfo?.HasLineInfo() == true)
|
||||
{
|
||||
lineNumber = lineInfo.LineNumber;
|
||||
linePosition = lineInfo.LinePosition;
|
||||
builder.AppendFormat(CultureInfo.InvariantCulture, ", line {0}, position {1}", lineNumber, linePosition);
|
||||
}
|
||||
|
||||
builder.Append('.');
|
||||
|
||||
return NewJsonSerializationException(
|
||||
message: builder.ToString(), reader.Path, lineNumber, linePosition, innerException);
|
||||
}
|
||||
|
||||
public static JsonWriterException CreateWriterException(this JsonWriter writer, string message, [AllowNull] Exception innerException = null)
|
||||
{
|
||||
StringBuilder builder = CreateStringBuilderWithSpaceAfter(message);
|
||||
|
||||
builder.AppendFormat(CultureInfo.InvariantCulture, "Path '{0}'.", writer.Path);
|
||||
|
||||
return new JsonWriterException(
|
||||
message: builder.ToString(), writer.Path, innerException);
|
||||
}
|
||||
|
||||
private static StringBuilder CreateStringBuilderWithSpaceAfter(string message)
|
||||
{
|
||||
var builder = new StringBuilder(message);
|
||||
|
||||
if (message.EndsWith("."))
|
||||
{
|
||||
builder.Append(' ');
|
||||
}
|
||||
else if (!message.EndsWith(". "))
|
||||
{
|
||||
builder.Append(". ");
|
||||
}
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
[return: MaybeNull]
|
||||
public static T ReadViaSerializer<T>(this JsonReader reader, JsonSerializer serializer)
|
||||
{
|
||||
reader.Read();
|
||||
return serializer.Deserialize<T>(reader);
|
||||
}
|
||||
|
||||
public static float? ReadAsFloat(this JsonReader reader)
|
||||
{
|
||||
// https://github.com/jilleJr/Newtonsoft.Json-for-Unity.Converters/issues/46
|
||||
|
||||
var str = reader.ReadAsString();
|
||||
|
||||
if (string.IsNullOrEmpty(str))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else if (float.TryParse(str, NumberStyles.Any, CultureInfo.InvariantCulture, out var valueParsed))
|
||||
{
|
||||
return valueParsed;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0f;
|
||||
}
|
||||
}
|
||||
|
||||
public static byte? ReadAsInt8(this JsonReader reader)
|
||||
{
|
||||
return checked((byte)(reader.ReadAsInt32() ?? 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 14d81b4b9fea2f8459dfdf3a02459316
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,152 @@
|
||||
#pragma warning disable MA0048 // File name must match type name
|
||||
#define INTERNAL_NULLABLE_ATTRIBUTES
|
||||
#if (NET_STANDARD_2_0 || NET_4_6 || NET_2_0 || NET_2_0_SUBSET || NET_LEGACY) && !NET_STANDARD_2_1
|
||||
|
||||
// https://github.com/dotnet/corefx/blob/48363ac826ccf66fbe31a5dcb1dc2aab9a7dd768/src/Common/src/CoreLib/System/Diagnostics/CodeAnalysis/NullableAttributes.cs
|
||||
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
namespace System.Diagnostics.CodeAnalysis
|
||||
{
|
||||
/// <summary>Specifies that null is allowed as an input even if the corresponding type disallows it.</summary>
|
||||
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property, Inherited = false)]
|
||||
#if INTERNAL_NULLABLE_ATTRIBUTES
|
||||
internal
|
||||
#else
|
||||
public
|
||||
#endif
|
||||
sealed class AllowNullAttribute : Attribute
|
||||
{ }
|
||||
|
||||
/// <summary>Specifies that null is disallowed as an input even if the corresponding type allows it.</summary>
|
||||
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property, Inherited = false)]
|
||||
#if INTERNAL_NULLABLE_ATTRIBUTES
|
||||
internal
|
||||
#else
|
||||
public
|
||||
#endif
|
||||
sealed class DisallowNullAttribute : Attribute
|
||||
{ }
|
||||
|
||||
/// <summary>Specifies that an output may be null even if the corresponding type disallows it.</summary>
|
||||
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, Inherited = false)]
|
||||
#if INTERNAL_NULLABLE_ATTRIBUTES
|
||||
internal
|
||||
#else
|
||||
public
|
||||
#endif
|
||||
sealed class MaybeNullAttribute : Attribute
|
||||
{ }
|
||||
|
||||
/// <summary>Specifies that an output will not be null even if the corresponding type allows it.</summary>
|
||||
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, Inherited = false)]
|
||||
#if INTERNAL_NULLABLE_ATTRIBUTES
|
||||
internal
|
||||
#else
|
||||
public
|
||||
#endif
|
||||
sealed class NotNullAttribute : Attribute
|
||||
{ }
|
||||
|
||||
/// <summary>Specifies that when a method returns <see cref="ReturnValue"/>, the parameter may be null even if the corresponding type disallows it.</summary>
|
||||
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
|
||||
#if INTERNAL_NULLABLE_ATTRIBUTES
|
||||
internal
|
||||
#else
|
||||
public
|
||||
#endif
|
||||
sealed class MaybeNullWhenAttribute : Attribute
|
||||
{
|
||||
/// <summary>Initializes the attribute with the specified return value condition.</summary>
|
||||
/// <param name="returnValue">
|
||||
/// The return value condition. If the method returns this value, the associated parameter may be null.
|
||||
/// </param>
|
||||
public MaybeNullWhenAttribute(bool returnValue)
|
||||
{
|
||||
ReturnValue = returnValue;
|
||||
}
|
||||
|
||||
/// <summary>Gets the return value condition.</summary>
|
||||
public bool ReturnValue { get; }
|
||||
}
|
||||
|
||||
/// <summary>Specifies that when a method returns <see cref="ReturnValue"/>, the parameter will not be null even if the corresponding type allows it.</summary>
|
||||
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
|
||||
#if INTERNAL_NULLABLE_ATTRIBUTES
|
||||
internal
|
||||
#else
|
||||
public
|
||||
#endif
|
||||
sealed class NotNullWhenAttribute : Attribute
|
||||
{
|
||||
/// <summary>Initializes the attribute with the specified return value condition.</summary>
|
||||
/// <param name="returnValue">
|
||||
/// The return value condition. If the method returns this value, the associated parameter will not be null.
|
||||
/// </param>
|
||||
public NotNullWhenAttribute(bool returnValue)
|
||||
{
|
||||
ReturnValue = returnValue;
|
||||
}
|
||||
|
||||
/// <summary>Gets the return value condition.</summary>
|
||||
public bool ReturnValue { get; }
|
||||
}
|
||||
|
||||
/// <summary>Specifies that the output will be non-null if the named parameter is non-null.</summary>
|
||||
[AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, AllowMultiple = true, Inherited = false)]
|
||||
#if INTERNAL_NULLABLE_ATTRIBUTES
|
||||
internal
|
||||
#else
|
||||
public
|
||||
#endif
|
||||
sealed class NotNullIfNotNullAttribute : Attribute
|
||||
{
|
||||
/// <summary>Initializes the attribute with the associated parameter name.</summary>
|
||||
/// <param name="parameterName">
|
||||
/// The associated parameter name. The output will be non-null if the argument to the parameter specified is non-null.
|
||||
/// </param>
|
||||
public NotNullIfNotNullAttribute(string parameterName)
|
||||
{
|
||||
ParameterName = parameterName;
|
||||
}
|
||||
|
||||
/// <summary>Gets the associated parameter name.</summary>
|
||||
public string ParameterName { get; }
|
||||
}
|
||||
|
||||
/// <summary>Applied to a method that will never return under any circumstance.</summary>
|
||||
[AttributeUsage(AttributeTargets.Method, Inherited = false)]
|
||||
#if INTERNAL_NULLABLE_ATTRIBUTES
|
||||
internal
|
||||
#else
|
||||
public
|
||||
#endif
|
||||
sealed class DoesNotReturnAttribute : Attribute
|
||||
{ }
|
||||
|
||||
/// <summary>Specifies that the method will not return if the associated Boolean parameter is passed the specified value.</summary>
|
||||
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
|
||||
#if INTERNAL_NULLABLE_ATTRIBUTES
|
||||
internal
|
||||
#else
|
||||
public
|
||||
#endif
|
||||
sealed class DoesNotReturnIfAttribute : Attribute
|
||||
{
|
||||
/// <summary>Initializes the attribute with the specified parameter value.</summary>
|
||||
/// <param name="parameterValue">
|
||||
/// The condition parameter value. Code after the method will be considered unreachable by diagnostics if the argument to
|
||||
/// the associated parameter matches this value.
|
||||
/// </param>
|
||||
public DoesNotReturnIfAttribute(bool parameterValue)
|
||||
{
|
||||
ParameterValue = parameterValue;
|
||||
}
|
||||
|
||||
/// <summary>Gets the condition parameter value.</summary>
|
||||
public bool ParameterValue { get; }
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6d204313f888a2e4d9ce61192bb09b2c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Newtonsoft.Json.UnityConverters.Helpers
|
||||
{
|
||||
internal static class TypeExtensions
|
||||
{
|
||||
public static IEnumerable<Type> GetLoadableTypes(this Assembly assembly)
|
||||
{
|
||||
try
|
||||
{
|
||||
return assembly.GetTypes();
|
||||
}
|
||||
catch (ReflectionTypeLoadException ex)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Newtonsoft.Json.UnityConverters.Helpers.TypeExtensions: "
|
||||
+ "Failed to load some types from assembly '{assembly.FullName}'. Maybe assembly is not fully loaded yet?\n"
|
||||
+ ex.ToString());
|
||||
#endif
|
||||
return ex.Types.Where(t => t != null);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the non-public instance field info <see cref="FieldInfo"/> for the converted type
|
||||
/// <typeparamref name="T"/>.
|
||||
/// If not found then will throw a missing member exception <see cref="MissingMemberException"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// If used in static initialization (ex: inside static constructor,
|
||||
/// static field, or static property backing field initialization)
|
||||
/// and the field does not exist it would invalidate the type for
|
||||
/// the entirety of the programs lifetime.
|
||||
/// </remarks>
|
||||
/// <param name="name">Name of the non-public instance field.</param>
|
||||
public static FieldInfo GetFieldInfoOrThrow(this Type type, string name)
|
||||
{
|
||||
return type.GetField(name, BindingFlags.NonPublic | BindingFlags.Instance)
|
||||
?? throw new MissingMemberException(type.FullName, name);
|
||||
}
|
||||
|
||||
public static void SetValueDirectRef<T1, T2>(this FieldInfo field, ref T1 state, T2 value)
|
||||
{
|
||||
#if ENABLE_IL2CPP
|
||||
object boxed = state;
|
||||
field.SetValue(boxed, value);
|
||||
state = (T1)boxed;
|
||||
#else
|
||||
TypedReference reference = __makeref(state);
|
||||
field.SetValueDirect(reference, value);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d5943f790b4af094da5f0d24b12c1ad5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user