public static void PackValue(object source, NetVariant destination) { if (source == null) { destination.Clear(); } else { var type = source.GetType(); if (type == typeof(bool)) { destination.Bool = (bool)source; } else if (type == typeof(char)) { destination.Char = (char)source; } else if (type == typeof(float)) { destination.Float = (float)source; } else if (type == typeof(double)) { destination.Double = (double)source; } else if (type == typeof(int)) { destination.Int = (int)source; } else if (type == typeof(uint)) { destination.UInt = (uint)source; } else if (type == typeof(long)) { destination.Long = (long)source; } else if (type == typeof(ulong)) { destination.ULong = (ulong)source; } else if (type == typeof(string)) { destination.String = (string)source; } else if (type == typeof(DateTimeOffset)) { destination.DateTime = ((DateTimeOffset)source).DateTime; } else if (typeof(INetJsValue).IsAssignableFrom(type)) { destination.JsValue = ((NetJsValue.NetJsValueDynamic)source).JsValue; } else { destination.Instance = NetReference.CreateForObject(source); } } }
private static void LoadObject(NetVariant variant, object value) { if (value != null) { if (value is bool valueBool) { variant.Bool = valueBool; } else if (value is char valueChar) { variant.Char = valueChar; } else if (value is int valueInt) { variant.Int = valueInt; } else if (value is uint valueUInt) { variant.UInt = valueUInt; } else if (value is long valueLong) { variant.Long = valueLong; } else if (value is ulong valueULong) { variant.ULong = valueULong; } else if (value is float valueFloat) { variant.Float = valueFloat; } else if (value is double valueDouble) { variant.Double = valueDouble; } else if (value is string valueString) { variant.String = valueString; } else if (value is DateTimeOffset valueDateTimeOffset) { variant.DateTime = valueDateTimeOffset; } else if (value is NetJsValue valueJsValue) { variant.JsValue = valueJsValue; } else { variant.Instance = NetReference.CreateForObject(value); } } else { variant.Clear(); } }
public void Can_clear_value() { var variant = new NetVariant(); variant.String = "test"; variant.VariantType.Should().Be(NetVariantType.String); variant.Clear(); variant.VariantType.Should().Be(NetVariantType.Invalid); }
private static void LoadUIntNullable(NetVariant variant, uint?value) { if (value.HasValue) { variant.UInt = value.Value; } else { variant.Clear(); } }
private static void LoadCharNullable(NetVariant variant, char?value) { if (value.HasValue) { variant.Char = value.Value; } else { variant.Clear(); } }
private static void LoadBoolNullable(NetVariant variant, bool?value) { if (value.HasValue) { variant.Bool = value.Value; } else { variant.Clear(); } }
private static void LoadDateTimeNullable(NetVariant variant, DateTimeOffset?value) { if (value.HasValue) { variant.DateTime = value.Value; } else { variant.Clear(); } }
private static void LoadString(NetVariant variant, string value) { if (value == null) { variant.Clear(); } else { variant.String = value; } }
private static void LoadDoubleNullable(NetVariant variant, double?value) { if (value.HasValue) { variant.Double = value.Value; } else { variant.Clear(); } }
private static void LoadFloatNullable(NetVariant variant, float?value) { if (value.HasValue) { variant.Float = value.Value; } else { variant.Clear(); } }
private static void LoadULongNullable(NetVariant variant, ulong?value) { if (value.HasValue) { variant.ULong = value.Value; } else { variant.Clear(); } }
public static void PackValue(object source, NetVariant destination) { if (source == null) { destination.Clear(); } else { var type = source.GetType(); Pack(source, destination, type); } }
private void PackValue(ref object source, NetVariant destination) { if (source == null) { destination.Clear(); } else { var type = source.GetType(); if (type == typeof(bool)) { destination.SetBool((bool)source); } else if (type == typeof(char)) { destination.SetChar((char)source); } else if (type == typeof(double)) { destination.SetDouble((double)source); } else if (type == typeof(int)) { destination.SetInt((int)source); } else if (type == typeof(uint)) { destination.SetUInt((uint)source); } else if (type == typeof(string)) { destination.SetString((string)source); } else if (type == typeof(DateTime)) { destination.SetDateTime((DateTime)source); } else { destination.SetNetInstance(NetTypeInfoManager.WrapCreatedInstance( GCHandle.ToIntPtr(GCHandle.Alloc(source)), NetTypeInfoManager.GetTypeInfo(GetUnproxiedType(type)))); } } }