473,725 Members | 2,383 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

I need help with Reflection

Hi all, i have a question about the framework reflection.
I have a project with some pages and a component class file. Inside
this file I've placed some custom objects.
Using the reflection and the Fieldinfo[] class i can look inside my
component and know names and properties of this objects.
My require is to recreate this objects using the informations contained
in the Fieldinfo[] depending by a selection (in my pages i use the
Fieldinfo[].Name to populate a dropdown list).
Can someone help me to do this operation?

Please forgive my english.
TIA

--
Layos

Dec 22 '05 #1
5 1450
Type type = fieldInfo.Refle ctedType;
ConstructorInfo ctor = type.GetConstru ctor(...);
object obj = ctor.Invoke(new object[n] {p1, p2, ... pn};

--
Vadym Stetsyak aka Vadmyst
http://vadmyst.blogspot.com

<gl****@gmail.c om> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .
Hi all, i have a question about the framework reflection.
I have a project with some pages and a component class file. Inside
this file I've placed some custom objects.
Using the reflection and the Fieldinfo[] class i can look inside my
component and know names and properties of this objects.
My require is to recreate this objects using the informations contained
in the Fieldinfo[] depending by a selection (in my pages i use the
Fieldinfo[].Name to populate a dropdown list).
Can someone help me to do this operation?

Please forgive my english.
TIA

--
Layos

Dec 22 '05 #2
Hi Vadym, thank you very much, I'm near the solution, but i have two
questions.
First, fieldinfo[n].ReflectedType match the Type of the Component Class
and not of the Object inside. I try to use fieldinfo[n].FieldType and
it appears to be correct. Is it right?
The second question is: my objects inside the component class have some
properties like "connection string", "query", "parameters " but the
object created at runtime does not appear to mantain them.

Where is my mistake?

FieldInfo[] f;
Type SqbqueriesType = typeof(sqbfilte rs);
f = SqbqueriesType. GetFields(Bindi ngFlags.NonPubl ic |
BindingFlags.In stance | BindingFlags.Pu blic);

DataSet ds = new DataSet();
SQB.SQBDataprov ider sqbdp;

for(int i = 0; i < f.Length; i++)
{
if(f[i].Name == "mysqbprovidert est")
{
Type[] constructorArgs = { typeof(SQB.SQBD ataprovider) };
Type t = f[i].FieldType;
ConstructorInfo c =
t.GetConstructo r(System.Type.E mptyTypes);
Object[] parameter = {};
Object o = c.Invoke(parame ter);
sqbdp = o as SQB.SQBDataprov ider;
sqbdp.Fill(ds);
}
}

"sqbfilter" is the name of Component Class where i instanciate the
SQB.SQBDataprov ider objects.

Thank you very much, I owe your beer ;)

--
Layos

Dec 22 '05 #3
Yes, you're right FieldType is what you need...

There are no values in the runtime object, because you didn't set them. This
can be done via constructor ( you specify parameters for the constructor,
also this assumes that you have appropriate constructor with the same
parameter list).

calling with Object[] parameter = {}; is equivalent to
SQB.SQBDataprov ider obj = new SQB.SQBDataprov ider();

and Object[] par = new object[2] {"connstr", "other"};
is equivalent to
SQB.SQBDataprov ider obj = new SQB.SQBDataprov ider("connstr", "other");

Another way is to set them manually
sqbdp = o as SQB.SQBDataprov ider;
sqbdp.Connectio nString = "somestring ";
etc.

Also after sqbdp = o as SQB.SQBDataprov ider;
you do not check for null, may result in NullRef Exception.

--
Vadym Stetsyak aka Vadmyst
http://vadmyst.blogspot.com

"layos" <gl****@gmail.c om> wrote in message
news:11******** **************@ g49g2000cwa.goo glegroups.com.. .
Hi Vadym, thank you very much, I'm near the solution, but i have two
questions.
First, fieldinfo[n].ReflectedType match the Type of the Component Class
and not of the Object inside. I try to use fieldinfo[n].FieldType and
it appears to be correct. Is it right?
The second question is: my objects inside the component class have some
properties like "connection string", "query", "parameters " but the
object created at runtime does not appear to mantain them.

Where is my mistake?

FieldInfo[] f;
Type SqbqueriesType = typeof(sqbfilte rs);
f = SqbqueriesType. GetFields(Bindi ngFlags.NonPubl ic |
BindingFlags.In stance | BindingFlags.Pu blic);

DataSet ds = new DataSet();
SQB.SQBDataprov ider sqbdp;

for(int i = 0; i < f.Length; i++)
{
if(f[i].Name == "mysqbprovidert est")
{
Type[] constructorArgs = { typeof(SQB.SQBD ataprovider) };
Type t = f[i].FieldType;
ConstructorInfo c =
t.GetConstructo r(System.Type.E mptyTypes);
Object[] parameter = {};
Object o = c.Invoke(parame ter);
sqbdp = o as SQB.SQBDataprov ider;
sqbdp.Fill(ds);
}
}

"sqbfilter" is the name of Component Class where i instanciate the
SQB.SQBDataprov ider objects.

Thank you very much, I owe your beer ;)

--
Layos

Dec 22 '05 #4
Thank you again :)

My requirement is exactly at this node. I'will create a Component Class
in wich my customers drag and drop only a SQBDataprovider object,
configure on it all parameters, and the pages automatically recreate
colones of this object at run time without other configuration and this
clones take them back well formed DataSets with data and structure.
Without any code written by customers.
The problem is, how can i select the right properties in the right
instance of dataprovider knowing the selection on the dropdown list?
Can i put the properties in the Fieldinfo[] array?

Is the right way in your opinion?

Many thanks again. :)

--
Layos

Dec 22 '05 #5
If the code is executed in the runtime, that you will have to introduce some
persistance model ( save properties somewhere e.g. databse ) and when
instantiating you will retrieve them from database.

If it will be a component then it can generate code that will intialize it
with the settings input by users, no reflection.

--
Vadym Stetsyak aka Vadmyst
http://vadmyst.blogspot.com

"layos" <gl****@gmail.c om> wrote in message
news:11******** *************@g 14g2000cwa.goog legroups.com...
Thank you again :)

My requirement is exactly at this node. I'will create a Component Class
in wich my customers drag and drop only a SQBDataprovider object,
configure on it all parameters, and the pages automatically recreate
colones of this object at run time without other configuration and this
clones take them back well formed DataSets with data and structure.
Without any code written by customers.
The problem is, how can i select the right properties in the right
instance of dataprovider knowing the selection on the dropdown list?
Can i put the properties in the Fieldinfo[] array?

Is the right way in your opinion?

Many thanks again. :)

--
Layos

Dec 22 '05 #6

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

Similar topics

1
2399
by: Raveendra M | last post by:
Hi! I am working with ASP.NET application. In my page I am creating one Application Domain and in that domain I am calling my DLL. Using the methods of the dll. And unloading the Application Domain. Till this point it is working fine. My problem is, while web page is open, than I am modifying the dll, and rebuilding. Then it is giving error: "The file 'MyClass.dll' cannot be copied to the run directory. The process cannot access the...
3
1937
by: Sky Sigal | last post by:
I coming unglued... really need some help. 3 days chasing my tail all over MSDN's documentation ...and I'm getting nowhere. I have a problem with TypeConverters and storage of expandableobjects to attributes in tags (think Style tag -> Style object). The problem that I am chasing is: Html side:
4
1585
by: Bill Borg | last post by:
Hello, I've got a simple shared property, e.g. Public Class dbObject Private Const m_ID As String = "ID" Public Shared ReadOnly Property ID() As String Get Return m_ID End Get End Property
5
4578
by: Anders Borum | last post by:
Hello! Whilst refactoring an application, I was looking at optimizing a ModelFactory with generics. Unfortunately, the business objects created by the ModelFactory doesn't provide public constructors (because we do not allow developers to instantiate them directly). Because our business objects are instantiated very frequently, the idea of using reflection sounds like a performance killer (I haven't done any tests on this, but the...
1
1716
by: John Bode | last post by:
I need a way to fake reflection in C++ code that makes as few assumptions about the data types involved as possible. I suspect there is no good answer for what I need to do, but I'll present the case anyway. We have a class that normally registers with another service, which then executes callbacks in our class. Since that other service isn't going to be available for testing for a while, we're simulating it with a simple script-based...
9
3848
by: Kuberan Naganathan | last post by:
Hello all Does anyone know of a good way to use reflection in c++? I don't mean simply using rtti or dynamic casting. I'm talking about java/c# style reflection where an actual instance of an object can be constructed through reflection and method calls can be made via the reflection apis.
0
1434
by: avukovi4 | last post by:
I've created rectangular coordinate system and a triangle movie clip and two buttons by which would like to be able to create a reflected image of the triangle movie clip according to x or y axis. I'm a math teacher so I want to create different geometrical functions with objects. For instance, I've created buttons for rotation, translation and reflection, but DON'T KNOW how to be able to reflect the triangle movie clip according to CURRENT...
1
7110
by: =?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?= | last post by:
I get the above error in some of the ASP.NET web applications on a server, and I need some help figuring out how to deal with it. This is a rather long post, and I hope I have enough details that someone who bothers to read all of it have some pointers. Note, I have posted the stack trace and the code exhibiting the problem further down so if you want to start by reading that, search for +++ Also note that I am unable to reproduce...
0
1699
by: Gustavo Arriola | last post by:
Hola a todos! Estoy intentando ejecutar un método usando Reflection. El código es el siguiente: public static void SoapHandler(Exception Error) { try { Type assemblyType;
6
1971
by: Cralis | last post by:
Hi guys, Someone once said, 'You can do that with reflection'. I can't recall what it was I was trying to do at the time, but then he said, 'Any developer knows what reflection is...'. I kept quiet and smiled. What is reflection!? I have been reading it up, and all I can work out is that it has something to do with Late Binding, and the use of GetType and Type.
0
8878
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8749
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9165
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8079
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6006
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4507
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3216
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2626
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2153
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.