Self() public static method

public static Self ( object self ) : void
self object
return void
Ejemplo n.º 1
0
        public static IEnumerable <string> Words(this TextReader self, TextReaderRocksOptions options)
        {
            Check.Self(self);
            CheckOptions(options);

            return(Tokens(self, options, (p, c) => !char.IsWhiteSpace(c)));
        }
Ejemplo n.º 2
0
        public static IEnumerable <string> MatchValues(this string self, string regex, RegexOptions options)
        {
            Check.Self(self);

            return(Matches(self, regex, options)
                   .Select(m => m.Value));
        }
Ejemplo n.º 3
0
        public static IEnumerable <string> Lines(this TextReader self, TextReaderRocksOptions options)
        {
            Check.Self(self);
            CheckOptions(options);

            return(CreateLineIterator(self, options));
        }
Ejemplo n.º 4
0
        public static IEnumerable <string> Captures(this string self, string regex, RegexOptions options)
        {
            Check.Self(self);

            return(Matches(self, regex, options)
                   .SelectMany(m => m.Groups.Cast <Group> ().Skip(1))
                   .Select(g => g.Value));
        }
Ejemplo n.º 5
0
        public static IEnumerable <IEnumerable <TSource> > Rows <TSource> (this TSource[,] self)
        {
            Check.Self(self);

            int rows = self.GetLength(0);
            int cols = self.GetLength(1);

            return(CreateRowsIterator(self, rows, cols));
        }
Ejemplo n.º 6
0
        public static ValueReader <TSource> Read <TSource, TValue> (this ValueReader <TSource> self, out TValue value)
        {
            Check.Self(self);

            value = Either.TryParse <TSource, TValue> (self.GetNextItem())
                    .Fold <TValue> (v => v, v => { throw v; });

            return(self);
        }
Ejemplo n.º 7
0
 public static IEnumerable <string> Tokens(this TextReader self, params Func <char?, char, bool>[] categories)
 {
     Check.Self(self);
     Check.Categories(categories);
     if (categories.Length == 0)
     {
         throw new ArgumentException("categories", "Must provide at least one catagory");
     }
     return(Tokens(self, TextReaderRocksOptions.CloseReader, categories));
 }
Ejemplo n.º 8
0
        public static IEnumerable <KeyValuePair <TSource, TResult> > TraverseBreadthFirstWithParent <TSource, TResult>(
            this TSource self,
            Func <TSource, TResult> valueSelector,
            Func <TSource, IEnumerable <TSource> > childrenSelector)
        {
            Check.Self(self);
            Check.ValueSelector(valueSelector);
            Check.ChildrenSelector(childrenSelector);

            return(CreateTraverseBreadthFirstWithParentIterator(self, valueSelector, childrenSelector));
        }
Ejemplo n.º 9
0
        public static TAttribute GetCustomAttribute <TAttribute> (this ICustomAttributeProvider self) where TAttribute : Attribute
        {
            Check.Self(self);

            var attributes = self.GetCustomAttributes <TAttribute> ();

            if (attributes == null || attributes.Length == 0)
            {
                return(null);
            }

            return(attributes [0]);
        }
Ejemplo n.º 10
0
        public static bool IsNullable(this Type self)
        {
            Check.Self(self);

            if (!self.IsValueType || !self.IsGenericType)
            {
                return(false);
            }

            return(self.IsGenericTypeDefinition
                                ? false
                                : self.GetGenericTypeDefinition() == typeof(Nullable <>));
        }
Ejemplo n.º 11
0
        public static StreamConverter Write <TValue> (this StreamConverter self, TValue value)
        {
            Check.Self(self);

            byte[] data = new byte [Marshal.SizeOf(typeof(TValue))];

            GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned);

            try {
                Marshal.StructureToPtr(value, handle.AddrOfPinnedObject(), false);
            } finally {
                handle.Free();
            }

            return(self.Write(data));
        }
Ejemplo n.º 12
0
        public static StreamConverter Read <TValue> (this StreamConverter self, out TValue value)
        {
            Check.Self(self);

            byte[] data = new byte [Marshal.SizeOf(typeof(TValue))];
            self.Read(data);
            GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned);

            try {
                value = (TValue)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(TValue));
            } finally {
                handle.Free();
            }

            return(self);
        }
Ejemplo n.º 13
0
        public static void WriteTo(this Stream self, Stream destination)
        {
            Check.Self(self);
            Check.Destination(destination);

            int size = self.CanSeek
                                ? (int)System.Math.Min(self.Length - self.Position, 4096)
                                : 4096;

            byte[] buf = new byte [size];
            int    r;

            while ((r = self.Read(buf, 0, buf.Length)) > 0)
            {
                destination.Write(buf, 0, r);
            }
        }
Ejemplo n.º 14
0
        public static string Remove(this string self, params string[] targets)
        {
            Check.Self(self);
            if (targets == null)
            {
                throw new ArgumentNullException("targets");
            }

            StringBuilder builder = new StringBuilder(self);

            for (int i = 0; i < targets.Length; ++i)
            {
                builder.Replace(targets[i], String.Empty);
            }

            return(builder.ToString());
        }
Ejemplo n.º 15
0
        public static string Slice(this string self, int start, int end)
        {
            Check.Self(self);

            if (start < 0 || start >= self.Length)
            {
                throw new ArgumentOutOfRangeException("start");
            }

            if (end < 0)
            {
                end += self.Length + 1;
            }

            if (end < start || end > self.Length)
            {
                throw new ArgumentOutOfRangeException("end");
            }

            return(self.Substring(start, end - start));
        }
Ejemplo n.º 16
0
        public static string Implode <TSource> (this IEnumerable <TSource> self, string separator, Func <TSource, string> selector)
        {
            Check.Self(self);
            Check.Selector(selector);

            var c = self as ICollection <TSource>;

            string[] values = new string [c != null ? c.Count : 10];
            int      i      = 0;

            foreach (var e in self)
            {
                if (values.Length == i)
                {
                    Array.Resize(ref values, i * 2);
                }
                values [i++] = selector(e);
            }
            if (i < values.Length)
            {
                Array.Resize(ref values, i);
            }
            return(string.Join(separator, values));
        }
Ejemplo n.º 17
0
        public static StreamConverter WithSystemConverter(this Stream self)
        {
            Check.Self(self);

            return(new SystemStreamConverter(self));
        }
Ejemplo n.º 18
0
 public static IEnumerable <IEnumerable <TSource> > Rows <TSource> (this TSource[][] self)
 {
     Check.Self(self);
     return(self);
 }
Ejemplo n.º 19
0
        public static IEnumerable <string> Captures(this string self, string regex)
        {
            Check.Self(self);

            return(Captures(self, regex, RegexOptions.None));
        }
Ejemplo n.º 20
0
        public static TAttribute [] GetCustomAttributes <TAttribute> (this ICustomAttributeProvider self) where TAttribute : Attribute
        {
            Check.Self(self);

            return((TAttribute [])self.GetCustomAttributes(typeof(TAttribute), true));
        }
Ejemplo n.º 21
0
        public static IEnumerable <string> Tokens(this string self, params Func <char?, char, bool>[] categories)
        {
            Check.Self(self);

            return(new StringReader(self).Tokens(categories));
        }
Ejemplo n.º 22
0
        public static TEnum ToEnum <TEnum> (this string self)
        {
            Check.Self(self);

            return((TEnum)Enum.Parse(typeof(TEnum), self));
        }
Ejemplo n.º 23
0
        public static ILookup <string, string> CaptureNamedGroups(this string self, string regex)
        {
            Check.Self(self);

            return(CaptureNamedGroups(self, regex, RegexOptions.None));
        }
Ejemplo n.º 24
0
        public static ILookup <string, string> CaptureNamedGroups(this string self, string regex, RegexOptions options)
        {
            Check.Self(self);

            return(CreateCaptureNamedGroupsIterator(self, regex, options).ToLookup(s => s.Key, s => s.Value));
        }
Ejemplo n.º 25
0
        public static IEnumerable <string> Lines(this string self)
        {
            Check.Self(self);

            return(new StringReader(self).Lines());
        }
Ejemplo n.º 26
0
        public static IEnumerable <Match> Matches(this string self, string regex, RegexOptions options)
        {
            Check.Self(self);

            return(new Regex(regex, options).Matches(self).Cast <Match> ());
        }