Ejemplo n.º 1
0
        // �v���W�F�N�g�̐ݒ�𔽉f���܂��B
        public override EcmResponse Post(HttpRequest rq)
        {
            // �V���� Setting �C���X�^���X��쐬

            Setting newSetting = new Setting();
            Type t = newSetting.GetType();
            PropertyInfo[] fields = t.GetProperties();
            foreach(PropertyInfo pi in fields){

                //XmlIgnore ��?
                bool ignore = false;
                Object[] attrs = pi.GetCustomAttributes(false);
                foreach(Object o in attrs){
                    if(o is XmlIgnoreAttribute){
                        ignore = true;
                        break;
                    }
                }
                if(ignore) continue;

                string propValue = rq.Form[pi.Name];
                Type propType = pi.PropertyType;
                Object result = null;
                if(propType == typeof(int)){
                    int intResult = 0;
                    int.TryParse(propValue, out intResult);
                    result = intResult;
                } else if(propType == typeof(bool)){
                    if(propValue != null){
                        result = true;
                    } else {
                        result = false;
                    }
                } else if(propType.IsEnum){
                    try{
                        result = Enum.Parse(propType, propValue);
                    } catch {
                        result = 0;
                    }
                } else if(propType == typeof(string)){
                    result = propValue;
                }
                pi.SetValue(newSetting, result, null);
            }

            XmlSerializer xs = new XmlSerializer(typeof(Setting));

            using(FileStream fs = myProject.Setting.BaseFile.Open(FileMode.Create, FileAccess.Write, FileShare.None)){
                using(StreamWriter sw = new StreamWriter(fs)){
                    xs.Serialize(fs, newSetting);
                    sw.Close();
                }
                fs.Close();
            }

            XmlElement p = myXhtml.P();
            p.InnerText = "�ݒ��ۑ����܂����B";
            return new HtmlResponse(myXhtml, p);
        }