Пример #1
0
        public static QsFlowingTuple FromStruct(ValueType value)
        {
            var StructType = value.GetType();

            var props = StructType.GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);

            var all = from o in props
                      where o.IsSpecialName == false && o.GetIndexParameters().Length == 0
                      select o;

            QsTupleValue[] fefe = new QsTupleValue[all.Count()];

            int id = 10;   // begin the properties from id == 10  like Basic auto numbering in old days

            for (int ix = 0; ix < all.Count(); ix++)
            {
                var StructProperty = all.ElementAt(ix);

                fefe[ix].Name = StructProperty.Name;
                fefe[ix].Id   = id;

                if (StructProperty.PropertyType.IsValueType)
                {
                    fefe[ix].SetLazyValue(StructProperty.GetValue(value, null));
                }
                else
                {
                    fefe[ix].Value = Root.NativeToQsConvert(StructProperty.GetValue(value, null));
                }

                id += 10;
            }

            return(new QsFlowingTuple(fefe));
        }
Пример #2
0
        public override QsValue ExclamationOperator(QsValue key)
        {
            if (key.ToString().Equals("TypeName", StringComparison.OrdinalIgnoreCase))
            {
                return(new QsText(InstanceType.Name));
            }

            if (key.ToString().Equals("Properties", StringComparison.OrdinalIgnoreCase))
            {
                QsFlowingTuple f   = new QsFlowingTuple();
                var            mms = InstanceType.GetProperties(BindingFlags.Public | BindingFlags.Instance);

                QsTupleValue[] fefe = new QsTupleValue[mms.Length];

                for (int ix = 0; ix < mms.Length; ix++)
                {
                    fefe[ix].Name = (string)mms[ix].Name;

                    fefe[ix].Value = new QsText(mms[ix].PropertyType.Name);
                }
                if (fefe.Length == 0)
                {
                    return(new QsFlowingTuple());
                }
                return(new QsFlowingTuple(fefe));
            }

            if (key.ToString().Equals("Methods", StringComparison.OrdinalIgnoreCase))
            {
                QsFlowingTuple f   = new QsFlowingTuple();
                var            mms = from m in InstanceType.GetMethods(BindingFlags.Public | BindingFlags.Instance)
                                     where m.IsSpecialName == false
                                     select m;

                QsTupleValue[] fefe = new QsTupleValue[mms.Count()];

                for (int ix = 0; ix < mms.Count(); ix++)
                {
                    fefe[ix].Name = (string)mms.ElementAt(ix).Name;

                    fefe[ix].Value = new QsText(mms.ElementAt(ix).ReturnType.Name);
                }
                if (fefe.Length == 0)
                {
                    return(new QsFlowingTuple());
                }
                return(new QsFlowingTuple(fefe));
            }

            if (key.ToString().Equals("Type", StringComparison.OrdinalIgnoreCase))
            {
                return(new QsObject(InstanceType));
            }
            return(new QsText("Unknown Command"));
        }
Пример #3
0
        /// <summary>
        /// Return Tuple from C# enum.
        /// </summary>
        /// <param name="enumType"></param>
        /// <returns></returns>
        public static QsFlowingTuple FromCSharpEnum(Type enumType)
        {
            Contract.Requires(enumType == typeof(Enum));
            var names = Enum.GetNames(enumType);

            QsTupleValue[] fefe   = new QsTupleValue[names.Length];
            var            values = Enum.GetValues(enumType);


            for (int ix = 0; ix < names.Length; ix++)
            {
                fefe[ix].Name  = (string)names[ix];
                fefe[ix].Id    = (int)values.GetValue(ix);
                fefe[ix].Value = ((int)values.GetValue(ix)).ToQuantity().ToScalarValue();
            }

            return(new QsFlowingTuple(fefe));
        }
Пример #4
0
        public override QsValue LeftShiftOperation(QsValue vl)
        {
            QsValue times;

            if (vl is QsReference)
            {
                times = ((QsReference)vl).ContentValue;
            }
            else
            {
                times = vl;
            }

            int itimes = Qs.IntegerFromQsValue((QsScalar)times);

            int c = InitialValues.Count();

            if (itimes > c)
            {
                itimes = itimes % c;
            }


            QsTupleValue[] NewValues = new QsTupleValue[c];

            int ix = 0;

            for (int i = itimes; i < c; i++)
            {
                NewValues[ix] = InitialValues[i];
                ix++;
            }

            for (int i = 0; i < itimes; i++)
            {
                NewValues[ix] = InitialValues[i];
                ix++;
            }

            return(new QsFlowingTuple(NewValues));
        }