Example #1
0
        public static void SetValue(this StageElement parent, string name, object value, bool removeIfNull = true)
        {
            bool      flag      = (!removeIfNull ? false : value == null);
            StageItem stageItem = parent.Item(name);

            if (stageItem == null)
            {
                if (!flag)
                {
                    parent.Add(SerializationMaster.ToStageValue(name, value));
                }
                return;
            }
            if (stageItem is StageAttribute)
            {
                throw new InvalidOperationException("Use SetTextAttribute to set text attributes.");
            }
            StageNull stageNull = stageItem as StageNull;

            if (stageItem != null)
            {
                if (value != null)
                {
                    stageNull.Remove();
                    parent.Add(SerializationMaster.ToStageValue(name, value));
                }
                return;
            }
            StageValue str = stageItem as StageValue;

            if (stageItem == null)
            {
                throw new InvalidOperationException("Only value elements can be set using this method.");
            }
            if (flag)
            {
                stageItem.Remove();
                return;
            }
            if (value == null)
            {
                stageItem.Remove();
                parent.Add(new StageNull(name));
                return;
            }
            if (str.isText && !(value is string))
            {
                throw new InvalidOperationException("Use SetTextValue to set text values.");
            }
            str.@value = SerializationMaster.ToString(value);
        }