473,326 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Serialize a base class?

Howdy,

A little background, using asp.net 2.0, i'm using a wizard object to create
a email interface for a user to email out their clientele, about 200 or so,
depending on the selection. The first step in the wizard is the email
selection, so it lists all the email accounts and distribution lists the
system has for the user, the user can select lists and/or individuals. I
then read through it all and throw it into an arraylist as a mailaddress
object. The next step in the wizard gives options of whether or not its
displays the selected recipients (including the ones in the lists), format
HTML vs Plain text, BCC the sender, etc. So I loop through all of the
selected emails in my arraylist to display which recipients the user is
emailing to. Here lies my issue.

I need the previously loaded arraylist of selected email addresses to still
be available. The only way i know how to do that is either throw it into a
session variable or the viewstate, both of which requires the class to be
serializable, which MailAddress isn't. I looked into Inheriting and trying
that but I got nowhere fast with that:

<Serializable()Public Class MailAddress1
Inherits MailAddress

Public Sub New(ByVal email As String, ByVal display As String)
MyBase.New(email, display)
End Sub
End Class

I tried overriding the New sub but it wouldn't let me. So I instead moved
the collecting of email addresses to when the user presses Send. And i do a
lighter collection of the email addresses to a string for displaying their
selected recipients.

SO

I would like to only collect the email addresses once and use the same
arraylist multiple times, on multiple postbacks. Is this possible? I thought
about creating a new class to hold the email address, then transfer them
from my class to the mailaddress class when going to send, but that didnt
make much sens to me to do.

Thanks!!!
May 7 '07 #1
1 2098

I think you're stuck with

Create your own Class.
I would write one that had the constructor value needs for the MailAddress
class.

MailAddress (String) Initializes a new instance of the MailAddress
class using the specified address.
MailAddress (String, String) Initializes a new instance of the
MailAddress class using the specified address and display name.
MailAddress (String, String, Encoding)
I'd probably pick the second one.

(Serializable _)
public class MyEMailAddressInfo
property EmailAddress as string
property DisplayName as string

public static (shared in vb.net) GetMailAddress ( e as
MyEMailAddressInfo ) as MailAddress

and then create a collection of these

public class MyEmailAddressInfoCollection : List (Of MyEMailAddressInfo )
( use the inherit keyword instead of the c# ":" of course).

And I'd keep a copy of this object in the Session.

That's what I would do, look for other ideas from others.
Even if that class was serializable, you probably want to keep a "lite"
version of the values (aka the custom collection above) for either Session
or ViewState keeping, because of memory issues.
Keeping around alot of MailAddress objects, just because you need a bunch of
jo*@joes.com values seems non-frugal with the resources
Use the
public static (shared in vb.net) GetMailAddress ( e as MyEMailAddressInfo )
to delay getting those MailAddress objects you need when you actually need
them.

"David Lozzi" <dl****@nospam.nospamwrote in message
news:8D**********************************@microsof t.com...
Howdy,

A little background, using asp.net 2.0, i'm using a wizard object to
create
a email interface for a user to email out their clientele, about 200 or
so,
depending on the selection. The first step in the wizard is the email
selection, so it lists all the email accounts and distribution lists the
system has for the user, the user can select lists and/or individuals. I
then read through it all and throw it into an arraylist as a mailaddress
object. The next step in the wizard gives options of whether or not its
displays the selected recipients (including the ones in the lists), format
HTML vs Plain text, BCC the sender, etc. So I loop through all of the
selected emails in my arraylist to display which recipients the user is
emailing to. Here lies my issue.

I need the previously loaded arraylist of selected email addresses to
still
be available. The only way i know how to do that is either throw it into a
session variable or the viewstate, both of which requires the class to be
serializable, which MailAddress isn't. I looked into Inheriting and trying
that but I got nowhere fast with that:

<Serializable()Public Class MailAddress1
Inherits MailAddress

Public Sub New(ByVal email As String, ByVal display As String)
MyBase.New(email, display)
End Sub
End Class

I tried overriding the New sub but it wouldn't let me. So I instead moved
the collecting of email addresses to when the user presses Send. And i do
a
lighter collection of the email addresses to a string for displaying their
selected recipients.

SO

I would like to only collect the email addresses once and use the same
arraylist multiple times, on multiple postbacks. Is this possible? I
thought
about creating a new class to hold the email address, then transfer them
from my class to the mailaddress class when going to send, but that didnt
make much sens to me to do.

Thanks!!!


May 7 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Lars-Erik Aabech | last post by:
Hi! I've got problems with serializing my collections of business objects. The objects themselves serialize fine, but the collections fail. I've got the following structure: Base collection...
5
by: David Sworder | last post by:
Hi, I've created a UserControl-derived class called MyUserControl that is able to persist and subsequently reload its state. It exposes two methods as follows: public void Serialize(Stream...
0
by: Mike Pollett | last post by:
Hi, I have used the ISerializable interface before and the code below worked fine. Until I derived it from CollectionBase. The code will still serialize and deserialize the properties in this class...
1
by: Mike Pollett | last post by:
Hi, I have used the ISerializable interface before and the code below worked fine. Until I derived it from CollectionBase. The code will still serialize and deserialize the properties in this class...
3
by: Pol Bawin | last post by:
A class has a private field of type IWizard (An interface) and a public property to access it. When I try to serialize the Geometry class in XML, i have an error but it works in Binary Can...
10
by: Dan | last post by:
All I Am Attempting To Serialize An Object To An XML File. Here Is The Code For That public string SaveNewSurvey( MutualSurveyObject mso_TempObject, int i_JobID ) { string s_RootFileName;...
2
by: Joe | last post by:
If I serialize an object from with the same class, any fields with the NonSerializableAttribute still get serialized but not if I serialize from outside the class. Why? This is a simple case to...
0
by: phobos7 | last post by:
Hi, I'm looking for a way to force a derived class to serialise/serialize as its base class. I was hoping that this was possible by just applying an attribute to the the sub class. public...
3
by: Julie | last post by:
Here's the scenario (public attributes, etc. omitted for brevity): class Base { } class Derived : Base { }
0
by: Ignace 'a0a' Saenen | last post by:
Hi, I have actually found 2 ways to do this. One uses the XmlInclude attribute in the base class A, specifying the valid derived types to deserialize from the stream, and one uses one of the 8...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.