Ejemplo n.º 1
0
        public static void DictionaryWithNullableValue()
        {
            Dictionary <string, float?> dictWithFloatValue = new Dictionary <string, float?> {
                { "key", 42.0f }
            };
            Dictionary <string, float?> dictWithFloatNull = new Dictionary <string, float?> {
                { "key", null }
            };

            TestDictionaryWithNullableValue <Dictionary <string, float?>, Dictionary <string, Dictionary <string, float?> >, float?>(
                dictWithFloatValue,
                dictWithFloatNull,
                dictOfDictWithValue: new Dictionary <string, Dictionary <string, float?> > {
                { "key", dictWithFloatValue }
            },
                dictOfDictWithNull: new Dictionary <string, Dictionary <string, float?> > {
                { "key", dictWithFloatNull }
            },
                42.0f);

            DateTime now = DateTime.Now;
            Dictionary <string, DateTime?> dictWithDateTimeValue = new Dictionary <string, DateTime?> {
                { "key", now }
            };
            Dictionary <string, DateTime?> dictWithDateTimeNull = new Dictionary <string, DateTime?> {
                { "key", null }
            };

            TestDictionaryWithNullableValue <Dictionary <string, DateTime?>, Dictionary <string, Dictionary <string, DateTime?> >, DateTime?>(
                dictWithDateTimeValue,
                dictWithDateTimeNull,
                dictOfDictWithValue: new Dictionary <string, Dictionary <string, DateTime?> > {
                { "key", dictWithDateTimeValue }
            },
                dictOfDictWithNull: new Dictionary <string, Dictionary <string, DateTime?> > {
                { "key", dictWithDateTimeNull }
            },
                now);

            MyDictionaryWrapper <float?> dictWrapperWithFloatValue = new MyDictionaryWrapper <float?>()
            {
                { "key", 42.0f }
            };
            MyDictionaryWrapper <float?> dictWrapperWithFloatNull = new MyDictionaryWrapper <float?>()
            {
                { "key", null }
            };

            TestDictionaryWithNullableValue <MyDictionaryWrapper <float?>, MyDictionaryWrapper <MyDictionaryWrapper <float?> >, float?>(
                dictWrapperWithFloatValue,
                dictWrapperWithFloatNull,
                dictOfDictWithValue: new MyDictionaryWrapper <MyDictionaryWrapper <float?> > {
                { "key", dictWrapperWithFloatValue }
            },
                dictOfDictWithNull: new MyDictionaryWrapper <MyDictionaryWrapper <float?> > {
                { "key", dictWrapperWithFloatNull }
            },
                42.0f);

            MyIDictionaryWrapper <float?> idictWrapperWithFloatValue = new MyIDictionaryWrapper <float?>()
            {
                { "key", 42.0f }
            };
            MyIDictionaryWrapper <float?> idictWrapperWithFloatNull = new MyIDictionaryWrapper <float?>()
            {
                { "key", null }
            };

            TestDictionaryWithNullableValue <MyIDictionaryWrapper <float?>, MyIDictionaryWrapper <MyIDictionaryWrapper <float?> >, float?>(
                idictWrapperWithFloatValue,
                idictWrapperWithFloatNull,
                dictOfDictWithValue: new MyIDictionaryWrapper <MyIDictionaryWrapper <float?> > {
                { "key", idictWrapperWithFloatValue }
            },
                dictOfDictWithNull: new MyIDictionaryWrapper <MyIDictionaryWrapper <float?> > {
                { "key", idictWrapperWithFloatNull }
            },
                42.0f);

            IDictionary <string, DateTime?> idictWithDateTimeValue = new Dictionary <string, DateTime?> {
                { "key", now }
            };
            IDictionary <string, DateTime?> idictWithDateTimeNull = new Dictionary <string, DateTime?> {
                { "key", null }
            };

            TestDictionaryWithNullableValue <IDictionary <string, DateTime?>, IDictionary <string, IDictionary <string, DateTime?> >, DateTime?>(
                idictWithDateTimeValue,
                idictWithDateTimeNull,
                dictOfDictWithValue: new Dictionary <string, IDictionary <string, DateTime?> > {
                { "key", idictWithDateTimeValue }
            },
                dictOfDictWithNull: new Dictionary <string, IDictionary <string, DateTime?> > {
                { "key", idictWithDateTimeNull }
            },
                now);

            ImmutableDictionary <string, DateTime?> immutableDictWithDateTimeValue = ImmutableDictionary.CreateRange(new Dictionary <string, DateTime?> {
                { "key", now }
            });
            ImmutableDictionary <string, DateTime?> immutableDictWithDateTimeNull = ImmutableDictionary.CreateRange(new Dictionary <string, DateTime?> {
                { "key", null }
            });

            TestDictionaryWithNullableValue <ImmutableDictionary <string, DateTime?>, ImmutableDictionary <string, ImmutableDictionary <string, DateTime?> >, DateTime?>(
                immutableDictWithDateTimeValue,
                immutableDictWithDateTimeNull,
                dictOfDictWithValue: ImmutableDictionary.CreateRange(new Dictionary <string, ImmutableDictionary <string, DateTime?> > {
                { "key", immutableDictWithDateTimeValue }
            }),
                dictOfDictWithNull: ImmutableDictionary.CreateRange(new Dictionary <string, ImmutableDictionary <string, DateTime?> > {
                { "key", immutableDictWithDateTimeNull }
            }),
                now);
        }
Ejemplo n.º 2
0
        public static void DictionaryWithNullableValue()
        {
            Dictionary <string, float?> dictWithFloatValue = new Dictionary <string, float?> {
                { "key", 42.0f }
            };
            Dictionary <string, float?> dictWithFloatNull = new Dictionary <string, float?> {
                { "key", null }
            };

            TestDictionaryWithNullableValue <Dictionary <string, float?>, Dictionary <string, Dictionary <string, float?> >, float?>(
                dictWithFloatValue,
                dictWithFloatNull,
                dictOfDictWithValue: new Dictionary <string, Dictionary <string, float?> > {
                { "key", dictWithFloatValue }
            },
                dictOfDictWithNull: new Dictionary <string, Dictionary <string, float?> > {
                { "key", dictWithFloatNull }
            },
                42.0f);

            DateTime now = DateTimeTestHelpers.FixedDateTimeValue;
            Dictionary <string, DateTime?> dictWithDateTimeValue = new Dictionary <string, DateTime?> {
                { "key", now }
            };
            Dictionary <string, DateTime?> dictWithDateTimeNull = new Dictionary <string, DateTime?> {
                { "key", null }
            };

            TestDictionaryWithNullableValue <Dictionary <string, DateTime?>, Dictionary <string, Dictionary <string, DateTime?> >, DateTime?>(
                dictWithDateTimeValue,
                dictWithDateTimeNull,
                dictOfDictWithValue: new Dictionary <string, Dictionary <string, DateTime?> > {
                { "key", dictWithDateTimeValue }
            },
                dictOfDictWithNull: new Dictionary <string, Dictionary <string, DateTime?> > {
                { "key", dictWithDateTimeNull }
            },
                now);

            MyDictionaryWrapper <float?> dictWrapperWithFloatValue = new MyDictionaryWrapper <float?>()
            {
                { "key", 42.0f }
            };
            MyDictionaryWrapper <float?> dictWrapperWithFloatNull = new MyDictionaryWrapper <float?>()
            {
                { "key", null }
            };

            TestDictionaryWithNullableValue <MyDictionaryWrapper <float?>, MyDictionaryWrapper <MyDictionaryWrapper <float?> >, float?>(
                dictWrapperWithFloatValue,
                dictWrapperWithFloatNull,
                dictOfDictWithValue: new MyDictionaryWrapper <MyDictionaryWrapper <float?> > {
                { "key", dictWrapperWithFloatValue }
            },
                dictOfDictWithNull: new MyDictionaryWrapper <MyDictionaryWrapper <float?> > {
                { "key", dictWrapperWithFloatNull }
            },
                42.0f);

            // https://github.com/dotnet/runtime/issues/66220
            if (!PlatformDetection.IsAppleMobile)
            {
                MyIDictionaryWrapper <float?> idictWrapperWithFloatValue = new MyIDictionaryWrapper <float?>()
                {
                    { "key", 42.0f }
                };
                MyIDictionaryWrapper <float?> idictWrapperWithFloatNull = new MyIDictionaryWrapper <float?>()
                {
                    { "key", null }
                };
                TestDictionaryWithNullableValue <MyIDictionaryWrapper <float?>, MyIDictionaryWrapper <MyIDictionaryWrapper <float?> >, float?>(
                    idictWrapperWithFloatValue,
                    idictWrapperWithFloatNull,
                    dictOfDictWithValue: new MyIDictionaryWrapper <MyIDictionaryWrapper <float?> > {
                    { "key", idictWrapperWithFloatValue }
                },
                    dictOfDictWithNull: new MyIDictionaryWrapper <MyIDictionaryWrapper <float?> > {
                    { "key", idictWrapperWithFloatNull }
                },
                    42.0f);

                IDictionary <string, DateTime?> idictWithDateTimeValue = new Dictionary <string, DateTime?> {
                    { "key", now }
                };
                IDictionary <string, DateTime?> idictWithDateTimeNull = new Dictionary <string, DateTime?> {
                    { "key", null }
                };
                TestDictionaryWithNullableValue <IDictionary <string, DateTime?>, IDictionary <string, IDictionary <string, DateTime?> >, DateTime?>(
                    idictWithDateTimeValue,
                    idictWithDateTimeNull,
                    dictOfDictWithValue: new Dictionary <string, IDictionary <string, DateTime?> > {
                    { "key", idictWithDateTimeValue }
                },
                    dictOfDictWithNull: new Dictionary <string, IDictionary <string, DateTime?> > {
                    { "key", idictWithDateTimeNull }
                },
                    now);
            }

            ImmutableDictionary <string, DateTime?> immutableDictWithDateTimeValue = ImmutableDictionary.CreateRange(new Dictionary <string, DateTime?> {
                { "key", now }
            });
            ImmutableDictionary <string, DateTime?> immutableDictWithDateTimeNull = ImmutableDictionary.CreateRange(new Dictionary <string, DateTime?> {
                { "key", null }
            });

            TestDictionaryWithNullableValue <ImmutableDictionary <string, DateTime?>, ImmutableDictionary <string, ImmutableDictionary <string, DateTime?> >, DateTime?>(
                immutableDictWithDateTimeValue,
                immutableDictWithDateTimeNull,
                dictOfDictWithValue: ImmutableDictionary.CreateRange(new Dictionary <string, ImmutableDictionary <string, DateTime?> > {
                { "key", immutableDictWithDateTimeValue }
            }),
                dictOfDictWithNull: ImmutableDictionary.CreateRange(new Dictionary <string, ImmutableDictionary <string, DateTime?> > {
                { "key", immutableDictWithDateTimeNull }
            }),
                now);
        }