Exemplo n.º 1
0
        /// <summary>
        /// Deserialize from an XML stream to an Account.
        /// </summary>
        /// <param name="xmlReader"></param>
        /// <returns></returns>
        public Account DeserializeAccount( XmlReader xmlReader, Version version )
        {
            if( xmlReader.NodeType != XmlNodeType.Element || xmlReader.Name.ToLower() != "account" )
                throw new ApplicationException( "Needs an Account node to deserialize an account object." );

            Account account = new Account();

            if( xmlReader.GetAttribute( "Id" ) != null )
                account.Id = Int32.Parse( xmlReader.GetAttribute( "Id" ) );
            if( xmlReader.GetAttribute( "id" ) != null )
                account.Id = Int32.Parse( xmlReader.GetAttribute( "id" ) );

            while( xmlReader.Read() )
            {
                switch( xmlReader.NodeType )
                {
                    case XmlNodeType.Attribute:
                        switch( xmlReader.Name.ToLower() )
                        {
                            case "id":
                                account.Id = Int32.Parse( xmlReader.Value );
                                break;
                            default:
                                break;
                        }
                        break;
                    case XmlNodeType.Element:
                        switch( xmlReader.Name.ToLower() )
                        {
                            case "name":
                                account.Name = xmlReader.ReadString();
                                break;
                            case "type":
                                account.AccountType = (AccountType)Enum.Parse( typeof( AccountType ), xmlReader.ReadString() );
                                break;
                            case "startingdate":
                                account.StartingDate = DateTime.Parse( xmlReader.ReadString() );
                                break;
                            case "startingbalance":
                                account.StartingBalance = Decimal.Parse( xmlReader.ReadString() );
                                break;
                            case "onlinesource":
                                account.OnlineSource = xmlReader.ReadString();
                                break;
                            default:
                                break;
                        }
                        break;
                    case XmlNodeType.EndElement:
                        if( xmlReader.Name.ToLower() == "account" ) return account;
                        break;
                }
            }

            account.SetUnmodified();

            return account;
        }