0

For example, "int" and "Int32" refer to the same type in C#.NET, but when I run var t = Type.GetType("int"); for example, no matching type is found.

The reason I'm wondering is because I'm writing tests that involve extracting the types from URL patterns like "foo/bar/{username:string}/{page:int}".

Ms. Corlib
  • 4,993
  • 4
  • 12
  • 19
  • 1
    There's a small finite number of them...just manually map them. – Servy Jul 25 '16 at 17:12
  • 2
    @Servy Well then where can I find documentation on what exactly these are? And what happens to my code 5 years from now? – Ms. Corlib Jul 25 '16 at 17:15
  • 1
    C# specification has them all: https://msdn.microsoft.com/en-us/library/ms228593.aspx – MarcinJuraszek Jul 25 '16 at 17:15
  • Google could give you that information, or the language specs if you want to go to the source. And realistically the list isn't ever going to change, as C# isn't going to add new reserved words. – Servy Jul 25 '16 at 17:15
  • What's wrong with `{username:String}/{page:Int32}`? – Mr Anderson Jul 25 '16 at 17:29
  • @Servy: note that the aliases defined by the specification aren't the only aliases that might be found in code. It doesn't change the answer (i.e. the aliases are mapped during compilation and aren't available via reflection), but depending on where these "URL patterns" come from, it's possible they would include user-defined aliases as well (e.g. `using MyAlias = MyNamespace.MyRealTypeName;`) – Peter Duniho Jul 25 '16 at 17:37
  • @PeterDuniho Those are file specific, and this isn't in the context of a .cs file, so I wouldn't expect it to apply. If he wants to be able to do that, then, as you said, there's nothing in the language that is going to be able to help him do it. – Servy Jul 25 '16 at 17:40
  • @Servy: you don't know that "this isn't in the context of a .cs file". Unless you've contacted the OP offline, you have no idea where these URLs come from. There's nothing in the question that explains that. Again, it doesn't matter where the aliases come from in terms of whether reflection will provide the types (it won't); but it is important to note that even if one hand-codes a map based on the specification, that won't necessarily address all possible type aliases. – Peter Duniho Jul 25 '16 at 17:47

0 Answers0