473,857 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How convert a string to a type for use in reflection

Hi all.

Is possible I coerce a value to a determined type informed by a string? See
the sample:
dim obj as Object

obj = SomeConversionT ype(2, "System.Windows .Forms.DockStyl e")

or

obj = SomeConversionT ype("System.Win dows.Forms.Dock Style.Bottom")

?

I need use that because I'm loading and setting an object via reflection,
and for reflection can find the corret Property, I must to inform the exact
value type.

Its possible do that? Or have other way?

[]s
Cesar
Nov 21 '05 #1
2 2243
I think this is what you want:

Imports System.Windows. Forms
....
Dim obj As Object
Dim ds As DockStyle
obj = [Enum].Parse(GetType( DockStyle), "Bottom")
ds = CType(obj, DockStyle)

--
Rob Windsor [MVP-VB]
G6 Consulting
Toronto, Canada
http://msmvps.com/windsor/
"Ronchese" <ro******@smlin fo.com.br> wrote in message
news:u1******** ******@tk2msftn gp13.phx.gbl...
Hi all.

Is possible I coerce a value to a determined type informed by a string?
See
the sample:
dim obj as Object

obj = SomeConversionT ype(2, "System.Windows .Forms.DockStyl e")

or

obj = SomeConversionT ype("System.Win dows.Forms.Dock Style.Bottom")

?

I need use that because I'm loading and setting an object via reflection,
and for reflection can find the corret Property, I must to inform the
exact
value type.

Its possible do that? Or have other way?

[]s
Cesar

Nov 21 '05 #2
Hmm.. no.

More exactly, I need to convert any string informed because I cant wonder
wich type the developer user will put in my xml config file (in my case, I
get from this file to use the reflection). This way, I need to convert the
complete string (for samples, System.String,
System.Windows. Forms.DockingSt yle, System.Drawing. Color, etc)

Cesar

"Rob Windsor [MVP]" <ro************ *****@gmail.com > wrote in message
news:uc******** ******@tk2msftn gp13.phx.gbl...
I think this is what you want:

Imports System.Windows. Forms
....
Dim obj As Object
Dim ds As DockStyle
obj = [Enum].Parse(GetType( DockStyle), "Bottom")
ds = CType(obj, DockStyle)

--
Rob Windsor [MVP-VB]
G6 Consulting
Toronto, Canada
http://msmvps.com/windsor/
"Ronchese" <ro******@smlin fo.com.br> wrote in message
news:u1******** ******@tk2msftn gp13.phx.gbl...
Hi all.

Is possible I coerce a value to a determined type informed by a string?
See
the sample:
dim obj as Object

obj = SomeConversionT ype(2, "System.Windows .Forms.DockStyl e")

or

obj = SomeConversionT ype("System.Win dows.Forms.Dock Style.Bottom")

?

I need use that because I'm loading and setting an object via reflection,
and for reflection can find the corret Property, I must to inform the
exact
value type.

Its possible do that? Or have other way?

[]s
Cesar


Nov 21 '05 #3

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

Similar topics

4
13697
by: muffinman | last post by:
Hello, I try to convert a string (char or string or CString, etc) into an executable function. For example : char sample = "cout << \"sample\""; char setColor = "glColor3f(1.0f, 1.0f, 0.0f);" execute(sample); // my wish is to do this!
2
9354
by: Prabhudhas Peter | last post by:
Hello, Need an easy way to Display the property values of an object (dynamically) ie I need to show the values of an Object in a rich text box. Background : We have a form, with a rich text box, where we want to display the values of any given object (say customer, order etc). We declared (Dim Obj as New Object) and assigned our application object. Now we want to print
7
7826
by: Sky | last post by:
I have been looking for a more powerful version of GetType(string) that will find the Type no matter what, and will work even if only supplied "{TypeName}", not the full "{TypeName},{AssemblyName}" As far as I know yet -- hence this question -- there is no 'one solution fits all', but instead there are several parts that have to be put together to check. What I have so far is, and would like as much feedback as possible to ensure I've...
7
16738
by: groups | last post by:
This is my first foray into writing a generic method and maybe I've bitten off more than I can chew. My intent is to have a generic method that accepts a value name and that value will be returned from the source. My first attempt was as follows; (please ignore that error handling is not present in this example) public T GetValue<T(string objName) { T results;
0
9923
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
9767
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,...
0
10394
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9549
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...
1
7939
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7104
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
5774
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...
0
5967
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4592
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

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.