private PropertyWalker(Type type, IPropertyVisitor visitor, int maxRecursion, ConcurrentDictionary<Type, int> seenTypes) { _type = type; _visitor = visitor; _maxRecursion = maxRecursion; _seenTypes = seenTypes; }
public PropertyWalker(Type type, IPropertyVisitor visitor, int maxRecursion = 0) { _type = GetUnderlyingType(type); _visitor = visitor ?? new NoopPropertyVisitor(); _maxRecursion = maxRecursion; _seenTypes = new ConcurrentDictionary<Type, int>(); _seenTypes.TryAdd(_type, 0); }
public void Serialize(object data, IPropertyVisitor visitor, ObjectSerializerSettings settings = null) { Visitor = visitor; Settings = settings ?? new ObjectSerializerSettings(); if (data != null && data.GetType() != DataType) throw new ArgumentException(string.Format("Cannot serialize {0} - expected {1}.", data.GetType(), DataType), "data"); visitor.Begin(); Serialize(data, DataType, ""); visitor.End(); }
public override void Accept(IPropertyVisitor visitor) { visitor.Visit(this); }
public VisitStatus Visit <TProperty, TContainer, TValue>(IPropertyVisitor visitor, TProperty property, ref TContainer container, ref TValue value, ref ChangeTracker changeTracker) where TProperty : IProperty <TContainer, TValue> { return(VisitStatus.Unhandled); }
public VisitStatus Visit <TProperty, TContainer>(IPropertyVisitor visitor, TProperty property, ref TContainer container, ref uint value, ref ChangeTracker changeTracker) where TProperty : IProperty <TContainer, uint> { Append(property, value, (builder, v) => { builder.Append(v); }); return(VisitStatus.Handled); }
public override TResult Accept <TResult, TContext>( IPropertyVisitor <TResult, TContext> visitor, TContext environment) { return(visitor.Visit(this, environment)); }
/// <summary> /// Convenience method to map as much as it can based on <see cref="ElasticsearchTypeAttribute"/> attributes set on the type. /// This particular overload is useful for automapping any children /// <pre>This method also automatically sets up mappings for known values types (int, long, double, datetime, etc)</pre> /// <pre>Class types default to object and Enums to int</pre> /// <pre>Later calls can override whatever is set is by this call.</pre> /// </summary> public TypeMappingDescriptor <T> AutoMap <TDocument>(IPropertyVisitor visitor = null, int maxRecursion = 0) where TDocument : class => Assign(a => a.Properties = a.Properties.AutoMap <TDocument>(visitor, maxRecursion));
internal static IProperties AutoMap(this IProperties existingProperties, Type documentType, IPropertyVisitor visitor = null, int maxRecursion = 0 ) { var properties = new Properties(); var autoProperties = new PropertyWalker(documentType, visitor, maxRecursion).GetProperties(); foreach (var autoProperty in autoProperties) { properties[autoProperty.Key] = autoProperty.Value; } if (existingProperties == null) { return(properties); } // Existing/manually mapped properties always take precedence foreach (var existing in existingProperties) { properties[existing.Key] = existing.Value; } return(properties); }
public abstract TResult Accept <TResult, TContext>(IPropertyVisitor <TResult, TContext> visitor, TContext environment) where TContext : IEnvironment;
public VisitStatus Visit <TProperty, TContainer>(IPropertyVisitor visitor, TProperty property, ref TContainer container, ref char value, ref ChangeTracker changeTracker) where TProperty : IProperty <TContainer, char> { DoField(property, ref container, ref value, ref changeTracker, (label, val) => EditorGUILayout.TextField(label, val.ToString()).FirstOrDefault()); return(VisitStatus.Handled); }
public VisitStatus Visit <TProperty, TContainer>(IPropertyVisitor visitor, TProperty property, ref TContainer container, ref Quaternion value, ref ChangeTracker changeTracker) where TProperty : IProperty <TContainer, Quaternion> { DoField(property, ref container, ref value, ref changeTracker, (label, val) => Quaternion.Euler(EditorGUILayout.Vector3Field(label, val.eulerAngles))); return(VisitStatus.Handled); }
internal VisitAtPathGetter(PropertyPath propertyPath, int propertyPathIndex, IPropertyVisitor visitor) { m_PropertyPath = propertyPath; m_PropertyPathIndex = propertyPathIndex; m_Visitor = visitor; ErrorCode = VisitErrorCode.Ok; }
public VisitStatus Visit <TProperty, TContainer>(IPropertyVisitor visitor, TProperty property, ref TContainer container, ref ushort value, ref ChangeTracker changeTracker) where TProperty : IProperty <TContainer, ushort> { DoField(property, ref container, ref value, ref changeTracker, (label, val) => (ushort)EditorGUILayout.IntField(label, val)); return(VisitStatus.Handled); }
private static VisitErrorCode VisitCollectionPropertyAtPath <TContainer, TProperty, TPropertyValue>(TProperty property, ref TContainer container, PropertyPath propertyPath, int propertyPathIndex, IPropertyVisitor visitor, ref ChangeTracker changeTracker) where TProperty : ICollectionProperty <TContainer, TPropertyValue> { if (propertyPathIndex < propertyPath.PartsCount - 1 || propertyPath[propertyPathIndex].IsListItem) { var index = propertyPath[propertyPathIndex].Index; if (index >= property.GetCount(ref container)) { return(VisitErrorCode.InvalidPath); } var getter = new VisitCollectionItemAtPathGetter <TContainer>(propertyPath, propertyPathIndex, visitor); property.GetPropertyAtIndex(ref container, index, ref changeTracker, ref getter); return(getter.ErrorCode); } visitor.VisitCollectionProperty <TProperty, TContainer, TPropertyValue>(property, ref container, ref changeTracker); return(VisitErrorCode.Ok); }
public static bool TryVisitAtPath <TContainer>(ref TContainer container, PropertyPath propertyPath, int propertyPathIndex, IPropertyVisitor visitor, ref ChangeTracker changeTracker) { return(TryVisitAtPathImpl(ref container, propertyPath, propertyPathIndex, visitor, ref changeTracker) == VisitErrorCode.Ok); }
static VisitErrorCode VisitPropertyAtPath <TContainer, TProperty, TPropertyValue>(TProperty property, ref TContainer container, PropertyPath propertyPath, int propertyPathIndex, IPropertyVisitor visitor, ref ChangeTracker changeTracker) where TProperty : IProperty <TContainer, TPropertyValue> { if (propertyPathIndex < propertyPath.PartsCount - 1) { var sub = property.GetValue(ref container); var status = TryVisitAtPathImpl(ref sub, propertyPath, propertyPathIndex + 1, visitor, ref changeTracker); if (status == VisitErrorCode.Ok) { property.SetValue(ref container, sub); } return(status); } else { visitor.VisitProperty <TProperty, TContainer, TPropertyValue>(property, ref container, ref changeTracker); } return(VisitErrorCode.Ok); }
public static VisitErrorCode TryExecute(object target, PropertyPath propertyName, int index, IPropertyVisitor visitor, ref ChangeTracker changeTracker) { var action = new VisitAtPathCallback(target, propertyName, index, visitor, ref changeTracker); PropertyBagResolver.Resolve(target.GetType()).Cast(ref action); changeTracker = action.m_ChangeTracker; return(action.errorCode); }
public VisitStatus Visit <TProperty, TContainer>(IPropertyVisitor visitor, TProperty property, ref TContainer container, ref Vector4 value, ref ChangeTracker changeTracker) where TProperty : IProperty <TContainer, Vector4> { DoField(property, ref container, ref value, ref changeTracker, (label, val) => EditorGUILayout.Vector4Field(label, val)); return(VisitStatus.Handled); }
public void EndContainer <TProperty, TValue, TContainer>(IPropertyVisitor visitor, TProperty property, ref TContainer container, ref TValue value, ref ChangeTracker changeTracker) where TProperty : IProperty <TContainer, TValue> { }
public TDescriptor AutoMap(IPropertyVisitor visitor = null, int maxRecursion = 0) => Assign(Self.Properties.AutoMap <TChild>(visitor, maxRecursion), (a, v) => a.Properties = v);
internal static IProperties AutoMap <T>(this IProperties existingProperties, IPropertyVisitor visitor = null, int maxRecursion = 0) where T : class => existingProperties.AutoMap(typeof(T), visitor, maxRecursion);
unsafe public VisitStatus Visit <TProperty, TContainer>(IPropertyVisitor visitor, TProperty property, ref TContainer container, ref string value, ref ChangeTracker changeTracker) where TProperty : IProperty <TContainer, string> { Buffer->ReadNext(out value); return(VisitStatus.Handled); }
/// <summary> /// Convenience method to map as much as it can based on ElasticType attributes set on the type. /// <para>This method also automatically sets up mappings for primitive values types (e.g. int, long, double, DateTime...)</para> /// <para>Class types default to object and Enums to int</para> /// <para>Later calls can override whatever is set by this call.</para> /// </summary> public PutMappingDescriptor <TDocument> AutoMap(IPropertyVisitor visitor = null, int maxRecursion = 0) { Self.Properties = Self.Properties.AutoMap <TDocument>(visitor, maxRecursion); return(this); }
public VisitStatus Visit <TProperty, TContainer>(IPropertyVisitor visitor, TProperty property, ref TContainer container, ref double value, ref ChangeTracker changeTracker) where TProperty : IProperty <TContainer, double> { m_Buffer->Add(value); return(VisitStatus.Handled); }
/// <summary> /// Convenience method to map as much as it can based on <see cref="ElasticsearchTypeAttribute"/> attributes set on the type. /// <pre>This method also automatically sets up mappings for known values types (int, long, double, datetime, etc)</pre> /// <pre>Class types default to object and Enums to int</pre> /// <pre>Later calls can override whatever is set is by this call.</pre> /// </summary> public TypeMappingDescriptor <T> AutoMap(IPropertyVisitor visitor = null, int maxRecursion = 0) => Assign(a => a.Properties = a.Properties.AutoMap <T>(visitor, maxRecursion));
public VisitStatus Visit <TProperty, TContainer>(IPropertyVisitor visitor, TProperty property, ref TContainer container, ref bool value, ref ChangeTracker changeTracker) where TProperty : IProperty <TContainer, bool> { m_Buffer->Add((byte)(value ? 1 : 0)); return(VisitStatus.Handled); }
unsafe public VisitStatus Visit <TProperty, TContainer>(IPropertyVisitor visitor, TProperty property, ref TContainer container, ref Entity value, ref ChangeTracker changeTracker) where TProperty : IProperty <TContainer, Entity> { value = EntityRemapUtility.RemapEntityForPrefab(RemapInfo, RemapInfoCount, value); return(VisitStatus.Handled); }
public static void Visit <TContainer>(ref TContainer container, IPropertyVisitor visitor) where TContainer : struct, IPropertyContainer { container.PropertyBag.Visit(ref container, visitor); }
public VisitStatus Visit <TProperty, TContainer>(IPropertyVisitor visitor, TProperty property, ref TContainer container, ref string value, ref ChangeTracker changeTracker) where TProperty : IProperty <TContainer, string> { Append(property, value, (builder, v) => { builder.Append(EncodeJsonString(v)); }); return(VisitStatus.Handled); }
public static VisitStatus TryVisitValue <TProperty, TContainer, TValue>(this IPropertyVisitorAdapter self, IPropertyVisitor visitor, TProperty property, ref TContainer container, ref TValue value, ref ChangeTracker changeTracker) where TProperty : IProperty <TContainer, TValue> { VisitStatus status; if (self is IVisitAdapter <TContainer, TValue> visitAdapterTypedContainerValue) { if ((status = visitAdapterTypedContainerValue.Visit(visitor, property, ref container, ref value, ref changeTracker)) != VisitStatus.Unhandled) { return(status); } } if (self is IVisitAdapter <TValue> visitAdapterTypedValue) { if ((status = visitAdapterTypedValue.Visit(visitor, property, ref container, ref value, ref changeTracker)) != VisitStatus.Unhandled) { return(status); } } if (self is IVisitAdapter visitAdapter) { if ((status = visitAdapter.Visit(visitor, property, ref container, ref value, ref changeTracker)) != VisitStatus.Unhandled) { return(status); } } return(VisitStatus.Unhandled); }
public virtual void Accept(IPropertyVisitor visitor) { visitor.Visit(this); }
public static VisitStatus TryVisitCollection <TProperty, TContainer, TValue>(this IPropertyVisitorAdapter self, IPropertyVisitor visitor, TProperty property, ref TContainer container, ref TValue value, ref ChangeTracker changeTracker) where TProperty : ICollectionProperty <TContainer, TValue> { VisitStatus status; if (self is IVisitAdapter <TContainer, TValue> visitAdapterTypedContainerValue) { if ((status = visitAdapterTypedContainerValue.Visit(visitor, property, ref container, ref value, ref changeTracker)) != VisitStatus.Unhandled) { return(status); } } if (self is IVisitAdapter <TValue> visitAdapterTypedValue) { if ((status = visitAdapterTypedValue.Visit(visitor, property, ref container, ref value, ref changeTracker)) != VisitStatus.Unhandled) { return(status); } } if (self is IVisitCollectionAdapter <TContainer, TValue> visitCollectionAdapterTypedContainerValue) { if ((status = visitCollectionAdapterTypedContainerValue.BeginCollection(visitor, property, ref container, ref value, ref changeTracker)) == VisitStatus.Handled) { VisitCollectionElements <TProperty, TContainer, TValue>(visitor, property, ref container, changeTracker); } visitCollectionAdapterTypedContainerValue.EndCollection(visitor, property, ref container, ref value, ref changeTracker); if (status != VisitStatus.Unhandled) { return(status); } } if (self is IVisitCollectionAdapterC <TContainer> visitCollectionAdapterTypedContainer) { if ((status = visitCollectionAdapterTypedContainer.BeginCollection(visitor, property, ref container, ref value, ref changeTracker)) == VisitStatus.Handled) { VisitCollectionElements <TProperty, TContainer, TValue>(visitor, property, ref container, changeTracker); } visitCollectionAdapterTypedContainer.EndCollection(visitor, property, ref container, ref value, ref changeTracker); if (status != VisitStatus.Unhandled) { return(status); } } if (self is IVisitCollectionAdapter <TValue> visitCollectionAdapterTypedValue) { if ((status = visitCollectionAdapterTypedValue.BeginCollection(visitor, property, ref container, ref value, ref changeTracker)) == VisitStatus.Handled) { VisitCollectionElements <TProperty, TContainer, TValue>(visitor, property, ref container, changeTracker); } visitCollectionAdapterTypedValue.EndCollection(visitor, property, ref container, ref value, ref changeTracker); if (status != VisitStatus.Unhandled) { return(status); } } if (self is IVisitCollectionAdapter visitCollectionAdapter) { if ((status = visitCollectionAdapter.BeginCollection(visitor, property, ref container, ref value, ref changeTracker)) == VisitStatus.Handled) { VisitCollectionElements <TProperty, TContainer, TValue>(visitor, property, ref container, changeTracker); } visitCollectionAdapter.EndCollection(visitor, property, ref container, ref value, ref changeTracker); if (status != VisitStatus.Unhandled) { return(status); } } return(VisitStatus.Unhandled); }
public VisitStatus Visit <TProperty, TContainer>(IPropertyVisitor visitor, TProperty property, ref TContainer container, ref char value, ref ChangeTracker changeTracker) where TProperty : IProperty <TContainer, char> { GuiFactory.CharField(property, ref container, ref value, Context); return(VisitStatus.Handled); }
public override void Reset() { base.Reset(); Visitor = default; ReadonlyVisit = true; }