Пример #1
0
		/// <summary>
		/// Set a Tag value. A null value removes the Tag.
		/// </summary>
		/// <param name="key">Tag Name</param>
		/// <param name="subkey">Nested SimpleTag to find (if non null) Tag name</param>
		/// <param name="value">value to be set. A list can be passed for a subtag by separating the values by ';'</param>
		public void Set(string key, string subkey, string value)
		{
			if (value == null)
			{
				Remove(key, subkey);
				return;
			}

			List<SimpleTag> list = null;

			SimpleTags.TryGetValue(key, out list);

			if (list == null)
				SimpleTags[key] = list = new List<SimpleTag>(1); 

			if (list.Count == 0)
				list.Add(new SimpleTag());

			if (subkey == null)
			{
				list[0].Value = value;
			}
			else
			{
				if (list[0].SimpleTags == null)
					list[0].SimpleTags = new Dictionary<string, List<SimpleTag>>(StringComparer.OrdinalIgnoreCase);

				List<SimpleTag> slist = null;
				list[0].SimpleTags.TryGetValue(subkey, out slist);

				if (slist == null)
					slist = new List<SimpleTag>(1);

				list[0].SimpleTags[subkey] = slist;

				if (slist.Count == 0)
					slist.Add(new SimpleTag());

				// Sub-values
				var svalues = value.Split(';');
				int j;
				for (j = 0; j < svalues.Length; j++)
				{
					SimpleTag subtag;
					if (j >= slist.Count)
						slist.Add(subtag = new SimpleTag());
					else
						subtag = slist[j];

					subtag.Value = svalues[j];
				}

				if (j < slist.Count)
					slist.RemoveRange(j, slist.Count - j);
			}

		}
Пример #2
0
        /// <summary>
        /// Create or overwrite the actual tags of a given name/sub-name by new values.
        /// </summary>
        /// <param name="key">Tag Name</param>
        /// <param name="subkey">Nested SimpleTag to find (if non null) Tag name</param>
        /// <param name="values">Array of values. for each subtag value, a list can be passed by separating the values by ';'</param>
        public void Set(string key, string subkey, string[] values)
        {
            if (values == null)
            {
                Remove(key, subkey);
                return;
            }

            List <SimpleTag> list = null;

            SimpleTags.TryGetValue(key, out list);

            if (list == null)
            {
                SimpleTags[key] = list = new List <SimpleTag>(1);
            }

            int i;

            for (i = 0; i < values.Length; i++)
            {
                SimpleTag stag;
                if (i >= list.Count)
                {
                    list.Add(stag = new SimpleTag());
                }
                else
                {
                    stag = list[i];
                }

                if (subkey == null)
                {
                    stag.Value = values[i];
                }
                else
                {
                    if (stag.SimpleTags == null)
                    {
                        stag.SimpleTags = new Dictionary <string, List <SimpleTag> >(StringComparer.OrdinalIgnoreCase);
                    }

                    List <SimpleTag> slist = null;
                    stag.SimpleTags.TryGetValue(subkey, out slist);

                    if (slist == null)
                    {
                        slist = new List <SimpleTag>(1);
                    }

                    stag.SimpleTags[subkey] = slist;

                    // Sub-values
                    var svalues = values[i].Split(';');
                    int j;
                    for (j = 0; j < svalues.Length; j++)
                    {
                        SimpleTag subtag;
                        if (j >= slist.Count)
                        {
                            slist.Add(subtag = new SimpleTag());
                        }
                        else
                        {
                            subtag = slist[j];
                        }

                        subtag.Value = svalues[j];
                    }

                    if (j < slist.Count)
                    {
                        slist.RemoveRange(j, slist.Count - j);
                    }
                }
            }


            if (subkey == null && i < list.Count)
            {
                list.RemoveRange(i, list.Count - i);
            }
        }