Re: Dynamically Creating instances of classes which subclass a com
- From: "Mark R. Dawson" <MarkRDawson@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sat, 12 Nov 2005 23:05:03 -0800
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? :)
>
>
.
- Follow-Ups:
- Re: Dynamically Creating instances of classes which subclass a com
- From: Brett Kelly
- Re: Dynamically Creating instances of classes which subclass a com
- References:
- Re: Dynamically Creating instances of classes which subclass a comman
- From: Brett Kelly
- Re: Dynamically Creating instances of classes which subclass a comman
- Prev by Date: Re: How do I find a string in a text file?
- Next by Date: Merits of using a DAL
- Previous by thread: Re: Dynamically Creating instances of classes which subclass a comman
- Next by thread: Re: Dynamically Creating instances of classes which subclass a com
- Index(es):
Relevant Pages
|