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

  • Home
  • SEARCH
  • 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 252661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:41:48+00:00 2026-05-11T21:41:48+00:00

I need some help trying to come up with a way to set this

  • 0

I need some help trying to come up with a way to set this line of code using reflection:

this.extensionCache.properties[attribute]
                          = new ExtensionCacheValue((object[]) value);

this.extensionCache is a internal private Field in the base class im inheriting from.

I can get at the extensionCache field with the following code:

FieldInfo field = typeof(Principal).GetField("extensionCache",BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

But I can’t figure out how to call the properties method with a index then set it to a instance of a class that I have no visibility over.

extensionCache is of the following type:

internal class ExtensionCache
{
    private Dictionary<string, ExtensionCacheValue> cache
                   = new Dictionary<string, ExtensionCacheValue>();

    internal ExtensionCache()
    {
    }

    internal bool TryGetValue(string attr, out ExtensionCacheValue o)
    {
        return this.cache.TryGetValue(attr, out o);
    }

    // Properties
    internal Dictionary<string, ExtensionCacheValue> properties
    {
        get
        {
            return this.cache;
        }
    }
}

Here is the Value Class

internal ExtensionCacheValue(object[] value)
{
    this.value = value;
    this.filterOnly = false;
}

If some backgroud helps im trying to extend System.DirectoryServices.AccountManagement.Principal which is where all these methods live.

See Method: ExtensionSet

Thanks for your help.

  • 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-11T21:41:48+00:00Added an answer on May 11, 2026 at 9:41 pm

    First off; reflection to this level is usually a code smell; take care…

    Take it one step at a time; first, we need to get the ExtensionCache:

    FieldInfo field = typeof(Principal).GetField("extensionCache",
        BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
    object extCache = field.GetValue(obj);
    

    Then we need the properties:

    field = extCache.GetType().GetField("properties",
        BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
    IDictionary dict = (IDictionary) field.GetValue(extCache);
    

    you can now use the indexer on dict, with the new value:

    dict[attribute] = ...
    

    The next problem is how to create an ExtensionCacheValue; I assume you don’t have access to this type (as internal)…

    Type type = extCache.GetType().Assembly.GetType(
          "Some.Namespace.ExtensionCacheValue");
    object[] args = {value}; // needed to double-wrap the array
    object newVal = Activator.CreateInstance(type, args);
    ...
    dict[attribute] = newVal;
    

    Any of that help?

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

Sidebar

Related Questions

No related questions found

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.