First off - thanks for the insight.
I am coming to C# from a PowerShell/scripting background rather than OO -
which might explain where my thought processes are at
I am constructing a class which I can use to pull information from Active
Directory using the DirectoryServices namespace. I want to use dynamic
properties for the search filter and propertiesToLoad. The return type is
System.DirectoryServices.SearchResult (the AD Object I'm after) which
contains one or more ResultPropertyCollection (multivalue properties).
I want to obscure the complexity of the SearchResult by converting the
ResultPropertyCollection(s) to single valued value types such that the final
return object has a set of simple properties to make asp.net data control
binding easy - and I wan't to do that without knowing which properties will
be returned.
Currently I have a class which defines a template for the return object
within which I do the type conversion (so I shoe horn the SearchResult into
a custom object with a set of predefined properties) - This will do for now
but it doesn't make the code very resilient to change - or nice to look at.
I am sure there is an easier way to do this! - I haven't looked at the
dictionary approach yet...
Cheers!
Neil
Ciaran O''Donnell said:
This isnt a simple thing to do in C# as it isnt a dynamic language. You
would
need to use the classes in the Reflection.Emit language to build the
class.
This is complex stuff and I havent found a need to ever do it.
Google Reflection.Emit and you should come up with some answers
If you want, let us know what you are trying to acheive in terms of the
big
picture as there might be and easier way
--
Ciaran O''Donnell
http://wannabedeveloper.spaces.live.com
Neil Chambers said:
I would like to pass an array of strings to an object and have the object
members built using the array items as property names. How would I go
about
doing this?
Example:
public class myDynamicObject
{
public myDynamicObject(string[] memberNames)
{
foreach (string s in memberNames)
{
//make s a public property of the object
//assign a value to s
}
}
}
Many thanks!
neil