public static void SetTime <TIndex>(this ICefValue @this, DateTime value, TIndex index = default(TIndex)) { SetTime(_ => { var valueType = @this.GetValueType(); switch (valueType) { case CefValueType.List: using (var listValue = @this.GetList()) { if (typeof(TIndex) == typeof(int)) { listValue.SetBinary((int)Convert.ChangeType(index, typeof(int)), _); } } break; case CefValueType.Dictionary: using (var dictValue = @this.GetDictionary()) { if (typeof(TIndex) == typeof(string)) { dictValue.SetBinary((string)Convert.ChangeType(index, typeof(string)), _); } } break; default: @this.SetBinary(_); break; } }, value); }
public object Deserialize(ICefValue source, Type targetType, ObjectSerializer objectSerializer) { if (!CanHandle(source, targetType)) { throw new InvalidOperationException(); } using (var lstVal = source.GetList()) { var elementType = targetType.GetElementType(); var array = Activator.CreateInstance(targetType, lstVal.Count) as Array; for (var i = 0; i < lstVal.Count; i++) { array.SetValue(objectSerializer.Deserialize(lstVal.GetValue(i), elementType), i); } return(array); } }
public object Deserialize(ICefValue value, Type targetType, ObjectSerializer objectSerializer) { if (!CanHandle(value, targetType)) { throw new InvalidOperationException(); } var valueType = value.GetValueType(); if (valueType == CefValueType.String) { return(CefV8Value.CreateString(value.GetString())); } if (valueType == CefValueType.Int) { return(CefV8Value.CreateInt(value.GetInt())); } if (valueType == CefValueType.Double) { return(CefV8Value.CreateDouble(value.GetDouble())); } if (value.IsType(CefTypes.Int64)) { return(CefV8Value.CreateDouble(value.GetInt64())); } if (value.IsType(CefTypes.Time)) { return(CefV8Value.CreateDate(value.GetTime())); } if (valueType == CefValueType.Bool) { return(CefV8Value.CreateBool(value.GetBool())); } if (valueType == CefValueType.List) { using (var list = value.GetList()) { if (list.Count > 0) { var array = CefV8Value.CreateArray(list.Count); for (var i = 0; i < list.Count; i++) { using (var cefValue = list.GetValue(i)) { array.SetValue(i, (ICefV8Value)objectSerializer.Deserialize(cefValue, typeof(ICefV8Value))); } } return(array); } } } if (valueType == CefValueType.Dictionary) { using (var dictionary = value.GetDictionary()) using (var valDict = dictionary.GetDictionary(ObjectSerializer.ValuePropertyName)) { var typeId = dictionary.GetString(ObjectSerializer.TypeIdPropertyName); if (typeId == ObjectSerializer.DictionaryTypeId) { var obj = CefV8Value.CreateObject(); foreach (var key in valDict.GetKeys()) { obj.SetValue(key, (ICefV8Value)objectSerializer.Deserialize(valDict.GetValue(key), typeof(ICefV8Value))); } return(obj); } else { var deserialized = objectSerializer.Deserialize(value, typeof(object)); if (deserialized is ObjectDescriptor descriptor) { return(new ObjectBinder(descriptor, objectSerializer, functionCallPromiseRegistry).BindToNew()); } } } } return(CefV8Value.CreateNull()); }