Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 379011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:51:02+00:00 2026-05-12T14:51:02+00:00

I have a specialized class, BusinessObjectList, with this declaration: public class BusinessObjectList<T> : List<BusinessObject>

  • 0

I have a specialized class, BusinessObjectList, with this declaration:

public class BusinessObjectList<T> : List<BusinessObject> where T: BusinessObject {}

And I want to serialize objects of this class, like:

info.AddValue("myList", myList);

I tried to add the interface ISerializable, but with no success.

public class BusinessObjectList<T> : List<BusinessObject>, ISerializable where T: BusinessObject {}

The list is always null when unserialized.
I think List<> objects are serializable, but what about subclasses of them?

EDIT:

Just for future reference, here is the entire class:

BusinessObjectList.cs (When you call save(), it automatically persists on DB all inserts and removes from the list, and also saves all modified values on the business objects):

[Serializable()]
public class BusinessObjectList<T> : List<BusinessObject>,ISerializable where T: BusinessObject
{
    public delegate void BusinessObjectListDeleteHandler(T objDeleted);
    public event BusinessObjectListDeleteHandler deleteHandler;

    List<BusinessObject> objsForDelete = new List<BusinessObject>();
    public BusinessObjectList()
    {

    }

    public new void Add(BusinessObject item)
    {
        base.Add(item);
    }
    public new T this[int index]
    {
        get
        {                 
            return (T)base[index];
        }
    }

    public bool save()
    {
        foreach (T obj in objsForDelete)
        {
            if (deleteHandler != null)
                deleteHandler(obj);
            obj.delete();
        }
        objsForDelete.Clear();
        foreach (BusinessObject obj in this)
        {
            obj.save();
        }
        return true;
    }

    public new void Clear()
    {
        foreach (BusinessObject obj in this)
        {
            //obj.delete();
            objsForDelete.Add(obj);
        }
        base.Clear();
    }

    public new void Remove(BusinessObject obj)
    {
        // obj.delete();
        objsForDelete.Add(obj);
        base.Remove(obj);
    }

    public new void RemoveAt(int index)
    {
        objsForDelete.Add(this[index]);
        base.RemoveAt(index);
    }


    #region ISerializable Members

    public void GetObjectData(SerializationInfo info, StreamingContext context)
    {
        // should I do something here??
    }

    #endregion
}

And BusinessObject.cs:

[Serializable()]
public abstract class BusinessObject:ISerializable
{
    public abstract bool save();
    public abstract bool delete();
    public abstract DbTransaction startTransaction();
    public abstract void useTransaction(DbTransaction transaction);
    public abstract DbTransaction getTransaction();

    #region ISerializable Members

    public void GetObjectData(SerializationInfo info, StreamingContext context)
    {            
        // nothing to serialize here            
    }

    #endregion
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T14:51:02+00:00Added an answer on May 12, 2026 at 2:51 pm

    First of all, you should inherit from System.Collections.ObjectModel.Collection<T>, not List<BusinessObject>. It’s better to inherit from Collection<T> so that you can have control over all changes to the list (even changes made through IList<T>) by overriding InsertItem, SetItem, etc. It’s probably also better to inherit from a collection of T than a collection of BusinessObject so that the methods and indexer you inherit from your base class use the correct type.

    To answer your question, none of the .Net collection types (including Collection<T>) are serializable. You’ll need to serialize and deserialize the collection yourself; see here for instructions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a specialized list that holds items of type IThing : public class
Given the following inheritance tree: I have a public class BaseForm : Form This
I have developed some custom DAO-like classes to meet some very specialized requirements for
I have to implement template specialization, in implementing the constructor for specialized template class
I want to have an abstract class Server with an abstract method called Initialize
I have a set of specialized templates. Now I want to create specialized templates
In C++, I'm trying to create a specialized point class as a union, like
I have A WCF service that has a class that inherits System.Web.Security.RoleProvider. In this
I have this functor: struct functor { template<class T> void operator()(T value) // (*)
I have an entity and specialized class which is derived from the entity. Is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.