private IProperty GetProperty(PropertyInfo propertyInfo, ElasticsearchPropertyAttributeBase attribute)
		{
			var property = _visitor.Visit(propertyInfo, attribute);
			if (property != null)
				return property;

			if (propertyInfo.GetGetMethod().IsStatic)
				return null;

			if (attribute != null)
				property = attribute;
			else
				property = InferProperty(propertyInfo.PropertyType);

			var objectProperty = property as IObjectProperty;
			if (objectProperty != null)
			{
				var type = GetUnderlyingType(propertyInfo.PropertyType);
				var seenTypes = new ConcurrentDictionary<Type, int>(_seenTypes);
				seenTypes.AddOrUpdate(type, 0, (t, i) => ++i);
				var walker = new PropertyWalker(type, _visitor, _maxRecursion, seenTypes);
				objectProperty.Properties = walker.GetProperties(seenTypes, _maxRecursion);
			}

			_visitor.Visit(property, propertyInfo, attribute);

			return property;
		}
예제 #2
0
        private IProperty GetProperty(PropertyInfo propertyInfo, ElasticsearchPropertyAttributeBase attribute)
        {
            var property = _visitor.Visit(propertyInfo, attribute);

            if (property != null)
            {
                return(property);
            }

            if (propertyInfo.GetGetMethod().IsStatic)
            {
                return(null);
            }

            property = attribute ?? InferProperty(propertyInfo.PropertyType);

            var objectProperty = property as IObjectProperty;

            if (objectProperty != null)
            {
                var type      = GetUnderlyingType(propertyInfo.PropertyType);
                var seenTypes = new ConcurrentDictionary <Type, int>(_seenTypes);
                seenTypes.AddOrUpdate(type, 0, (t, i) => ++ i);
                var walker = new PropertyWalker(type, _visitor, _maxRecursion, seenTypes);
                objectProperty.Properties = walker.GetProperties(seenTypes, _maxRecursion);
            }

            _visitor.Visit(property, propertyInfo, attribute);

            return(property);
        }
예제 #3
0
 /// <summary>
 /// Convenience method to map as much as it can based on ElasticType attributes set on the type.
 /// <pre>This method also automatically sets up mappings for known values types (int, long, double, datetime, etcetera)</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 PutMappingDescriptor <T> AutoMap(IPropertyVisitor visitor = null, int maxRecursion = 0) => Assign(a =>
 {
     a.Properties       = a.Properties ?? new Properties();
     var autoProperties = new PropertyWalker(typeof(T), visitor).GetProperties();
     foreach (var autoProperty in (IEnumerable <KeyValuePair <PropertyName, IProperty> >)autoProperties)
     {
         a.Properties[autoProperty.Key] = autoProperty.Value;
     }
 });
 public TDescriptor AutoMap(IPropertyVisitor visitor = null, int maxRecursion = 0) => Assign(a =>
 {
     a.Properties       = a.Properties ?? new Properties();
     var autoProperties = new PropertyWalker(typeof(TChild), visitor, maxRecursion).GetProperties();
     foreach (var autoProperty in autoProperties)
     {
         a.Properties[autoProperty.Key] = autoProperty.Value;
     }
 });
예제 #5
0
        internal static IProperties AutoMap <T>(this IProperties existingProperties, IPropertyVisitor visitor = null, int maxRecursion = 0)
            where T : class
        {
            var properties     = new Properties();
            var autoProperties = new PropertyWalker(typeof(T), visitor, maxRecursion).GetProperties();

            foreach (var autoProperty in (IEnumerable <KeyValuePair <PropertyName, IProperty> >)autoProperties)
            {
                properties[autoProperty.Key] = autoProperty.Value;
            }

            // Existing/manually mapped properties always take precedence
            if (existingProperties != null)
            {
                foreach (var existing in (IEnumerable <KeyValuePair <PropertyName, IProperty> >)existingProperties)
                {
                    properties[existing.Key] = existing.Value;
                }
            }

            return(properties);
        }
예제 #6
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);
        }