Skip to content

Latest commit

 

History

History
35 lines (25 loc) · 873 Bytes

File metadata and controls

35 lines (25 loc) · 873 Bytes

StringToStronglyTyped

A simple utility to convert string values to strongly-typed objects.

NuGet

Examples

Converting a string to another type

int @int = StronglyTypedConverter.ToType<int>("123");

decimal @decimal = StronglyTypedConverter.ToType<decimal>("123.456");

Converting a Hashtable to a Strongly-typed object

public class TestModel
{
    [StronglyTypedMetadata]
    public short Int16 { get; private set; }

    [StronglyTypedMetadata]
    public decimal Decimal { get; private set; }  
}

...

var hashtable = new Hashtable();
hashtable.Add("Int16", "123");
hashtable.Add("Decimal", "0.123");

var testModel = StronglyTypedConverter.ToType<TestModel>(hashtable);