Esempio n. 1
0
        public Tuple <string, string>[] IsInvalid(Type type, object instance)
        {
            var warnings = new List <Tuple <string, string> >();

            var info = this.GetReflctedInfo(type);

            foreach (var rule in info.ValidationRules)
            {
                PropertyInfo notificationProperty;

                bool inotify = info.Notifications.TryGetValue(rule.Item1.Name, out notificationProperty);

                object value = rule.Item1.GetValue(instance);

                if (!info.Required.Contains(rule.Item1.Name))
                {
                    if (DataTypeFactory.IsEmpty(rule.Item1.PropertyType, value))
                    {
                        if (inotify)
                        {
                            notificationProperty.SetValue(instance, null);
                        }

                        continue;
                    }
                }

                if (rule.Item2.IsValid(value))
                {
                    if (inotify)
                    {
                        notificationProperty.SetValue(instance, null);
                    }

                    continue;
                }

                if (inotify)
                {
                    notificationProperty.SetValue(instance, "*" + rule.Item2.ErrorMessage);
                }

                string message = string.IsNullOrEmpty(rule.Item3) ? rule.Item2.ErrorMessage : rule.Item3;

                warnings.Add(new Tuple <string, string>(rule.Item1.Name, message));
            }

            return(warnings.ToArray());
        }
        private static async Task SetCurrentContext()
        {
            await DataTypeFactory.SetCurrentAsync(new Type[] { typeof(Contractor) });

            mCurrent = new ContractorsContext();

            mCurrent.noImage = await GetNoImageSplash();

            mCurrent.Items = new ObservableCollection <Contractor>();

            foreach (var item in await ContractorsRepository.Current.GetItems())
            {
                mCurrent.Items.Add(item);
            }
        }
Esempio n. 3
0
        public static void SetCurrent(Type[] types = null)
        {
            Monitor.Enter(mCurrentLock);

            if (mCurrent == null)
            {
                mCurrent = new DataTypeFactory();

                if (types != null)
                {
                    foreach (var type in types)
                    {
                        mCurrent.ReflectFast(type);
                    }
                }
            }

            Monitor.Exit(mCurrentLock);
        }