Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Applying Object values to another object dynamically

Applying Object values to another object dynamically

Scheduled Pinned Locked Moved C#
questiondatabasevisual-studiohelptutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    shwaguy
    wrote on last edited by
    #1

    -I am querying MS AD Objects and want to transfer the properties to my own object with as little code as possible. -I know that there are other ways around this like creating an XLM table to store values but think that might be too much overhead. -If I cannot do something like what is below I will have to write a line for each propertry I want to retrieve. -If I simply copy(not sure how to do this, I dont want to keep running the query) the object I will not be able to see a list of available properties in my IDE.: Any comments or help? Class MyClass { private string cn; private string sn; public void GetADObjectInfo(string dn) { DirectoryEntry entry = new DirectoryEntry("LDAP://"+ dn); foreach (string strAttrName in entry.Properties.PropertyNames) { try { //this is the part I want done dynamically this.strAttrName = (string)result.Properties[strAttName][0]; } catch { } } } } with Regards, shwa guy

    E 1 Reply Last reply
    0
    • S shwaguy

      -I am querying MS AD Objects and want to transfer the properties to my own object with as little code as possible. -I know that there are other ways around this like creating an XLM table to store values but think that might be too much overhead. -If I cannot do something like what is below I will have to write a line for each propertry I want to retrieve. -If I simply copy(not sure how to do this, I dont want to keep running the query) the object I will not be able to see a list of available properties in my IDE.: Any comments or help? Class MyClass { private string cn; private string sn; public void GetADObjectInfo(string dn) { DirectoryEntry entry = new DirectoryEntry("LDAP://"+ dn); foreach (string strAttrName in entry.Properties.PropertyNames) { try { //this is the part I want done dynamically this.strAttrName = (string)result.Properties[strAttName][0]; } catch { } } } } with Regards, shwa guy

      E Offline
      E Offline
      eggsovereasy
      wrote on last edited by
      #2

      public class MyClass {   private readonly Dictionary properties = new Dictionary();   public string this[string name]   {     get { return properties[name]; }     set     {       if (properties.ContainsKey(name))         properties[name] = value;       else         properties.Add(name, value);     }   }   public void GetADObjectInfo(string dn)   {     DirectoryEntry entry = new DirectoryEntry("LDAP://" + dn);     foreach (string strAttrName in entry.Properties.PropertyNames)     {       this[strAttrName] = entry.Properties[strAttrName][0] as string;     }   } } Then access it like: string myString = MyClass["PropertyName"]; But you can't get it strongly typed (MyClass.PropertyName) without doing it one at a time I think.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups