473,385 Members | 1,506 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,385 software developers and data experts.

How pass type in as parameter?

I want to something as simple as:

UserControl uctTemp;

But the type will be passed in to the function (which will be an existing
user control like "uctMyUserControl1")

So, how can I pass in the string "uctMyUserControl1" and then somehow dim an
instance of it?

uctMyUserControl1 uctTemp;

Thanks,
Ron
Mar 20 '07 #1
3 2116
Ronald,

Are you sure you want to pass the name of the control to your function,
or the name of the type of the control? If you pass the name of the type of
the control (or a Type instance itself), then you can use reflection to get
the Type (if you pass a string) and then construct an instance of that type
using reflection.

If you pass simply a field name, you could use reflection, but you need
to know the class on which the field is declared as well as the instance
holding it in order to get the instance that you are referring to.

All in all, it's easier to just pass the type to your method, and
construct an instance from there.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Ronald S. Cook" <rc***@westinis.comwrote in message
news:uG*************@TK2MSFTNGP04.phx.gbl...
>I want to something as simple as:

UserControl uctTemp;

But the type will be passed in to the function (which will be an existing
user control like "uctMyUserControl1")

So, how can I pass in the string "uctMyUserControl1" and then somehow dim
an instance of it?

uctMyUserControl1 uctTemp;

Thanks,
Ron


Mar 20 '07 #2
Can you do something like

private void someFunction (object userControl, string userControlType)
{
//code here
}

"Ronald S. Cook" wrote:
I want to something as simple as:

UserControl uctTemp;

But the type will be passed in to the function (which will be an existing
user control like "uctMyUserControl1")

So, how can I pass in the string "uctMyUserControl1" and then somehow dim an
instance of it?

uctMyUserControl1 uctTemp;

Thanks,
Ron
Mar 20 '07 #3
Yup, I was able to figure it out that way.. thanks for the reply.
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote in
message news:eg****************@TK2MSFTNGP06.phx.gbl...
Ronald,

Are you sure you want to pass the name of the control to your function,
or the name of the type of the control? If you pass the name of the type
of the control (or a Type instance itself), then you can use reflection to
get the Type (if you pass a string) and then construct an instance of that
type using reflection.

If you pass simply a field name, you could use reflection, but you need
to know the class on which the field is declared as well as the instance
holding it in order to get the instance that you are referring to.

All in all, it's easier to just pass the type to your method, and
construct an instance from there.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Ronald S. Cook" <rc***@westinis.comwrote in message
news:uG*************@TK2MSFTNGP04.phx.gbl...
>>I want to something as simple as:

UserControl uctTemp;

But the type will be passed in to the function (which will be an existing
user control like "uctMyUserControl1")

So, how can I pass in the string "uctMyUserControl1" and then somehow dim
an instance of it?

uctMyUserControl1 uctTemp;

Thanks,
Ron



Mar 20 '07 #4

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

Similar topics

110
by: Mr A | last post by:
Hi! I've been thinking about passing parameteras using references instead of pointers in order to emphasize that the parameter must be an object. Exemple: void func(Objec& object); //object...
1
by: Dion Heskett | last post by:
How can I pass a Class as a parameter to in a method ? i.e. Private myMethod( string pram1, Classobject as pram2) { Classobject.DataSource = reader; Classobject.DataBind(); }
9
by: Jay Douglas | last post by:
Hello, I am needing to pass a class object (this) by reference to a method in a different class. When I do the following code I get the error (Cannot pass '<this>' as a ref or out argument because...
9
by: Alan Silver | last post by:
Hello, I'm a bit surprised at the amount of boilerplate code required to do standard data access in .NET and was looking for a way to improve matters. In Classic ASP, I used to have a common...
1
by: | last post by:
Hi, I've defined an ObjectDataSource and a parameterized DataSet. I would like it if I could pass the parameter value that describes the query that creates the DataSet as part of a user control...
3
by: Brett | last post by:
I have several classes that create arrays of data and have certain properties. Call them A thru D classes, which means there are four. I can call certain methods in each class and get back an...
5
by: David++ | last post by:
Hi folks, I would be interested to hear peoples views on whether or not 'pass by reference' is allowed when using a Web Service method. The thing that troubles me about pass-by-reference into...
12
by: Fred | last post by:
Is it possible to create a function which will take any number of structures as an argument? For example, what if I wanted depending on the circumstances to pass a structure named astruct, or...
13
by: Francois Appert | last post by:
This post was originally in the C# Corner site, but their server is down. I'd like to see if this group can answer. I program in C++ and am learning C#. The issue is: why should anybody...
5
by: JohnDriver | last post by:
Hi, I am having a form which has a text box and 3 radio buttons. I am using GET method in Ajax to pass the value. I can pass the value of the textbox fine but how to pass the value of radio...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.