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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:31:02+00:00 2026-05-18T06:31:02+00:00

I am writing a class library to interact with a domain Active Directory. In

  • 0

I am writing a class library to interact with a domain Active Directory. In my object model, I have the following:

  1. Domain;
  2. Organizational Unit;
  3. Group;
  4. User.

In my Domain object, I have an Entries property and an Add() method.

public class Domain {
    // The ReadOnlyDictionary<TKey, TValue> is a custom wrapper over an IDictionary.
    public ReadOnlyDictionary<string, IDirectoryEntry> Entries { get; }

    public void Add(IDirectoryEntry entry) {
        Entries.Add(entry.Name, entry);
    }
}

Now, let’s suppose I have the following code testing for changes.

[Test()]
public void ChangeTesting {
    Domain domain = new Domain("LDAP://...");
    Group g = new Group("groupName");

    domain.Add(g);

    g.Name = "ChangedName";

    Assert.IsTrue(domain.ContainsKey("ChangedName"));
}

For your information, I implemented the INotifyPropertyChanged interface to ease my life, but I don’t seem to find a way to make it work the way I want. Perhaps am I not doing things right somehow, as for the location of different methods, I don’t know.

How can I make my Domain aware of a change that occured within one of its Entries, so that the TKey value is also changed?

That is wanted because one could possibly add an entry, change its name meanwhile adding a new entry with the “old” name of the actual within entry, and cause a conflict, etc. In the end, causing the test to fail. But I’d like to make it pass like it actually is.

Is there another better approach or workaround?

  • 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-18T06:31:02+00:00Added an answer on May 18, 2026 at 6:31 am

    This is a really bad hack, and it will probably fail miserably in a multithreaded environment, but here goes:

    private Dictionary<IDirectoryEntry, PropertyChangedEventHandler> eventHandlers =
        new Dictionary<IDirectoryEntry, PropertyChangedEventHandler>();
    
    public void Add(IDirectoryEntry entry) {
        string oldName = entry.Name;
    
        PropertyChangedEventHandler h;
        h = (o, args) => {
            if (args.PropertyName == "Name" &&
                    entry.Name != oldName &&
                    Entries[oldName] == entry) {
                entry.PropertyChanged -= h;
                Entries.Remove(oldName);
                Add(entry);
            }
        };
    
        eventHandlers[entry] = h;
        entry.PropertyChanged += h;
    
        Entries.Add(entry.Name, entry);
    }
    
    public void Remove(IDirectoryEntry entry) {
        if (Entries[entry.Name] == entry) {
            Entries.Remove(entry.Name);
            eventHandlers.Remove(entry);
        }
    }
    

    You will probably want to lock on something for each handler AND inside the anonymous method if you expect concurrent activity. (This could mean removing an entry from one thread and changing the name of an entry from another!)

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

Sidebar

Related Questions

I am writing a class library where i need to extend System.DateTime to have
When writing a class do you group members variables of the same type together?
I'm currently writing a class that implements the SeekableIterator interface and have run into
I am writing a class library for Mac OS X and iOS to be
I'm writing a library class to encapsulate some of my logic in my first
I'm writing a two-project solution with a class library designed for re-use, and an
I'm busy writing a class that monitors the status of RAS connections. I need
I'm currently writing a class to handle all database-activity in my application, and so
When writing an abstract class, or a class that doesn't get instantiated directly... do
I'm writing a JavaSCript class that has a method that recursively calls itself. Scheduler.prototype.updateTimer

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.