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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:12:42+00:00 2026-05-25T12:12:42+00:00

Background: This question is about logging the change tracking of a POCO class in

  • 0

Background: This question is about logging the change tracking of a POCO class in C# .NET 4.0.

Let’s say I have a Person class with a Name (string) property. That Name property has a custom Attribute called [IsDirty(true/false)] that is set dynamically by a property-auditing class.

[IsDirty(true)]
public string Name { get; set; }

After the changes are detected and the attributes are set, I’m storing the object via normal XML Serialization in a MS SQL Database (XML column type).

What I can’t figure out is if it’s possible to somehow serialize my custom attribute IsDirty along with it’s current value – preferably as an XML attribute on the serialized XML element (Name) so that the final xml is like:

<Name IsDirty="true">John</Name>

Any ideas/info would be appreciated-

  • 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-25T12:12:43+00:00Added an answer on May 25, 2026 at 12:12 pm

    I think you’re going to have to write your own XML serialization for this and mix in some reflection to check attribute values on properties.

    There’s a good guide to implementing the IXMLSerializable interface here. Unfortunately you will have to implement serialization of all properties in the class, but on the bright side, if you implement IXmlSerializable correctly, you can still use the XmlSerializer class.

    In your serialization code, you can check the attribute value using something like this:

    public class YourClass : IXmlSerializable
    {
        [IsDirty(true)]
        public string Name { get; set; }
    
        // skipped ReadXml and GetSchema interface methods for brevity
    
        public void WriteXml(XmlWriter writer)
        {
            writer.WriteStartElement("YourClass");
    
            var myType = typeof(YourClass);
    
            foreach(var propInfo in myType.GetProperties())
            {
                writer.WriteStartElement(propInfo.Name);
                foreach(var attr in propInfo.GetCustomAttributes(typeof(IsDirtyAttribute), false))
                {
                    var myAttr = attr as IsDirtyAttribute;
                    writer.WriteAttributeString("Dirty", attr.Value ? "true" : "false");
                }
                writer.WriteEndElement();
            }
    
            writer.WriteEndElement();       
        }
    }
    

    This code is untested and written from memory, so there are probably some bugs lurking around, but hopefully it’ll get you on the right track.

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

Sidebar

Related Questions

I have a question about Objective-C today involving NSMutableArray. Coming from a .net/c# background
Background This question is in two parts. I have a one-way WCF operation hosted
Background: This is a follow-up question to this thread about handling EINTR for system
This is not the apparently-common question about how to put text over a background
First a little background about why I'm asking this question... I'm working on a
I have a question about how PHP handles filesystem operations. I'm running this code
Background: I have written a generic logging library in .NET 3.5. Basically the developer
Background: I am aware of this SO question about Transactional NTFS (TxF) and this
Yes, I know, yet another question about mutable objects. See this for general background
Background/context for this question: I have a WPF desktop application. It uses LINQ to

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.