Automap viewmodels for details display
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
|
||||
namespace LeafWeb.WebCms.Utility
|
||||
{
|
||||
public static class NameValueCollectionUtil
|
||||
{
|
||||
public static NameValueCollection GetNameValueCollection(this object obj, string prefix = "")
|
||||
{
|
||||
var nvs = new NameValueCollection();
|
||||
|
||||
prefix =
|
||||
string.IsNullOrEmpty(prefix)
|
||||
? ""
|
||||
: prefix + ".";
|
||||
|
||||
foreach (var pi in obj.GetType().GetProperties().Where(p => p.CanWrite))
|
||||
{
|
||||
var value = pi.GetValue(obj, null);
|
||||
if (value == null)
|
||||
continue;
|
||||
nvs.Add(prefix + pi.Name, value.ToString());
|
||||
}
|
||||
|
||||
return nvs;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user