Ejemplo n.º 1
0
        /// <summary>
        /// Convert string to TargetType array using first character as separator
        /// </summary>
        /// <returns>The array.</returns>
        /// <param name="value">string value.</param>
        /// <param name="TargetType">Target type.</param>
        /// <param name="getInstance">Get instance.</param>
        public static Array AsArray(this string value, Type TargetType, Func<Type, string, object> getInstance)
        {
            if (TargetType.HasElementType)
            {
                Type type = TargetType.GetElementType();

                if (type.HasElementType)
                {
                    return value.AsArray().AsEnumerable().Select(a => a.AsArray(type, getInstance)).ToArray(type);
                }
                else
                {
                    return value.AsArray().AsEnumerable().Select(s => getInstance(type, s)).ToArray(type);
                }
            }

            throw new InvalidCastException("Not an array");
        }
Ejemplo n.º 2
0
        public static IEnumerable<DisplayText> Virtualise(this IEnumerable<DisplayText> source, TextScrollInfo scroll)
        {
            var items = source.AsArray();

            if (scroll == null || scroll.TotalChars == 0)
                return items;

            // var list = new List<DisplayText>(items.Length);
            int lastIndex = scroll.FirstIndex + scroll.TotalChars;

            var displayBounds = items.Aggregate(new List<DisplayWithIndex>(), (state, latest) =>
            {

                if (state.Count == 0)
                {
                    state.Add( new DisplayWithIndex(latest, 0));
                }
                else
                {
                    var last = state.Last();
                    state.Add(new DisplayWithIndex(latest, last.StartIndex + last.Text.Length));
                }

                return state;
            }).ToArray();

            var result = displayBounds
                .Select(item =>
                {
                    if (item.Inbounds(scroll.FirstIndex, lastIndex))
                    {
                        //clip it and yield
                        return item.Clip(scroll.FirstIndex, lastIndex);
                    }
                    return null;
                }).Where(item => item != null)
                .ToArray();

            return result;
        }
Ejemplo n.º 3
0
 public static Type[] LookupThisAndBaseTypes(this Type t)
 {
     return t.AsArray().Concat(t.LookupBaseTypes()).ToArray();
 }