Пример #1
0
        /// <summary>
        /// Creates a new DataTypeDefinition based on the Type in the PropertyTypeAttribute
        /// </summary>
        /// <param name="attribute"></param>
        /// <param name="dataTypeDefinitionName"></param>
        /// <returns></returns>
        public static IDataTypeDefinition CreateDataTypeDefinitionFromAttribute(PropertyTypeAttribute attribute, string dataTypeDefinitionName)
        {
            var instance = Activator.CreateInstance(attribute.Type);
            var dataType = instance as IDataType;

            var definition = new DataTypeDefinition(-1, dataType.Id)
                                 {
                                     DatabaseType = attribute.DatabaseType,
                                     Name = dataTypeDefinitionName
                                 };
			ApplicationContext.Current.Services.DataTypeService.Save(definition, 0);
            return definition;
        }
Пример #2
0
        /// <summary>
        /// Convention to get a DataTypeDefinition from the PropertyTypeAttribute or the type of the property itself
        /// </summary>
        /// <param name="attribute"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static IDataTypeDefinition GetDataTypeDefinitionByAttributeOrType(PropertyTypeAttribute attribute, Type type)
        {
            if (attribute != null)
            {
                var instance = Activator.CreateInstance(attribute.Type);
                var dataType = instance as IDataType;
                var definition = GetDataTypeByControlId(dataType.Id);
                //If the DataTypeDefinition doesn't exist we create a new one
                if (definition == null)
                {
                    definition = new DataTypeDefinition(-1, dataType.Id)
                                     {
                                         DatabaseType = attribute.DatabaseType,
                                         Name = dataType.DataTypeName
                                     };
					ApplicationContext.Current.Services.DataTypeService.Save(definition, 0);
                }
                return definition;
            }

            return GetPredefinedDataTypeDefinitionByType(type);
        }