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);
		}
예제 #3
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();
        }
예제 #4
0
 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);
 }
예제 #7
0
 public override TResult Accept <TResult, TContext>(
     IPropertyVisitor <TResult, TContext> visitor,
     TContext environment)
 {
     return(visitor.Visit(this, environment));
 }
예제 #8
0
 /// <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));
예제 #9
0
        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);
        }
예제 #10
0
 public abstract TResult Accept <TResult, TContext>(IPropertyVisitor <TResult, TContext> visitor, TContext environment)
     where TContext : IEnvironment;
예제 #11
0
 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);
 }
예제 #12
0
 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);
 }
예제 #13
0
 internal VisitAtPathGetter(PropertyPath propertyPath, int propertyPathIndex, IPropertyVisitor visitor)
 {
     m_PropertyPath      = propertyPath;
     m_PropertyPathIndex = propertyPathIndex;
     m_Visitor           = visitor;
     ErrorCode           = VisitErrorCode.Ok;
 }
예제 #14
0
 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);
 }
예제 #15
0
        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);
        }
예제 #16
0
 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);
 }
예제 #17
0
 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);
 }
예제 #18
0
            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);
            }
예제 #19
0
 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);
 }
예제 #20
0
 public void EndContainer <TProperty, TValue, TContainer>(IPropertyVisitor visitor, TProperty property, ref TContainer container, ref TValue value, ref ChangeTracker changeTracker) where TProperty : IProperty <TContainer, TValue>
 {
 }
예제 #21
0
 public TDescriptor AutoMap(IPropertyVisitor visitor = null, int maxRecursion = 0) =>
 Assign(Self.Properties.AutoMap <TChild>(visitor, maxRecursion), (a, v) => a.Properties = v);
예제 #22
0
 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);
 }
예제 #26
0
 /// <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);
 }
예제 #29
0
 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);
 }
예제 #31
0
        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);
        }
예제 #32
0
 public virtual void Accept(IPropertyVisitor visitor)
 {
     visitor.Visit(this);
 }
예제 #33
0
        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);
        }
예제 #34
0
 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);
 }
예제 #35
0
 public override void Reset()
 {
     base.Reset();
     Visitor       = default;
     ReadonlyVisit = true;
 }