Beispiel #1
0
        protected void WriteCollectionValue(CollectionPropertyPayloadBuilder propertyBuilder, bool writeCollectionTypeName)
        {
            var collectionItemEdmTypeName = propertyBuilder.CollectionEdmTypeName;
            var collectionItems           = (ICollection)propertyBuilder.Value;

            // In some cases we don't want to write the type name even if it's specified. E.g. we do write it with JSON Verbose even for collections inside of other objects
            // but with JSON Light we don't. So in that case the test case would specify the type name but the JSON Light generator would explicitly request it not to be written.
            bool wrapInComplexType = !String.IsNullOrEmpty(collectionItemEdmTypeName) && writeCollectionTypeName;

            if (wrapInComplexType)
            {
                this.WriteStartObject();
                this.WriteTypeMetadata(collectionItemEdmTypeName);
                this.WriteKey(this.CollectionWrapperPropertyName);
            }

            this.WriteStartArray();
            bool firstElement = true;

            foreach (object coll in collectionItems)
            {
                PayloadBuilder sp = coll as PayloadBuilder;
                if (sp != null)
                {
                    if (!firstElement)
                    {
                        this.WriteValue(",");
                    }
                    this.GenerateJson(sp);
                    firstElement = false;
                }
                else if (coll != null && coll.GetType().IsEnum)
                {
                    this.WriteValue(JsonPrimitiveTypesUtil.PrimitiveToString(coll.ToString(), null));
                }
                else
                {
                    this.WriteValue(JsonPrimitiveTypesUtil.PrimitiveToString(coll, null));
                }
            }

            this.WriteEndArray();

            if (wrapInComplexType)
            {
                this.WriteEndObject();
            }
        }
Beispiel #2
0
        protected void WriteCollectionValue(CollectionPropertyPayloadBuilder propertyBuilder, bool writeCollectionTypeName)
        {
            var collectionItemEdmTypeName = propertyBuilder.CollectionEdmTypeName;
            var collectionItems = (ICollection)propertyBuilder.Value;

            // In some cases we don't want to write the type name even if it's specified. E.g. we do write it with JSON Verbose even for collections inside of other objects
            // but with JSON Light we don't. So in that case the test case would specify the type name but the JSON Light generator would explicitly request it not to be written.
            bool wrapInComplexType = !String.IsNullOrEmpty(collectionItemEdmTypeName) && writeCollectionTypeName;
            if (wrapInComplexType)
            {
                this.WriteStartObject();
                this.WriteTypeMetadata(collectionItemEdmTypeName);
                this.WriteKey(this.CollectionWrapperPropertyName);
            }

            this.WriteStartArray();
            bool firstElement = true;
            foreach (object coll in collectionItems)
            {
                PayloadBuilder sp = coll as PayloadBuilder;
                if (sp != null)
                {
                    if (!firstElement)
                    {
                        this.WriteValue(",");
                    }
                    this.GenerateJson(sp);
                    firstElement = false;
                }
                else if (coll != null && coll.GetType().IsEnum)
                {
                    this.WriteValue(JsonPrimitiveTypesUtil.PrimitiveToString(coll.ToString(), null));
                }
                else
                {
                    this.WriteValue(JsonPrimitiveTypesUtil.PrimitiveToString(coll, null));
                }
            }

            this.WriteEndArray();

            if (wrapInComplexType)
            {
                this.WriteEndObject();
            }
        }
Beispiel #3
0
 public string GenerateLiteral(CollectionPropertyPayloadBuilder collectionBuilder)
 {
     this.WriteCollectionValue(collectionBuilder, writeCollectionTypeName: true);
     return stringBuilder.ToString();
 }
Beispiel #4
0
 public string GenerateLiteral(CollectionPropertyPayloadBuilder collectionBuilder)
 {
     this.WriteCollectionValue(collectionBuilder, writeCollectionTypeName: true);
     return(stringBuilder.ToString());
 }