[C#] Add Union Constructor Utility for ObjectAPI. (#6105)

* [C#] add union constructor utility.

* add union utility test.

* std::tolower -> CharToLower

* use std::transform instead

* rebase to master. and regenerate test code
This commit is contained in:
mugisoba
2021-07-27 02:01:41 +09:00
committed by GitHub
parent ac23482022
commit e77926f0ed
7 changed files with 53 additions and 9 deletions

View File

@@ -488,6 +488,26 @@ namespace FlatBuffers.Test
TestObjectAPI(movie);
}
[FlatBuffersTestMethod]
public void TestUnionUtility()
{
var movie = new MovieT
{
MainCharacter = CharacterUnion.FromRapunzel(new RapunzelT { HairLength = 40 }),
Characters = new System.Collections.Generic.List<CharacterUnion>
{
CharacterUnion.FromMuLan(new AttackerT { SwordAttackDamage = 10 }),
CharacterUnion.FromBelle(new BookReaderT { BooksRead = 20 }),
CharacterUnion.FromOther("Chip"),
},
};
var fbb = new FlatBufferBuilder(100);
Movie.FinishMovieBuffer(fbb, Movie.Pack(fbb, movie));
TestObjectAPI(Movie.GetRootAsMovie(fbb.DataBuffer));
}
private void AreEqual(Monster a, MonsterT b)
{
Assert.AreEqual(a.Hp, b.Hp);