Parse string to TimeSpan

I have some strings of xxh:yym format where xx is hours and yy is minutes like "05h:30m". What is an elegant way to convert a string of this type to TimeSpan?…


VB.NET Get underlying system.type from nullable type

I'm attempting to create a dataset based on the properties of an object. For example, I have an instance of a Person class with properties including ID, Forename, Surname, DOB etc. Using reflection,…


Generic conversion function doesn't seem to work with Guids

I have the following code: public static T ParameterFetchValue<T>(string parameterKey){Parameter result=null; result=ParameterRepository.FetchParameter(parameterKey); return(T)Co…


how to set nullable type via reflection code(c#)?

I need to set the properties of a class using reflection. I have a Dictionary<string,string> with property names and string values. Inside a reflection loop, I need to convert the string value to the…


Convert.ChangeType and converting to enums?

I got an Int16 value, from the database, and need to convert this to an enum type. This is unfortunately done in a layer of the code that knows very little about the objects except for what it can ga…


c# - Convert string to nullable type(int, double, etc…)

I am attempting to do some data conversion. Unfortunately, much of the data is in strings, where it should be int's or double, etc... So what I've got is something like: double? amount=Convert.ToDo…



c# - Test if Convert.ChangeType will work between two types

This is a follow-up to this question about converting values with reflection. Converting an object of a certain type to another type can be done like this: object convertedValue=Convert.ChangeType(v…


c# - How to Convert a String to a Nullable Type Which is Determined at Runtime?

I have the below code and I'd need to convert a string to a type which is also specified from String: Type t=Type.GetType("System.Nullable`1[[System.DateTime, mscorlib, Version=2.0.0.0, Culture=neu…


Cast T to bool and vice versa

I have the following extensionmethods for strings to be able to do this("true").As<bool>(false) Especially for booleans it will use AsBool() to do some custom conversion. Somehow I can not cast from…


c# - Type conversion issue when setting property through reflection

We have a property of type long? that gets filled with an int. This works fine when i just set the property directly obj.Value=v; but when i try and set the property through reflection info.SetValue…




changetype string object type nullable int generic cast system int32