Re: Dynamically Creating instances of classes which subclass a com

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



Hi Brett,
looking at your code it looks like your problem is in your variable
definitions which are not the same as the constructor, hence the class you
are trying to create and the variables you are passing do not match:

> string fname = "foobar.txt";
> string target = @"C:\";
> string execargs = "";

the execargs is an array of strings in your exe class constructor not a
string, it should be:

string[] execargs = new string[]{};

also you are going to have problems with your properties, in the set methods
you are not assigning to a variable, you are just calling the property
recursively and it will cause a stack overflow, your code is like:

public class Sql : File
{

public override string Filename
{
get { return this.Filename; }
set { this.Filename = value; }
}

The filename is calling itself in an infinite recursive state.

Hope that helps
Mark
http://www.markdawson.org



"Brett Kelly" wrote:

> OK, I'm looking at that now, but the problem is that the constructor
> takes parameters and I'm having a hell of a time figuring out how to
> pass them. I figured i could use the overload that took a Type arg and
> an object array representing the constructor parameters, but that's not
> working either. Here's what I've got:
>
> private void button1_Click(object sender, System.EventArgs e)
> {
> string fname = "foobar.txt";
> string target = @"C:\";
> string execargs = "";
>
> object[] targs = new object[] {fname,target,execargs};
>
> Assembly a = Assembly.Load("FilePusherFramework");
> Type[] types = a.GetTypes();
>
>
> foreach(Type t in types)
> {
> if(t.IsSubclassOf(typeof(FilePusherFramework.FileTypes.File)))
> {
> FilePusherFramework.FileTypes.File i =
> (FilePusherFramework.FileTypes.File)Activator.CreateInstance(t,targs);
> textBox1.Text += "Type Extension: " + i.TypeExt +
> Environment.NewLine;
> }
> }
> }
>
> this code throws a MemberNotFound exception.
>
> Mark - thanks for the reply!
>
> Any other ideas? :)
>
>
.



Relevant Pages

  • Re: creating/copying files..
    ... Mark Thomas wrote: ... You need to realise that there is a difference between creating a File object, which is what the constructor does, and creating an actual File on your computer. ... I now have a file object in memory which will eventually 'represent' a file on the hard disc. ...
    (comp.lang.java.help)
  • Re: creating/copying files..
    ... > Mark Thomas wrote: ... >> create, say a FileWriter passing this File object to the constructor, you ... > pass this File Obj to constructor when creating the file... ... Frances ...
    (comp.lang.java.help)
  • Re: [uml-devel] [PATCH 5/6] slab: Annotate slab
    ... On Wed, Sep 3, 2008 at 6:42 PM, Steve VanDeBogart ... We can't mark all of them as initialized ... initialize all the bytes of an object). ... run the constructor on the memory region. ...
    (Linux-Kernel)
  • Re: Question concerning object-oriented programming
    ... If at the end of the constructor the ... inspectof the state fails to verify key assertions, ... should mark themselves Unusable and thereafter all procedures should ...
    (comp.programming)
  • Re: Is this a bug in the java compiler?
    ... AFAIK this should be forbidden (super ... should be the first instruction to execute in the constructor.) ... like constructor parameters, are available at this time and are not ...
    (comp.lang.java.programmer)