Deckarep <de******@gmail.comwrote:
I want to be able to pass in a function a string say: "TextBox"
Then I need a way to convert that string representation into a Type
object so i can search through some controls and check their type.
If you pass in the fully-qualified name of the type (including
namespace), you can use Type.GetType. However, be warned that it will
only search mscorlib and the currently executing assembly unless you
*also* provide the assembly details. Look at Type.GetType for more
information. If the types you're interested in are always from the same
assembly, you could use Assembly.GetType.
Then I can do my check: If ( control is type) { //continue }
No, you can't do it like that - you need to use Type.IsAssignableTo (or
a similar method). The right hand operand of "is" is the name of a type
at compile time.
P.S. I would pass in a Type object to begin with into my recursive
call like typeof(TextBox) but my recursive function breaks and claims
that it doesn't have access to protected type member. I have no idea
why this happens.
I'd try to fix that rather than using Type.GetType.
Could you post a short but complete program which demonstrates the
problem?
See
http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog:
http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too