Out with MagicOnion, in with LiteNetLib
Removed MagicOnion Added LiteNetLib Created client and server abstractions Fixed serialization bugs
This commit is contained in:
parent
433a7b4ae4
commit
e96146b7bb
869 changed files with 59401 additions and 16812 deletions
|
|
@ -0,0 +1,31 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace RethinkDb.Driver.Ast
|
||||
{
|
||||
/// <summary>
|
||||
/// Extension helpers for working with the AST.
|
||||
/// </summary>
|
||||
public static class ExtensionHelper
|
||||
{
|
||||
internal static JObject ToJObject(this object anonType)
|
||||
{
|
||||
return anonType == null ? null : JObject.FromObject(anonType);
|
||||
}
|
||||
|
||||
internal static IDictionary<string, object> ToDict(this object anonType)
|
||||
{
|
||||
return anonType == null ? null : PropertyHelper.ObjectToDictionary(anonType);
|
||||
}
|
||||
/// <summary>
|
||||
/// Uses a collection as parameters for a method call.
|
||||
/// </summary>
|
||||
/// <param name="args">Same as calling params object[] overload. Instead of specifying each param, ICollection can be used for convenience.</param>
|
||||
public static object[] AsParams<T>(this ICollection<T> args)
|
||||
{
|
||||
return args.OfType<object>().ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4a823fc8988297f4aabe8019ae3310cd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
45
Assets/Scripts/ServerShared/NIH/RethinkDb.Driver/Ast/Poco.cs
Normal file
45
Assets/Scripts/ServerShared/NIH/RethinkDb.Driver/Ast/Poco.cs
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
using Newtonsoft.Json.Linq;
|
||||
using RethinkDb.Driver.Net;
|
||||
using RethinkDb.Driver.Proto;
|
||||
|
||||
namespace RethinkDb.Driver.Ast
|
||||
{
|
||||
internal class Poco : ReqlExpr
|
||||
{
|
||||
private readonly object obj;
|
||||
|
||||
public Poco(object obj) : base(new TermType(), null, null)
|
||||
{
|
||||
this.obj = obj;
|
||||
}
|
||||
|
||||
|
||||
internal class PocoWriter : JTokenWriter
|
||||
{
|
||||
public override void WriteStartArray()
|
||||
{
|
||||
base.WriteStartArray();
|
||||
this.WriteValue(Proto.TermType.MAKE_ARRAY);
|
||||
base.WriteStartArray();
|
||||
}
|
||||
|
||||
public override void WriteEndArray()
|
||||
{
|
||||
base.WriteEndArray();
|
||||
base.WriteEndArray();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected internal override object Build()
|
||||
{
|
||||
JToken token;
|
||||
using( var writer = new PocoWriter() )
|
||||
{
|
||||
Converter.Serializer.Serialize(writer, this.obj);
|
||||
token = writer.Token;
|
||||
}
|
||||
return token;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 977e5c4e6b4f6364d9f1675f07332c78
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,515 @@
|
|||
#pragma warning disable 419
|
||||
|
||||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
namespace RethinkDb.Driver.Ast
|
||||
{
|
||||
internal class PropertyHelper
|
||||
{
|
||||
// Delegate type for a by-ref property getter
|
||||
private delegate TValue ByRefFunc<TDeclaringType, TValue>(ref TDeclaringType arg);
|
||||
|
||||
private static readonly MethodInfo CallPropertyGetterOpenGenericMethod =
|
||||
typeof(PropertyHelper).GetTypeInfo().GetDeclaredMethod(nameof(CallPropertyGetter));
|
||||
|
||||
private static readonly MethodInfo CallPropertyGetterByReferenceOpenGenericMethod =
|
||||
typeof(PropertyHelper).GetTypeInfo().GetDeclaredMethod(nameof(CallPropertyGetterByReference));
|
||||
|
||||
private static readonly MethodInfo CallNullSafePropertyGetterOpenGenericMethod =
|
||||
typeof(PropertyHelper).GetTypeInfo().GetDeclaredMethod(nameof(CallNullSafePropertyGetter));
|
||||
|
||||
private static readonly MethodInfo CallNullSafePropertyGetterByReferenceOpenGenericMethod =
|
||||
typeof(PropertyHelper).GetTypeInfo().GetDeclaredMethod(nameof(CallNullSafePropertyGetterByReference));
|
||||
|
||||
private static readonly MethodInfo CallPropertySetterOpenGenericMethod =
|
||||
typeof(PropertyHelper).GetTypeInfo().GetDeclaredMethod(nameof(CallPropertySetter));
|
||||
|
||||
// Using an array rather than IEnumerable, as target will be called on the hot path numerous times.
|
||||
private static readonly ConcurrentDictionary<Type, PropertyHelper[]> PropertiesCache =
|
||||
new ConcurrentDictionary<Type, PropertyHelper[]>();
|
||||
|
||||
private static readonly ConcurrentDictionary<Type, PropertyHelper[]> VisiblePropertiesCache =
|
||||
new ConcurrentDictionary<Type, PropertyHelper[]>();
|
||||
|
||||
private Action<object, object> _valueSetter;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a fast <see cref="PropertyHelper"/>.
|
||||
/// This constructor does not cache the helper. For caching, use <see cref="GetProperties(object)"/>.
|
||||
/// </summary>
|
||||
public PropertyHelper(PropertyInfo property)
|
||||
{
|
||||
if( property == null )
|
||||
{
|
||||
throw new ArgumentNullException(nameof(property));
|
||||
}
|
||||
|
||||
Property = property;
|
||||
Name = property.Name;
|
||||
ValueGetter = MakeFastPropertyGetter(property);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the backing <see cref="PropertyInfo"/>.
|
||||
/// </summary>
|
||||
public PropertyInfo Property { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets (or sets in derived types) the property name.
|
||||
/// </summary>
|
||||
public virtual string Name { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the property value getter.
|
||||
/// </summary>
|
||||
public Func<object, object> ValueGetter { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the property value setter.
|
||||
/// </summary>
|
||||
public Action<object, object> ValueSetter
|
||||
{
|
||||
get
|
||||
{
|
||||
if( _valueSetter == null )
|
||||
{
|
||||
// We'll allow safe races here.
|
||||
_valueSetter = MakeFastPropertySetter(Property);
|
||||
}
|
||||
|
||||
return _valueSetter;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the property value for the specified <paramref name="instance"/>.
|
||||
/// </summary>
|
||||
/// <param name="instance">The object whose property value will be returned.</param>
|
||||
/// <returns>The property value.</returns>
|
||||
public object GetValue(object instance)
|
||||
{
|
||||
return ValueGetter(instance);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the property value for the specified <paramref name="instance" />.
|
||||
/// </summary>
|
||||
/// <param name="instance">The object whose property value will be set.</param>
|
||||
/// <param name="value">The property value.</param>
|
||||
public void SetValue(object instance, object value)
|
||||
{
|
||||
ValueSetter(instance, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates and caches fast property helpers that expose getters for every public get property on the
|
||||
/// underlying type.
|
||||
/// </summary>
|
||||
/// <param name="instance">the instance to extract property accessors for.</param>
|
||||
/// <returns>a cached array of all public property getters from the underlying type of target instance.
|
||||
/// </returns>
|
||||
public static PropertyHelper[] GetProperties(object instance)
|
||||
{
|
||||
return GetProperties(instance.GetType());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates and caches fast property helpers that expose getters for every public get property on the
|
||||
/// specified type.
|
||||
/// </summary>
|
||||
/// <param name="type">the type to extract property accessors for.</param>
|
||||
/// <returns>a cached array of all public property getters from the type of target instance.
|
||||
/// </returns>
|
||||
public static PropertyHelper[] GetProperties(Type type)
|
||||
{
|
||||
return GetProperties(type, CreateInstance, PropertiesCache);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>
|
||||
/// Creates and caches fast property helpers that expose getters for every non-hidden get property
|
||||
/// on the specified type.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// <see cref="GetVisibleProperties"/> excludes properties defined on base types that have been
|
||||
/// hidden by definitions using the <c>new</c> keyword.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <param name="instance">The instance to extract property accessors for.</param>
|
||||
/// <returns>
|
||||
/// A cached array of all public property getters from the instance's type.
|
||||
/// </returns>
|
||||
public static PropertyHelper[] GetVisibleProperties(object instance)
|
||||
{
|
||||
return GetVisibleProperties(instance.GetType(), CreateInstance, PropertiesCache, VisiblePropertiesCache);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>
|
||||
/// Creates a caches fast property helpers that expose getters for every non-hidden get property
|
||||
/// on the specified type.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// <see cref="GetVisibleProperties"/> excludes properties defined on base types that have been
|
||||
/// hidden by definitions using the <c>new</c> keyword.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <param name="type">The type to extract property accessors for.</param>
|
||||
/// <returns>
|
||||
/// A cached array of all public property getters from the type.
|
||||
/// </returns>
|
||||
public static PropertyHelper[] GetVisibleProperties(Type type)
|
||||
{
|
||||
return GetVisibleProperties(type, CreateInstance, PropertiesCache, VisiblePropertiesCache);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a single fast property getter. The result is not cached.
|
||||
/// </summary>
|
||||
/// <param name="propertyInfo">propertyInfo to extract the getter for.</param>
|
||||
/// <returns>a fast getter.</returns>
|
||||
/// <remarks>
|
||||
/// This method is more memory efficient than a dynamically compiled lambda, and about the
|
||||
/// same speed.
|
||||
/// </remarks>
|
||||
public static Func<object, object> MakeFastPropertyGetter(PropertyInfo propertyInfo)
|
||||
{
|
||||
Debug.Assert(propertyInfo != null);
|
||||
|
||||
return MakeFastPropertyGetter(
|
||||
propertyInfo,
|
||||
CallPropertyGetterOpenGenericMethod,
|
||||
CallPropertyGetterByReferenceOpenGenericMethod);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a single fast property getter which is safe for a null input object. The result is not cached.
|
||||
/// </summary>
|
||||
/// <param name="propertyInfo">propertyInfo to extract the getter for.</param>
|
||||
/// <returns>a fast getter.</returns>
|
||||
/// <remarks>
|
||||
/// This method is more memory efficient than a dynamically compiled lambda, and about the
|
||||
/// same speed.
|
||||
/// </remarks>
|
||||
public static Func<object, object> MakeNullSafeFastPropertyGetter(PropertyInfo propertyInfo)
|
||||
{
|
||||
Debug.Assert(propertyInfo != null);
|
||||
|
||||
return MakeFastPropertyGetter(
|
||||
propertyInfo,
|
||||
CallNullSafePropertyGetterOpenGenericMethod,
|
||||
CallNullSafePropertyGetterByReferenceOpenGenericMethod);
|
||||
}
|
||||
|
||||
private static Func<object, object> MakeFastPropertyGetter(
|
||||
PropertyInfo propertyInfo,
|
||||
MethodInfo propertyGetterWrapperMethod,
|
||||
MethodInfo propertyGetterByRefWrapperMethod)
|
||||
{
|
||||
Debug.Assert(propertyInfo != null);
|
||||
|
||||
// Must be a generic method with a Func<,> parameter
|
||||
Debug.Assert(propertyGetterWrapperMethod != null);
|
||||
Debug.Assert(propertyGetterWrapperMethod.IsGenericMethodDefinition);
|
||||
Debug.Assert(propertyGetterWrapperMethod.GetParameters().Length == 2);
|
||||
|
||||
// Must be a generic method with a ByRefFunc<,> parameter
|
||||
Debug.Assert(propertyGetterByRefWrapperMethod != null);
|
||||
Debug.Assert(propertyGetterByRefWrapperMethod.IsGenericMethodDefinition);
|
||||
Debug.Assert(propertyGetterByRefWrapperMethod.GetParameters().Length == 2);
|
||||
|
||||
var getMethod = propertyInfo.GetMethod;
|
||||
Debug.Assert(getMethod != null);
|
||||
Debug.Assert(!getMethod.IsStatic);
|
||||
Debug.Assert(getMethod.GetParameters().Length == 0);
|
||||
|
||||
// Instance methods in the CLR can be turned into static methods where the first parameter
|
||||
// is open over "target". This parameter is always passed by reference, so we have a code
|
||||
// path for value types and a code path for reference types.
|
||||
if( getMethod.DeclaringType.GetTypeInfo().IsValueType )
|
||||
{
|
||||
// Create a delegate (ref TDeclaringType) -> TValue
|
||||
return MakeFastPropertyGetter(
|
||||
typeof(ByRefFunc<,>),
|
||||
getMethod,
|
||||
propertyGetterByRefWrapperMethod);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Create a delegate TDeclaringType -> TValue
|
||||
return MakeFastPropertyGetter(
|
||||
typeof(Func<,>),
|
||||
getMethod,
|
||||
propertyGetterWrapperMethod);
|
||||
}
|
||||
}
|
||||
|
||||
private static Func<object, object> MakeFastPropertyGetter(
|
||||
Type openGenericDelegateType,
|
||||
MethodInfo propertyGetMethod,
|
||||
MethodInfo openGenericWrapperMethod)
|
||||
{
|
||||
var typeInput = propertyGetMethod.DeclaringType;
|
||||
var typeOutput = propertyGetMethod.ReturnType;
|
||||
|
||||
var delegateType = openGenericDelegateType.MakeGenericType(typeInput, typeOutput);
|
||||
var propertyGetterDelegate = propertyGetMethod.CreateDelegate(delegateType);
|
||||
|
||||
var wrapperDelegateMethod = openGenericWrapperMethod.MakeGenericMethod(typeInput, typeOutput);
|
||||
var accessorDelegate = wrapperDelegateMethod.CreateDelegate(
|
||||
typeof(Func<object, object>),
|
||||
propertyGetterDelegate);
|
||||
|
||||
return (Func<object, object>)accessorDelegate;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a single fast property setter for reference types. The result is not cached.
|
||||
/// </summary>
|
||||
/// <param name="propertyInfo">propertyInfo to extract the setter for.</param>
|
||||
/// <returns>a fast getter.</returns>
|
||||
/// <remarks>
|
||||
/// This method is more memory efficient than a dynamically compiled lambda, and about the
|
||||
/// same speed. This only works for reference types.
|
||||
/// </remarks>
|
||||
public static Action<object, object> MakeFastPropertySetter(PropertyInfo propertyInfo)
|
||||
{
|
||||
Debug.Assert(propertyInfo != null);
|
||||
Debug.Assert(!propertyInfo.DeclaringType.GetTypeInfo().IsValueType);
|
||||
|
||||
var setMethod = propertyInfo.SetMethod;
|
||||
Debug.Assert(setMethod != null);
|
||||
Debug.Assert(!setMethod.IsStatic);
|
||||
Debug.Assert(setMethod.ReturnType == typeof(void));
|
||||
var parameters = setMethod.GetParameters();
|
||||
Debug.Assert(parameters.Length == 1);
|
||||
|
||||
// Instance methods in the CLR can be turned into static methods where the first parameter
|
||||
// is open over "target". This parameter is always passed by reference, so we have a code
|
||||
// path for value types and a code path for reference types.
|
||||
var typeInput = setMethod.DeclaringType;
|
||||
var parameterType = parameters[0].ParameterType;
|
||||
|
||||
// Create a delegate TDeclaringType -> { TDeclaringType.Property = TValue; }
|
||||
var propertySetterAsAction =
|
||||
setMethod.CreateDelegate(typeof(Action<,>).MakeGenericType(typeInput, parameterType));
|
||||
var callPropertySetterClosedGenericMethod =
|
||||
CallPropertySetterOpenGenericMethod.MakeGenericMethod(typeInput, parameterType);
|
||||
var callPropertySetterDelegate =
|
||||
callPropertySetterClosedGenericMethod.CreateDelegate(
|
||||
typeof(Action<object, object>), propertySetterAsAction);
|
||||
|
||||
return (Action<object, object>)callPropertySetterDelegate;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Given an object, adds each instance property with a public get method as a key and its
|
||||
/// associated value to a dictionary.
|
||||
///
|
||||
/// If the object is already an IDictionary{string,object} instance, then a copy
|
||||
/// is returned.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The implementation of PropertyHelper will cache the property accessors per-type. This is
|
||||
/// faster when the same type is used multiple times with ObjectToDictionary.
|
||||
/// </remarks>
|
||||
public static IDictionary<string, object> ObjectToDictionary(object value)
|
||||
{
|
||||
var dictionary = value as IDictionary<string, object>;
|
||||
if( dictionary != null )
|
||||
{
|
||||
return new Dictionary<string, object>(dictionary, StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
dictionary = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
if( value != null )
|
||||
{
|
||||
foreach( var helper in GetProperties(value) )
|
||||
{
|
||||
dictionary[helper.Name] = helper.GetValue(value);
|
||||
}
|
||||
}
|
||||
|
||||
return dictionary;
|
||||
}
|
||||
|
||||
private static PropertyHelper CreateInstance(PropertyInfo property)
|
||||
{
|
||||
return new PropertyHelper(property);
|
||||
}
|
||||
|
||||
// Called via reflection
|
||||
private static object CallPropertyGetter<TDeclaringType, TValue>(
|
||||
Func<TDeclaringType, TValue> getter,
|
||||
object target)
|
||||
{
|
||||
return getter((TDeclaringType)target);
|
||||
}
|
||||
|
||||
// Called via reflection
|
||||
private static object CallPropertyGetterByReference<TDeclaringType, TValue>(
|
||||
ByRefFunc<TDeclaringType, TValue> getter,
|
||||
object target)
|
||||
{
|
||||
var unboxed = (TDeclaringType)target;
|
||||
return getter(ref unboxed);
|
||||
}
|
||||
|
||||
// Called via reflection
|
||||
private static object CallNullSafePropertyGetter<TDeclaringType, TValue>(
|
||||
Func<TDeclaringType, TValue> getter,
|
||||
object target)
|
||||
{
|
||||
if( target == null )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return getter((TDeclaringType)target);
|
||||
}
|
||||
|
||||
// Called via reflection
|
||||
private static object CallNullSafePropertyGetterByReference<TDeclaringType, TValue>(
|
||||
ByRefFunc<TDeclaringType, TValue> getter,
|
||||
object target)
|
||||
{
|
||||
if( target == null )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var unboxed = (TDeclaringType)target;
|
||||
return getter(ref unboxed);
|
||||
}
|
||||
|
||||
private static void CallPropertySetter<TDeclaringType, TValue>(
|
||||
Action<TDeclaringType, TValue> setter,
|
||||
object target,
|
||||
object value)
|
||||
{
|
||||
setter((TDeclaringType)target, (TValue)value);
|
||||
}
|
||||
|
||||
protected static PropertyHelper[] GetVisibleProperties(
|
||||
Type type,
|
||||
Func<PropertyInfo, PropertyHelper> createPropertyHelper,
|
||||
ConcurrentDictionary<Type, PropertyHelper[]> allPropertiesCache,
|
||||
ConcurrentDictionary<Type, PropertyHelper[]> visiblePropertiesCache)
|
||||
{
|
||||
PropertyHelper[] result;
|
||||
if( visiblePropertiesCache.TryGetValue(type, out result) )
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
// The simple and common case, this is normal POCO object - no need to allocate.
|
||||
var allPropertiesDefinedOnType = true;
|
||||
var allProperties = GetProperties(type, createPropertyHelper, allPropertiesCache);
|
||||
foreach( var propertyHelper in allProperties )
|
||||
{
|
||||
if( propertyHelper.Property.DeclaringType != type )
|
||||
{
|
||||
allPropertiesDefinedOnType = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( allPropertiesDefinedOnType )
|
||||
{
|
||||
result = allProperties;
|
||||
visiblePropertiesCache.TryAdd(type, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
// There's some inherited properties here, so we need to check for hiding via 'new'.
|
||||
var filteredProperties = new List<PropertyHelper>(allProperties.Length);
|
||||
foreach( var propertyHelper in allProperties )
|
||||
{
|
||||
var declaringType = propertyHelper.Property.DeclaringType;
|
||||
if( declaringType == type )
|
||||
{
|
||||
filteredProperties.Add(propertyHelper);
|
||||
continue;
|
||||
}
|
||||
|
||||
// If this property was declared on a base type then look for the definition closest to the
|
||||
// the type to see if we should include it.
|
||||
var ignoreProperty = false;
|
||||
|
||||
// Walk up the hierarchy until we find the type that actually declares this
|
||||
// PropertyInfo.
|
||||
var currentTypeInfo = type.GetTypeInfo();
|
||||
var declaringTypeInfo = declaringType.GetTypeInfo();
|
||||
while( currentTypeInfo != null && currentTypeInfo != declaringTypeInfo )
|
||||
{
|
||||
// We've found a 'more proximal' public definition
|
||||
var declaredProperty = currentTypeInfo.GetDeclaredProperty(propertyHelper.Name);
|
||||
if( declaredProperty != null )
|
||||
{
|
||||
ignoreProperty = true;
|
||||
break;
|
||||
}
|
||||
|
||||
currentTypeInfo = currentTypeInfo.BaseType?.GetTypeInfo();
|
||||
}
|
||||
|
||||
if( !ignoreProperty )
|
||||
{
|
||||
filteredProperties.Add(propertyHelper);
|
||||
}
|
||||
}
|
||||
|
||||
result = filteredProperties.ToArray();
|
||||
visiblePropertiesCache.TryAdd(type, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
protected static PropertyHelper[] GetProperties(
|
||||
Type type,
|
||||
Func<PropertyInfo, PropertyHelper> createPropertyHelper,
|
||||
ConcurrentDictionary<Type, PropertyHelper[]> cache)
|
||||
{
|
||||
// Unwrap nullable types. This means Nullable<T>.Value and Nullable<T>.HasValue will not be
|
||||
// part of the sequence of properties returned by this method.
|
||||
type = Nullable.GetUnderlyingType(type) ?? type;
|
||||
|
||||
PropertyHelper[] helpers;
|
||||
if( !cache.TryGetValue(type, out helpers) )
|
||||
{
|
||||
// We avoid loading indexed properties using the Where statement.
|
||||
var properties = type.GetRuntimeProperties().Where(IsInterestingProperty);
|
||||
|
||||
var typeInfo = type.GetTypeInfo();
|
||||
if( typeInfo.IsInterface )
|
||||
{
|
||||
// Reflection does not return information about inherited properties on the interface itself.
|
||||
properties = properties.Concat(typeInfo.ImplementedInterfaces.SelectMany(
|
||||
interfaceType => interfaceType.GetRuntimeProperties().Where(IsInterestingProperty)));
|
||||
}
|
||||
|
||||
helpers = properties.Select(p => createPropertyHelper(p)).ToArray();
|
||||
cache.TryAdd(type, helpers);
|
||||
}
|
||||
|
||||
return helpers;
|
||||
}
|
||||
|
||||
// Indexed properties are not useful (or valid) for grabbing properties off an object.
|
||||
private static bool IsInterestingProperty(PropertyInfo property)
|
||||
{
|
||||
return property.GetIndexParameters().Length == 0 &&
|
||||
property.GetMethod != null &&
|
||||
property.GetMethod.IsPublic &&
|
||||
!property.GetMethod.IsStatic;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1dffb6ae397451d4984cf8a0dce3796e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
#pragma warning disable 1591
|
||||
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using RethinkDb.Driver.Model;
|
||||
using RethinkDb.Driver.Proto;
|
||||
|
||||
namespace RethinkDb.Driver.Ast
|
||||
{
|
||||
/* An instance for a query that has been sent to the server. Keeps
|
||||
* track of its token, the args to .run() it was called with, and its
|
||||
* query type.
|
||||
*/
|
||||
|
||||
/// <summary>
|
||||
/// DO NOT USE DIRECTLY
|
||||
/// </summary>
|
||||
public class Query
|
||||
{
|
||||
public QueryType Type { get; }
|
||||
public long Token { get; }
|
||||
public ReqlAst Term { get; }
|
||||
public OptArgs GlobalOptions { get; }
|
||||
|
||||
public Query(QueryType type, long token, ReqlAst term, OptArgs globalOptions)
|
||||
{
|
||||
this.Type = type;
|
||||
this.Token = token;
|
||||
this.Term = term;
|
||||
this.GlobalOptions = globalOptions;
|
||||
}
|
||||
|
||||
public Query(QueryType type, long token) : this(type, token, null, null)
|
||||
{
|
||||
}
|
||||
|
||||
public static Query Stop(long token)
|
||||
{
|
||||
return new Query(QueryType.STOP, token, null, null);
|
||||
}
|
||||
|
||||
public static Query Continue(long token)
|
||||
{
|
||||
return new Query(QueryType.CONTINUE, token, null, null);
|
||||
}
|
||||
|
||||
public static Query Start(long token, ReqlAst term, OptArgs globalOptions)
|
||||
{
|
||||
return new Query(QueryType.START, token, term, globalOptions);
|
||||
}
|
||||
|
||||
public static Query ServerInfo(long token)
|
||||
{
|
||||
return new Query(QueryType.SERVER_INFO, token, null, null);
|
||||
}
|
||||
|
||||
public static Query NoReplyWait(long token)
|
||||
{
|
||||
return new Query(QueryType.NOREPLY_WAIT, token, null, null);
|
||||
}
|
||||
|
||||
public virtual string Serialize()
|
||||
{
|
||||
var queryArr = new JArray();
|
||||
|
||||
queryArr.Add(Type);
|
||||
|
||||
if( Term != null )
|
||||
{
|
||||
queryArr.Add(Term.Build());
|
||||
}
|
||||
if( GlobalOptions != null )
|
||||
{
|
||||
queryArr.Add(ReqlAst.BuildOptarg(GlobalOptions));
|
||||
}
|
||||
|
||||
return queryArr.ToString(Formatting.None);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: cef144145ff323247ab108fe4eaa76c5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
450
Assets/Scripts/ServerShared/NIH/RethinkDb.Driver/Ast/ReqlAst.cs
Normal file
450
Assets/Scripts/ServerShared/NIH/RethinkDb.Driver/Ast/ReqlAst.cs
Normal file
|
|
@ -0,0 +1,450 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using RethinkDb.Driver.Model;
|
||||
using RethinkDb.Driver.Net;
|
||||
using RethinkDb.Driver.Proto;
|
||||
using RethinkDb.Driver.Utils;
|
||||
|
||||
namespace RethinkDb.Driver.Ast
|
||||
{
|
||||
/// <summary>
|
||||
/// Base class for all reql queries.
|
||||
/// </summary>
|
||||
public class ReqlAst
|
||||
{
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
protected internal TermType TermType { get; }
|
||||
protected internal Arguments Args { get; }
|
||||
protected internal OptArgs OptArgs { get; }
|
||||
|
||||
protected internal ReqlAst(TermType termType, Arguments args, OptArgs optargs)
|
||||
{
|
||||
this.TermType = termType;
|
||||
this.Args = args ?? new Arguments();
|
||||
this.OptArgs = optargs ?? new OptArgs();
|
||||
}
|
||||
|
||||
protected internal virtual object Build()
|
||||
{
|
||||
// Create a JSON object from the Ast
|
||||
JArray list = new JArray();
|
||||
list.Add(TermType);
|
||||
if( Args.Count > 0 )
|
||||
{
|
||||
var collect = Args.Select(a => { return a.Build(); });
|
||||
list.Add(new JArray(collect));
|
||||
}
|
||||
else
|
||||
{
|
||||
list.Add(new JArray());
|
||||
}
|
||||
|
||||
if( OptArgs.Count > 0 )
|
||||
{
|
||||
list.Add(BuildOptarg(this.OptArgs));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
protected internal static JObject BuildOptarg(OptArgs opts)
|
||||
{
|
||||
var dict = opts.ToDictionary(kvp => kvp.Key, kvp => kvp.Value.Build());
|
||||
return JObject.FromObject(dict);
|
||||
}
|
||||
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
#region DYNAMIC LANGUAGE RUNTIME (DLR) RUNNERS
|
||||
|
||||
/// <summary>
|
||||
/// Runs the query on the connection. If you know the response type
|
||||
/// of your query, T (SUCCESS_ATOM) or Cursor[T] (SUCCESS_SEQUENCE or SUCCESS_PARTIAL)
|
||||
/// it's recommended to use `.RunAtom`, `.RunCursor` or `.RunResult` helpers
|
||||
/// as they offer a slight edge in performance since both bypass the
|
||||
/// dynamic language runtime execution engine.
|
||||
/// </summary>
|
||||
/// <returns>Returns T or Cursor[T]</returns>
|
||||
public virtual Task<dynamic> RunAsync<T>(IConnection conn, object runOpts = null, CancellationToken cancelToken = default)
|
||||
{
|
||||
return conn.RunAsync<T>(this, runOpts, cancelToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Runs the query on the connection. If you know the response type
|
||||
/// of your query, T (SUCCESS_ATOM) or Cursor[T] (SUCCESS_SEQUENCE or SUCCESS_PARTIAL)
|
||||
/// it's recommended to use `.RunAtom`, `.RunCursor` or `.RunResult` helpers
|
||||
/// as they offer a slight edge in performance since both bypass the
|
||||
/// dynamic language runtime execution engine.
|
||||
/// </summary>
|
||||
/// <returns>Returns T or Cursor[T]</returns>
|
||||
public virtual Task<dynamic> RunAsync<T>(IConnection conn, CancellationToken cancelToken)
|
||||
{
|
||||
return RunAsync<T>(conn, null, cancelToken);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Runs the query on the connection. If you know the response type
|
||||
/// of your query, T (SUCCESS_ATOM) or Cursor[T] (SUCCESS_SEQUENCE or SUCCESS_PARTIAL)
|
||||
/// it's recommended to use `.RunAtom`, `.RunCursor` or `.RunResult` helpers
|
||||
/// as they offer a slight edge in performance since both bypass the
|
||||
/// dynamic language runtime execution engine.
|
||||
/// </summary>
|
||||
/// <returns>Returns T or Cursor[T]</returns>
|
||||
/// /// <param name="conn">connection</param>
|
||||
/// <param name="runOpts">global anonymous type optional arguments</param>
|
||||
/// <param name="cancelToken">Cancellation token used to stop *waiting* for a query response. The cancellation token does not cancel the query's execution on the server.</param>
|
||||
public virtual Task<dynamic> RunAsync(IConnection conn, object runOpts = null, CancellationToken cancelToken = default)
|
||||
{
|
||||
return RunAsync<dynamic>(conn, runOpts, cancelToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Runs the query on the connection. If you know the response type
|
||||
/// of your query, T (SUCCESS_ATOM) or Cursor[T] (SUCCESS_SEQUENCE or SUCCESS_PARTIAL)
|
||||
/// it's recommended to use `.RunAtom`, `.RunCursor` or `.RunResult` helpers
|
||||
/// as they offer a slight edge in performance since both bypass the
|
||||
/// dynamic language runtime execution engine.
|
||||
/// </summary>
|
||||
/// <returns>Returns T or Cursor[T]</returns>
|
||||
/// /// <param name="conn">connection</param>
|
||||
/// <param name="cancelToken">Cancellation token used to stop *waiting* for a query response. The cancellation token does not cancel the query's execution on the server.</param>
|
||||
public virtual Task<dynamic> RunAsync(IConnection conn, CancellationToken cancelToken)
|
||||
{
|
||||
return RunAsync(conn, null, cancelToken);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Runs the query on the connection. If you know the response type
|
||||
/// of your query, T (SUCCESS_ATOM) or Cursor[T] (SUCCESS_SEQUENCE or SUCCESS_PARTIAL)
|
||||
/// it's recommended to use `.RunAtom`, `.RunCursor` or `.RunResult` helpers
|
||||
/// as they offer a slight edge in performance since both bypass the
|
||||
/// dynamic language runtime execution engine.
|
||||
/// </summary>
|
||||
/// <returns>Returns T or Cursor[T]</returns>
|
||||
public virtual dynamic Run<T>(IConnection conn, object runOpts = null)
|
||||
{
|
||||
return RunAsync<T>(conn, runOpts).WaitSync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Runs the query on the connection. If you know the response type
|
||||
/// of your query, T (SUCCESS_ATOM) or Cursor[T] (SUCCESS_SEQUENCE or SUCCESS_PARTIAL)
|
||||
/// it's recommended to use `.RunAtom`, `.RunCursor` or `.RunResult` helpers
|
||||
/// as they offer a slight edge in performance since both bypass the
|
||||
/// dynamic language runtime execution engine.
|
||||
/// </summary>
|
||||
/// <returns>Returns T or Cursor[T]</returns>
|
||||
public virtual dynamic Run(IConnection conn, object runOpts = null)
|
||||
{
|
||||
return Run<dynamic>(conn, runOpts);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region RESPONSE TYPED RUNNERS
|
||||
|
||||
/// <summary>
|
||||
/// Executes a query with no expected response. Useful for fire-and-forget queries like insert, update.
|
||||
/// </summary>
|
||||
public void RunNoReply(IConnection conn, object runOpts = null)
|
||||
{
|
||||
conn.RunNoReply(this, runOpts);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use this method if you're expecting a cursor (SUCCESS_SEQUENCE or SUCCESS_PARTIAL) response
|
||||
/// from your query. This method offers a slight edge in performance without the need for the
|
||||
/// dynamic language runtime like the run() method uses.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="conn">connection</param>
|
||||
/// <param name="runOpts">global anonymous type optional arguments</param>
|
||||
/// <param name="cancelToken">Cancellation token used to stop *waiting* for a query response. The cancellation token does not cancel the query's execution on the server.</param>
|
||||
/// <returns>A Cursor</returns>
|
||||
public virtual Task<Cursor<T>> RunCursorAsync<T>(IConnection conn, object runOpts = null, CancellationToken cancelToken = default)
|
||||
{
|
||||
return conn.RunCursorAsync<T>(this, runOpts, cancelToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use this method if you're expecting a cursor (SUCCESS_SEQUENCE or SUCCESS_PARTIAL) response
|
||||
/// from your query. This method offers a slight edge in performance without the need for the
|
||||
/// dynamic language runtime like the run() method uses.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="conn">connection</param>
|
||||
/// <param name="cancelToken">Cancellation token used to stop *waiting* for a query response. The cancellation token does not cancel the query's execution on the server.</param>
|
||||
/// <returns>A Cursor</returns>
|
||||
public virtual Task<Cursor<T>> RunCursorAsync<T>(IConnection conn, CancellationToken cancelToken)
|
||||
{
|
||||
return RunCursorAsync<T>(conn, null, cancelToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use this method if you're expecting a cursor (SUCCESS_SEQUENCE or SUCCESS_PARTIAL) response
|
||||
/// from your query. This method offers a slight edge in performance without the need for the
|
||||
/// dynamic language runtime like the run() method uses.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="conn">connection</param>
|
||||
/// <param name="runOpts">global anonymous type optional arguments</param>
|
||||
/// <returns>A Cursor</returns>
|
||||
public virtual Cursor<T> RunCursor<T>(IConnection conn, object runOpts = null)
|
||||
{
|
||||
return RunCursorAsync<T>(conn, runOpts).WaitSync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use this method if you're expecting SUCCESS_ATOM response from your query. This
|
||||
/// method offers a slight edge in performance without the need for the
|
||||
/// dynamic language runtime like the run() method uses.
|
||||
/// </summary>
|
||||
/// <param name="conn">connection</param>
|
||||
/// <param name="runOpts">global anonymous type optional arguments</param>
|
||||
/// <param name="cancelToken">Cancellation token used to stop *waiting* for a query response. The cancellation token does not cancel the query's execution on the server.</param>
|
||||
public virtual Task<T> RunAtomAsync<T>(IConnection conn, object runOpts = null, CancellationToken cancelToken = default)
|
||||
{
|
||||
return conn.RunAtomAsync<T>(this, runOpts, cancelToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use this method if you're expecting SUCCESS_ATOM response from your query. This
|
||||
/// method offers a slight edge in performance without the need for the
|
||||
/// dynamic language runtime like the run() method uses.
|
||||
/// </summary>
|
||||
/// <param name="conn">connection</param>
|
||||
/// <param name="cancelToken">Cancellation token used to stop *waiting* for a query response. The cancellation token does not cancel the query's execution on the server.</param>
|
||||
public virtual Task<T> RunAtomAsync<T>(IConnection conn, CancellationToken cancelToken)
|
||||
{
|
||||
return RunAtomAsync<T>(conn, null, cancelToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use this method if you're expecting SUCCESS_ATOM response from your query. This
|
||||
/// method offers a slight edge in performance without the need for the
|
||||
/// dynamic language runtime like the run() method uses.
|
||||
/// </summary>
|
||||
/// <param name="conn">connection</param>
|
||||
/// <param name="runOpts">global anonymous type optional arguments</param>
|
||||
public virtual T RunAtom<T>(IConnection conn, object runOpts = null)
|
||||
{
|
||||
return RunAtomAsync<T>(conn, runOpts).WaitSync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use this method if you're expecting SUCCESS_ATOM or SUCCESS_SEQUENCE response from your query. This
|
||||
/// method offers a slight edge in performance without the need for the
|
||||
/// dynamic language runtime like the run() method uses. Consider using RunAtom or RunCursor if your
|
||||
/// response is either SUCCESS_ATOM or SUCCESS_SEQUENCE respectively. Exercise caution using this method
|
||||
/// with large datasets as the server can switch responses from SUCESS_SEQUENCE to SUCCESS_PARTIAL for the
|
||||
/// same exact query. Refer to the online documentation for this run helper.
|
||||
/// </summary>
|
||||
/// <param name="conn">connection</param>
|
||||
/// <param name="runOpts">global anonymous type optional arguments</param>
|
||||
/// <param name="cancelToken">Cancellation token used to stop *waiting* for a query response. The cancellation token does not cancel the query's execution on the server.</param>
|
||||
public virtual Task<T> RunResultAsync<T>(IConnection conn, object runOpts = null, CancellationToken cancelToken = default)
|
||||
{
|
||||
return conn.RunResultAsync<T>(this, runOpts, cancelToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use this method if you're expecting SUCCESS_ATOM or SUCCESS_SEQUENCE response from your query. This
|
||||
/// method offers a slight edge in performance without the need for the
|
||||
/// dynamic language runtime like the run() method uses. Consider using RunAtom or RunCursor if your
|
||||
/// response is either SUCCESS_ATOM or SUCCESS_SEQUENCE respectively. Exercise caution using this method
|
||||
/// with large datasets as the server can switch responses from SUCESS_SEQUENCE to SUCCESS_PARTIAL for the
|
||||
/// same exact query. Refer to the online documentation for this run helper.
|
||||
/// </summary>
|
||||
/// <param name="conn">connection</param>
|
||||
/// <param name="cancelToken">Cancellation token used to stop *waiting* for a query response. The cancellation token does not cancel the query's execution on the server.</param>
|
||||
public virtual Task<T> RunResultAsync<T>(IConnection conn, CancellationToken cancelToken)
|
||||
{
|
||||
return RunResultAsync<T>(conn, null, cancelToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use this method if you're expecting SUCCESS_ATOM or SUCCESS_SEQUENCE response from your query. This
|
||||
/// method offers a slight edge in performance without the need for the
|
||||
/// dynamic language runtime like the run() method uses. Consider using RunAtom or RunCursor if your
|
||||
/// response is either SUCCESS_ATOM or SUCCESS_SEQUENCE respectively. Exercise caution using this method
|
||||
/// with large datasets as the server can switch responses from SUCESS_SEQUENCE to SUCCESS_PARTIAL for the
|
||||
/// same exact query. Refer to the online documentation for this run helper.
|
||||
/// </summary>
|
||||
/// <param name="conn">connection</param>
|
||||
/// <param name="runOpts">global anonymous type optional arguments</param>
|
||||
public virtual T RunResult<T>(IConnection conn, object runOpts = null)
|
||||
{
|
||||
return RunResultAsync<T>(conn, runOpts).WaitSync();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region EXTRA RUN HELPERS
|
||||
|
||||
/// <summary>
|
||||
/// OBSOLETE: Please use the .RunWriteAsync() method instead.
|
||||
/// </summary>
|
||||
[Obsolete("The .RunResultAsync() method has been renamed to .RunWriteAsync(). Please use the new method name instead.", error: false)]
|
||||
public virtual Task<Result> RunResultAsync(IConnection conn, object runOpts = null, CancellationToken cancelToken = default)
|
||||
{
|
||||
return RunWriteAsync(conn, runOpts, cancelToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// OBSOLETE: Please use .RunWriteAsync() method instead.
|
||||
/// </summary>
|
||||
[Obsolete("The .RunResultAsync() method has been renamed to .RunWriteAsync(). Please use the new method name instead.", error: false)]
|
||||
public virtual Task<Result> RunResultAsync(IConnection conn, CancellationToken cancelToken)
|
||||
{
|
||||
return RunWriteAsync(conn, null, cancelToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// OBSOLETE: Please use .RunWrite() method instead.
|
||||
/// </summary>
|
||||
[Obsolete("The .RunResult() method has been renamed to .RunWrite(). Please use the new method name instead.", error: false)]
|
||||
public virtual Result RunResult(IConnection conn, object runOpts = null)
|
||||
{
|
||||
return RunWriteAsync(conn, runOpts).WaitSync();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Helper shortcut for DML type of queries that returns # of inserts, deletes, errors.
|
||||
/// This method bypasses the dynamic language runtime for extra performance.
|
||||
/// </summary>
|
||||
/// <param name="conn">connection</param>
|
||||
/// <param name="runOpts">global anonymous type optional arguments</param>
|
||||
/// <param name="cancelToken">Cancellation token used to stop *waiting* for a query response. The cancellation token does not cancel the query's execution on the server.</param>
|
||||
public virtual Task<Result> RunWriteAsync(IConnection conn, object runOpts = null, CancellationToken cancelToken = default)
|
||||
{
|
||||
return conn.RunAtomAsync<Result>(this, runOpts, cancelToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper shortcut for DML type of queries that returns # of inserts, deletes, errors.
|
||||
/// This method bypasses the dynamic language runtime for extra performance.
|
||||
/// </summary>
|
||||
/// <param name="conn">connection</param>
|
||||
/// <param name="cancelToken">Cancellation token used to stop *waiting* for a query response. The cancellation token does not cancel the query's execution on the server.</param>
|
||||
public virtual Task<Result> RunWriteAsync(IConnection conn, CancellationToken cancelToken)
|
||||
{
|
||||
return RunWriteAsync(conn, null, cancelToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper shortcut for DML type of queries that returns # of inserts, deletes, errors.
|
||||
/// This method bypasses the dynamic language runtime for extra performance.
|
||||
/// </summary>
|
||||
/// <param name="conn">connection</param>
|
||||
/// <param name="runOpts">global anonymous type optional arguments</param>
|
||||
public virtual Result RunWrite(IConnection conn, object runOpts = null)
|
||||
{
|
||||
return RunWriteAsync(conn, runOpts).WaitSync();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Runs a query on the server and returns the raw <see cref="Response"/> object in an unsafe way
|
||||
/// with minimal client-side processing. The unbridled use of this method can
|
||||
/// lead to memory leaks on both the client and server. This method should only
|
||||
/// be used in well-understood and advanced scenarios.
|
||||
/// </summary>
|
||||
/// <param name="conn">The connection object</param>
|
||||
/// <param name="runOpts">global anonymous type optional arguments</param>
|
||||
/// <param name="cancelToken">Cancellation token used to stop *waiting* for a query response. The cancellation token does not cancel the query's execution on the server.</param>
|
||||
public virtual Task<Response> RunUnsafeAsync(IConnection conn, object runOpts = null, CancellationToken cancelToken = default)
|
||||
{
|
||||
return conn.RunUnsafeAsync(this, runOpts, cancelToken);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Helper shortcut for change feeds, use if your query is expecting an infinite changes() stream.
|
||||
/// This method bypasses the dynamic language runtime for extra performance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The document type of new/old value</typeparam>
|
||||
/// <param name="conn">connection</param>
|
||||
/// <param name="runOpts">global anonymous type optional arguments</param>
|
||||
/// <param name="cancelToken">Cancellation token used to stop *waiting* for a query response. The cancellation token does not cancel the query's execution on the server.</param>
|
||||
public virtual Task<Cursor<Change<T>>> RunChangesAsync<T>(IConnection conn, object runOpts = null, CancellationToken cancelToken = default)
|
||||
{
|
||||
return conn.RunCursorAsync<Change<T>>(this, runOpts, cancelToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper shortcut for change feeds, use if your query is expecting an infinite changes() stream.
|
||||
/// This method bypasses the dynamic language runtime for extra performance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The document type of new/old value</typeparam>
|
||||
/// <param name="conn">connection</param>
|
||||
/// <param name="cancelToken">Cancellation token used to stop *waiting* for a query response. The cancellation token does not cancel the query's execution on the server.</param>
|
||||
public virtual Task<Cursor<Change<T>>> RunChangesAsync<T>(IConnection conn, CancellationToken cancelToken)
|
||||
{
|
||||
return RunChangesAsync<T>(conn, null, cancelToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper shortcut for change feeds, use if your query is expecting an infinite changes() stream.
|
||||
/// This method bypasses the dynamic language runtime for extra performance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The document type of new/old value</typeparam>
|
||||
/// <param name="conn">connection</param>
|
||||
/// <param name="runOpts">global anonymous type optional arguments</param>
|
||||
public virtual Cursor<Change<T>> RunChanges<T>(IConnection conn, object runOpts = null)
|
||||
{
|
||||
return RunChangesAsync<T>(conn, runOpts).WaitSync();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Helper shortcut for grouping queries.
|
||||
/// This method bypasses the dynamic language runtime for extra performance.
|
||||
/// </summary>
|
||||
/// <typeparam name="TKey">The key type of how items are grouped</typeparam>
|
||||
/// <typeparam name="TItem">The type of items</typeparam>
|
||||
/// <param name="conn">connection</param>
|
||||
/// <param name="runOpts">global anonymous type optional arguments</param>
|
||||
/// <param name="cancelToken">Cancellation token used to stop *waiting* for a query response. The cancellation token does not cancel the query's execution on the server.</param>
|
||||
public virtual async Task<IEnumerable<GroupedResult<TKey, TItem>>> RunGroupingAsync<TKey, TItem>(IConnection conn, object runOpts = null,
|
||||
CancellationToken cancelToken = default)
|
||||
{
|
||||
var tsk = await RunAtomAsync<GroupedResultSet<TKey, TItem>>(conn, runOpts, cancelToken).ConfigureAwait(false);
|
||||
return tsk;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper shortcut for grouping queries.
|
||||
/// This method bypasses the dynamic language runtime for extra performance.
|
||||
/// </summary>
|
||||
/// <typeparam name="TKey">The key type of how items are grouped</typeparam>
|
||||
/// <typeparam name="TItem">The type of items</typeparam>
|
||||
/// <param name="conn">connection</param>
|
||||
/// <param name="cancelToken">Cancellation token used to stop *waiting* for a query response. The cancellation token does not cancel the query's execution on the server.</param>
|
||||
public virtual Task<IEnumerable<GroupedResult<TKey, TItem>>> RunGroupingAsync<TKey, TItem>(IConnection conn, CancellationToken cancelToken)
|
||||
{
|
||||
return RunGroupingAsync<TKey, TItem>(conn, null, cancelToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper shortcut for grouping queries.
|
||||
/// This method bypasses the dynamic language runtime for extra performance.
|
||||
/// </summary>
|
||||
/// <typeparam name="TKey">The key type of how items are grouped</typeparam>
|
||||
/// <typeparam name="TItem">The type of items</typeparam>
|
||||
/// <param name="conn">connection</param>
|
||||
/// <param name="runOpts">global anonymous type optional arguments</param>
|
||||
public virtual IEnumerable<GroupedResult<TKey, TItem>> RunGrouping<TKey, TItem>(IConnection conn, object runOpts = null)
|
||||
{
|
||||
return RunAtomAsync<GroupedResultSet<TKey, TItem>>(conn, runOpts).WaitSync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 525d7b2d52e0ac044a7b5761bed6ef78
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
194
Assets/Scripts/ServerShared/NIH/RethinkDb.Driver/Ast/ReqlExpr.cs
Normal file
194
Assets/Scripts/ServerShared/NIH/RethinkDb.Driver/Ast/ReqlExpr.cs
Normal file
|
|
@ -0,0 +1,194 @@
|
|||
#pragma warning disable 1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
|
||||
using System;
|
||||
|
||||
namespace RethinkDb.Driver.Ast
|
||||
{
|
||||
//Partial class for overloads expression overloads! :)
|
||||
//Cool man. Yeeah. That's right. So 1337.
|
||||
#pragma warning disable 660,661
|
||||
public partial class ReqlExpr
|
||||
#pragma warning restore 660,661
|
||||
{
|
||||
#region INDEXERS, READ WARNING
|
||||
// WARNING:
|
||||
// ANY ADDITIONAL INDEXERS YOU SPECIFY HERE MUST BE NEWLY
|
||||
// IMPLEMENTED IN THE AST SUBCLASS TEMPLATE TO BE PROPERLY
|
||||
// RESOLVED DURING OPERATOR RESOLUTION. REGEN OF THE AST
|
||||
// IS REQUIRED.
|
||||
//
|
||||
// SEE ReqlExprHelpers SECTION IN AstSublcassTemplate FOR
|
||||
// MORE INFORMATION.
|
||||
///
|
||||
/// <summary>
|
||||
/// Get a single field from an object. If called on a sequence, gets that field from every object in the sequence, skipping objects that lack it.
|
||||
/// </summary>
|
||||
/// <param name="bracket"></param>
|
||||
public Bracket this[string bracket] => this.bracket(bracket);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get the nth element of a sequence, counting from zero. If the argument is negative, count from the last element.
|
||||
/// </summary>
|
||||
/// <param name="bracket"></param>
|
||||
/// <returns></returns>
|
||||
public Bracket this[int bracket] => this.bracket(bracket);
|
||||
#endregion
|
||||
|
||||
public static ReqlExpr operator >(ReqlExpr a, ReqlExpr b)
|
||||
{
|
||||
return a.gt(b);
|
||||
}
|
||||
|
||||
public static ReqlExpr operator <(ReqlExpr a, ReqlExpr b)
|
||||
{
|
||||
return a.lt(b);
|
||||
}
|
||||
|
||||
public static ReqlExpr operator >=(ReqlExpr a, ReqlExpr b)
|
||||
{
|
||||
return a.ge(b);
|
||||
}
|
||||
|
||||
public static ReqlExpr operator <=(ReqlExpr a, ReqlExpr b)
|
||||
{
|
||||
return a.le(b);
|
||||
}
|
||||
|
||||
public static ReqlExpr operator ==(ReqlExpr a, ReqlExpr b)
|
||||
{
|
||||
return a.eq(b);
|
||||
}
|
||||
|
||||
public static ReqlExpr operator !=(ReqlExpr a, ReqlExpr b)
|
||||
{
|
||||
return a.ne(b);
|
||||
}
|
||||
|
||||
public static ReqlExpr operator +(ReqlExpr a, ReqlExpr b)
|
||||
{
|
||||
return a.add(b);
|
||||
}
|
||||
|
||||
public static ReqlExpr operator -(ReqlExpr a, ReqlExpr b)
|
||||
{
|
||||
return a.sub(b);
|
||||
}
|
||||
|
||||
public static ReqlExpr operator *(ReqlExpr a, ReqlExpr b)
|
||||
{
|
||||
return a.mul(b);
|
||||
}
|
||||
|
||||
public static ReqlExpr operator /(ReqlExpr a, ReqlExpr b)
|
||||
{
|
||||
return a.div(b);
|
||||
}
|
||||
|
||||
public static ReqlExpr operator %(ReqlExpr a, ReqlExpr b)
|
||||
{
|
||||
return a.mod(b);
|
||||
}
|
||||
|
||||
public static ReqlExpr operator !(ReqlExpr a)
|
||||
{
|
||||
return a.not();
|
||||
}
|
||||
|
||||
|
||||
//&& and || might be a bit tricky here.
|
||||
public static bool operator false(ReqlExpr a)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool operator true(ReqlExpr a)
|
||||
{
|
||||
return false; //forces evaluation of & and | ?
|
||||
//this might be a bug here.
|
||||
}
|
||||
|
||||
public static ReqlExpr operator &(ReqlExpr a, ReqlExpr b)
|
||||
{
|
||||
return a.and(b);
|
||||
}
|
||||
|
||||
public static ReqlExpr operator |(ReqlExpr a, ReqlExpr b)
|
||||
{
|
||||
return a.or(b);
|
||||
}
|
||||
|
||||
|
||||
//Can we do implicit operators???
|
||||
public static implicit operator ReqlExpr(string a)
|
||||
{
|
||||
return Util.ToReqlExpr(a);
|
||||
}
|
||||
|
||||
public static implicit operator ReqlExpr(int a)
|
||||
{
|
||||
return Util.ToReqlExpr(a);
|
||||
}
|
||||
|
||||
public static implicit operator ReqlExpr(uint a)
|
||||
{
|
||||
return Util.ToReqlExpr(a);
|
||||
}
|
||||
|
||||
public static implicit operator ReqlExpr(byte a)
|
||||
{
|
||||
return Util.ToReqlExpr(a);
|
||||
}
|
||||
|
||||
public static implicit operator ReqlExpr(sbyte a)
|
||||
{
|
||||
return Util.ToReqlExpr(a);
|
||||
}
|
||||
|
||||
public static implicit operator ReqlExpr(long a)
|
||||
{
|
||||
return Util.ToReqlExpr(a);
|
||||
}
|
||||
|
||||
public static implicit operator ReqlExpr(ulong a)
|
||||
{
|
||||
return Util.ToReqlExpr(a);
|
||||
}
|
||||
|
||||
public static implicit operator ReqlExpr(double a)
|
||||
{
|
||||
return Util.ToReqlExpr(a);
|
||||
}
|
||||
|
||||
public static implicit operator ReqlExpr(decimal a)
|
||||
{
|
||||
return Util.ToReqlExpr(a);
|
||||
}
|
||||
|
||||
public static implicit operator ReqlExpr(float a)
|
||||
{
|
||||
return Util.ToReqlExpr(a);
|
||||
}
|
||||
|
||||
public static implicit operator ReqlExpr(DateTime a)
|
||||
{
|
||||
return Util.ToReqlExpr(a);
|
||||
}
|
||||
|
||||
public static implicit operator ReqlExpr(DateTimeOffset a)
|
||||
{
|
||||
return Util.ToReqlExpr(a);
|
||||
}
|
||||
|
||||
public static implicit operator ReqlExpr(Delegate a)
|
||||
{
|
||||
return Util.ToReqlExpr(a);
|
||||
}
|
||||
|
||||
public string ToRawString()
|
||||
{
|
||||
return ReqlRaw.ToRawString(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 32b53a1e5fbf70e48bd6200f09e30341
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
116
Assets/Scripts/ServerShared/NIH/RethinkDb.Driver/Ast/ReqlRaw.cs
Normal file
116
Assets/Scripts/ServerShared/NIH/RethinkDb.Driver/Ast/ReqlRaw.cs
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using RethinkDb.Driver.Model;
|
||||
using RethinkDb.Driver.Proto;
|
||||
|
||||
namespace RethinkDb.Driver.Ast
|
||||
{
|
||||
/// <summary>
|
||||
/// Used to inject raw protocol strings when the AST is dumped on the wire.
|
||||
/// </summary>
|
||||
public class ReqlRawExpr : ReqlExpr
|
||||
{
|
||||
private string RawProtocol { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Create an AST mid-flight with the raw protocol string.
|
||||
/// </summary>
|
||||
/// <param name="rawProtocol">Raw protocol string from ReqlAst.Build()</param>
|
||||
internal ReqlRawExpr(string rawProtocol) : base(new TermType(), null, null)
|
||||
{
|
||||
this.RawProtocol = rawProtocol;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return the JToken representation of the raw protocol
|
||||
/// </summary>
|
||||
protected internal override object Build()
|
||||
{
|
||||
return JToken.Parse(this.RawProtocol);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Used to inject raw protocol strings when the AST is dumped on the wire.
|
||||
/// </summary>
|
||||
public class ReqlRaw : ReqlAst
|
||||
{
|
||||
private string RawProtocol { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Create an AST mid-flight with the raw protocol string.
|
||||
/// </summary>
|
||||
/// <param name="rawProtocol">Raw protocol string from ReqlAst.Build()</param>
|
||||
internal ReqlRaw(string rawProtocol) : base(new TermType(), null, null)
|
||||
{
|
||||
this.RawProtocol = rawProtocol;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return the JToken representation of the raw protocol
|
||||
/// </summary>
|
||||
protected internal override object Build()
|
||||
{
|
||||
return JToken.Parse(this.RawProtocol);
|
||||
}
|
||||
|
||||
private const string RawTokenType = "$reql_reqlraw$";
|
||||
|
||||
/// <summary>
|
||||
/// Convert an AST item into a raw protocol string representation.
|
||||
/// Useful for serialization.
|
||||
/// </summary>
|
||||
/// <param name="astItem">Can be anything, ReqlFunction or otherwise</param>
|
||||
public static string ToRawString(object astItem)
|
||||
{
|
||||
var list = new List<Guid>();
|
||||
var token = Util.ToReqlAst(astItem, o => HookFuncTypes(o, list)).Build() as JToken;
|
||||
var query = token.ToString(Formatting.None);
|
||||
//pack
|
||||
return $"{string.Join("|", list)}{RawTokenType}{query}";
|
||||
}
|
||||
|
||||
internal static string HydrateProtocolString(string reqlRawString)
|
||||
{
|
||||
var tokenLocation = reqlRawString.IndexOf(RawTokenType, StringComparison.Ordinal);
|
||||
var guidStrings = reqlRawString.Substring(0, tokenLocation);
|
||||
var query = reqlRawString.Substring(tokenLocation + RawTokenType.Length);
|
||||
|
||||
//unpack
|
||||
var replaceTokens = guidStrings.Split('|')
|
||||
.Select(g => new { GuidString = $@"""{g}""", VarId = Func.NextVarId() });
|
||||
|
||||
foreach (var token in replaceTokens)
|
||||
{
|
||||
query = query.Replace(token.GuidString, token.VarId.ToString());
|
||||
}
|
||||
return query;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert a raw protocol string into an AST term that will
|
||||
/// be injected when the AST is serialized.
|
||||
/// </summary>
|
||||
/// <param name="reqlRawString">The raw protocol string to inject</param>
|
||||
/// <returns>A raw AST term</returns>
|
||||
public static ReqlRaw FromRawString(string reqlRawString)
|
||||
{
|
||||
var query = HydrateProtocolString(reqlRawString);
|
||||
return new ReqlRaw(query);
|
||||
}
|
||||
|
||||
|
||||
private static ReqlAst HookFuncTypes(object val, List<Guid> context)
|
||||
{
|
||||
var del = val as Delegate;
|
||||
if( del != null )
|
||||
{
|
||||
return Func.Serialize(del, context);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 97581729a9e4faf43bd2272864fd6bc7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
#pragma warning disable 1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
using System;
|
||||
using RethinkDb.Driver.Net.JsonConverters;
|
||||
|
||||
namespace RethinkDb.Driver.Ast
|
||||
{
|
||||
public partial class TopLevel
|
||||
{
|
||||
/// <summary>
|
||||
/// Type-safe helper method for R.Iso8601
|
||||
/// </summary>
|
||||
public Iso8601 Iso8601(DateTime? datetime)
|
||||
{
|
||||
var str = datetime?.ToString("o");
|
||||
return Ast.Iso8601.FromString(str);
|
||||
}
|
||||
/// <summary>
|
||||
/// Type-safe helper method for R.Iso8601
|
||||
/// </summary>
|
||||
public Iso8601 Iso8601(DateTimeOffset? datetime)
|
||||
{
|
||||
var str = datetime?.ToString("o");
|
||||
return Ast.Iso8601.FromString(str);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Type-safe helper for R.EpochTime
|
||||
/// </summary>
|
||||
public EpochTime EpochTime(DateTime? datetime)
|
||||
{
|
||||
var ticks = datetime?.ToUniversalTime().Ticks;
|
||||
var epoch = ReqlDateTimeConverter.ToUnixTime(ticks.Value);
|
||||
return EpochTime(epoch);
|
||||
}
|
||||
/// <summary>
|
||||
/// Type-safe helper for R.EpochTime
|
||||
/// </summary>
|
||||
public EpochTime EpochTime(DateTimeOffset? datetime)
|
||||
{
|
||||
var ticks = datetime?.UtcTicks;
|
||||
var epoch = ReqlDateTimeConverter.ToUnixTime(ticks.Value);
|
||||
return EpochTime(epoch);
|
||||
}
|
||||
|
||||
public ReqlRawExpr FromRawString(string reqlRawString)
|
||||
{
|
||||
var rawProtocol = ReqlRaw.HydrateProtocolString(reqlRawString);
|
||||
return new ReqlRawExpr(rawProtocol);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d17489d39926b8b4096c3d0f3d00600c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
142
Assets/Scripts/ServerShared/NIH/RethinkDb.Driver/Ast/Util.cs
Normal file
142
Assets/Scripts/ServerShared/NIH/RethinkDb.Driver/Ast/Util.cs
Normal file
|
|
@ -0,0 +1,142 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using RethinkDb.Driver.Model;
|
||||
|
||||
namespace RethinkDb.Driver.Ast
|
||||
{
|
||||
internal static class Util
|
||||
{
|
||||
public static ReqlAst ToReqlAst(object val)
|
||||
{
|
||||
return ToReqlAst(val, 100, null);
|
||||
}
|
||||
public static ReqlAst ToReqlAst(object val, Func<object, ReqlAst> hook)
|
||||
{
|
||||
return ToReqlAst(val, 100, hook);
|
||||
}
|
||||
|
||||
public static ReqlExpr ToReqlExpr(object val)
|
||||
{
|
||||
var converted = ToReqlAst(val);
|
||||
var reqlAst = converted as ReqlExpr;
|
||||
if( !ReferenceEquals(reqlAst, null) )
|
||||
{
|
||||
return reqlAst;
|
||||
}
|
||||
throw new ReqlDriverError($"Cannot convert {val} to ReqlExpr");
|
||||
}
|
||||
|
||||
private static ReqlAst ToReqlAst(object val, int remainingDepth, Func<object, ReqlAst> hook = null )
|
||||
{
|
||||
if( remainingDepth <= 0 )
|
||||
{
|
||||
throw new ReqlDriverCompileError("Recursion limit reached converting to ReqlAst");
|
||||
}
|
||||
if( hook != null )
|
||||
{
|
||||
var converted = hook(val);
|
||||
if( !ReferenceEquals(converted, null) )
|
||||
{
|
||||
return converted;
|
||||
}
|
||||
}
|
||||
var ast = val as ReqlAst;
|
||||
if( !ReferenceEquals(ast, null) )
|
||||
{
|
||||
return ast;
|
||||
}
|
||||
|
||||
if( val is JToken token )
|
||||
{
|
||||
return new Poco(token);
|
||||
}
|
||||
|
||||
if( val is IList lst )
|
||||
{
|
||||
Arguments innerValues = new Arguments();
|
||||
foreach( object innerValue in lst )
|
||||
{
|
||||
innerValues.Add(ToReqlAst(innerValue, remainingDepth - 1));
|
||||
}
|
||||
return new MakeArray(innerValues, null);
|
||||
}
|
||||
|
||||
if( val is IDictionary dict )
|
||||
{
|
||||
var obj = new Dictionary<string, ReqlAst>();
|
||||
foreach( var keyObj in dict.Keys )
|
||||
{
|
||||
var key = keyObj as string;
|
||||
if( key == null )
|
||||
{
|
||||
throw new ReqlDriverCompileError("Object keys can only be strings");
|
||||
}
|
||||
|
||||
obj[key] = ToReqlAst(dict[keyObj]);
|
||||
}
|
||||
return MakeObj.fromMap(obj);
|
||||
}
|
||||
|
||||
if( val is Delegate del )
|
||||
{
|
||||
return Func.FromLambda(del);
|
||||
}
|
||||
|
||||
var dt = val as DateTime?;
|
||||
if( dt != null )
|
||||
{
|
||||
return new Poco(dt);
|
||||
}
|
||||
var dto = val as DateTimeOffset?;
|
||||
if( dto != null )
|
||||
{
|
||||
return new Poco(dto);
|
||||
}
|
||||
|
||||
var @int = val as int?;
|
||||
if( @int != null )
|
||||
{
|
||||
return new Datum(@int);
|
||||
}
|
||||
|
||||
if( IsNumber(val) )
|
||||
{
|
||||
return new Datum(val);
|
||||
}
|
||||
|
||||
var @bool = val as bool?;
|
||||
if( @bool != null )
|
||||
{
|
||||
return new Datum(@bool);
|
||||
}
|
||||
|
||||
if( val is string str )
|
||||
{
|
||||
return new Datum(str);
|
||||
}
|
||||
if( val == null )
|
||||
{
|
||||
return new Datum(null);
|
||||
}
|
||||
|
||||
return new Poco(val);
|
||||
}
|
||||
|
||||
public static bool IsNumber(object value)
|
||||
{
|
||||
return value is sbyte
|
||||
|| value is byte //maybe have char here?
|
||||
|| value is short
|
||||
|| value is ushort
|
||||
|| value is int
|
||||
|| value is uint
|
||||
|| value is long
|
||||
|| value is ulong
|
||||
|| value is float
|
||||
|| value is double
|
||||
|| value is decimal;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 82410c8fb9920e940aa61c94125dd688
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
Reference in a new issue