Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
CreateObject
Message
De
12/04/2006 16:30:41
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Titre:
Divers
Thread ID:
01112449
Message ID:
01113155
Vues:
17
This message has been marked as the solution to the initial question of the thread.
Is there another type called manageftp? Even if there is why are you casting there when you want an object.
You want late binding w/o adding any reference, right?
using System.Reflection;
//...
 Type t = Type.GetTypeFromProgID("VisualFoxpro.Application");
 object oApp = Activator.CreateInstance(t);
 string VFPversion =
       (string)oApp.GetType().InvokeMember("eval", 
        BindingFlags.InvokeMethod, null, oApp, new object[1] { "Version()" });
Cetin


>
>Type t = Type.GetTypeFromProgID("ftpmanager.manageftp","localhost");
>object FTPMan = (manageftp)Activator.CreateInstance(t);
>
>
>In the above scenario the compiler does not understand that the type ftpmanager.manageftp is the type that FTPMan needs to be. It fails to compile and says I am missing an assembly reference. In this case I don't want to use an assembly reference, I want .net to create this type on the fly without a compiled Interop assembly. I also need the compiler to understand this type's members so I can build code to call methods on that type in other places in my class.
>
>I think I need to brush up on reflection. ;P
>
>>Eric,
>>
>>I may be misunderstanding what you want to do, but it sounds like you just want to cast the object to the correct type (I'm assuming, maybe incorrectly, that you know what that type should be?)
>>
>>Type t = Type.GetTypeFromProgID(cProdID)
>>MyBaseObject MyClass = (MyBaseObject)Activator.CreateInstance(t)
>>
>>
>>~~Bonnie
>>
>>
>>>In this case I want to create an object from a registered VFP DLL. But not referenced as an Interop Assembly. I need VFP objects available in a windows service app. I want to pause the service, rebuild my DLLs then continue the service. This works fine if I re-add the reference in the service project and rebuild the service but it's not practical to do that. I tried this:
>>>
>>>Type t = Type.GetTypeFromProgID(cProdID)
>>>object MyClass = Activator.CreateInstance(t)
>>>
>>>The trouble is the IDE doesn't recognize the typeof Myclass until runtime. It only sees typeof object not the type represented in cProgID.
>>>
>>>I think I need to declare MyClass as the typeof(cProgID) but i'm having trouble with the syntax.
>>>
>>>Thanks,
>>>
>>>-E
>>>
>>>
>>>
>>>
>>>>>Does anyone have a preferred way to create an object from a registered server?
>>>>>
>>>>>What is the equivalent of CreateObject in C#?
>>>>
>>>>new
>>>>
>>>>Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform