Convert Dictionary To Anonymous Object?

后端 未结 7 1390
挽巷
挽巷 2020-11-27 16:33

First, and to make things clearer I\'ll explain my scenario from the top:

I have a method which has the following signature:

public virtual void Send         


        
7条回答
  •  失恋的感觉
    2020-11-27 16:45

    The credit here goes to the accepted answer. Adding this because I wanted to turn a List< Dictionary< string,object >> into a List< dynamic>. The purpose is for pulling records from a database table. Here is what I did.

        public static List ListDictionaryToListDynamic(List> dbRecords)
        {
            var eRecords = new List();
            foreach (var record in dbRecords)
            {
                var eRecord = new ExpandoObject() as IDictionary;
                foreach (var kvp in record)
                {
                    eRecord.Add(kvp);
                }
                eRecords.Add(eRecord);
            }
            return eRecords;
        }
    

提交回复
热议问题