예제 #1
0
        /// <summary>
        /// Take the key/values of the argument ItemVersion and return the result of copying them all
        /// into the current ItemVersion, overwriting any existing ones
        /// </summary>
        /// <param name="other">An item version</param>
        /// <returns>A new ItemVersion made by copying the keys of the argument over the keys of this one</returns>
        public ItemVersion Superimpose(ItemVersion other)
        {
            var combined = new ItemVersion(this);

            other.Do(kvp => combined[kvp.Key] = kvp.Value);
            return(combined);
        }
예제 #2
0
        /// <summary>
        /// Create an ItemVersion from a serialized string
        /// </summary>
        /// <param name="desc">ItemVersion serialized to string</param>
        public ItemVersion(string desc)
            : base()
        {
            if (string.IsNullOrEmpty(desc))
            {
                return;
            }
            ItemVersion newIv = JsonConvert.DeserializeObject <ItemVersion>(desc);

            newIv.Do(kvp => this.Add(kvp.Key, kvp.Value is Int64 ? Convert.ToInt32(kvp.Value) : kvp.Value));
        }
예제 #3
0
        /// <summary>
        /// Find the most specific ItemVersion which contains both this ItemVersion and the argument
        /// </summary>
        /// <param name="other">Other ItemVersion</param>
        /// <returns>Most specific ItemVersion containing this and the other</returns>
        public ItemVersion LeastAbstractCommonVersion(ItemVersion other)
        {
            var extended = new ItemVersion();

            other.Do(kvp =>
            {
                if (this.ContainsKey(kvp.Key) && this[kvp.Key] == kvp.Value)
                {
                    extended.Add(kvp.Key, kvp.Value);
                }
            });
            return(extended);
        }
예제 #4
0
        /// <summary>
        /// Where the other version contains a key, and this version contains a key, set this version's key to the other's value
        /// </summary>
        /// <param name="other">The version to overlay on this one</param>
        /// <returns></returns>
        public ItemVersion Overlay(ItemVersion other)
        {
            var overlaid = new ItemVersion(this);

            other.Do(kvp =>
            {
                if (overlaid.ContainsKey(kvp.Key))
                {
                    overlaid[kvp.Key] = kvp.Value;
                }
            });
            return(overlaid);
        }
예제 #5
0
        /// <summary>
        /// Mask returns a new ItemVersion made by taking all the key value pairs from the argument ItemVersion
        /// and where the value is null, and this ItemVersion has the corresponding key, taking the value from
        /// this ItemVersion.  The null values in the argument can be viewed as holes in the mask.
        /// </summary>
        /// <param name="other">ItemVersion with which to mask this one to get the result</param>
        /// <returns>Resulting ItemVersion</returns>
        public ItemVersion Mask(ItemVersion other)
        {
            var masked = new ItemVersion();

            other.Do(kvp =>
            {
                if (kvp.Value == null && this.ContainsKey(kvp.Key))
                {
                    masked.Add(kvp.Key, this[kvp.Key]);
                }
                else if (kvp.Value != null)
                {
                    masked.Add(kvp.Key, kvp.Value);
                }
            });
            return(masked);
        }
예제 #6
0
        /// <summary>
        /// Special constructor for use in JSON deserialization which corrects integer values to Int32 from Int64
        /// </summary>
        /// <param name="info"></param>
        /// <param name="context"></param>
        public ItemVersion(SerializationInfo info, StreamingContext context)
        {
            ItemVersion newIv = JsonConvert.DeserializeObject <ItemVersion>((string)info.GetValue("vsn", typeof(string)));

            newIv.Do(kvp => this.Add(kvp.Key, kvp.Value is Int64 ? Convert.ToInt32(kvp.Value) : kvp.Value));
        }