Get and Set value with Reflection

using System.Reflection; foreach (var p in Obj.GetType().GetProperties().Where(p => p.GetGetMethod().GetParameters().Count() == 0)) { //Get name of attribute var name = p.Name; if(p.Name != "id") { //Get value of attribute var value = p.GetValue(Obj, null); //set value in new object the same type. 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.