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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:59:44+00:00 2026-05-11T17:59:44+00:00

I have a DataContract class that I have to fill by values from the

  • 0

I have a DataContract class that I have to fill by values from the Active Directory of our company.

[DataContract(Namespace = Global.Namespace)]
public class UserProfile
{
    [DataMember(IsRequired = true, EmitDefaultValue = false)]
    public string EmployeeID { get; private set; }

    [DataMember(IsRequired = true, EmitDefaultValue = false)]
    public string GivenName { get; private set; }

    ...

    public static readonly string[] PropertiesToLoad = new[] { "EmployeeID", "GivenName" };
}

I was considering to make a custom attribute to decorate my properties, so that the code that would fill my object from the AD would not need to have the Mapping hardcoded, but much rather I could just decorate the properties to automatically fill the object.

And in the long run, I might also be able to get rid of this “PropertiesToLoad”. Do you think that Attributes are a good way of solving this issue? And another question, if I do solve this by Attributes, am I likely to make a huge performance bottle neck or is the use of Attributes not really a performance issue.

  • 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-11T17:59:45+00:00Added an answer on May 11, 2026 at 5:59 pm

    I like to use attributes for this kind of concern because it helps make it clear in the code that the property is being used in a certain way. There is a trade-off between having the PropertiesToLoad in one place (as it is in the example above) or at the point of property declaration. I tend to find that using attributes helps code maintenance because I don’t have to hunt down changes if the property is removed or modified.

    As for performance, yes it will cause a performance hit but not huge. It is measurable but unless this is performance critical code, you probably won’t notice. And even at that point, I’m guessing you’ll find bigger issues. If the attribute reflection becomes an issue, there are way to mitigate the performance impact by using caching or other methods.

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

Sidebar

Related Questions

I have a simple class I'm serializing. [DataContract(Name = Test, Namespace = )] public
I have class that is a DataContract and the member values are holding default
I have WCF service that return Json. Data contract defined below [DataContract] public class
I have a class that is marked with DataContract attributes and I would like
I have a class Team that holds a generic list: [DataContract(Name = TeamDTO, IsReference
I have the following DTO definition:- [DataContract] public class AddProductDTO { [DataMember] public string
Just imagine you have the following class [DataContract] public class NamedList { [DataMember] public
I have a public class that won't serialize properly. When attempted, the following exception
I have the following: [DataContract] public class Foo { [DataMember(EmitDefaultValue = true) public bool
Basically if I have the following: [DataContract] public class Foo { [MyCustomAttribute(...)] [DataMember(IsRequired =

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.