digitalmars.D.learn - Check whether string value represents a type
- Timoses (20/20) Jul 21 2017 I'd love to check whether a string value is the name of a type at
- Steven Schveighoffer (6/34) Jul 21 2017 In order to do this, the list of types must be stored somewhere to
- Timoses (6/43) Jul 23 2017 Thanks Steve!
- Basile B. (7/15) Jul 24 2017 I used custom Runtime Type Infos for this:
- Timoses (2/18) Jul 24 2017 Awesome, that's helping a lot : D.
I'd love to check whether a string value is the name of a type at run-time. E.g.: string a = "int"; string b = "im no type"; assert( isStringType(a) ); assert( !isStringType(b) ); or struct TestStruct { int test; } string t = "TestStruct"; assert( isStringType(t) ); Is anything like this possible? The goal is to identify whether a string represents a custom type within a package. I'm also trying to iterate over all modules within the package to get the struct name. However, that seems like a struggle... Any ideas?..
Jul 21 2017
On 7/21/17 10:21 AM, Timoses wrote:I'd love to check whether a string value is the name of a type at run-time. E.g.: string a = "int"; string b = "im no type"; assert( isStringType(a) ); assert( !isStringType(b) ); or struct TestStruct { int test; } string t = "TestStruct"; assert( isStringType(t) ); Is anything like this possible? The goal is to identify whether a string represents a custom type within a package. I'm also trying to iterate over all modules within the package to get the struct name. However, that seems like a struggle... Any ideas?..In order to do this, the list of types must be stored somewhere to compare with at runtime. At this time, this is not done. You could potentially do this with the RTInfo template, but it would have to be part of a custom druntime. -Steve
Jul 21 2017
On Friday, 21 July 2017 at 14:44:23 UTC, Steven Schveighoffer wrote:On 7/21/17 10:21 AM, Timoses wrote:Thanks Steve! That's sound too much of a strugge for a newbie like me : D. I'll probably evaluate and compare the type names as strings then and derive further processing from there.I'd love to check whether a string value is the name of a type at run-time. E.g.: string a = "int"; string b = "im no type"; assert( isStringType(a) ); assert( !isStringType(b) ); or struct TestStruct { int test; } string t = "TestStruct"; assert( isStringType(t) ); Is anything like this possible? The goal is to identify whether a string represents a custom type within a package. I'm also trying to iterate over all modules within the package to get the struct name. However, that seems like a struggle... Any ideas?..In order to do this, the list of types must be stored somewhere to compare with at runtime. At this time, this is not done. You could potentially do this with the RTInfo template, but it would have to be part of a custom druntime. -Steve
Jul 23 2017
On Friday, 21 July 2017 at 14:21:37 UTC, Timoses wrote:I'd love to check whether a string value is the name of a type at run-time. [...] The goal is to identify whether a string represents a custom type within a package. I'm also trying to iterate over all modules within the package to get the struct name. However, that seems like a struggle... Any ideas?..I used custom Runtime Type Infos for this: https://github.com/BBasile/iz/blob/master/import/iz/rtti.d#L550 Each type for which that's interesting to have extra information is registered. When a type is not registered than it can be considered as not a type.
Jul 24 2017
On Monday, 24 July 2017 at 07:08:56 UTC, Basile B. wrote:On Friday, 21 July 2017 at 14:21:37 UTC, Timoses wrote:Awesome, that's helping a lot : D.I'd love to check whether a string value is the name of a type at run-time. [...] The goal is to identify whether a string represents a custom type within a package. I'm also trying to iterate over all modules within the package to get the struct name. However, that seems like a struggle... Any ideas?..I used custom Runtime Type Infos for this: https://github.com/BBasile/iz/blob/master/import/iz/rtti.d#L550 Each type for which that's interesting to have extra information is registered. When a type is not registered than it can be considered as not a type.
Jul 24 2017