Esempio n. 1
0
        public static void Initialize(this object target)
        {
            if (target == null)
            {
                return;
            }

            object defaultValue = null;

            foreach (PropertyDescriptor pd in ChoTypeDescriptor.GetProperties <DefaultValueAttribute>(target.GetType()))
            {
                try
                {
                    defaultValue = ChoTypeDescriptor.GetPropetyAttribute <DefaultValueAttribute>(pd).Value;
                    if (defaultValue != null)
                    {
                        ChoType.ConvertNSetMemberValue(target, pd.Name, defaultValue);
                    }
                }
                catch (Exception ex)
                {
                    ChoETLFramework.WriteLog(ChoETLFramework.TraceSwitch.TraceError, "Error while assigning default value '{0}' to '{1}' member. {2}".FormatString(defaultValue, ChoType.GetMemberName(pd), ex.Message));
                }
            }

            ChoETLFramework.InitializeObject(target);

            if (target is IChoInitializable)
            {
                ((IChoInitializable)target).Initialize();
            }
        }