コード例 #1
0
ファイル: ValueConverter.cs プロジェクト: yglcode/jsii
        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));
            }
        }
コード例 #2
0
            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);
            }
コード例 #3
0
            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);
            }