コード例 #1
0
 private static bool IsEqualBooking(IDictionaryObject left, IDictionaryObject right)
 {
     return(left["destinationairport"].ToString() == right["destinationairport"].ToString() &&
            left["equipment"].ToString() == right["equipment"].ToString() &&
            left["flight"].ToString() == right["flight"].ToString() &&
            left["flighttime"].ToString() == right["flighttime"].ToString() &&
            left["name"].ToString() == right["name"].ToString() &&
            FloatEqual(left["price"].Float, right["price"].Float) &&
            left["sourceairport"].ToString() == right["sourceairport"].ToString() &&
            left["utc"].ToString() == right["utc"].ToString());
 }
コード例 #2
0
        private static bool IsEqual(IDictionaryObject left, object right)
        {
            if (right == null || !(right is IDictionaryObject dict))
            {
                return(false);
            }

            if (left.Keys.Intersect(dict.Keys).Count() != left.Keys.Count)
            {
                return(false);
            }

            return(!(from key in left.Keys
                     let leftObj = left.GetValue(key)
                                   let rightObj = dict.GetValue(key)
                                                  where !leftObj.RecursiveEqual(rightObj)
                                                  select leftObj).Any());
        }
コード例 #3
0
 public void SerializesIDictionary()
 {
     var start = new IDictionaryObject();
     start.Names.Add("Duncan Idaho", 2);
     var bytes = BsonSerializer.Serialize(start);
     var end = BsonDeserializer.Deserialize<IDictionaryObject>(bytes);
     Assert.Equal(1, end.Names.Count);
     Assert.Equal("Duncan Idaho", end.Names.ElementAt(0).Key);
     Assert.Equal(2, end.Names.ElementAt(0).Value);
 }
コード例 #4
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="source">The source information for the flight</param>
 public BookingCellModel(IDictionaryObject source)
 {
     Source = source;
 }
コード例 #5
0
 public static T ToObject <T>(this IDictionaryObject dictionaryObj)
 {
     return((T)ToObject(dictionaryObj, typeof(T)));
 }
コード例 #6
0
        public static object ToObject(this IDictionaryObject dictionaryObj, Type fallbackType = null)
        {
            object obj = null;

            string typeString = dictionaryObj.GetString("$type");
            Type   type       = null;

            if (!string.IsNullOrEmpty(typeString))
            {
                type = Type.GetType(typeString);
            }

            if (type == null)
            {
                if (fallbackType != null)
                {
                    type = fallbackType;
                }
                else
                {
                    if (string.IsNullOrEmpty(typeString))
                    {
                        throw new Exception("Could not find $type");
                    }
                    else if (fallbackType == null)
                    {
                        throw new Exception($"Unable to turn {typeString} into a valid Type.");
                    }
                    else
                    {
                        throw new Exception($"Unable to turn {typeString} or fallbackType into a valid Type.");
                    }
                }
            }

            JsonSerializer serializer = new JsonSerializer()
            {
                TypeNameHandling = TypeNameHandling.All
            };

            try
            {
                if (dictionaryObj != null)
                {
                    if (dictionaryObj.ToDictionary()?.Count > 0)
                    {
                        var settings = Constants.JsonSettings;

                        var dictionary = dictionaryObj?.ToDictionary();

                        if (dictionary != null)
                        {
                            var json = JsonConvert.SerializeObject(dictionary, settings);

                            if (!string.IsNullOrEmpty(json))
                            {
                                var jObj = JObject.Parse(json);

                                if (jObj != null)
                                {
                                    obj = jObj.ToObject(type, serializer);
                                }
                                else
                                {
                                    obj = Activator.CreateInstance(type);
                                }
                            }
                        }
                    }
                    else
                    {
                        obj = Activator.CreateInstance(type);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Couchbase.Lite.Mapper - Error: {ex.Message}");
            }

            return(obj);
        }