コード例 #1
0
        public void NullableEnumImportTest()
        {
            string           json  = @"{
                ""TestEnum"": 1
            }";
            NullableEnumTest value = JsonMapper.ToObject <NullableEnumTest>(json);

            Assert.AreNotEqual(value.TestEnum, null);
            NullableEnum enumValue = (NullableEnum)value.TestEnum;

            Assert.AreEqual(value.TestEnum, NullableEnum.TestVal1);

            json  = @"{
                ""TestEnum"": null
            }";
            value = JsonMapper.ToObject <NullableEnumTest>(json);
            Assert.AreEqual(value.TestEnum, null);
        }
コード例 #2
0
        internal void WriteInheritedOptionInfo()
        {
            Console.WriteLine("Int:{0},BoolValue:{1},EnumValue:{2},NullableInt:{3},NullableBoolValue:{4},NullableEnum:{5}",
                              Int,
                              BoolValue,
                              EnumValue,
                              NullableInt.HasValue ? NullableInt.ToString() : "null",
                              NullableBoolValue.HasValue ? NullableBoolValue.ToString() : "null",
                              NullableEnum.HasValue ? NullableEnum.ToString() : "null",
                              StringValue);

            Console.WriteLine($"StringValue:{StringValue}");

            Console.WriteLine($"MutiIntValues{MutiIntValues.Length}:");
            for (int i = 0; i < MutiIntValues.Length; i++)
            {
                Console.WriteLine($"\t[{i}]:{MutiIntValues[i]}");
            }
        }
コード例 #3
0
ファイル: ProductService.cs プロジェクト: opcion1/Training1
        public async Task <SearchSortPageResult <Product> > SearchSortAndPageProductAll(SearchSortPageParameters parameters)
        {
            SearchSortPageResult <Product> result = new SearchSortPageResult <Product>();

            result.ItemsPerPage = _gridConfiguration.ItemsPerPage;
            IEnumerable <Product> products;

            if (NullableEnum.TryParse(parameters.searchOrFilter, out ProductCategory? category))
            {
                products = await ListAsyncByCategory((ProductCategory)category);
            }
            else
            {
                products = await this.ListAsync();
            }
            result.TotalItems = products.Count();
            switch (parameters.sortOrder)
            {
            case "name_desc":
                products = products.OrderByDescending(p => p.Name);
                break;

            case "category":
                products = products.OrderBy(p => p.Category.ToString());
                break;

            case "category_desc":
                products = products.OrderByDescending(p => p.Category.ToString());
                break;

            default:
                products = products.OrderBy(p => p.Name);
                break;
            }
            result.Entities = products
                              .Skip(((parameters.indexPage ?? 1) - 1) * result.ItemsPerPage)
                              .Take(result.ItemsPerPage);

            return(result);
        }
コード例 #4
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = Boolean.GetHashCode();
         hashCode = (hashCode * 397) ^ NullableBoolean.GetHashCode();
         hashCode = (hashCode * 397) ^ Byte.GetHashCode();
         hashCode = (hashCode * 397) ^ NullableByte.GetHashCode();
         hashCode = (hashCode * 397) ^ SByte.GetHashCode();
         hashCode = (hashCode * 397) ^ NullableSByte.GetHashCode();
         hashCode = (hashCode * 397) ^ Char.GetHashCode();
         hashCode = (hashCode * 397) ^ NullableChar.GetHashCode();
         hashCode = (hashCode * 397) ^ Decimal.GetHashCode();
         hashCode = (hashCode * 397) ^ NullableDecimal.GetHashCode();
         hashCode = (hashCode * 397) ^ Double.GetHashCode();
         hashCode = (hashCode * 397) ^ NullableDouble.GetHashCode();
         hashCode = (hashCode * 397) ^ Single.GetHashCode();
         hashCode = (hashCode * 397) ^ NullableSingle.GetHashCode();
         hashCode = (hashCode * 397) ^ Int32;
         hashCode = (hashCode * 397) ^ NullableInt32.GetHashCode();
         hashCode = (hashCode * 397) ^ (int)UInt32;
         hashCode = (hashCode * 397) ^ NullableUInt32.GetHashCode();
         hashCode = (hashCode * 397) ^ Int64.GetHashCode();
         hashCode = (hashCode * 397) ^ NullableInt64.GetHashCode();
         hashCode = (hashCode * 397) ^ UInt64.GetHashCode();
         hashCode = (hashCode * 397) ^ NullableUInt64.GetHashCode();
         hashCode = (hashCode * 397) ^ Int16.GetHashCode();
         hashCode = (hashCode * 397) ^ NullableInt16.GetHashCode();
         hashCode = (hashCode * 397) ^ UInt16.GetHashCode();
         hashCode = (hashCode * 397) ^ NullableUInt16.GetHashCode();
         hashCode = (hashCode * 397) ^ (int)Enum;
         hashCode = (hashCode * 397) ^ NullableEnum.GetHashCode();
         hashCode = (hashCode * 397) ^ (String != null ? String.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Nested != null ? Nested.GetHashCode() : 0);
         return(hashCode);
     }
 }