Skip to content

Instantly share code, notes, and snippets.

@rarous
Last active December 18, 2015 16:48
Show Gist options
  • Save rarous/5813519 to your computer and use it in GitHub Desktop.
Save rarous/5813519 to your computer and use it in GitHub Desktop.
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);
}
}
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();
}
}
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