Added AltSpider project to implement MySQL-based view enabled solution with different...
[LanSpider.git] / src / Extensions / Extensions.cs
blob151f3663eabb420aecc5ed01780eafd160af179e
1 using System;
3 namespace Extensions
5 public static class Extensions
7 /// <summary>
8 /// Get the array slice between the index (inclusive and end of array).
9 /// </summary>
10 public static T[] Slice< T >( this T[] source, int start )
12 // Return new array
13 T[] res = new T[source.Length - start];
14 for ( int i = 0; i < source.Length - start; ++i )
16 res[ i ] = source[ i + start ];
18 return res;
21 /// <summary>
22 /// Get the array slice between the two indexes.
23 /// Inclusive for start index, exclusive for end index.
24 /// </summary>
25 public static T[] Slice< T >( this T[] source, int start, int end )
27 // Handles negative ends
28 if ( end < 0 )
30 end = source.Length - start - end - 1;
32 int len = end - start;
34 // Return new array
35 T[] res = new T[len];
36 for ( int i = 0; i < len; ++i )
38 res[ i ] = source[ i + start ];
40 return res;
43 /// <summary>
44 /// Get count of arguments ocurances in this string.
45 /// </summary>
46 /// <param name="string"></param>
47 /// <param name="char"></param>
48 /// <returns></returns>
49 public static int Count( this string @string, char @char )
51 int count = 0;
52 int index = 0;
53 while ( index != -1 )
55 index = @string.IndexOf( @char, index );
56 if ( index != -1 )
58 ++count;
59 ++index;
63 return count;
66 /// <summary>
67 /// Replaces this string with the text equivalent of the value of
68 /// specified System.Object instance.
69 /// </summary>
70 /// <param name="string"></param>
71 /// <param name="arg"></param>
72 /// <returns></returns>
73 public static string Fmt( this string @string, object arg )
75 return String.Format( @string, arg );
78 /// <summary>
79 /// Replaces this string with the text equivalent of the value of
80 /// two specified System.Object instances.
81 /// </summary>
82 /// <param name="string"></param>
83 /// <param name="arg0"></param>
84 /// <param name="arg1"></param>
85 /// <returns></returns>
86 public static string Fmt( this string @string, object arg0, object arg1 )
88 return String.Format( @string, arg0, arg1 );
91 /// <summary>
92 /// Replaces this string with the text equivalent of the value of
93 /// three specified System.Object instances.
94 /// </summary>
95 /// <param name="string"></param>
96 /// <param name="arg0"></param>
97 /// <param name="arg1"></param>
98 /// <param name="arg2"></param>
99 /// <returns></returns>
100 public static string Fmt( this string @string, object arg0, object arg1, object arg2 )
102 return String.Format( @string, arg0, arg1, arg2 );
106 /// <summary>
107 /// eplaces this string with the text equivalent of the value of
108 /// a corresponding System.Object instance in a specified array.
109 /// </summary>
110 /// <param name="string"></param>
111 /// <param name="args"></param>
112 /// <returns></returns>
113 public static string Fmt( this string @string, params object[] args )
115 return String.Format( @string, args );