Exemplo n.º 1
0
        protected void WriteValue(string section, INIFile file, PropertyDescriptor item)
        {
            object iniData = item.GetValue(this);

            if (iniData == null)
            {
                file.DeleteKey(section, item.Name);
            }
            else
            {
                string tempVal      = null;
                Type   propertyType = item.PropertyType;

                if (item.PropertyType.GenericTypeArguments.Length > 0)
                {
                    propertyType = item.PropertyType.GenericTypeArguments.FirstOrDefault();
                }

                if (item.PropertyType == typeof(string))
                {
                    tempVal = (iniData as string)?.Trim();
                }
                else if (propertyType == typeof(int))
                {
                    tempVal = iniData.ToString();
                }
                else if (propertyType == typeof(bool))
                {
                    tempVal = iniData.ToString().ToLower();
                }
                else if (propertyType == typeof(double))
                {
                    tempVal = iniData.ToString();
                }
                else if (propertyType == typeof(long))
                {
                    tempVal = iniData.ToString();
                }
                else if (propertyType == typeof(float))
                {
                    tempVal = iniData.ToString();
                }
                else
                {
                    tempVal = iniData.ToString()?.Trim();
                }

                if (string.IsNullOrWhiteSpace(tempVal))
                {
                    file.DeleteKey(section, item.Name);
                }
                else
                {
                    file.WriteValue(section, item.Name, tempVal);
                }
            }
        }
Exemplo n.º 2
0
        public override void SaveSection(string section, INIFile file)
        {
            foreach (PropertyDescriptor item in TypeDescriptor.GetProperties(this))
            {
                if (item.IsBrowsable)
                {
                    if (item.Name == "WaitForEXEN")
                    {
                        for (int index = 1; index < MaxWaitExeCount; index++)
                        {
                            var key     = string.Format("WaitForEXE{0}", index);
                            var iniData = file.ReadValue(section, key, null);
                            if (string.IsNullOrWhiteSpace(iniData))
                            {
                                break;
                            }
                            file.DeleteKey(section, key);
                        }

                        for (int index = 0; index < WaitForEXEN.Count; index++)
                        {
                            var key = string.Format("WaitForEXE{0}", index + 1);
                            file.WriteValue(section, key, WaitForEXEN[index].ExeName);
                        }
                    }
                    else if (item.Name == "KillProcN")
                    {
                        for (int index = 1; index < MaxWaitExeCount; index++)
                        {
                            var key     = string.Format("KillProc{0}", index);
                            var iniData = file.ReadValue(section, key, null);
                            if (string.IsNullOrWhiteSpace(iniData))
                            {
                                break;
                            }
                            file.DeleteKey(section, key);
                        }

                        for (int index = 0; index < WaitForEXEN.Count; index++)
                        {
                            var key = string.Format("KillProc{0}", index + 1);
                            file.WriteValue(section, key, WaitForEXEN[index].ExeName);
                        }
                    }
                    else
                    {
                        WriteValue(section, file, item);
                    }
                }
            }
        }
Exemplo n.º 3
0
        public virtual void SaveSection(string section, INIFile file)
        {
            if (string.IsNullOrWhiteSpace(section))
            {
                return;
            }

            var listOfKeys = file.ReadKeys(section);

            if (listOfKeys != null)
            {
                foreach (var item in listOfKeys)
                {
                    file.DeleteKey(section, item);
                }
            }

            foreach (var item in this)
            {
                if (item.IsRemoved)
                {
                    continue;
                }
                else if (!string.IsNullOrWhiteSpace(item.IniValue))
                {
                    file.WriteValue(section, item.IniKey, item.IniValue);
                }
            }
        }
Exemplo n.º 4
0
        protected void WriteValue(string section, INIFile file, PropertyDescriptor item)
        {
            object iniData = item.GetValue(this);

            if (iniData == null)
            {
                file.DeleteKey(section, item.Name);
            }
            else
            {
                string tempVal = iniData.ToString();
                if (string.IsNullOrWhiteSpace(tempVal))
                {
                    file.DeleteKey(section, item.Name);
                }
                else
                {
                    file.WriteValue(section, item.Name, iniData.ToString());
                }
            }
        }