/// <summary>
        /// This method sorts the items in a listbox.
        /// </summary>
        /// <param name="items">The list control.</param>
        /// <param name="Descending">Whether to sort the list box descending. </param>
        public static void SortListItems(this ListItemCollection items, bool Descending)
        {
            System.Collections.Generic.List<ListItem> list = new System.Collections.Generic.List<ListItem>();
            foreach (ListItem i in items)
            {
                list.Add(i);
            }

            if (Descending)
            {
                IEnumerable<ListItem> itemEnum =
                    from item in list
                    orderby item.Text descending
                    select item;
                items.Clear();
                items.AddRange(itemEnum.ToArray());
                // anonymous delegate list.Sort(delegate(ListItem x, ListItem y) { return y.Text.CompareTo(x.Text); });
            }
            else
            {
                IEnumerable<ListItem> itemEnum =
                    from item in list
                    orderby item.Text ascending
                    select item;
                items.Clear();
                items.AddRange(itemEnum.ToArray());

                //list.Sort(delegate(ListItem x, ListItem y) { return x.Text.CompareTo(y.Text); });
            }
        }
Example #2
0
        public static void Load( this TextBuffer TextBuffer, string Xml, bool Clear = true )
        {
            if( Clear )
            {
                TextBuffer.Clear();
            }

            TextIter oIter = TextBuffer.	GetIterAtOffset (0);
            XmlDocument oXML = new XmlDocument ( );

            oXML.LoadXml (Xml);

            XmlNodeList oParagraphList = oXML.DocumentElement.SelectNodes ("paragraph");

            foreach(XmlNode oParagraph in oParagraphList)
            {
                XmlNodeList oSectionList = oParagraph.SelectNodes ("section");

                foreach (XmlNode oSection in oSectionList)
                {
                    string szStyle = oSection.Attributes.GetNamedItem ("style") != null ? oSection.Attributes.GetNamedItem ("style").Value : null;

                    TextBuffer.InsertWithTagsByName (ref oIter, oSection.InnerText, szStyle);
                }

                TextBuffer.Insert(ref oIter, "\n");
            }
        }
		/// <summary>
		/// 	Sets all of the keys on the AnimationCurve to the given value.
		/// 	If there are no keys, we add one.
		/// </summary>
		/// <param name="extends">Extends.</param>
		/// <param name="value">Value.</param>
		public static void SetValue(this AnimationCurve extends, float value)
		{
			extends.Clear();

			extends.AddKey(0.0f, value);
			extends.AddKey(1.0f, value);
		}
 public static void Add(this Wd.ContentControlListEntries ListEntries, IList<string> items)
 {
     ListEntries.Clear();
     foreach (string item in items)
         if (!string.IsNullOrEmpty(item))
             ListEntries.Add(item, item);
 }
		public static bool Deserialize(this Dictionary<string, string> value, byte[] bytes)
		{
			if (bytes == null)
				throw new ArgumentNullException("bytes");

			Dictionary<string, string> cache = new Dictionary<string, string>();
			try
			{
				int position = 0;
				while (position < bytes.Length)
				{
					string key = DecodeString(bytes, ref position);
					string val = DecodeString(bytes, ref position);
					cache.Add(key, val);
				}
			}
			catch
			{
				return false;
			}

			value.Clear();
			foreach (var item in cache)
				value.Add(item.Key, item.Value);
			return true;
		}
Example #6
0
		/// <summary>
		/// 通过脚本跳转到指定url
		/// 用这个代替301跳转可以保留referer
		/// </summary>
		/// <param name="response">Http回应</param>
		/// <param name="url">跳转到的url地址</param>
		public static void RedirectByScript(this HttpResponse response, string url) {
			var urlJson = JsonConvert.SerializeObject(url);
			response.Clear();
			response.ContentType = "text/html";
			response.Write([email protected]"<script type='text/javascript'>location.href = {urlJson};</script>");
			response.End();
		}
	public static StringBuilder Substring(this StringBuilder sb, int index, int length)
	{
		if (index < 0)
		{
			throw new ArgumentOutOfRangeException("index");
		}
		if (index > sb.Length)
		{
			throw new ArgumentOutOfRangeException("index");
		}
		if (length < 0)
		{
			throw new ArgumentOutOfRangeException("length");
		}
		if (index > sb.Length - length)
		{
			throw new ArgumentOutOfRangeException("length");
		}
		if (length == 0)
		{
			return sb.Clear();
		}
		if (index == 0 && length == sb.Length)
		{
			return sb;
		}

		return new StringBuilder(sb.ToString().Substring(index, length));
	}
    public static void MergeIdenticalItems(this List<ChromosomeCountSlimItem> chroms)
    {
      Console.WriteLine("All groups = {0}", chroms.Count);
      var uniqueQueryGroups = (from g in chroms.GroupBy(l => l.Queries.Count)
                               select g.ToArray()).ToArray();

      Console.WriteLine("Groups with same unique queries = {0}", uniqueQueryGroups.Length);

      chroms.Clear();
      foreach (var uqg in uniqueQueryGroups)
      {
        var queryCountGroups = (from g in uqg.GroupBy(l => l.GetQueryCount())
                                select g.ToArray()).ToArray();
        foreach (var qcg in queryCountGroups)
        {
          var qnameGroups = (from g in qcg.GroupBy(g => g.Queries[0].Qname)
                             select g.ToList()).ToArray();
          foreach (var qg in qnameGroups)
          {
            if (qg.Count > 1)
            {
              DoMergeIdentical(qg);
            }
            chroms.AddRange(qg);
          }
          qnameGroups = null;
        }
        queryCountGroups = null;
      }
      uniqueQueryGroups = null;
    }
 /// <summary>
 /// Clear the text from a buffer, and set the text in the buffer based message,tag pairs.
 /// </summary>
 public static void SetText(this TextBuffer tb, IEnumerable<Message> messages)
 {
     tb.Clear();
     foreach (Message m in messages) {
         tb.Add(m.msg, m.tag);
     }
 }
		public static StringBuilder StringBuilderSubstring(this StringBuilder sb, int start, int count)
		{
			string substring  = sb.ToString().Substring(start, count);
			sb = sb.Clear().Append(substring);

			return sb;
		}
Example #11
0
 public static void JsonResult(this HttpResponse response, object data)
 {
     response.Clear();
     response.AddHeader("Content-Type", "application/json");
     response.Write(LogManager.JsonSerializer.SerializeObject(data));
     response.End();
 }
Example #12
0
 public static void HtmlResult(this HttpResponse response, string html)
 {
     response.Clear();
     response.AddHeader("Content-Type", "text/html");
     response.Write(html);
     response.End();
 }
        internal static void Dispose(this HashAlgorithm algorithm)
        {
            if (algorithm == null)
                throw new NullReferenceException();

            algorithm.Clear();
        }
Example #14
0
 public static void SetPushPinData(this List<Pushpin> pl, List<PushpinData> pld)
 {
     pl.Clear();
         foreach (var itm in pld) {
             pl.Add(itm.GetPushPin());
         }
 }
 public static IWebElement FillInWith(this IWebElement element, string text)
 {
     element.Clear();
     if (!string.IsNullOrEmpty(text))
         element.SendKeys(text);
     return element;
 }
Example #16
0
 public static void ClearAndMerge(this DataTable table, DataTable newtable)
 {
     table.BeginLoadData();
     table.Clear();
     table.Merge(newtable, false, MissingSchemaAction.Ignore);
     table.EndLoadData();
 }
Example #17
0
        public static void Deserialize(this Template template)
        {
            template.Clear();

            var tplJs = new JSONObject(template.JSON);

            // Discard templates without the Operators and Connections fields
            if (tplJs.HasField("Operators") && tplJs.HasField("Connections")) {
                var opsJs = tplJs.GetField("Operators");
                var connsJs = tplJs.GetField("Connections");
                foreach (var opJs in opsJs.list) {
                    var type = System.Type.GetType(opJs["Type"].str);
                    var op = (Operator) System.Activator.CreateInstance(type);
                    op.Deserialize(opJs);
                    template.AddOperator(op, false);
                }
                foreach (var connJs in connsJs.list) {

                    // Discard connections with invalid Operator GUIDs
                    if (!template.Operators.ContainsKey(connJs["From"].str) || !template.Operators.ContainsKey(connJs["To"].str)) {
                        Debug.LogWarning("Discarding connection in template due to an invalid Operator GUID");
                        continue;
                    }

                    Operator fromOp = template.Operators[connJs["From"].str];
                    IOOutlet output = fromOp.GetOutput(connJs["Output"].str);

                    Operator toOp = template.Operators[connJs["To"].str];
                    IOOutlet input = toOp.GetInput(connJs["Input"].str);

                    template.Connect(fromOp, output, toOp, input, false);
                }
            }
        }
Example #18
0
        public static void Compare(this Collection<Candidate> Collection, IEnumerable<Candidate> Items)
        {
            if (Items.Count() > 0)
            {
                Collection<Candidate> Temporary = new Collection<Candidate>();
                foreach (Candidate c in Collection)
                {
                    Temporary.Add(c);
                }

                Collection.Clear(); // Remove our items
                bool bHasItems = (Temporary.Count() > 0) ? true : false;

                foreach (Candidate c in Items) // For each item in our enumeration
                {
                    if (bHasItems) // If our current collection has any items
                    {
                        foreach (Candidate e in Temporary) // For each item in our temporary collection
                        {
                            if (c.Id == e.Id) // If the Id is the same as the id in our items collection
                                Collection.Add(c); // Add to the current collection
                        }
                    }
                    else // If we have no items in our collection
                        Collection.Add(c); // Add all the items to our collection
                }
            }
        }
 public static String GetString(this IList<char> chars)
 {
     char[] array = new char[chars.Count];
     chars.CopyTo(array, 0);
     chars.Clear();
     return new String(array);
 }
 //Forces Download/Save rather than opening in Browser//
 public static void ForceDownload(this HttpResponse Response, string virtualPath, string fileName)
 {
     Response.Clear();
     Response.AddHeader("content-disposition", "attachment; filename=" + fileName);
     Response.WriteFile(virtualPath);
     Response.ContentType = "";
     Response.End();
 }
Example #21
0
 /// <summary>
 /// Disposes the content of a collection
 /// </summary>
 /// <param name="collection">The colletion to dispose</param>
 public static void Dispose(this ICollection<IDisposable> collection)
 {
     foreach (var item in collection.ToArray()) // Iterate over copy of the collection in case the collection is changed by the disposes
     {
         item.Dispose();
     }
     collection.Clear();
 }
Example #22
0
        public static void AddEventsOrClearOnSnapshot(
			this ICollection<object> events, Commit commit, bool applySnapshot)
        {
            if (applySnapshot && commit.Snapshot != null)
                events.Clear();
            else
                events.AddEvents(commit);
        }
	public static void SortByX(this List<Transform> list) {
		Transform[] array = list.ToArray();
		Array.Sort(array, delegate(Transform t1, Transform t2) { return t1.position.x.CompareTo(t2.position.x); });
		List<Transform> newList = new List<Transform>();
		for (int i = 0; i < array.Length; i++) newList.Add(array[i]);
		list.Clear();
		for (int i = 0; i < newList.Count; i++) list.Add(newList[i]);
	}
Example #24
0
        /// <summary>
        /// Extracts the buffered value and resets the buffer
        /// </summary>
        public static string Extract(this StringBuilder builder)
        {
            var text = builder.ToString();

            builder.Clear();

            return text;
        }
 public static void CustomSendKeys(this IWebElement webelement, string key)
 {
     webelement.Clear();
     if (!string.IsNullOrWhiteSpace(key))
     {
         webelement.SendKeys(key);
     }
 }
Example #26
0
        public static Stream ClearWriteReset(this Stream stream, byte[] contents)
        {
            stream.Clear();
            stream.Write(contents, 0, contents.Length);
            stream.Reset();

            return stream;
        }
Example #27
0
        public static Stream ClearWriteReset(this Stream stream, Action<Stream> write)
        {
            stream.Clear();
            write(stream);
            stream.Reset();

            return stream;
        }
 public static String Release(this StringBuilder builder)
 {
     // Stringify it and return a (clean) one
     var str = builder.ToString();
     pool.Push(builder.Clear());
     // Return the generated string
     return str;
 }
Example #29
0
        internal static IList<double> Initialize(this IList<double> list, int count)
        {
            list.Clear();
              for (int i = 0; i < count; i++)
            list.Add(0);

              return list;
        }
 public static void AddRange(this ModelStateDictionary modelState, IEnumerable<ValidationMessage> messages)
 {
     modelState.Clear();
     foreach (var msg in messages)
     {
         modelState.AddModelError(msg.PropertyName, msg.ErrorMessage);
     }
 }