コード例 #1
0
ファイル: Mo.cs プロジェクト: youlin1210/MySample
        /// <summary>
        /// Implements the operator &amp;. This is used for conjunctions.
        /// </summary>
        /// <param name="modifier1">The modifier1.</param>
        /// <param name="modifier2">The modifier2.</param>
        /// <returns>The result of the modifier.</returns>
        public static Mo operator &(Mo modifier1, Mo modifier2)
        {
            var mo = new Mo();

            //Todo: move as DeepMerge to Document

            foreach (var key in modifier1.Keys)
            {
                mo[key] = modifier1[key];
            }

            foreach (var pair2 in modifier2)
            {
                object value1;
                if (mo.TryGetValue(pair2.Key, out value1))
                {
                    if (pair2.Value is Document && value1 is Document)
                    {
                        mo[pair2.Key] = new Document()
                                        .Merge((Document)value1)
                                        .Merge((Document)pair2.Value);
                    }
                    else
                    {
                        mo[pair2.Key] = pair2.Value;
                    }
                }
                else
                {
                    mo.Add(pair2.Key, pair2.Value);
                }
            }

            return(mo);
        }
コード例 #2
0
ファイル: Mo.cs プロジェクト: gaoninggn/mongodb-csharp
        /// <summary>
        /// Implements the operator &amp;. This is used for conjunctions.
        /// </summary>
        /// <param name="modifier1">The modifier1.</param>
        /// <param name="modifier2">The modifier2.</param>
        /// <returns>The result of the modifier.</returns>
        public static Mo operator &(Mo modifier1, Mo modifier2){
            var mo = new Mo();

            //Todo: move as DeepMerge to Document

            foreach(var key in modifier1.Keys)
                mo[key] = modifier1[key];

            foreach(var pair2 in modifier2)
            {
                object value1;
                if(mo.TryGetValue(pair2.Key, out value1))
                {
                    if(pair2.Value is Document && value1 is Document)
                    {
                        mo[pair2.Key] = new Document()
                            .Merge((Document)value1)
                            .Merge((Document)pair2.Value);
                    }
                    else
                        mo[pair2.Key] = pair2.Value;

                }
                else
                    mo.Add(pair2.Key, pair2.Value);
            }

            return mo;
        }