我正在一个项目中,在该项目中反序列化XML,然后将其读取到数据库中。我能够做到这一点,只有一个问题。问题是我希望能够null
在反序列化XML之前对其进行两次检查。现在我只能检查null
一次。
我有以下代码:
Console.WriteLine("Deserilizing FolkbokföringsPost");
var myPersons = Deserialize<List<FolkbokforingspostTYPE>>()
.Select(x => new Person
{
PersonalIdentityNumber = x.Personpost.PersonId.PersonNr != null ? x.Personpost.PersonId.PersonNr : null,
SpecialIdentityNumber = x.Personpost.PersonId.Tilltalsnamnsmarkering != null ? x.Personpost.PersonId.Tilltalsnamnsmarkering : null,
LastName = x.Personpost.Namn.Efternamn != null ? x.Personpost.Namn.Efternamn : null,
FirstName = x.Personpost.Namn.Fornamn != null ? x.Personpost.Namn.Fornamn : null,
NationalRegistrationCountyCode = x.Personpost.Folkbokforing.LanKod != null ? x.Personpost.Folkbokforing.LanKod : null,
NationalRegistrationMunicipalityCode = x.Personpost.Folkbokforing.KommunKod != null ? x.Personpost.Folkbokforing.KommunKod : null,
ForeignDistrubtionAddress1 = x.Personpost.Adresser.Utlandsadress != null ? x.Personpost.Adresser.Utlandsadress.Utdelningsadress1 : null,
ForeignDistrubtionAddress2 = x.Personpost.Adresser.Utlandsadress != null ? x.Personpost.Adresser.Utlandsadress.Utdelningsadress2 : null,
ForeignDistrubtionAddress3 = x.Personpost.Adresser.Utlandsadress != null ? x.Personpost.Adresser.Utlandsadress.Utdelningsadress3 : null,
NationalRegistrationDistributionAddress1 = x.Personpost.Adresser.Folkbokforingsadress != null ? x.Personpost.Adresser.Folkbokforingsadress.Utdelningsadress1 : null,
NationalRegistrationDistributionAddress2 = x.Personpost.Adresser.Folkbokforingsadress != null ? x.Personpost.Adresser.Folkbokforingsadress.Utdelningsadress2 : null,
NationalRegistrationPostCode = x.Personpost.Adresser.Folkbokforingsadress != null ? x.Personpost.Adresser.Folkbokforingsadress.PostNr : null,
UnregistrationReason = x.Personpost.Avregistrering != null ? x.Personpost.Avregistrering.AvregistreringsorsakKod : null,
UnregistrationDate = x.Personpost.Avregistrering != null ? x.Personpost.Avregistrering.Avregistreringsdatum : null,
NationalRegistrationCity = x.Personpost.Adresser.Folkbokforingsadress != null ? x.Personpost.Adresser.Folkbokforingsadress.Postort : null,
BirthCountyCode = x.Personpost.Fodelse.HemortSverige != null ? x.Personpost.Fodelse.HemortSverige.FodelselanKod : null,
BirthParish = x.Personpost.Fodelse.HemortSverige != null ? x.Personpost.Fodelse.HemortSverige.Fodelseforsamling : null,
CitizenshipDate = x.Personpost.Medborgarskap != null ? x.Personpost.Medborgarskap.Medborgarskapsdatum : null,
GivenNameNumber = x.Personpost.Namn.Tilltalsnamnsmarkering != null ? x.Personpost.Namn.Tilltalsnamnsmarkering : null,
NationalRegistrationDate = x.Personpost.Folkbokforing != null ? x.Personpost.Folkbokforing.Folkbokforingsdatum : null,
ProtectedIdentity = x.Sekretessmarkering != null ? x.Sekretessmarkering : null,
CitizenshipCode = x.Personpost.Medborgarskap.MedborgarskapslandKod != null ? x.Personpost.Medborgarskap.MedborgarskapslandKod : null
});
如您在上面的代码中看到的,我检查了null
一次。例如ForeignDistrubtionAddress1 = x.Personpost.Adresser.Utlandsadress != null ? x.Personpost.Adresser.Utlandsadress.Utdelningsadress1 : null
在该示例中,它确保x.Personpost.Adresser.Utlandsadress
不在进行此操作null
之前。但是,如果我还想确保x.Personpost.Adresser
没有该null
怎么办,该怎么办?
有人知道如何null
在分配值之前进行两次检查吗?
谢谢
ForeignDistrubtionAddress1 = (x.Personpost.Adresser!= null
&& x.Personpost.Adresser.Utlandsadress != null)
? x.Personpost.Adresser.Utlandsadress.Utdelningsadress1
: null
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句