protected SpriteKernel(IConvertible initialVersion)
 {
     SourceList = new Dictionary<IConvertible, SpriteSource>();
     Animation = new PeriodicFunction<SpriteTransformation>(stage => new SpriteTransformation(0));
     RegisteredVersion = new Collection<IConvertible>();
     Version = initialVersion;
 }
Example #2
0
        protected override IConvertible DoBinOp(IConvertible left, IConvertible right)
        {
            Boolean left1 = Convert.ToBoolean(left);
            Boolean right1 = Convert.ToBoolean(right);

            return left1 && right1;
        }
Example #3
0
 private void SetOperand(IConvertible operand)
 {
     switch (Instruction)
     {
         case BFInstruction.SetVariable:
         case BFInstruction.PushVariable:
         case BFInstruction.PushUInt16:
         case BFInstruction.JumpIfFalse:
         case BFInstruction.Jump:
         case BFInstruction.CallProcedure:
         case BFInstruction.CallNative:
         case BFInstruction.BeginProcedure:
         case BFInstruction.PushUInt32:
             if (operand == null)
                 throw new ArgumentException("You must specify 1 operand for this instruction.");
             _operand = new BFOperand(Convert.ToInt64(operand));
             break;
         case BFInstruction.PushFloat:
             if (operand == null)
                 throw new ArgumentException("You must specify 1 operand for this instruction.");
             _operand = new BFOperand(Convert.ToSingle(operand));
             break;
         default:
             if (operand != null)
                 _operand = new BFOperand(Convert.ToInt64(operand));
             break;
     }
 }
Example #4
0
 public ValueCell(StructField def, IConvertible value, string displayValue, int offset)
     : base(def)
 {
     _value = value;
     _displayValue = displayValue;
     _offset = offset;
 }
Example #5
0
        protected override IConvertible GetValue()
        {
           // if (!isGotValue)
           // {
                if (OnGetValue == null)
                {
                    throw new InvalidOperationException("This variable is not bound to a formula, so it's value cannot be read.");
                }
                VariableReadEventArgs args = new VariableReadEventArgs(Name);
                args.Type = Type;
                OnGetValue(this, args);

                if (Type != typeof(IConvertible))
                {
                    _Value = (IConvertible)Convert.ChangeType(args.Value, Type);
                }
                else
                {
                    _Value = args.Value;
                }
              //  isGotValue = true;
         //   }
            return _Value;
            
        }
Example #6
0
 public override string AddNumber(IConvertible number, IList<DbParameter> parameters)
 {
     if (number == null)
     {
         throw new ArgumentNullException("number");
     }
     return number.ToString();
 }
		public Aggregation (bool cacheResults, DataRow[] rows, AggregationFunction function, ColumnReference column)
		{
			this.cacheResults = cacheResults;
			this.rows = rows;
			this.column = column;
			this.function = function;
			this.result = null;
		}
Example #8
0
		public Aggregation (bool cacheResults, DataRow[] rows, AggregationFunction function, ColumnReference column)
		{
			this.cacheResults = cacheResults;
			this.rows = rows;
			this.column = column;
			this.function = function;
			this.result = null;
			if (cacheResults)
				RowChangeHandler = new DataRowChangeEventHandler (InvalidateCache);
		}
        protected override IConvertible DoBinOp(IConvertible left, IConvertible right)
        {
            IComparable left1 = (IComparable)left;
            IComparable right1 = (IComparable)right;

            if (left1.CompareTo(right1) > 0)
            {
                return true;
            }
            return false;
        }
Example #10
0
 public ProxyNumber( IConvertible value )
 {
     if (value is string)
     {
         this.value = Parse( value as string );
     }
     else
     {
         this.value = value;
     }
 }
Example #11
0
 public Tokenizer Ignore(int priority, IConvertible tokenName, String tokenRegex)
 {
     try {
         Regex.Replace("", tokenRegex, "");
         tokenPriorities[tokenName] = priority;
         tokens[tokenName] = new Regex("^" + tokenRegex + "$");
         ignore[tokenName] = true;
     } catch (Exception e) {
         throw (e);
     }
     return (this);
 }
 private static object AddDecimal(IConvertible Left, IConvertible Right)
 {
     decimal num = Left.ToDecimal(null);
     decimal num2 = Right.ToDecimal(null);
     try
     {
         return decimal.Add(num, num2);
     }
     catch (OverflowException)
     {
         return (Convert.ToDouble(num) + Convert.ToDouble(num2));
     }
 }
Example #13
0
        /// <summary>
        /// Set one or more properties for the set of matched elements.
        /// </summary>
        ///
        /// <param name="name">
        /// The property to set
        /// </param>
        /// <param name="value">
        /// The value
        /// </param>
        ///
        /// <returns>
        /// The current CQ object
        /// </returns>

        public CQ Prop(string name, IConvertible value)
        {
            // Prop actually works on things other than boolean - e.g. SelectedIndex. For now though only use prop for booleans

            if (HtmlData.IsBoolean(name))
            {
                SetProp(name, value);
            }
            else
            {
                Attr(name, value);
            }
            return this;
        }
 private static object AddDecimal(IConvertible conv1, IConvertible conv2)
 {
     decimal num;
     if (conv1 != null)
     {
         num = conv1.ToDecimal(null);
     }
     decimal num2 = conv2.ToDecimal(null);
     try
     {
         return decimal.Add(num, num2);
     }
     catch (OverflowException)
     {
         return (Convert.ToDouble(num) + Convert.ToDouble(num2));
     }
 }
 public DateTimeFormatPartOptionTO(int length, Func<string, bool, bool> predicate, bool isNumeric,
     IConvertible actualValue, Action<IDateTimeResultTO, bool, IConvertible> assignAction, int resultLength = -1)
 {
     Length = length;
     Predicate = predicate;
     IsNumeric = isNumeric;
     ActualValue = actualValue;
     AssignAction = assignAction;
     if (resultLength == -1)
     {
         ResultLength = Length;
     }
     else
     {
         ResultLength = resultLength;
     }
 }
		public override object Eval (DataRow row)
		{
			//TODO: implement a better caching strategy and a mechanism for cache invalidation.
			//for now only aggregation over the table owning 'row' (e.g. 'sum(parts)'
			//in constrast to 'sum(parent.parts)' and 'sum(child.parts)') is cached.
			if (cacheResults && result != null && column.ReferencedTable == ReferencedTable.Self)
				return result;
				
			count = 0;
			result = null;
			
			object[] values;
			if (rows == null)
				values = column.GetValues (column.GetReferencedRows (row));
			else
				values = column.GetValues (rows);
			
			foreach (object val in values) {
				if (val == null)
					continue;
					
				count++;
				Aggregate ((IConvertible)val);
			}
			
			switch (function) {
			case AggregationFunction.StDev:
			case AggregationFunction.Var:
				result = CalcStatisticalFunction (values);
				break;
					
			case AggregationFunction.Avg:
				result = Numeric.Divide (result, count);
				break;
			
			case AggregationFunction.Count:
				result = count;
				break;
			}
			
			if (result == null)
				result = DBNull.Value;
				
			return result;
		}
Example #17
0
        public void SetProperty(string property, IConvertible prop_val)
        {
            PropertyInfo prop_info = item.GetType ().GetProperty (property);

            if (prop_info == null)
                throw new ApplicationException (String.Format (
                    "Unable to set property {0}.{1} to \"{2}\"",
                    item.GetType (), property, prop_val));

            Type prop_type = prop_info.PropertyType;
            object param;

            try {
                param = prop_val.ToType (prop_type, NumberFormatInfo.InvariantInfo);
            } catch (FormatException e) {
                throw new ApplicationException (String.Format (
                    "prop_val cannot be converted to a {0}", prop_type), e);
            }

            prop_info.SetValue (item, param, null);
        }
Example #18
0
        protected override IConvertible DoBinOp(IConvertible left, IConvertible right)
        {
            TypeCode typeCode = GetValueType(left, right);

            switch (typeCode)
            {
                case TypeCode.SByte:
                    return (Convert.ToSByte(left) * Convert.ToSByte(right));

                case TypeCode.Byte:
                    return (Convert.ToByte(left) * Convert.ToByte(right));

                case TypeCode.Int16:
                    return (Convert.ToInt16(left) * Convert.ToInt16(right));

                case TypeCode.UInt16:
                    return (Convert.ToUInt16(left) * Convert.ToUInt16(right));

                case TypeCode.Int32:
                    return (Convert.ToInt32(left) * Convert.ToInt32(right));

                case TypeCode.UInt32:
                    return (Convert.ToUInt32(left) * Convert.ToUInt32(right));

                case TypeCode.Int64:
                    return (Convert.ToInt64(left) * Convert.ToInt64(right));

                case TypeCode.UInt64:
                    return (Convert.ToUInt64(left) * Convert.ToUInt64(right));

                case TypeCode.Double:
                    return (Convert.ToDouble(left) * Convert.ToDouble(right));

                case TypeCode.Decimal:
                    return (Convert.ToDecimal(left) * Convert.ToDecimal(right));

            }

            throw new Exception("invalid type for MULTIPLY");
        }
Example #19
0
        protected override IConvertible DoBinOp(IConvertible left, IConvertible right)
        {
            TypeCode typeCode = GetValueType(left, right);

            switch (typeCode)
            {
                case TypeCode.SByte:
                    return (Convert.ToSByte(left) + Convert.ToSByte(right));

                case TypeCode.Byte:
                    return (Convert.ToByte(left) + Convert.ToByte(right));

                case TypeCode.Int16:
                    return (Convert.ToInt16(left) + Convert.ToInt16(right));

                case TypeCode.UInt16:
                    return (Convert.ToUInt16(left) + Convert.ToUInt16(right));

                case TypeCode.Int32:
                    return (Convert.ToInt32(left) + Convert.ToInt32(right));

                case TypeCode.UInt32:
                    return (Convert.ToUInt32(left) + Convert.ToUInt32(right));

                case TypeCode.Int64:
                    return (Convert.ToInt64(left) + Convert.ToInt64(right));

                case TypeCode.UInt64:
                    return (Convert.ToUInt64(left) + Convert.ToUInt64(right));

                case TypeCode.Double:
                    return (Convert.ToDouble(left) + Convert.ToDouble(right));

                case TypeCode.Decimal:
                    return (Convert.ToDecimal(left) + Convert.ToDecimal(right));

            }

            return left.ToString() + right.ToString();
        }
Example #20
0
		//extends to Int32/Int64/Decimal/Double
		internal static IConvertible Unify (IConvertible o)
		{
			switch (o.GetTypeCode()) {
			case TypeCode.Char:
			case TypeCode.SByte:
			case TypeCode.Byte:
			case TypeCode.Int16:
			case TypeCode.UInt16:
				return (IConvertible)Convert.ChangeType (o, TypeCode.Int32);
			
			case TypeCode.UInt32:
				return (IConvertible)Convert.ChangeType (o, TypeCode.Int64);
				
			case TypeCode.UInt64:
				return (IConvertible)Convert.ChangeType (o, TypeCode.Decimal);
				
			case TypeCode.Single:
				return (IConvertible)Convert.ChangeType (o, TypeCode.Double);
			
			default:
				return o;
			}
		}
Example #21
0
        /// <summary>
        /// Set a specific item, identified by the 2nd parameter, of a named option group, identified by
        /// the first parameter, as selected.
        /// </summary>
        ///
        /// <param name="groupName">
        /// The value of the name attribute identifying this option group.
        /// </param>
        /// <param name="value">
        /// The option value to set as selected
        /// </param>
        ///
        /// <returns>
        /// The current CQ object
        /// </returns>

        public CQ SetSelected(string groupName, IConvertible value)
        {
            var group = this.Find("input[name='" + groupName + "']");
            var item = group.Filter("[value='" + value + "']");
            if (group.Length == 0)
            {
                item = this.Find("#" + groupName);
            }
            if (item.Length > 0)
            {
                ushort nodeNameID = group[0].NodeNameID;
                string type = group[0]["type"].ToUpper();
                if (nodeNameID == HtmlData.tagOPTION)
                {
                    var ownerMultiple = group.Closest("select").Prop("multiple");
                    if (Objects.IsTruthy(ownerMultiple))
                    {
                        item.Prop("selected", true);
                    }
                    else
                    {
                        group.Prop("selected", false);
                        item.Prop("selected", true);
                    }
                }
                else if (nodeNameID == HtmlData.tagINPUT && 
                    (type == "radio" || type == "checkbox"))
                {
                    if (type == "radio")
                    {
                        group.Prop("checked", false);
                    }
                    item.Prop("checked", true);
                }
            }
            return this;
        }
Example #22
0
		//(note: o1 and o2 must both be of type Int32/Int64/Decimal/Double)
		internal static TypeCode ToSameType (ref IConvertible o1, ref IConvertible o2)
		{
			TypeCode tc1 = o1.GetTypeCode();
			TypeCode tc2 = o2.GetTypeCode();
			
			if (tc1 == tc2)
				return tc1;

			if (tc1 == TypeCode.DBNull || tc2 == TypeCode.DBNull)
				return TypeCode.DBNull;


			// is it ok to make such assumptions about the order of an enum?
			if (tc1 < tc2)
			{
				o1 = (IConvertible)Convert.ChangeType (o1, tc2);
				return tc2;
			}
			else
			{
				o2 = (IConvertible)Convert.ChangeType (o2, tc1);
				return tc1;
			}
		}
Example #23
0
 public QuayRoadsPanelField(NetInfo netInfo, int sectionIndex, FieldInfo fieldInfo, IConvertible flag, UIPanel parent, RoadEditorPanel parentPanel)
 {
     netInfo_      = netInfo;
     sectionIndex_ = sectionIndex;
     fieldInfo_    = fieldInfo;
     flag_         = flag;
     parentPanel_  = parentPanel;
     if (flag_ is not null)
     {
         Log.Debug(flag.ToString());
         Log.Debug(flag.ToUInt64().ToString());
         var propertyCheckbox = parent.AddUIComponent <UICheckBoxExt>();
         propertyCheckbox.Label              = "";
         propertyCheckbox.width              = 20f;
         propertyCheckbox.isChecked          = (AssetValue as IConvertible).IsFlagSet(flag);
         propertyCheckbox.eventCheckChanged += (_, _isChecked) => {
             //TODO: find a better / more robust way to do this.
             if (_isChecked)
             {
                 if (Enum.GetUnderlyingType(fieldInfo_.FieldType) == typeof(Int32))
                 {
                     AssetValue = (AssetValue as IConvertible).ToInt32(CultureInfo.InvariantCulture) | flag.ToInt32(CultureInfo.InvariantCulture);
                 }
                 else
                 {
                     AssetValue = (AssetValue as IConvertible).ToInt64() | flag.ToInt64();
                 }
             }
             else
             {
                 if (Enum.GetUnderlyingType(fieldInfo_.FieldType) == typeof(Int32))
                 {
                     AssetValue = (AssetValue as IConvertible).ToInt32(CultureInfo.InvariantCulture) & ~flag.ToInt32(CultureInfo.InvariantCulture);
                 }
                 else
                 {
                     AssetValue = (AssetValue as IConvertible).ToInt64() & ~flag.ToInt64();
                 }
             }
         };
     }
     else
     {
         // TODO: right now, this assumes everything that is not a flags enum is a float
         // TODO: find a better way to create a text field - maybe something similar to UICheckBoxExt from KianCommons?
         var propertyHelper    = new UIHelper(parent);
         var propertyTextField = propertyHelper.AddTextfield("wawa", (AssetValue as float?).ToString(), (_) => { }, (_) => { }) as UITextField;
         var labelObject       = parent.Find <UILabel>("Label");
         labelObject.parent.RemoveUIComponent(labelObject);
         Destroy(labelObject.gameObject);
         (propertyTextField.parent as UIPanel).autoFitChildrenHorizontally = true;
         (propertyTextField.parent as UIPanel).autoFitChildrenVertically   = true;
         propertyTextField.numericalOnly       = true;
         propertyTextField.allowFloats         = true;
         propertyTextField.allowNegative       = true;
         propertyTextField.eventTextSubmitted += (_, value) => {
             float newValue = (float)LenientStringToDouble(value, (double)(float)AssetValue);
             propertyTextField.text = newValue.ToString();
             if (newValue != (float)AssetValue)
             {
                 AssetValue = newValue;
             }
         };
     }
 }
        private static double JScriptCompare2(object v1, object v2, IConvertible ic1, IConvertible ic2, TypeCode t1, TypeCode t2)
        {
            double num7;
            if (t1 == TypeCode.Object)
            {
                v1 = Microsoft.JScript.Convert.ToPrimitive(v1, PreferredType.Number, ref ic1);
                t1 = Microsoft.JScript.Convert.GetTypeCode(v1, ic1);
            }
            if (t2 == TypeCode.Object)
            {
                v2 = Microsoft.JScript.Convert.ToPrimitive(v2, PreferredType.Number, ref ic2);
                t2 = Microsoft.JScript.Convert.GetTypeCode(v2, ic2);
            }
            switch (t1)
            {
                case TypeCode.Char:
                    if (t2 != TypeCode.String)
                    {
                        break;
                    }
                    return (double) string.CompareOrdinal(Microsoft.JScript.Convert.ToString(v1, ic1), ic2.ToString(null));

                case TypeCode.SByte:
                case TypeCode.Byte:
                case TypeCode.Int16:
                case TypeCode.UInt16:
                case TypeCode.Int32:
                case TypeCode.UInt32:
                case TypeCode.Int64:
                    break;

                case TypeCode.UInt64:
                {
                    ulong num3 = ic1.ToUInt64(null);
                    switch (t2)
                    {
                        case TypeCode.SByte:
                        case TypeCode.Byte:
                        case TypeCode.Int16:
                        case TypeCode.UInt16:
                        case TypeCode.Int32:
                        case TypeCode.UInt32:
                        case TypeCode.Int64:
                        {
                            long num4 = ic2.ToInt64(null);
                            if (num4 < 0L)
                            {
                                return 1.0;
                            }
                            if (num3 == num4)
                            {
                                return 0.0;
                            }
                            return -1.0;
                        }
                        case TypeCode.UInt64:
                        {
                            ulong num5 = ic2.ToUInt64(null);
                            if (num3 < num5)
                            {
                                return -1.0;
                            }
                            if (num3 == num5)
                            {
                                return 0.0;
                            }
                            return 1.0;
                        }
                        case TypeCode.Single:
                        case TypeCode.Double:
                            return (num3 - ic2.ToDouble(null));

                        case TypeCode.Decimal:
                            return (double) (new decimal(num3) - ic2.ToDecimal(null));
                    }
                    object obj3 = Microsoft.JScript.Convert.ToNumber(v2, ic2);
                    return JScriptCompare2(v1, obj3, ic1, Microsoft.JScript.Convert.GetIConvertible(obj3), t1, TypeCode.Double);
                }
                case TypeCode.Decimal:
                {
                    decimal num6 = ic1.ToDecimal(null);
                    switch (t2)
                    {
                        case TypeCode.SByte:
                        case TypeCode.Byte:
                        case TypeCode.Int16:
                        case TypeCode.UInt16:
                        case TypeCode.Int32:
                        case TypeCode.UInt32:
                        case TypeCode.Int64:
                            return (double) (num6 - new decimal(ic2.ToInt64(null)));

                        case TypeCode.UInt64:
                            return (double) (num6 - new decimal(ic2.ToUInt64(null)));

                        case TypeCode.Single:
                        case TypeCode.Double:
                            return (double) (num6 - new decimal(ic2.ToDouble(null)));

                        case TypeCode.Decimal:
                            return (double) (num6 - ic2.ToDecimal(null));
                    }
                    return (double) (num6 - new decimal(Microsoft.JScript.Convert.ToNumber(v2, ic2)));
                }
                case TypeCode.String:
                {
                    TypeCode code5 = t2;
                    if (code5 == TypeCode.Char)
                    {
                        return (double) string.CompareOrdinal(ic1.ToString(null), Microsoft.JScript.Convert.ToString(v2, ic2));
                    }
                    if (code5 != TypeCode.String)
                    {
                        goto Label_0355;
                    }
                    return (double) string.CompareOrdinal(ic1.ToString(null), ic2.ToString(null));
                }
                default:
                    goto Label_0355;
            }
            long num = ic1.ToInt64(null);
            switch (t2)
            {
                case TypeCode.SByte:
                case TypeCode.Byte:
                case TypeCode.Int16:
                case TypeCode.UInt16:
                case TypeCode.Int32:
                case TypeCode.UInt32:
                case TypeCode.Int64:
                    return (double) (num - ic2.ToInt64(null));

                case TypeCode.UInt64:
                    if (num >= 0L)
                    {
                        ulong num2 = ic2.ToUInt64(null);
                        if (num < num2)
                        {
                            return -1.0;
                        }
                        if (num == num2)
                        {
                            return 0.0;
                        }
                        return 1.0;
                    }
                    return -1.0;

                case TypeCode.Single:
                case TypeCode.Double:
                    return (num - ic2.ToDouble(null));

                case TypeCode.Decimal:
                    return (double) (new decimal(num) - ic2.ToDecimal(null));

                default:
                {
                    object obj2 = Microsoft.JScript.Convert.ToNumber(v2, ic2);
                    return JScriptCompare2(v1, obj2, ic1, Microsoft.JScript.Convert.GetIConvertible(obj2), t1, TypeCode.Double);
                }
            }
        Label_0355:
            num7 = Microsoft.JScript.Convert.ToNumber(v1, ic1);
            double num8 = Microsoft.JScript.Convert.ToNumber(v2, ic2);
            if (num7 == num8)
            {
                return 0.0;
            }
            return (num7 - num8);
        }
Example #25
0
        public static TypeInformation GetTypeInformation(IConvertible convertable)
        {
            TypeInformation typeInformation = PrimitiveTypeCodes[(int)convertable.GetTypeCode()];

            return(typeInformation);
        }
Example #26
0
            protected override void EndImpl()
            {
                if (g.reachable)
                {
                    g.il.Emit(OpCodes.Br, lbEnd);
                    endReachable = true;
                }

                EndScope();
                g.il.MarkLabel(lbDecision);

                if (govType == typeof(string))
                {
                    foreach (KeyValuePair <IComparable, Label> kvp in cases)
                    {
                        g.il.Emit(OpCodes.Ldloc, exp);
                        g.il.Emit(OpCodes.Ldstr, kvp.Key.ToString());
                        g.il.Emit(OpCodes.Call, strCmp);
                        g.il.Emit(OpCodes.Brtrue, kvp.Value);
                    }
                }
                else
                {
                    bool         first  = true;
                    IConvertible prev   = null;
                    List <Label> labels = new List <Label>();

                    foreach (KeyValuePair <IComparable, Label> kvp in cases)
                    {
                        IConvertible val = (IConvertible)kvp.Key;
                        if (prev != null)
                        {
                            int diff = Diff(prev, val);
                            if (diff > 3)
                            {
                                Finish(labels);
                                labels.Clear();
                                prev  = null;
                                first = true;
                            }
                            else
                            {
                                while (diff-- > 1)
                                {
                                    labels.Add(lbDefault);
                                }
                            }
                        }

                        if (first)
                        {
                            g.il.Emit(OpCodes.Ldloc, exp);
                            EmitValue(val);
                            first = false;
                        }

                        labels.Add(kvp.Value);
                        prev = val;
                    }

                    Finish(labels);
                }
                if (lbDefault != lbEnd)
                {
                    g.il.Emit(OpCodes.Br, lbDefault);
                }
                g.il.MarkLabel(lbEnd);
                g.reachable = endReachable;
            }
Example #27
0
 public override void AddOperand(IConvertible operand)
 {
     base.AddOperand(Utils.EnsureOperand(operand));
     _Operators.Add(PrimaryOperator);
 }
Example #28
0
        /// <summary>
        /// 向属性填充值(强制使用指定的类型)
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="entity"></param>
        /// <param name="prop"></param>
        /// <param name="value"></param>
        /// <param name="specialType"></param>
        public static void FillSystemType <T>(T entity, PropertyInfo prop, IConvertible value, Type specialType)
        {
            object setValue = null;

            if (value.GetType() != specialType)
            {
                switch (specialType.Name)
                {
                case "Boolean":
                    setValue = value.ConvertTo <bool>();
                    break;

                case "DateTime":
                    setValue = DateTimeHelper.GetDateTimeFromXml(value.ToString());
                    break;

                case "Int32":
                    setValue = value.ConvertTo <int>();
                    break;

                case "Int64":
                    setValue = value.ConvertTo <long>();
                    break;

                case "Double":
                    setValue = value.ConvertTo <double>();
                    break;

                case "String":
                    setValue = value.ToString(CultureInfo.InvariantCulture);
                    break;

                default:
                    setValue = value;
                    break;
                }
            }

            switch (specialType.Name)
            {
            case "Nullable`1":     //可为空对象
            {
                if (!string.IsNullOrEmpty(value as string))
                {
                    var genericArguments = prop.PropertyType.GetGenericArguments();
                    FillSystemType(entity, prop, value, genericArguments[0]);
                }
                else
                {
                    prop.SetValue(entity, null, null);        //默认通常为null
                }
                break;
            }

            //case "String":
            //    goto default;
            //case "Boolean":
            //case "DateTime":
            //case "Int32":
            //case "Int64":
            //case "Double":
            default:
                prop.SetValue(entity, setValue ?? value, null);
                break;
            }
        }
Example #29
0
 public abstract T convert(IConvertible value);
Example #30
0
 public override BigInteger convert(IConvertible value) =>
 BigInteger.Parse(value.ToString());
Example #31
0
 public static UInt64 ToUInt64(this IConvertible @this)
 {
     return(@this.ToUInt64(CultureInfo.CurrentCulture));
 }
 public static T To <T>(this IConvertible obj)
 {
     return((T)Convert.ChangeType(obj, typeof(T)));
 }
Example #33
0
        private void SerializeConvertibleObject(IConvertible value, string format, IFormatProvider formatProvider, StringBuilder builder)
        {
            TypeCode convertibleTypeCode = value.GetTypeCode();

            if (convertibleTypeCode == TypeCode.String)
            {
                SerializeStringObject(value.ToString(), format, builder);
                return;
            }

            if (!string.IsNullOrEmpty(format) && value is IFormattable formattable)
            {
                builder.Append(formattable.ToString(format, formatProvider));
                return;
            }

            switch (convertibleTypeCode)
            {
            case TypeCode.Boolean:
            {
                builder.Append(value.ToBoolean(CultureInfo.InvariantCulture) ? "true" : "false");
                break;
            }

            case TypeCode.Char:
            {
                bool includeQuotes = format != LiteralFormatSymbol;
                if (includeQuotes)
                {
                    builder.Append('"');
                }
                builder.Append(value.ToChar(CultureInfo.InvariantCulture));
                if (includeQuotes)
                {
                    builder.Append('"');
                }
                break;
            }

            case TypeCode.Byte:
            case TypeCode.SByte:
            case TypeCode.Int16:
            case TypeCode.Int32:
            case TypeCode.Int64:
            case TypeCode.UInt16:
            case TypeCode.UInt32:
            case TypeCode.UInt64:
            {
                if (value is Enum enumValue)
                {
                    AppendEnumAsString(builder, enumValue);
                }
                else
                {
                    builder.AppendNumericInvariant(value, convertibleTypeCode);
                }
                break;
            }

            case TypeCode.Object:       // Guid, TimeSpan, DateTimeOffset
            default:                    // Single, Double, Decimal, etc.
                SerializeConvertToString(value, formatProvider, builder);
                break;
            }
        }
Example #34
0
 public override float convert(IConvertible value) => value.ToSingle(null);
Example #35
0
 public override long convert(IConvertible value) => value.ToInt64(null);
Example #36
0
 public override int convert(IConvertible value) => value.ToInt32(null);
Example #37
0
 /// <summary>
 ///     Converts an item to another Type
 /// </summary>
 /// <typeparam name="T">Type to convert to</typeparam>
 /// <param name="object">The object to conver to</param>
 /// <returns>The converted object</returns>
 public static T To <T>(this IConvertible @object)
 {
     return((T)Convert.ChangeType(@object, typeof(T)));
 }
Example #38
0
 public override decimal convert(IConvertible value) => value.ToDecimal(null);
Example #39
0
        /// <summary>
        /// Converts <paramref name="value"/> to a <see cref="@string"/>.
        /// </summary>
        /// <param name="value">Value to convert.</param>
        /// <returns><paramref name="value"/> converted to a <see cref="@string"/>.</returns>
        public static @string @string(object value)
        {
            // Only reference types can be null, therefore "" is its default value
            if (value == null)
            {
                return("");
            }

            Type itemType = value.GetType();

            if (!itemType.IsValueType)
            {
                return(itemType.ToString());
            }

            // Handle common types
            IConvertible convertible = value as IConvertible;
            bool         isIntValue  = false;
            ulong        intValue    = 0UL;

            if ((object)convertible != null)
            {
                switch (convertible.GetTypeCode())
                {
                case TypeCode.Char:
                case TypeCode.Boolean:
                case TypeCode.SByte:
                case TypeCode.Byte:
                case TypeCode.Int16:
                case TypeCode.UInt16:
                case TypeCode.Int32:
                case TypeCode.UInt32:
                case TypeCode.Int64:
                case TypeCode.UInt64:
                    intValue   = (ulong)value;
                    isIntValue = true;
                    break;
                }
            }

            if (isIntValue)
            {
                char charValue = '\uFFFD';

                if (intValue >= char.MinValue && intValue <= char.MaxValue)
                {
                    charValue = (char)intValue;
                }

                return(new string(charValue, 1));
            }

            if (itemType == typeof(@byte[]))
            {
                return(new @string((@byte[])value));
            }

            if (itemType == typeof(slice <@byte>))
            {
                return(new @string((slice <@byte>)value));
            }

            if (itemType == typeof(byte[]))
            {
                return(new @string((byte[])value));
            }

            if (itemType == typeof(slice <byte>))
            {
                return(new @string((slice <byte>)value));
            }

            if (itemType == typeof(char[]))
            {
                return(new @string((char[])value));
            }

            if (itemType == typeof(slice <char>))
            {
                return(new @string((slice <char>)value));
            }

            if (itemType == typeof(rune[]))
            {
                return(new @string((rune[])value));
            }

            if (itemType == typeof(slice <rune>))
                return(new @string((slice <rune>)value)); }
Example #40
0
 public override double convert(IConvertible value) => value.ToDouble(null);
Example #41
0
        /**
         * This will parse the stream and create a cmap object.
         *
         * @param input The CMAP stream to parse.
         * @return The parsed stream as a java object.
         *
         * @throws IOException If there is an error parsing the stream.
         */
        public CMap Parse(Stream input)
        {
            PushbackStream cmapStream    = new PushbackStream(input);
            CMap           result        = new CMap();
            Object         previousToken = null;
            Object         token         = null;

            while ((token = ParseNextToken(cmapStream)) != null)
            {
                if (token is Operator)
                {
                    Operator op = (Operator)token;
                    if (op.op.Equals(BEGIN_CODESPACE_RANGE))
                    {
                        IConvertible cosCount = (IConvertible)previousToken;
                        for (int j = 0; j < cosCount.ToInt32(CultureInfo.InvariantCulture); j++)
                        {
                            byte[]         startRange = (byte[])ParseNextToken(cmapStream);
                            byte[]         endRange   = (byte[])ParseNextToken(cmapStream);
                            CodespaceRange range      = new CodespaceRange();
                            range.SetStart(startRange);
                            range.SetEnd(endRange);
                            result.AddCodespaceRange(range);
                        }
                    }
                    else if (op.op.Equals(BEGIN_BASE_FONT_CHAR))
                    {
                        IConvertible cosCount = (IConvertible)previousToken;
                        for (int j = 0; j < cosCount.ToInt32(CultureInfo.InvariantCulture); j++)
                        {
                            byte[] inputCode = (byte[])ParseNextToken(cmapStream);
                            Object nextToken = ParseNextToken(cmapStream);
                            if (nextToken is byte[])
                            {
                                byte[] bytes = (byte[])nextToken;
                                String value = CreateStringFromBytes(bytes);
                                result.AddMapping(inputCode, value);
                            }
                            else if (nextToken is LiteralName)
                            {
                                result.AddMapping(inputCode, ((LiteralName)nextToken).name);
                            }
                            else
                            {
                                throw new IOException(MessageLocalization.GetComposedMessage("error.parsing.cmap.beginbfchar.expected.cosstring.or.cosname.and.not.1", nextToken));
                            }
                        }
                    }
                    else if (op.op.Equals(BEGIN_BASE_FONT_RANGE))
                    {
                        IConvertible cosCount = (IConvertible)previousToken;

                        for (int j = 0; j < cosCount.ToInt32(CultureInfo.InvariantCulture); j++)
                        {
                            byte[]         startCode  = (byte[])ParseNextToken(cmapStream);
                            byte[]         endCode    = (byte[])ParseNextToken(cmapStream);
                            Object         nextToken  = ParseNextToken(cmapStream);
                            IList <byte[]> array      = null;
                            byte[]         tokenBytes = null;
                            if (nextToken is IList <byte[]> )
                            {
                                array      = (IList <byte[]>)nextToken;
                                tokenBytes = array[0];
                            }
                            else
                            {
                                tokenBytes = (byte[])nextToken;
                            }

                            String value = null;

                            int  arrayIndex = 0;
                            bool done       = false;
                            while (!done)
                            {
                                if (Compare(startCode, endCode) >= 0)
                                {
                                    done = true;
                                }
                                value = CreateStringFromBytes(tokenBytes);
                                result.AddMapping(startCode, value);
                                Increment(startCode);

                                if (array == null)
                                {
                                    Increment(tokenBytes);
                                }
                                else
                                {
                                    arrayIndex++;
                                    if (arrayIndex < array.Count)
                                    {
                                        tokenBytes = array[arrayIndex];
                                    }
                                }
                            }
                        }
                    }
                }
                previousToken = token;
            }
            return(result);
        }
Example #42
0
 public override T convert(IConvertible value) => (T)Enum.ToObject(typeof(T), value);
Example #43
0
 /// <summary>
 /// 向属性填充值
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="entity"></param>
 /// <param name="prop"></param>
 /// <param name="value"></param>
 public static void FillSystemType <T>(T entity, PropertyInfo prop, IConvertible value)
 {
     FillSystemType(entity, prop, value, prop.PropertyType);
 }
 public static T To <T>(this IConvertible self)
 {
     return((T)Convert.ChangeType(self, typeof(T)));
 }   // eo To<T>
Example #45
0
 public static Int64 ToInt64Inv(this IConvertible @this)
 {
     return(@this.ToInt64(CultureInfo.InvariantCulture));
 }
Example #46
0
 public static UInt32 ToUInt32Inv(this IConvertible @this)
 {
     return(@this.ToUInt32(CultureInfo.InvariantCulture));
 }
 protected override ulong ToRaw(IConvertible value)
 {
     float tmp = value.ToSingle(null);
     return *(uint*)&tmp;
 }
Example #48
0
		public static IConvertible CheckNumericPromotion(IConvertible convertible)
		{
			if (IsPromotableNumeric(convertible.GetTypeCode()))
				return convertible;
			throw new InvalidCastException();
		}
Example #49
0
 internal static Double ToDouble(this IConvertible @this)
 {
     return(@this.ToDouble(System.Globalization.NumberFormatInfo.InvariantInfo));
 }
 public Literal(IConvertible value) : this()
 {
     Value = value;
 }
Example #51
0
        public void SetAsIConvertible(IConvertible value) {
            Debug.Assert(IsEmpty); // The setter can only be called once as VariantClear might be needed otherwise

            TypeCode tc = value.GetTypeCode();
            CultureInfo ci = CultureInfo.CurrentCulture;

            switch (tc) {
                case TypeCode.Empty: break;
                case TypeCode.Object: AsUnknown = value; break;
                case TypeCode.DBNull: SetAsNull(); break;
                case TypeCode.Boolean: AsBool = value.ToBoolean(ci); break;
                case TypeCode.Char: AsUi2 = value.ToChar(ci); break;
                case TypeCode.SByte: AsI1 = value.ToSByte(ci); break;
                case TypeCode.Byte: AsUi1 = value.ToByte(ci); break;
                case TypeCode.Int16: AsI2 = value.ToInt16(ci); break;
                case TypeCode.UInt16: AsUi2 = value.ToUInt16(ci); break;
                case TypeCode.Int32: AsI4 = value.ToInt32(ci); break;
                case TypeCode.UInt32: AsUi4 = value.ToUInt32(ci); break;
                case TypeCode.Int64: AsI8 = value.ToInt64(ci); break;
                case TypeCode.UInt64: AsI8 = value.ToInt64(ci); break;
                case TypeCode.Single: AsR4 = value.ToSingle(ci); break;
                case TypeCode.Double: AsR8 = value.ToDouble(ci); break;
                case TypeCode.Decimal: AsDecimal = value.ToDecimal(ci); break;
                case TypeCode.DateTime: AsDate = value.ToDateTime(ci); break;
                case TypeCode.String: AsBstr = value.ToString(ci); break;

                default:
                    throw Assert.Unreachable;
            }
        }
Example #52
0
 protected void AddCell(StructInstance instance, IConvertible value, string displayValue, int offset)
 {
     instance.AddCell(new ValueCell(this, value, displayValue, offset), _hidden);
 }
 protected override ulong ToRaw(IConvertible value)
 {
     double tmp = value.ToDouble(null);
     return *(ulong*)&tmp;
 }
Example #54
0
        [System.Security.SecurityCritical]  // auto-generated
        internal static void MarshalHelperCastVariant(Object pValue, int vt, ref Variant v)
        {
            IConvertible iv = pValue as IConvertible;

            if (iv == null)
            {
                switch (vt)
                {
                case 9:     /*VT_DISPATCH*/
                    v = new Variant(new DispatchWrapper(pValue));
                    break;

                case 12:     /*VT_VARIANT*/
                    v = new Variant(pValue);
                    break;

                case 13:     /*VT_UNKNOWN*/
                    v = new Variant(new UnknownWrapper(pValue));
                    break;

                case 36:     /*VT_RECORD*/
                    v = new Variant(pValue);
                    break;

                case 8:     /*VT_BSTR*/
                    if (pValue == null)
                    {
                        v         = new Variant(null);
                        v.m_flags = CV_STRING;
                    }
                    else
                    {
                        throw new InvalidCastException(Environment.GetResourceString("InvalidCast_CannotCoerceByRefVariant"));
                    }
                    break;

                default:
                    throw new InvalidCastException(Environment.GetResourceString("InvalidCast_CannotCoerceByRefVariant"));
                }
            }
            else
            {
                IFormatProvider provider = CultureInfo.InvariantCulture;
                switch (vt)
                {
                case 0:     /*VT_EMPTY*/
                    v = Empty;
                    break;

                case 1:     /*VT_NULL*/
                    v = DBNull;
                    break;

                case 2:     /*VT_I2*/
                    v = new Variant(iv.ToInt16(provider));
                    break;

                case 3:     /*VT_I4*/
                    v = new Variant(iv.ToInt32(provider));
                    break;

                case 4:     /*VT_R4*/
                    v = new Variant(iv.ToSingle(provider));
                    break;

                case 5:     /*VT_R8*/
                    v = new Variant(iv.ToDouble(provider));
                    break;

                case 6:     /*VT_CY*/
                    v = new Variant(new CurrencyWrapper(iv.ToDecimal(provider)));
                    break;

                case 7:     /*VT_DATE*/
                    v = new Variant(iv.ToDateTime(provider));
                    break;

                case 8:     /*VT_BSTR*/
                    v = new Variant(iv.ToString(provider));
                    break;

                case 9:     /*VT_DISPATCH*/
                    v = new Variant(new DispatchWrapper((Object)iv));
                    break;

                case 10:     /*VT_ERROR*/
                    v = new Variant(new ErrorWrapper(iv.ToInt32(provider)));
                    break;

                case 11:     /*VT_BOOL*/
                    v = new Variant(iv.ToBoolean(provider));
                    break;

                case 12:     /*VT_VARIANT*/
                    v = new Variant((Object)iv);
                    break;

                case 13:     /*VT_UNKNOWN*/
                    v = new Variant(new UnknownWrapper((Object)iv));
                    break;

                case 14:     /*VT_DECIMAL*/
                    v = new Variant(iv.ToDecimal(provider));
                    break;

                // case 15: /*unused*/
                //  NOT SUPPORTED

                case 16:     /*VT_I1*/
                    v = new Variant(iv.ToSByte(provider));
                    break;

                case 17:     /*VT_UI1*/
                    v = new Variant(iv.ToByte(provider));
                    break;

                case 18:     /*VT_UI2*/
                    v = new Variant(iv.ToUInt16(provider));
                    break;

                case 19:     /*VT_UI4*/
                    v = new Variant(iv.ToUInt32(provider));
                    break;

                case 20:     /*VT_I8*/
                    v = new Variant(iv.ToInt64(provider));
                    break;

                case 21:     /*VT_UI8*/
                    v = new Variant(iv.ToUInt64(provider));
                    break;

                case 22:     /*VT_INT*/
                    v = new Variant(iv.ToInt32(provider));
                    break;

                case 23:     /*VT_UINT*/
                    v = new Variant(iv.ToUInt32(provider));
                    break;

                default:
                    throw new InvalidCastException(Environment.GetResourceString("InvalidCast_CannotCoerceByRefVariant"));
                }
            }
        }
Example #55
0
		//
		// Utility methods
		//
		internal static TypeCode GetTypeCode (object obj, IConvertible ic)
		{
			if (obj == null)
				return TypeCode.Empty;
			else if (ic == null)
				return TypeCode.Object;
			else
				return ic.GetTypeCode ();
		}
Example #56
0
        [System.Security.SecuritySafeCritical]  // auto-generated
        internal static void MarshalHelperConvertObjectToVariant(Object o, ref Variant v)
        {
#if FEATURE_REMOTING
            IConvertible ic = System.Runtime.Remoting.RemotingServices.IsTransparentProxy(o) ? null : o as IConvertible;
#else
            IConvertible ic = o as IConvertible;
#endif
            if (o == null)
            {
                v = Empty;
            }
            else if (ic == null)
            {
                // This path should eventually go away. But until
                // the work is done to have all of our wrapper types implement
                // IConvertible, this is a cheapo way to get the work done.
                v = new Variant(o);
            }
            else
            {
                IFormatProvider provider = CultureInfo.InvariantCulture;
                switch (ic.GetTypeCode())
                {
                case TypeCode.Empty:
                    v = Empty;
                    break;

                case TypeCode.Object:
                    v = new Variant((Object)o);
                    break;

                case TypeCode.DBNull:
                    v = DBNull;
                    break;

                case TypeCode.Boolean:
                    v = new Variant(ic.ToBoolean(provider));
                    break;

                case TypeCode.Char:
                    v = new Variant(ic.ToChar(provider));
                    break;

                case TypeCode.SByte:
                    v = new Variant(ic.ToSByte(provider));
                    break;

                case TypeCode.Byte:
                    v = new Variant(ic.ToByte(provider));
                    break;

                case TypeCode.Int16:
                    v = new Variant(ic.ToInt16(provider));
                    break;

                case TypeCode.UInt16:
                    v = new Variant(ic.ToUInt16(provider));
                    break;

                case TypeCode.Int32:
                    v = new Variant(ic.ToInt32(provider));
                    break;

                case TypeCode.UInt32:
                    v = new Variant(ic.ToUInt32(provider));
                    break;

                case TypeCode.Int64:
                    v = new Variant(ic.ToInt64(provider));
                    break;

                case TypeCode.UInt64:
                    v = new Variant(ic.ToUInt64(provider));
                    break;

                case TypeCode.Single:
                    v = new Variant(ic.ToSingle(provider));
                    break;

                case TypeCode.Double:
                    v = new Variant(ic.ToDouble(provider));
                    break;

                case TypeCode.Decimal:
                    v = new Variant(ic.ToDecimal(provider));
                    break;

                case TypeCode.DateTime:
                    v = new Variant(ic.ToDateTime(provider));
                    break;

                case TypeCode.String:
                    v = new Variant(ic.ToString(provider));
                    break;

                default:
                    throw new NotSupportedException(Environment.GetResourceString("NotSupported_UnknownTypeCode", ic.GetTypeCode()));
                }
            }
        }
Example #57
0
 public virtual void AddOperand(IConvertible operand, bool invert)
 {
     base.AddOperand(Utils.EnsureOperand(operand));
     _Operators.Add(invert ? ComplementaryOperator  : PrimaryOperator);
 }
Example #58
0
 public IHasUnit SetValue(IConvertible value)
 {
     paramEdit.Param.Value = value;
     return(new HasUnit(paramEdit));
 }
Example #59
0
 public void SetPrimaryKey(IConvertible value)
 {
     ClassInfo.PrimaryKey.SetValue(Owner, value);
 }
Example #60
0
 /// <summary>
 /// Convert to a different type.
 /// </summary>
 public static R Cast <R>(this IConvertible source) =>
 (R)Convert.ChangeType(source, typeof(R));