Get and Set value with Reflection

using System.Reflection; foreach (var p in obj.GetType().GetProperties().Where(p => p.GetGetMethod().GetParameters().Count() == 0)) { //to get value of each attribute var value = p.GetValue(obj, null); //set value in new object p.SetValue(newObj, value); }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.