Some Bits On Reflection

Some Bits On Reflection

There are some hard to find solutions for reflection issues that work on both .NET 4.61 and .Net Core 1.1

I'm just putting there here so I can find them again.

Turning a collection of objects into a List of objects

List<object> entityList = (objCollection as IEnumerable<object>).Cast<object>().ToList();

Getting an attribute from a class when you only have an instance (Core & 4.61)

HtmlClass = entity.GetType().GetTypeInfo().GetCustomAttribute<MergeableContentAttribute>().HtmlClass

Reinstantiating an object from it's name and JSON string

var qualifiedName = Type.GetType(message.NotificationObject.Name);
var objectForNotification =  (ObjectForNotification)JsonConvert.DeserializeObject(message.NotificationObject.SerializedObject, qualifiedName);