Esempio n. 1
0
            public static Func <IEnumerable <IEnumerable <RHS_ElemT> >, MotherT> MkFun <RHS_ElemT>(Func <RHS_ElemT, ElemT> elemFunc, int len_outer, int len_inner)
            {
                // can't really determine wheter indexer property is implemented from the type system
                MethodInfo setterMI = typeof(MotherT).GetMethod("set_Item", new [] { typeof(int), typeof(int), typeof(ElemT) });
                Func <IEnumerable <IEnumerable <RHS_ElemT> >, MotherT> F = (L_in) =>
                {
                    var    R           = new MotherT();
                    object obR         = RuntimeHelpers.GetObjectValue(R); // todo only for value types - how is this different from casting to (object) ??
                    var    rator_outer = L_in.GetEnumerator();
                    for (int i_outer = 0; i_outer < len_outer; i_outer++)
                    {
                        if (!rator_outer.MoveNext())
                        {
                            throw new RHS_Shape_Exception();                              // <- these don't fly properly they are somehow
                        }
                        var rator_inner = rator_outer.Current.GetEnumerator();

                        for (int i_inner = 0; i_inner < len_inner; i_inner++)
                        {
                            if (!rator_inner.MoveNext())
                            {
                                throw new RHS_Shape_Exception();
                            }
                            setterMI.Invoke(obR, new object[] { i_outer, i_inner, elemFunc(rator_inner.Current) });
                        }
                    }
                    return((MotherT)obR);
                };

                return(F);
            }
Esempio n. 2
0
            /*
             *  the sole reason for this indirection is that c# can't translate member calls on open generic types
             *  e.g. i need T in: List<T>.Count() bound here
             *  (introduce RHS_ElemT as generic variable, only to specialize it the constructor )
             *  ... there probably is a less convoluted way of doing this
             */
            public static Func <IEnumerable <RHS_ElemT>, LHS_ElemT[]> MkFunc <RHS_ElemT>(Func <RHS_ElemT, LHS_ElemT> elemFunc)
            {
                Func <IEnumerable <RHS_ElemT>, LHS_ElemT[]> F = (L_in) =>
                {
                    int len   = L_in.Count();
                    var R     = new LHS_ElemT[len];
                    var rator = L_in.GetEnumerator();
                    for (int i = 0; i < len; i++)
                    {
                        rator.MoveNext();
                        R[i] = elemFunc(rator.Current);
                    }
                    return(R);
                };

                return(F);
            }
Esempio n. 3
0
            public static Func <IEnumerable <RHS_ElemT>, MotherT> MkFun <RHS_ElemT>(Func <RHS_ElemT, ElemT> elemFunc, int len)
            {
                // can't really determine wheter indexer property is implemented from the type system
                MethodInfo setterMI = typeof(MotherT).GetProperty("Item").GetSetMethod();
                Func <IEnumerable <RHS_ElemT>, MotherT> F = (L_in) =>
                {
                    var    R     = new MotherT();
                    object obR   = RuntimeHelpers.GetObjectValue(R); // todo only for value types - how is this different from casting to (object) ??
                    var    rator = L_in.GetEnumerator();
                    for (int i = 0; i < len; i++)
                    {
                        if (!rator.MoveNext())
                        {
                            throw new RHS_Shape_Exception();
                        }
                        setterMI.Invoke(obR, new object[] { i, elemFunc(rator.Current) });
                    }
                    return((MotherT)obR);
                };

                return(F);
            }