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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:50:37+00:00 2026-05-26T17:50:37+00:00

Is there a way to find out whether an object property is called as

  • 0

Is there a way to find out whether an object property is called as part of the DeSerialization process (e.g. by the XmlSerializationReaderXXX).

Background: A typical scenario is to disable events and complex operations in that case, until the initialization is complete.

One approach I have found, is to “interpret” the stack and look up whether the call is triggered by XmlSerializationReaderXXX, which is not so elegant IMHO. Is there anything better?

public SomeClass SomeProperty
    {
        get { ..... }
        set
        {
            this._somePropertyValue = value;
            this.DoSomeMoreStuff(); // Do not do this during DeSerialization
        }
    }

— Update —

As Salvatore has mentioned, somehow similar to How do you find out when you've been loaded via XML Serialization?

  • 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-26T17:50:37+00:00Added an answer on May 26, 2026 at 5:50 pm

    I have a possible solution.

    public class xxx
    {
        private int myValue;
    
        [XmlElement("MyProperty")]
        public int MyPropertyForSerialization
        {
            get { return this.myValue; }
            set
            {
                Console.WriteLine("DESERIALIZED");
                this.myValue = value;
            }
        }
    
        [XmlIgnore]
        public int MyProperty
        {
            get { return this.myValue; }
            set
            {
                Console.WriteLine("NORMAL");
                this.myValue = value;
            }
        }
    }
    
    class Program
    {
        static void Main(string[] args)
        {
            xxx instance = new xxx();
    
            instance.MyProperty = 100; // This should print "NORMAL"
    
            // We serialize
    
            var serializer = new XmlSerializer(typeof(xxx));
    
            var memoryStream = new MemoryStream();
            serializer.Serialize(memoryStream, instance);
    
            // Let's print our XML so we understand what's going on.
    
            memoryStream.Position = 0;
            var reader = new StreamReader(memoryStream);
            Console.WriteLine(reader.ReadToEnd());
    
            // Now we deserialize
    
            memoryStream.Position = 0;
            var deserialized = serializer.Deserialize(memoryStream) as xxx; // This should print DESERIALIZED
    
            Console.ReadLine();
        }
    }
    

    The trick is using the XmlIgnore, it will force the xml serializer to ignore our property, then we use XmlElement to rename the property for serialization with the name of the property we want.

    The problem with this technique is that you have to expose a public property for serialization, and is in some way bad because it can virtually be called by everyone.
    It will not work if the member is private, unfortunally.

    It works, is not totally clean, but is thread safe and don’t rely on any flag.

    Another possibility is to use something like the Memento pattern.
    Using the same trick you can add a property called for example Memento that returns another object that contains properties suitable only for serialization, it can makes things a little cleaner.

    Did you think instead of changing approach and using DataContractSerializer? It is much more powerful and produces pure XML. It supports the OnDeserializationCallback mechanism.

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

Sidebar

Related Questions

Is there a way to find out the final location of my animated object
Q. Is there a way to find out if an object has any "strong
Is there a way to find out whether there are unsaved changes in my
Is there a way to find out whether a Java function (or a constructor)
Given the path, is there a way to find out whether the file exists
Is there a way to find out whether the back button (Navigation bar) is
Is there a way to find out if a light is enabled in GLSL
Is there any way to find out diagonals of quadrilateral if I only know
Is there some way to find out when the text gets wrapped (WordWrap) inside
Is there a way to find out the checkin history of a user in

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.