Пример #1
0
        // Methods
        public void Add(string entityName, ReflectBuilder builder)
        {
            #region Contracts

            if (string.IsNullOrEmpty(entityName) == true)
            {
                throw new ArgumentNullException();
            }
            if (builder == null)
            {
                throw new ArgumentNullException();
            }

            #endregion

            // Setting
            ReflectSetting setting = builder.ToSetting();
            if (setting == null)
            {
                throw new InvalidOperationException();
            }

            // Repository
            _repository.AddSetting(_groupName, entityName, setting);
        }
Пример #2
0
        public ReflectBuilder GetValue(string entityName)
        {
            #region Contracts

            if (string.IsNullOrEmpty(entityName) == true)
            {
                throw new ArgumentNullException();
            }

            #endregion

            // Setting
            ReflectSetting setting = _repository.GetSetting(_groupName, entityName);
            if (setting == null)
            {
                return(null);
            }

            // Builder
            ReflectBuilder builder = setting.ToBuilder();
            if (builder == null)
            {
                throw new InvalidOperationException();
            }

            // Return
            return(builder);
        }
Пример #3
0
        // Convert
        public static ReflectBuilder ToBuilder(this ReflectSetting setting)
        {
            #region Contracts

            if (setting == null)
            {
                throw new ArgumentNullException();
            }

            #endregion

            // Type
            Type type = Type.GetType(setting.BuilderType);
            if (type == null)
            {
                throw new InvalidOperationException(string.Format("Fail to create type:{0}", setting.BuilderType));
            }

            // Builder
            ReflectBuilder builder = Activator.CreateInstance(type) as ReflectBuilder;
            if (type == null)
            {
                throw new InvalidOperationException(string.Format("Fail to create instance:{0}", setting.BuilderType));
            }

            // Parameters
            foreach (string parameterKey in setting.Parameters.Keys)
            {
                builder.Parameters.Add(parameterKey, setting.Parameters[parameterKey]);
            }

            // Return
            return(builder);
        }
        // Convert
        public static ReflectSetting ToSetting(this ReflectBuilder builder)
        {
            #region Contracts

            if (builder == null)
            {
                throw new ArgumentNullException();
            }

            #endregion

            // Create
            ReflectSetting setting = new ReflectSetting(builder.GetType().AssemblyQualifiedName);

            // Parameters
            foreach (string parameterKey in builder.Parameters.Keys)
            {
                setting.Parameters.Add(parameterKey, builder.Parameters[parameterKey]);
            }

            // Return
            return(setting);
        }