i defined an interface and a class bellow
public interface IXmlKey
{
string Name { get; set; }
string Value { get; set; }
bool HasChildren { get; set; }
}
public interface IXmlKey<T> : IXmlKey where T : IXmlKey<T>
{
public T[] Children { get; set; }
}
and a method , code
private static bool ReadSubXmlKeys(XmlReader subReader, IXmlKey objInstance, bool hasChildren, out string error)
{
error = null;
var childrenProp = objInstance.GetType().GetProperties().Single(p => p.Name.Equals("Children"));
var childType = childrenProp.PropertyType.GetElementType();
var childPis = childType.GetProperties();
var generateList = typeof(List<>).MakeGenericType(childType);
var childrenList = Activator.CreateInstance(generateList);
var childrenListType = childrenList.GetType();
//public static bool Any<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate)
var fun = typeof(Func<,>).MakeGenericType(childType, typeof(bool));
var anyMethod = typeof(Enumerable).GetMethodWithLinq("Any", typeof(IEnumerable<>), typeof(Func<,>)).MakeGenericMethod(childType);
var startNodeName = objInstance.Name;
do
{
var nodeName = subReader.Name;
//var isExist = anyMethod.Invoke(null, [childrenList, <what here>]); ---> here
}
while (subReader.Read());
return true;
}
as you can see, i’m not sure what’s the correct parameter to invoke List.Any(t => t.Name.Equals(nodeName )) where T : IXmlKey
pls help.