示例#1
0
        public SettingsCollectionDTO GenerateDTO(SettingsCollectionBase settingsCollection)
        {
            var dto = new SettingsCollectionDTO();

            var settingCollectionType = settingsCollection.GetType();

            dto.TypeFullName              = settingCollectionType.FullName;
            dto.AssemblyFullName          = settingCollectionType.Assembly.FullName;
            dto.TypeAssemblyQualifiedName = settingCollectionType.AssemblyQualifiedName;

            // Translate properties
            var properties = GetType().GetProperties()
                             .Where(p => typeof(SettingBase).IsAssignableFrom(p.PropertyType));

            foreach (var prop in properties)
            {
                var set        = (SettingBase)prop.GetValue(settingsCollection);
                var settingDto = new SettingDTO();
                settingDto.Name = prop.Name;
                settingDto.ValueTypeFullName = set.ValueType.FullName;
                settingDto.ValueTypeAssemblyQualifiedName = set.ValueType.AssemblyQualifiedName;
                settingDto.ValueAssemblyFullName          = set.ValueType.Assembly.FullName;
                settingDto.ValueTypeAssemblyQualifiedName = set.ValueType.AssemblyQualifiedName;
                settingDto.Value = set.Value;
            }

            return(dto);
        }
示例#2
0
        public SettingsCollectionBase ParseDTO(SettingsCollectionDTO settingsCollectionDTO)
        {
            var collectionType    = Type.GetType(settingsCollectionDTO.TypeAssemblyQualifiedName);
            var settingCollection = (SettingsCollectionBase)Activator.CreateInstance(collectionType);

            // Assign property values
            List <SettingBase> settings = new List <SettingBase>();

            // Get all properties which are derived from SettingBase class
            var properties = GetType().GetProperties()
                             .Where(p => typeof(SettingBase).IsAssignableFrom(p.PropertyType));

            if (properties == null || properties.Count() == 0)
            {
                return(settingCollection);
            }

            foreach (var prop in properties)
            {
                var setting = settingsCollectionDTO.Settings.FirstOrDefault(x => x.Name == prop.Name);
                prop.SetValue(settingCollection, setting.Value);
            }

            return(settingCollection);
        }
        /// <summary>
        /// Tranforms the objects into a DTO, which can be consumed by Storage
        /// </summary>
        /// <returns>Return a DTO</returns>
        /// <remarks>All the tranformations required for the storage are to be done here. We might want to move this function to Settings Manager</remarks>
        public SettingsCollectionDTO GenerateDTO()
        {
            var dto = new SettingsCollectionDTO();

            dto.TypeFullName = GetType().FullName;
            dto.TypeAssemblyQualifiedName = GetType().AssemblyQualifiedName;
            dto.AssemblyFullName          = GetType().Assembly.FullName;

            var Settings    = this.AllSettingsToList();
            var SettingsDTO = new List <SettingDTO>();

            foreach (var setting in Settings)
            {
                SettingsDTO.Add(setting.GenerateDTO());
            }

            dto.Settings = SettingsDTO;

            return(dto);
        }