jeudi 13 août 2015

Reflection : Convert the returned property value based on Property Data Type

public class Sample
{
  public VehicleEnum Keyword { get;set;}
}

public enum VehicleEnum { CAR = 0 , BIKE = 1 };


object modelObject = Activator.CreateInstance("ModelAssembly", "ModelAssembly.Sample");
object propValue = modelObject.GetType().GetProperty("Keyword").GetValue(modelObject);

  1. Is there any way to return value in string data type(i.e. "Car").
  2. Is there anyway of getting the list of Enumeration values as list of strings (not only assigned value) i.e. In this case, {"CAR", "BIKE" }




Aucun commentaire:

Enregistrer un commentaire