How to get function parameter names/values dynamically?

Is there a way to get the function parameter names of a function dynamically? Let’s say my function looks like this: function doSomething(param1, param2, …. paramN){ // fill an array with the parameter name and value // some other code } Now, how would I get a list of the parameter names and their values … Read more

Convert.ChangeType() fails on Nullable Types

I want to convert a string to an object property value, whose name I have as a string. I am trying to do this like so: string modelProperty = “Some Property Name”; string value = “SomeValue”; var property = entity.GetType().GetProperty(modelProperty); if (property != null) { property.SetValue(entity, Convert.ChangeType(value, property.PropertyType), null); } The problem is this is … Read more

Setting a property by reflection with a string value

I’d like to set a property of an object through Reflection, with a value of type string. So, for instance, suppose I have a Ship class, with a property of Latitude, which is a double. Here’s what I’d like to do: Ship ship = new Ship(); string value = “5.5”; PropertyInfo propertyInfo = ship.GetType().GetProperty(“Latitude”); propertyInfo.SetValue(ship, … Read more