Пример #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CalendarProperties{TModel}"/> class.
        /// </summary>
        public CalendarProperties()
        {
            AmplaModules? temp;
            List <string> properties = new List <string>();

            foreach (PropertyInfo property in typeof(TModel).GetProperties())
            {
                string propertyName;
                AmplaFieldAttribute.TryGetField(property, out propertyName);

                properties.Add(propertyName);
                //propertyInfoDictionary[propertyName] = property;
                TypeConverterAttribute typeConverterAttribute;
                TypeConverter          typeConverter = GetTypeConverter(property);
                if (property.TryGetAttribute(out typeConverterAttribute))
                {
                    Type converterType = Type.GetType(typeConverterAttribute.ConverterTypeName);
                    if (converterType != null)
                    {
                        typeConverter = Activator.CreateInstance(converterType) as TypeConverter;
                    }
                }
                //typeConverterDictionary[propertyName] = typeConverter;

                //AddModelValidators(property, modelValidators);
            }
            //modelValidators.Add(new NullModelValidator<TModel>());
            //propertyNames = properties.ToArray();

            //if (!AmplaDefaultFiltersAttribute.TryGetFilter<TModel>(out defaultFilters))
            {
                //   defaultFilters = new FilterValue[0];
            }
        }
Пример #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ModelProperties{TModel}"/> class.
        /// </summary>
        public ModelProperties()
        {
            AmplaModules?temp;
            bool         ok = AmplaLocationAttribute.TryGetLocation <TModel>(out locationFilter);

            ok &= AmplaModuleAttribute.TryGetModule <TModel>(out temp);

            if (!ok)
            {
                throw new ArgumentException("Unable to read the AmplaLocationAttribute or AmplaModuleAttribute on type: " + typeof(TModel).FullName);
            }

            module = temp ?? AmplaModules.Downtime;

            List <string> properties = new List <string>();

            foreach (PropertyInfo property in typeof(TModel).GetProperties())
            {
                string propertyName;
                AmplaFieldAttribute.TryGetField(property, out propertyName);

                properties.Add(propertyName);
                propertyInfoDictionary[propertyName] = property;
                TypeConverterAttribute typeConverterAttribute;
                TypeConverter          typeConverter = GetTypeConverter(property);
                if (property.TryGetAttribute(out typeConverterAttribute))
                {
                    Type converterType = Type.GetType(typeConverterAttribute.ConverterTypeName);
                    if (converterType != null)
                    {
                        typeConverter = Activator.CreateInstance(converterType) as TypeConverter;
                    }
                }
                typeConverterDictionary[propertyName] = typeConverter;

                AddModelValidators(property, modelValidators);
            }

            modelValidators.Add(new NullModelValidator <TModel>());
            propertyNames = properties.ToArray();

            if (!AmplaDefaultFiltersAttribute.TryGetFilter <TModel>(out defaultFilters))
            {
                defaultFilters = new FilterValue[0];
            }
        }