Exemplo n.º 1
0
        static public T Read <T>(this StreamSystem item, string path, TryOperation <T, Stream> operation, long milliseconds = StreamSystem.DEFAULT_WAIT)
        {
            T output;

            item.AttemptRead <T>(path, operation, out output, milliseconds);
            return(output);
        }
Exemplo n.º 2
0
        static public IEnumerable <T> Squish <T>(this IEnumerable <T> item, TryOperation <T, T, T> operation)
        {
            List <T> list       = item.ToList();
            bool     did_squish = false;

            do
            {
                did_squish = false;
                for (int i = 0; i < list.Count; i++)
                {
                    T sub_item1 = list[i];

                    for (int j = i + 1; j < list.Count; j++)
                    {
                        T sub_item2 = list[j];

                        T squished;
                        if (operation(sub_item1, sub_item2, out squished))
                        {
                            list[i] = squished;
                            list.RemoveAt(j);

                            did_squish = true;
                            break;
                        }
                    }
                }
            } while (did_squish);

            return(list);
        }
Exemplo n.º 3
0
 public void Do <T>(TryOperation <T> tryOperation) where T : class, Operator
 {
     for (int priority = operators.Count - 1; priority >= 0; priority--)
     {
         for (int i = operators[priority].Count - 1; i >= 0; i--)
         {
             var candidate = operators[priority][i] as T;
             if (candidate != null && tryOperation(candidate))
             {
                 return;
             }
         }
     }
     throw new ApplicationException(string.Format("No default for {0}", typeof(T).Name));
 }
Exemplo n.º 4
0
 internal static int CatchError(TryOperation operation)
 {
     try
     {
         if (!operation())
         {
             return((int)Win32Api.Error.ERROR_FILE_NOT_FOUND);
         }
         return(0);
     }
     catch (Win32Exception ex)
     {
         return(ex.ErrorCode);
     }
 }
Exemplo n.º 5
0
        static public AttemptResult AttemptRead <T>(this StreamSystem item, string path, TryOperation <T, Stream> operation, out T output, long milliseconds = StreamSystem.DEFAULT_WAIT)
        {
            T temp = default(T);

            AttemptResult result = item.AttemptRead(path, delegate(Stream stream) {
                return(operation(stream, out temp));
            }, milliseconds);

            output = temp;
            return(result);
        }
Exemplo n.º 6
0
 static public T Read <T>(this StreamSystemStream item, TryOperation <T, Stream> operation, long milliseconds = StreamSystem.DEFAULT_WAIT)
 {
     return(item.GetStreamSystem().Read <T>(item.GetPath(), operation, milliseconds));
 }
Exemplo n.º 7
0
 static public AttemptResult AttemptRead <T>(this StreamSystemStream item, TryOperation <T, Stream> operation, out T output, long milliseconds = StreamSystem.DEFAULT_WAIT)
 {
     return(item.GetStreamSystem().AttemptRead <T>(item.GetPath(), operation, out output, milliseconds));
 }
Exemplo n.º 8
0
        static public IEnumerable <Tuple <PRIMARY_TYPE, SECONDARY_TYPE> > TryNarrow <PRIMARY_TYPE, SECONDARY_TYPE>(this IEnumerable <PRIMARY_TYPE> item, TryOperation <SECONDARY_TYPE, PRIMARY_TYPE> operation)
        {
            if (item != null)
            {
                foreach (PRIMARY_TYPE sub_item in item)
                {
                    SECONDARY_TYPE secondary_item;

                    if (operation(sub_item, out secondary_item))
                    {
                        yield return(Tuple.New(sub_item, secondary_item));
                    }
                }
            }
        }
Exemplo n.º 9
0
        static public IEnumerable <OUTPUT_TYPE> TryConvert <INPUT_TYPE, OUTPUT_TYPE>(this IEnumerable <INPUT_TYPE> item, TryOperation <OUTPUT_TYPE, INPUT_TYPE> operation)
        {
            foreach (INPUT_TYPE sub_item in item)
            {
                OUTPUT_TYPE cast;

                if (operation(sub_item, out cast))
                {
                    yield return(cast);
                }
            }
        }
Exemplo n.º 10
0
 public EditorGUIElement_Popup_ProcessOperation(IEnumerable <T> es, Process <T> sp, TryOperation <T> go) : this(es, e => e.ToStringEX(), sp, go)
 {
 }
Exemplo n.º 11
0
 public EditorGUIElement_Popup_ProcessOperation(IEnumerable <T> es, Operation <string, T> op, Process <T> sp, TryOperation <T> go) : this(es, op, sp, go, DEFAULT_HEIGHT)
 {
 }
Exemplo n.º 12
0
 public EditorGUIElement_Popup_ProcessOperation(IEnumerable <T> es, Operation <string, T> op, Process <T> sp, TryOperation <T> go, float h) : base(es, op, h)
 {
     set_process = sp;
     get_process = go;
 }