Esempio n. 1
0
        internal void WriteProperties(JsonWriter jsonWriter)
        {
            var properties = this._type.GetProperties();

            foreach (var p in properties)
            {
                var att = ElasticAttributes.Property(p);
                if (att != null && att.OptOut)
                {
                    continue;
                }

                var propertyName = this.Infer.PropertyName(p);
                var type         = GetElasticSearchType(att, p);

                if (type == null)                 //could not get type from attribute or infer from CLR type.
                {
                    continue;
                }

                jsonWriter.WritePropertyName(propertyName);
                jsonWriter.WriteStartObject();
                {
                    if (att == null)                     //properties that follow can not be inferred from the CLR.
                    {
                        jsonWriter.WritePropertyName("type");
                        jsonWriter.WriteValue(type);
                        //jsonWriter.WriteEnd();
                    }
                    if (att != null)
                    {
                        this.WritePropertiesFromAttribute(jsonWriter, att, propertyName, type);
                    }
                    if (type == "object" || type == "nested")
                    {
                        var deepType     = GetUnderlyingType(p.PropertyType);
                        var deepTypeName = this.Infer.TypeName(deepType);
                        var seenTypes    = new ConcurrentDictionary <Type, int>(this.SeenTypes);
                        seenTypes.AddOrUpdate(deepType, 0, (t, i) => ++ i);

                        var newTypeMappingWriter = new TypeMappingWriter(deepType, deepTypeName, this._connectionSettings, MaxRecursion, seenTypes);
                        var nestedProperties     = newTypeMappingWriter.MapPropertiesFromAttributes();

                        jsonWriter.WritePropertyName("properties");
                        nestedProperties.WriteTo(jsonWriter);
                    }
                }
                jsonWriter.WriteEnd();
            }
        }
		internal void WriteProperties(JsonWriter jsonWriter)
		{
			var properties = this._type.GetProperties();
			foreach (var p in properties)
			{
				var att = ElasticAttributes.Property(p);
				if (att != null && att.OptOut)
					continue;

				var propertyName = this.Infer.PropertyName(p);
				var type = GetElasticSearchType(att, p);
				
				if (type == null) //could not get type from attribute or infer from CLR type.
					continue;

				jsonWriter.WritePropertyName(propertyName);
				jsonWriter.WriteStartObject();
				{
					if (att == null) //properties that follow can not be inferred from the CLR.
					{
						jsonWriter.WritePropertyName("type");
						jsonWriter.WriteValue(type);
						//jsonWriter.WriteEnd();
					}
					if (att != null)
						this.WritePropertiesFromAttribute(jsonWriter, att, propertyName, type);
					if (type == "object" || type == "nested")
					{

						var deepType = GetUnderlyingType(p.PropertyType);
						var deepTypeName = this.Infer.TypeName(deepType);
						var seenTypes = new ConcurrentDictionary<Type, int>(this.SeenTypes);
						seenTypes.AddOrUpdate(deepType, 0, (t, i) => ++i);

						var newTypeMappingWriter = new TypeMappingWriter(deepType, deepTypeName, this._connectionSettings, MaxRecursion, seenTypes);
						var nestedProperties = newTypeMappingWriter.MapPropertiesFromAttributes();

						jsonWriter.WritePropertyName("properties");
						nestedProperties.WriteTo(jsonWriter);
					}
				}
				jsonWriter.WriteEnd();
			}
		}