vendredi 16 août 2019

How to Initialize object property

I create a function which takes object of Type (eg: MyEntity) and i have to initialize all the properties of MyEntity . This is the code i came with but got stuck. dont know how to initialize the property.

thank you in advance.

public  void InitializeViewModel(MyEntity entity)
{

             Type objectType = entity.GetType();
            var properties = 
              entity.GetType().GetProperties().Where(p=>p.PropertyType.IsClass
               && !p.PropertyType.FullName.StartsWith("System."));

            foreach (PropertyInfo propertyInfo in properties)
            {

                var instance = 
                   Activator.CreateInstance(propertyInfo.PropertyType);

            }


 }






Aucun commentaire:

Enregistrer un commentaire