GetObject in .NET c#

  • Thread starter Thread starter Yong Yu
  • Start date Start date
Y

Yong Yu

Dear All,

I have to move my VB code to C#. But I have no idea on the GetObject method
in Vb.

-----------------------------------------
Set dom = GetObject("WinNT://" & domain)
-----------------------------------------

This is easy for VB to get the object by COM monikor interface.

However, what I use the following code to active a object via monikor in c#,
what I got is a OBJECT Type.
----------------------------------------------
Marshal.BindToMoniker("WinNT://" + strDomain); //c# code
----------------------------------------------

Is there any way for me to KNOW the returned object type and case it to the
right type in .net???
Thanks very much!

-yy
 
You shouldn't do this in .NET, the System.DirecotoryServices namespace
contains the classes you are looking for to access the WinNT provider
intetrface.

Willy.
 
Thanks!

I know there is a DirecotoryServices in .net. However, my task is to create
NT user and mailbox, create and update the Exchagne 5.5 Distributed List.
All this requirement have detailed sample in ADSI 2.5 SDK.

I just donot like VB:-) And I want to know how to get the type of a
late-bind interface in .net

thanks very much!

- yy
 
Did you actualy read the docs /samples in msdn?.
The DirectoryServices namespace classes are simple wrappers around ADSI, so
everything what can be done with ADSI can be done using these classes.
ADSI exposes a set of COM interfaces to be consumed by COM clients, the
DirectoryServices classes expose these COM interfaces as .NET managed
classes. When using managed tools like C# you should use the managed classes
(where available) and stay away from COM interop in your code.

Willy.
 
Yong Yu said:
I just donot like VB:-) And I want to know how to get the type of a
late-bind interface in .net

Too bad you don't like VB, because C# doesn't support late binding (and I'm
not just talking about ADSI calls).
In order to deal with late binding, you need to go through the cumbersome
steps of reflection/invokation.
Also note that binding has nothing to do with object creation. In other
words, the use of a function like GetObject does not mean you are
late-binding to an instance.
Invoking members on an object with a type that is unknown until runtime is
late-binding. You can use a function like GetObject with a specificly-typed
reference, and you are early-binding to the instance.
Getting back on track, like the others are pointing out, you should
certainly use the Directory Services classes in .NET (whether you are in VB
or C#).

-Rob Teixeira [MVP]
 
Rob Thanks for your input!

I got this for the late binding
============================================================================
==
object objValue =
Marshal.BindToMoniker(LDAP://OU=OUName,DC=DomainName,DC=com);
Type type = objValue.GetType();
string name = (string)type.InvokeMember("Name",
BindingFlags.Instance | BindingFlags.Public |
BindingFlags.GetProperty,
null,
objValue,
null,
null,
null,
null);
Console.WriteLine(name);
============================================================================
==

BTW, I will goto use the .NET DS, thank you Willy!

- yy
 
Back
Top