473,549 Members | 2,247 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(emai l, 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 2114

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 MyEMailAddressI nfo
property EmailAddress as string
property DisplayName as string

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

and then create a collection of these

public class MyEmailAddressI nfoCollection : List (Of MyEMailAddressI nfo )
( 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 MyEMailAddressI nfo )
to delay getting those MailAddress objects you need when you actually need
them.

"David Lozzi" <dl****@nospam. nospamwrote in message
news:8D******** *************** ***********@mic rosoft.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(emai l, 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
6531
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 class: Derives MarshalByValueComponent Implements ICollection, IList and ISerializable Explicitly implements the IList methods as private members,...
5
24678
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 s); public void Deserialize(Stream s); Within the MyUserControl class, there is a field of type MyInnerClass
0
2162
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 and properties derived from this class but will not serialize or deserialize the properties in CollectionBase. Like InnerList, which is a read only...
1
7077
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 and properties derived from this class but will not serialize or deserialize the properties in CollectionBase. Like InnerList, which is a read only...
3
2298
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 you help me public class Geometry {
10
4133
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; string s_FinalFileName; try
2
2313
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 reproduce the problem. Notice that m_table should NOT be serialized. public partial class Form1 : Form {
0
2497
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 class BaseClass { }
3
10218
by: Julie | last post by:
Here's the scenario (public attributes, etc. omitted for brevity): class Base { } class Derived : Base { }
0
1060
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 XmlSerializer ctor's to specify base class A and derived class B relationships. However, XmlInclude only works at compile-time, and I would like to...
0
7548
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7472
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7986
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7504
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7832
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
3518
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3499
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1083
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
786
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.