473,387 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Creating unknown objects at runtime

Howdy

I need to create an instance of a subclass of one of my classes, but I won't know the name of the subclass until runtime. How can I create an instance of a class when all I have is the class' name in a string

Also, these subclasses will be uploaded to a website (by clients) and used as part of an ASP.NET page, so I need to make sure they don't contain any malicious code. If I was to scan the .cs files for the word System and disallow any files that contain it, would this be enough to stop any harmful code being uploaded and run on the webserver

Cheers
LittleC
Nov 16 '05 #1
1 1775
Hi,

On your first issue user Reflection. Chekc the code below:

Type t = Type.GetType("MyClass");
MyClass obj = (MyClass) Activator.CreateInstance(t);
Second issue, you need to use Code Access Security (search the MSDN - you
will find a lot of material).

hth

Fitim Skenderi

"littlecharva" <an*******@discussions.microsoft.com> wrote in message
news:8D**********************************@microsof t.com...
Howdy,

I need to create an instance of a subclass of one of my classes, but I won't know the name of the subclass until runtime. How can I create an
instance of a class when all I have is the class' name in a string?
Also, these subclasses will be uploaded to a website (by clients) and used as part of an ASP.NET page, so I need to make sure they don't contain any
malicious code. If I was to scan the .cs files for the word System and
disallow any files that contain it, would this be enough to stop any harmful
code being uploaded and run on the webserver?
Cheers,
LittleC

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: ikl | last post by:
When creating a list of objects of the same class, what should be concerned to decide if using "new" or not? Since how many number of the objects are unknown until runtime, probably it is not a...
8
by: Nanda | last post by:
hi, I am trying to generate parameters for the updatecommand at runtime. this.oleDbDeleteCommand1.CommandText=cmdtext; this.oleDbDeleteCommand1.Connection =this.oleDbConnection1;...
1
by: littlecharva | last post by:
Howdy I need to create an instance of a subclass of one of my classes, but I won't know the name of the subclass until runtime. How can I create an instance of a class when all I have is the...
3
by: Just D. | last post by:
Can we deserialize an unknown object? The task is simple - we have many different types of objects stored in ArrayList. We can implement Serialize() method for each object and serialize all...
3
by: Seth | last post by:
I have been trying to create a mock httpcontext for the purpose of unit testing. I have a class, Customer, that uses cookies. I have set it up to be able to take a httpcontext as a parameter in...
5
by: Lars-Erik Aabech | last post by:
Hi! Guess it's my day again.. Tried to deploy a test release of a new asp.net web today, and got a terrible error. The web is running swell on three development computers, but when it's copied...
7
by: John | last post by:
Hi Everyone, I'm having this extremely annoying problem with Internet Explorer 6, giving me an error message saying "unknown runtime error" whenever I try to alter the contents of a <divelement...
31
by: JoeC | last post by:
I have read books and have ideas on how to create objects. I often create my own projects and programs. They end up getting pretty complex and long. I often use objects in my programs they are...
8
by: julia_beresford | last post by:
Hi I need to create the following class at runtime: public class MyCollection : CollectionBase { public void Add(MyItem item) { List.Add(item); }
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.