private void ProcessArrayOrCollectionAsNestedObject(EntityContextInfo entityInfo, ElasticsearchCrudJsonWriter elasticsearchCrudJsonWriter, PropertyInfo prop, bool createPropertyMappings)
        {
            elasticsearchCrudJsonWriter.JsonWriter.WritePropertyName(prop.Name().ToLower(MapToLowerCase));
            TraceProvider.Trace(TraceEventType.Verbose, "ElasticsearchMapping: BEGIN ARRAY or COLLECTION: {0} {1}", prop.Name().ToLower(MapToLowerCase), elasticsearchCrudJsonWriter.JsonWriter.Path);
            var typeOfEntity = prop.GetValue(entityInfo.Document).GetType().GetGenericArguments();
            if (typeOfEntity.Length > 0)
            {
                var child = GetDocumentType(typeOfEntity[0]);
                var parent = GetDocumentType(entityInfo.EntityType);

                if (!SerializedTypes.Contains(child + parent))
                {
                    SerializedTypes.Add(parent + child);
                    TraceProvider.Trace(TraceEventType.Verbose,
                        "ElasticsearchMapping: SerializedTypes type ok, BEGIN ARRAY or COLLECTION: {0}", typeOfEntity[0]);
                    TraceProvider.Trace(TraceEventType.Verbose, "ElasticsearchMapping: SerializedTypes new Type added: {0}",
                        GetDocumentType(typeOfEntity[0]));
                    MapCollectionOrArray(prop, entityInfo, elasticsearchCrudJsonWriter, createPropertyMappings);
                }
                else
                {
                    elasticsearchCrudJsonWriter.JsonWriter.WriteRawValue("null");
                }
            }
            else
            {
                TraceProvider.Trace(TraceEventType.Verbose, "ElasticsearchMapping: BEGIN ARRAY or COLLECTION NOT A GENERIC: {0}",
                    prop.Name().ToLower(MapToLowerCase));
                // Not a generic
                MapCollectionOrArray(prop, entityInfo, elasticsearchCrudJsonWriter, createPropertyMappings);
            }
        }
        private void ProcessSingleObjectAsNestedObject(EntityContextInfo entityInfo, ElasticsearchCrudJsonWriter elasticsearchCrudJsonWriter, PropertyInfo prop, bool createPropertyMappings)
        {
            elasticsearchCrudJsonWriter.JsonWriter.WritePropertyName(prop.Name().ToLower(MapToLowerCase));
            elasticsearchCrudJsonWriter.JsonWriter.WriteStartObject();

            if (createPropertyMappings)
            {
                // "properties": {
                elasticsearchCrudJsonWriter.JsonWriter.WritePropertyName("properties");
                elasticsearchCrudJsonWriter.JsonWriter.WriteStartObject();
            }
            // Do class mapping for nested type
            var entity = prop.GetValue(entityInfo.Document);
            var routingDefinition = new RoutingDefinition {ParentId = entityInfo.Id};
            var child = new EntityContextInfo { Document = entity, RoutingDefinition = routingDefinition, EntityType = entity.GetType(), DeleteDocument = entityInfo.DeleteDocument };

            MapEntityValues(child, elasticsearchCrudJsonWriter, false, createPropertyMappings);
            elasticsearchCrudJsonWriter.JsonWriter.WriteEndObject();

            if (createPropertyMappings)
            {

                elasticsearchCrudJsonWriter.JsonWriter.WriteEndObject();
            }
        }
        private void ProcessArrayOrCollection(EntityContextInfo entityInfo, ElasticsearchCrudJsonWriter elasticsearchCrudJsonWriter, PropertyInfo prop, bool createPropertyMappings)
        {
            TraceProvider.Trace(TraceEventType.Verbose, "ElasticsearchMapping: IsPropertyACollection: {0}", prop.Name().ToLower(MapToLowerCase));

            if (createPropertyMappings && prop.GetValue(entityInfo.Document) == null)
            {
                if (prop.PropertyType.IsArray)
                {
                    prop.SetValue(entityInfo.Document, Array.CreateInstance(prop.PropertyType.GetElementType(), 0));
                }
                else
                {
                    prop.SetValue(entityInfo.Document, Activator.CreateInstance(prop.PropertyType));
                }
            }

            if (prop.GetValue(entityInfo.Document) != null && SaveChildObjectsAsWellAsParent)
            {
                if (ProcessChildDocumentsAsSeparateChildIndex)
                {
                    ProcessArrayOrCollectionAsChildDocument(entityInfo, elasticsearchCrudJsonWriter, prop, createPropertyMappings);
                }
                else
                {
                    ProcessArrayOrCollectionAsNestedObject(entityInfo, elasticsearchCrudJsonWriter, prop, createPropertyMappings);
                }
            }
        }