not yet working support for list input parameters

This commit is contained in:
Wolfgang Hottgenroth
2021-12-14 18:11:57 +01:00
parent 2860cab9ee
commit 7b039b4fa4
4 changed files with 58 additions and 16 deletions

View File

@ -2,8 +2,10 @@
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
@ -106,10 +108,27 @@ namespace com.krohne.genericdatabaseapiservice.Services {
Logger.LogInformation("Input Property name: {0} {1} ", propertyInfo.Name, propertyInfo.PropertyType);
var attributes = propertyInfo.GetCustomAttributes(typeof(DataMemberAttribute), true);
var dma = (DataMemberAttribute)attributes[0];
Logger.LogInformation("Input DataMember name: {0} {1} ", dma.Name, dma.TypeId);
Logger.LogInformation("Input DataMember name: {0} {1}", dma.Name, dma.TypeId);
var value = propertyInfo.GetValue(input);
Logger.LogInformation("Input Value: {0}", value);
cmd.Parameters.AddWithValue(dma.Name, propertyInfo.GetValue(input));
Type typ = value.GetType();
var isList = typ.IsGenericType && (typ.GetGenericTypeDefinition() == typeof(List<>));
if (isList) {
var p1 = propertyInfo.GetValue(input) as System.Collections.IEnumerable;
var p2 = new StringBuilder();
var sep = "";
foreach (var x in p1) {
Logger.LogInformation("x: {0}", x);
p2.Append(sep);
p2.Append(x);
sep = ",";
}
var p3 = p2.ToString();
Logger.LogInformation("Input Value: p3:{0} typ:{1} isList:{2}", p3, typ, isList);
cmd.Parameters.AddWithValue(dma.Name, p3);
} else {
Logger.LogInformation("Input Value: {0} {1} {2}", value, typ, isList);
cmd.Parameters.AddWithValue(dma.Name, value);
}
}
} else {
Logger.LogInformation("no input data");