Re: Creating object from type

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: R.Balaji (rbalaji007_at_hotmail.com)
Date: 04/07/04


Date: Wed, 7 Apr 2004 19:12:50 +0530

Hi,

Yes. You can.

If you want to manipulate the dynamically created objects, then you need to
have reference to them.

To do that either you can go for Interfaces and Classes.

eg)

using System;

using System.Reflection;

namespace sampleNamespace

{

public class Class1

{

public Class1()

{

Assembly sampleAssembly = Assembly.LoadFrom(@"c:\\sample.dll");

ISample sampleObj =
sampleAssembly.CreateInstance("sampleNameSpace.SampleClass");

sampleObj.sampleMethod(1);

}

}

}

Regards,

R.Balaji

"Irfan" <gowani009@yahoo.com> wrote in message
news:eeZy6OKHEHA.2224@TK2MSFTNGP12.phx.gbl...
> Hi all
> I am new to DotNet and C#
>
> Is there any way to get a type of object from a string. Lets suppose i
have
> a string variable containing a type "MyNameSpace.MyComponent" where
> MyComponent.dll is already been referenced in the client project.
>
> Now i want to create any object from that string. I think this require
> getting a type from that string and then creating object from that type.
If
> this or any alternative is possible, pls let me know with a little
example.
>
> Regards,
> Irfan
>
>
>
>
>



Relevant Pages

  • Re: Pass by reference or value?
    ... The method or constructor can *always* manipulate any object it ... String or other so-called immutable classes; ... There are other immutable classes as well as String, ... a new reference to the object is created and put on the ...
    (comp.lang.java.programmer)
  • Re: programming concepts > specific languages
    ... When you pass a reference, you are "passing by reference", if the term ... However I can manipulate either the reference or ... The latter is what you implied was happening in your Java example. ... If you had used an object other than a string, ...
    (comp.programming)
  • Re: can you return an object from a proc?
    ... a reference which you ... then use to manipulate the object. ... object creation call uses that string to reference the ... This sort of thing is why many OO systems for Tcl allow you to create ...
    (comp.lang.tcl)
  • Re: Complex Specified Information - Pitman Formula
    ... Therefore a significant match between a reference and a test ... string is good evidence of non-random production. ... and there are no finite algorithms to compute their digits. ... probabilities of the different symbols the information source can produce. ...
    (talk.origins)
  • Re: String Reference Type
    ... All unary and binary operators have predefined implementations that are ... Therefore its always allocated in the heap and a variable of string ... As with all classes in this case y and x both reference the same String ... language depandant matter as below. ...
    (microsoft.public.dotnet.framework.aspnet)