Recursive call to generic function with DataRow parameter - MakeGenericMethod Fails?

The reason for the error is because you are calling MyConvertDataRowToEntity(T item, string columnName, object rowValue) { var prefixColumn=columnName. IndexOf(". ")==-1?

ColumnName : columnName. Split(". ")0; var pi = typeof(T).

GetProperty(prefixColumn // Add your binding flags); // if pi==null then there is an error... if (column.ColumnName. IndexOf(". ") == (-1)) { // No Nesting pi.

SetValue(item,rowValue); return; } // Nesting var child=pi. GetValue(item); if (child==null) { // Logic here to get childs type and create an instance then call pi. SetValue with child } var remainder=string.

Join(',',columnName. Split(". ").

Skip(1).ToArray()); // make your generic method info for UpdateItemProperty with pi. PropertyType into mi mi. Invoke(null,new object { child,remainder,value }; }.

The reason for the error is because you are calling MyConvertDataRowToEntity but then passing in the getaccessor methodinfo for the property as the parameter instead of a data row containing only those fields. If you want to continue with the code processing logic you are currently using you would need to construct a new datarow containing the fields you wanted (with the prefix and ". ") removed from the start of the column names.

Alternatively you could create a helper method the accepted a column name, the source object and it simply updated the value. Static void UpdateItemProperty(T item, string columnName, object rowValue) { var prefixColumn=columnName. IndexOf(".")==-1?

ColumnName : columnName. Split(".")0; var pi = typeof(T). GetProperty(prefixColumn // Add your binding flags); // if pi==null then there is an error... if (column.ColumnName.

IndexOf(".") == (-1)) { // No Nesting pi. SetValue(item,rowValue); return; } // Nesting var child=pi. GetValue(item); if (child==null) { // Logic here to get childs type and create an instance then call pi.

SetValue with child } var remainder=string. Join(',',columnName. Split(".").

Skip(1).ToArray()); // make your generic method info for UpdateItemProperty with pi. PropertyType into mi mi. Invoke(null,new object { child,remainder,value }; }.

Thank you for the response. The problem is not the modification of the data , but sending the parameter through . I mean that when I invoke the method with childType I can't send the row through.It fails with : " 'System.Reflection.

RuntimeMethodInfo' cannot be converted to type 'System.Data. DataRow'." That's the trouble!

– Gregory Jul 24 at 4:40 The whole point of my response is that your invoke line is passing the method info for the property as a parameter and NOT a datarow which is what the method needs. Are you needing to invoke the getmethod first to get the return value? – Bob Vale Jul 24 at 11:19 Maybe I was not clear with my problem.

I have an hierarchical object with children . When I meet some property in my object that is Strongly Typed I'd like to perform MyConvertDataRowToEntity on that property recursively . I'll try out the datarow creation only of relevant columns and get back to you .

Thanks a lot for your help! – Gregory Jul 26 at 12:15.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions


Thank You!
send