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 7951561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:35:56+00:00 2026-06-04T02:35:56+00:00

for some reasons I need to control the process of object serialization in .NET.

  • 0

for some reasons I need to control the process of object serialization in .NET. I have to control that properties should be serialized. This process should be dynamical so, at one request one set of properties should be serialized and at the other one – another. I’m curious is it possible to implement by the already existed mechanism or I have to design some custom serializer?

  • 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-06-04T02:35:58+00:00Added an answer on June 4, 2026 at 2:35 am

    The ISerializable interface allows you to do exactly that. Basically, you control which values are added to the “property bag” (SerializationInfo) when the serialization is being performed. Notice that you’re not even limited to properties of the type, as shown below.

    public class StackOverflow_10639264
    {
        [Serializable]
        public class MyType : ISerializable
        {
            public string SerializedAM { get; set; }
            public string SerializedPM { get; set; }
            public void GetObjectData(SerializationInfo info, StreamingContext context)
            {
                DateTime now = DateTime.Now;
                if (now.Hour < 12)
                {
                    info.AddValue("MyValue", this.SerializedAM);
                }
                else
                {
                    info.AddValue("MyValue", this.SerializedPM);
                    info.AddValue("NotAProperty", "Hello");
                }
            }
        }
        public static void Test()
        {
            MemoryStream ms = new MemoryStream();
            DataContractSerializer dcs = new DataContractSerializer(typeof(MyType));
            dcs.WriteObject(ms, new MyType { SerializedAM = "AM", SerializedPM = "PM" });
            Console.WriteLine(Encoding.UTF8.GetString(ms.ToArray()));
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some classes that, for one reason or another, cannot be or need
For historical reasons, I have some WSE 3.0 web services that I cannot upgrade
I have need of a checked combobox control like this one --> DevExpress (I
I have a datagridview control that where I need to color the rows based
due to some unavoidable reasons I need to disable Google Chrome's Chrome PDF Viewer
I am developing a web application. For some reasons, I need to use external
Let's say that for some reason you need to write a macro: MACRO(X,Y) .
i have a large user Database (13k+), and for some reason i need to
For some reasons, my will_paginate collection is stuck on page 2. I have the
I've got some delimited data that I need to get into a Flex tree

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.