예제 #1
0
        static RootDescriptor <Person> GetPersonDescriptor()
        {
            string ownName = nameof(Person);

            RootDescriptor <String>      stringDesc      = GetStringDescriptor();
            RootDescriptor <Int32>       int32Desc       = GetInt32Descriptor();
            RootDescriptor <Address>     adressDesc      = GetAdressDescriptor();
            RootDescriptor <Country>     countryDesc     = GetCountryDescriptor();
            RootDescriptor <PhoneNumber> phoneNumberDesc = GetPhoneNumberDescriptor();

            SerializerHelperPointingToVariableValue <Person>[] variables = new SerializerHelperPointingToVariableValue <Person>[]
            {
                new SerializerHelperPointingToVariableValue <Person>(FirstName),
                new SerializerHelperPointingToVariableValue <Person>(LastName),
                new SerializerHelperPointingToVariableValue <Person>(HomeAddress),
                new SerializerHelperPointingToVariableValue <Person>(WorkAddress),
                new SerializerHelperPointingToVariableValue <Person>(CitizenOf),
                new SerializerHelperPointingToVariableValue <Person>(MobilePhone),
            };

            string FirstName(Person person) => stringDesc.Serialize(nameof(FirstName), person.FirstName);
            string LastName(Person person) => stringDesc.Serialize(nameof(LastName), person.LastName);
            string HomeAddress(Person person) => adressDesc.Serialize(nameof(HomeAddress), person.HomeAddress);
            string WorkAddress(Person person) => adressDesc.Serialize(nameof(WorkAddress), person.WorkAddress);
            string CitizenOf(Person person) => countryDesc.Serialize(nameof(CitizenOf), person.CitizenOf);
            string MobilePhone(Person person) => phoneNumberDesc.Serialize(nameof(MobilePhone), person.MobilePhone);

            return(new RootDescriptor <Person>(ownName, variables));
        }
예제 #2
0
        static void Main(string[] args)
        {
            RootDescriptor <Person> rootDesc = GetPersonDescriptor();

            var czechRepublic = new Country {
                Name = "Czech Republic", AreaCode = 420
            };
            var person = new Person
            {
                FirstName   = "Pavel",
                LastName    = "Jezek",
                HomeAddress = new Address {
                    Street = "Patkova", City = "Prague"
                },
                WorkAddress = new Address {
                    Street = "Malostranske namesti", City = "Prague"
                },
                CitizenOf   = czechRepublic,
                MobilePhone = new PhoneNumber {
                    Country = czechRepublic, Number = 123456789
                }
            };

            rootDesc.Serialize(Console.Out, person);
        }
예제 #3
0
        static void Main(string[] args)
        {
            RootDescriptor <Person> rootDesc = GetPersonDescriptor();

            var czechRepublic = new Country {
                Name = "Czech Republic", AreaCode = 420
            };
            var person = new Person
            {
                FirstName   = "David",
                LastName    = "Napravnik",
                HomeAddress = new Address {
                    Street = "Vetrna", City = "Predboj"
                },
                WorkAddress = new Address {
                    Street = "U kastanu", City = "Prague"
                },
                CitizenOf   = czechRepublic,
                MobilePhone = new PhoneNumber {
                    Country = czechRepublic, Number = 987654321
                }
            };

            rootDesc.Serialize(Console.Out, person);
            Console.ReadKey();
        }
예제 #4
0
        static RootDescriptor <Address> GetAdressDescriptor()
        {
            string ownName = nameof(Address);

            RootDescriptor <String> stringDesc = GetStringDescriptor();

            SerializerHelperPointingToVariableValue <Address>[] variables = new SerializerHelperPointingToVariableValue <Address>[]
            {
                new SerializerHelperPointingToVariableValue <Address>(Street),
                new SerializerHelperPointingToVariableValue <Address>(City),
            };

            string Street(Address address) => stringDesc.Serialize(nameof(Street), address.Street);
            string City(Address address) => stringDesc.Serialize(nameof(City), address.City);

            return(new RootDescriptor <Address>(ownName, variables));
        }
예제 #5
0
        static RootDescriptor <Country> GetCountryDescriptor()
        {
            string ownName = nameof(Country);

            RootDescriptor <String> stringDesc = GetStringDescriptor();
            RootDescriptor <Int32>  int32Desc  = GetInt32Descriptor();

            SerializerHelperPointingToVariableValue <Country>[] variables = new SerializerHelperPointingToVariableValue <Country>[]
            {
                new SerializerHelperPointingToVariableValue <Country>(Name),
                new SerializerHelperPointingToVariableValue <Country>(AreaCode),
            };

            string Name(Country country) => stringDesc.Serialize(nameof(Name), country.Name);
            string AreaCode(Country country) => int32Desc.Serialize(nameof(AreaCode), country.AreaCode);

            return(new RootDescriptor <Country>(ownName, variables));
        }
예제 #6
0
        static RootDescriptor <PhoneNumber> GetPhoneNumberDescriptor()
        {
            string ownName = nameof(PhoneNumber);

            RootDescriptor <Country> adressDesc = GetCountryDescriptor();
            RootDescriptor <Int32>   int32Desc  = GetInt32Descriptor();

            SerializerHelperPointingToVariableValue <PhoneNumber>[] variables = new SerializerHelperPointingToVariableValue <PhoneNumber>[]
            {
                new SerializerHelperPointingToVariableValue <PhoneNumber>(Country),
                new SerializerHelperPointingToVariableValue <PhoneNumber>(Number),
            };

            string Country(PhoneNumber phoneNumber) => adressDesc.Serialize(nameof(Country), phoneNumber.Country);
            string Number(PhoneNumber phoneNumber) => int32Desc.Serialize(nameof(Number), phoneNumber.Number);

            return(new RootDescriptor <PhoneNumber>(ownName, variables));
        }