41 lines
1.1 KiB
C#
41 lines
1.1 KiB
C#
|
// /**
|
|||
|
// * File: JSONArrayMapping.cs
|
|||
|
// * Author: haraldwolff
|
|||
|
// *
|
|||
|
// * This file and it's content is copyrighted by the Author and / or copyright holder.
|
|||
|
// * Any use wihtout proper permission is illegal and may lead to legal actions.
|
|||
|
// *
|
|||
|
// *
|
|||
|
// **/
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
namespace ln.json.mapping
|
|||
|
{
|
|||
|
public class JSONEnumerableMapping<T> : JSONMapping
|
|||
|
{
|
|||
|
Type elementType;
|
|||
|
|
|||
|
public JSONEnumerableMapping()
|
|||
|
:base(typeof(T))
|
|||
|
{
|
|||
|
elementType = typeof(T).GetGenericArguments()[0];
|
|||
|
}
|
|||
|
|
|||
|
public override object FromJson(JSONMapper mapper, JSONValue json)
|
|||
|
{
|
|||
|
throw new NotSupportedException("IEnumerable<> can not be set from JSON");
|
|||
|
}
|
|||
|
public override JSONValue ToJson(JSONMapper mapper, object value)
|
|||
|
{
|
|||
|
IEnumerable<T> ie = (IEnumerable<T>)value;
|
|||
|
JSONArray jsonArray = new JSONArray();
|
|||
|
|
|||
|
foreach (object element in ie)
|
|||
|
jsonArray.Add(mapper.ToJson(element));
|
|||
|
|
|||
|
return jsonArray;
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|