-
-
Save rarous/5813519 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PublishedAccount | |
{ | |
readonly DateTime publishedDate; | |
readonly Maybe<DateTime> publishedDateEnd; | |
readonly AccountTypeStandard standardAccount; | |
readonly AccountTypeNonstandard nonstandardAccount; | |
public PublishedAccount(DateTime publishedDate, Maybe<DateTime> publishedDateEnd, AccountTypeStandard standardAccount, AccountTypeNonstandard nonstandardAccount) | |
{ | |
this.publishedDate = publishedDate; | |
this.publishedDateEnd = publishedDateEnd; | |
this.standardAccount = standardAccount; | |
this.nonstandardAccount = nonstandardAccount; | |
} | |
public static PublishedAccount Parse(ZverejnenyUcetType ucet) | |
{ | |
return new PublishedAccount( | |
ucet.datumZverejneni, | |
ucet.datumZverejneniUkonceni.ToMaybe(), | |
ucet.Item.GetType() == typeof(StandardniUcetType) | |
? AccountTypeStandard.Parse((StandardniUcetType)ucet.Item) | |
: null, | |
ucet.Item.GetType() == typeof(NestandardniUcetType) | |
? AccountTypeNonstandard.Parse((NestandardniUcetType)ucet.Item) | |
: null | |
); | |
} | |
public XElement ToXElement() | |
{ | |
return new XElement(Ns.Response + "PublishedAccount", | |
new XElement(Ns.Response + "PublishDate", publishedDate), | |
publishedDateEnd.ToXElement(Ns.Response + "PublishDateEnd"), | |
standardAccount != null ? standardAccount.ToXElement() : null, | |
nonstandardAccount != null ? nonstandardAccount.ToXElement() : null); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PublishedAccount | |
{ | |
readonly DateTime publishedDate; | |
readonly Maybe<DateTime> publishedDateEnd; | |
readonly AccountType account; | |
public PublishedAccount(DateTime publishedDate, Maybe<DateTime> publishedDateEnd, AccountType account) | |
{ | |
this.publishedDate = publishedDate; | |
this.publishedDateEnd = publishedDateEnd; | |
this.account = account; | |
} | |
public static PublishedAccount Parse(ZverejnenyUcetType ucet) | |
{ | |
return new PublishedAccount( | |
ucet.datumZverejneni, | |
ucet.datumZverejneniUkonceni.ToMaybe(), | |
AccountType.Parse(ucet.Item)); | |
} | |
public XElement ToXElement() | |
{ | |
return new XElement(Ns.Response + "PublishedAccount", | |
new XElement(Ns.Response + "PublishDate", publishedDate), | |
publishedDateEnd.ToXElement(Ns.Response + "PublishDateEnd"), | |
account.ToXElement()); | |
} | |
} | |
public class AccountType | |
{ | |
readonly AccountTypeStandard standardAccount; | |
readonly AccountTypeNonstandard nonstandardAccount; | |
public AccountType(AccountTypeStandard standardAccount) | |
{ | |
this.standardAccount = standardAccount; | |
} | |
public AccountType(AccountTypeNonstandard nonstandardAccount) | |
{ | |
this.nonstandardAccount = nonstandardAccount; | |
} | |
public static AccountType Parse(object account) | |
{ | |
var standard = account as StandardniUcetType; | |
if (standard != null) | |
return new AccountType(AccountTypeStandard.Parse(standard)); | |
var nonstandard = account as NestandardniUcetType; | |
return new AccountType(AccountTypeNonstandard.Parse(nonstandard)); | |
} | |
public XElement ToXElement() | |
{ | |
return standardAccount != null ? standardAccount.ToXElement() : nonstandardAccount.ToXElement(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class AccountType | |
{ | |
public static AccountType Parse(object account) | |
{ | |
var standard = account as StandardniUcetType; | |
if (standard != null) | |
return StandardAccount.Parse(standard); | |
var nonstandard = account as NestandardniUcetType; | |
return NonstandardAccount.Parse(nonstandard); | |
} | |
public abstract XElement ToXElement(); | |
class StandardAccount : AccountType | |
{ | |
readonly string accountPrefix; | |
readonly string accountNumber; | |
readonly string bankCode; | |
StandardAccount(string accountPrefix, string accountNumber, string bankCode) | |
{ | |
this.accountPrefix = accountPrefix; | |
this.accountNumber = accountNumber; | |
this.bankCode = bankCode; | |
} | |
public static StandardAccount Parse(StandardniUcetType ucet) | |
{ | |
return new StandardAccount(ucet.predcisli, ucet.cislo, ucet.kodBanky); | |
} | |
public override XElement ToXElement() | |
{ | |
return new XElement(Ns.Response + "AccountTypeStandard", | |
new XElement(Ns.Response + "AccountPrefix", accountPrefix), | |
new XElement(Ns.Response + "AccountNumber", accountNumber), | |
new XElement(Ns.Response + "BankCode", bankCode)); | |
} | |
} | |
class NonstandardAccount : AccountType | |
{ | |
readonly string accountNumber; | |
NonstandardAccount(string accountNumber) | |
{ | |
this.accountNumber = accountNumber; | |
} | |
public static NonstandardAccount Parse(NestandardniUcetType ucet) | |
{ | |
return new NonstandardAccount(ucet.cislo); | |
} | |
public override XElement ToXElement() | |
{ | |
return new XElement(Ns.Response + "AccountTypeNonstandard", | |
new XElement(Ns.Response + "AccountNumber", accountNumber)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment