コード例 #1
0
        public virtual bool Set(string key, DateTime value)
        {
            if (NSJSDateTime.Invalid(value))
            {
                throw new ArgumentNullException("Parameter cannot be an invalid time");
            }
            long time = NSJSDateTime.DateTimeToLocalDate(value);

            return(this.Set(key, (name) => nsjs_localvalue_object_property_set_datetime(this.Isolate, this.Handle, name, time)));
        }
コード例 #2
0
 public override object GetValue()
 {
     lock (this)
     {
         if (this.value == null)
         {
             this.value = NSJSDateTime.LocalDateToDateTime(nsjs_localvalue_get_int64(this.Handle));
         }
     }
     return this.value;
 }
コード例 #3
0
 public static NSJSDateTime operator -(NSJSDateTime x, long y)
 {
     if (x == null)
     {
         return null;
     }
     long ticks = unchecked((long)x) - y;
     if (ticks < 0)
     {
         ticks = 0;
     }
     return NSJSDateTime.New(x.VirtualMachine, ticks);
 }
コード例 #4
0
 public static bool operator ==(NSJSDateTime x, DateTime y)
 {
     long ticks = NSJSDateTime.DateTimeToLocalDate(y);
     if (x == null)
     {
         return ticks == 0;
     }
     else if (ticks < 0)
     {
         return false;
     }
     return unchecked(x.Value == y);
 }
コード例 #5
0
 public static NSJSDateTime New(NSJSVirtualMachine machine, DateTime value)
 {
     if (NSJSDateTime.Invalid(value))
     {
         throw new ArgumentOutOfRangeException("Parameter cannot be an invalid time");
     }
     if (machine == null)
     {
         throw new ArgumentNullException("machine");
     }
     IntPtr isolate = machine.Isolate;
     if (isolate == NULL)
     {
         throw new InvalidOperationException("machine");
     }
     long time = NSJSDateTime.DateTimeToLocalDate(value);
     IntPtr handle = nsjs_localvalue_datetime_new(isolate, time);
     if (handle == NULL)
     {
         throw new InvalidOperationException("machine");
     }
     return new NSJSDateTime(handle, machine);
 }
コード例 #6
0
 public static NSJSDateTime New(NSJSVirtualMachine machine, long ticks)
 {
     return NSJSDateTime.New(machine, NSJSDateTime.LocalDateToDateTime(ticks));
 }
コード例 #7
0
 public void SetReturnValue(DateTime value)
 {
     this.SetReturnValue((NSJSValue)NSJSDateTime.New(this.VirtualMachine, value));
 }
コード例 #8
0
ファイル: NSJSArray.cs プロジェクト: liulilittle/nsjs
 public void Add(DateTime value)
 {
     this.Add((NSJSValue)NSJSDateTime.New(this.VirtualMachine, value));
 }
コード例 #9
0
        protected static internal object ConvertValue(Type type, NSJSValue value)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            object o = FetchValue(type, value);

            if (type == typeof(int))
            {
                o = (o == null ? 0 : Converter.ToInt32(o));
            }
            else if (type == typeof(uint))
            {
                o = (o == null ? 0u : Converter.ToUInt32(o));
            }
            else if (type == typeof(short))
            {
                o = (o == null ? (short)0 : Converter.ToInt16(o));
            }
            else if (type == typeof(ushort))
            {
                o = (o == null ? (ushort)0 : Converter.ToUInt16(o));
            }
            else if (type == typeof(sbyte))
            {
                o = (o == null ? (sbyte)0 : Converter.ToSByte(o));
            }
            else if (type == typeof(byte))
            {
                o = (o == null ? (byte)0 : Converter.ToByte(o));
            }
            else if (type == typeof(long))
            {
                o = (o == null ? 0L : Converter.ToInt64(o));
            }
            else if (type == typeof(ulong))
            {
                o = (o == null ? 0ul : Converter.ToUInt64(o));
            }
            else if (type == typeof(float))
            {
                o = (o == null ? 0f : Converter.ToSingle(o));
            }
            else if (type == typeof(double))
            {
                o = (o == null ? 0d : Converter.ToDouble(o));
            }
            else if (type == typeof(decimal))
            {
                o = (o == null ? 0m : Converter.ToDecimal(o));
            }
            else if (type == typeof(char))
            {
                o = (o == null ? '\0' : Converter.ToChar(o));
            }
            else if (type == typeof(DateTime))
            {
                long ticks = 0;
                if (o is long)
                {
                    ticks = (long)o;
                }
                else if (o != null)
                {
                    ticks = Converter.ToInt64(o);
                }
                o = NSJSDateTime.LocalDateToDateTime(ticks);
            }
            else if (type == typeof(string))
            {
                if (o == null)
                {
                    o = null;
                }
                else if (!(o is string))
                {
                    o = o.ToString();
                }
            }
            else if (typeof(NSJSValue).IsAssignableFrom(type))
            {
                return(type.IsInstanceOfType(value) ? value : null);
            }
            return(o);
        }