lundi 20 février 2017

Convert Type to myType

I want to set default values for all decimal fields in Object. Method that do it looking like this:

private Type SetAllFieldsAsDefault(Type register)
{
    var fields = register.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
    foreach (var field in fields)
    {
        if (field.FieldType != typeof(double)) continue;
        field.SetValue(field, 0);
    }
    return register;
}

After I'm try casting to myType but it is not works myType = (MyType )SetAllFieldsAsDefault(myType.GetType());

How can i do it?





Aucun commentaire:

Enregistrer un commentaire