60 lines
1.6 KiB
C#
60 lines
1.6 KiB
C#
// /**
|
|
// * File: ListMapping.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 ln.types.odb.values;
|
|
using System.Collections;
|
|
using System.Linq;
|
|
|
|
namespace ln.types.odb
|
|
{
|
|
public class ListMapping : IODBMapping
|
|
{
|
|
public Type TargetType { get; }
|
|
|
|
public ListMapping(Type targetType)
|
|
{
|
|
TargetType = targetType;
|
|
}
|
|
|
|
public object UnmapValue(ODBMapper mapper,ODBValue oval)
|
|
{
|
|
ODBList list = oval as ODBList;
|
|
|
|
if (TargetType.IsArray)
|
|
{
|
|
Array a = Array.CreateInstance(TargetType.GetElementType(), list.Count);
|
|
for (int n = 0; n < list.Count; n++)
|
|
a.SetValue(list[n], n);
|
|
return a;
|
|
} else if (TargetType.GetInterfaces().Contains(typeof(IList)))
|
|
{
|
|
IList ilist = (IList)Activator.CreateInstance(TargetType, true);
|
|
for (int n = 0; n < list.Count; n++)
|
|
ilist.Add(list[n]);
|
|
return ilist;
|
|
}
|
|
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public ODBValue MapValue(ODBMapper mapper,object value)
|
|
{
|
|
ODBList list = new ODBList();
|
|
|
|
foreach (object item in (IEnumerable)value)
|
|
{
|
|
list.Add(ODBMapper.Default.MapValue(item));
|
|
}
|
|
|
|
return list;
|
|
}
|
|
}
|
|
}
|