Exemple #1
0
        bool TryConvertCollection(IReferenceMap referenceMap, object?value, CollectionTypeReference collectionType, out object?result)
        {
            switch (collectionType.Kind)
            {
            case CollectionKind.Array:
                return(TryConvertArray(referenceMap, collectionType.ElementType, value, out result));

            case CollectionKind.Map:
                return(TryConvertMap(referenceMap, collectionType.ElementType, value, out result));

            default:
                throw new ArgumentException($"Unknown collection kind '{collectionType.Kind}'", nameof(collectionType));
            }
        }
            public void ShouldDeserializeAllMembers()
            {
                const string json = @"{
  ""kind"": ""array"",
  ""elementtype"": {
    ""fqn"": ""myElementFqn""
  }
}";

                CollectionTypeReference actual = JsonConvert.DeserializeObject <CollectionTypeReference>(json);

                Assert.Equal(CollectionKind.Array, actual.Kind);
                Assert.NotNull(actual.ElementType);
            }
            public void ShouldSerializeAllMembers()
            {
                CollectionTypeReference classType = new CollectionTypeReference
                                                    (
                    kind: CollectionKind.Array,
                    elementType: new TypeReference("myElementFqn")
                                                    );

                string       actual   = JsonConvert.SerializeObject(classType, Formatting.Indented);
                const string expected = @"{
  ""kind"": ""array"",
  ""elementtype"": {
    ""fqn"": ""myElementFqn""
  }
}";

                Assert.Equal(expected, actual, ignoreLineEndingDifferences: true);
            }