What is the equivalent of "FieldType.IsEnum" in Metro?
-
Sunday, March 04, 2012 7:59 PMOr what is the best way to find out if a FieldType/PropertyType is an enum?
Chris Muench, MVP
All Replies
-
Sunday, March 04, 2012 10:46 PM
Assuming you have a Member? --
if (yourMember is FieldInfo)
Tim Heuer | Program Manager, XAML | http://timheuer.com/blog | @timheuer
(if my post has answered your question, please consider using the 'mark as answer' feature in the forums to help others) -
Sunday, March 04, 2012 10:58 PM
yes, assuming I have a "FieldInfo"
bool tIsEnum=pInfo.FieldType.IsEnum; // (that is the function in regular .NET reflection)
pInfo is a valid FieldInfo I got from "foreach (PropertyInfo pInfo in PropertyInfoArray)"
Chris Muench, MVP
-
Sunday, March 04, 2012 11:24 PM
Can you get to the TypeInfo (GetType().GetTypeInfo()) which I believe has IsEnum (not near my machine right this moment)
Tim Heuer | Program Manager, XAML | http://timheuer.com/blog | @timheuer
(if my post has answered your question, please consider using the 'mark as answer' feature in the forums to help others)- Proposed As Answer by PermanentTan Monday, March 05, 2012 2:04 AM
-
Sunday, March 04, 2012 11:29 PM
Aha! Yes, that works. Looks like this is an extra step necessary in Metro.
Chris Muench, MVP
-
Monday, September 17, 2012 6:35 PM
now there is no GetTypeInfo() anymore.. what to do now to find out if a System.Type is an Enum Type?
Thanks
-
Monday, September 17, 2012 7:59 PMGetTypeInfo is there...I'm not sure why you don't think it is.
Tim Heuer | Program Manager, XAML | http://timheuer.com/blog | @timheuer
(if my post has answered your question, please consider using the 'mark as answer' feature in the forums to help others) -
Tuesday, September 18, 2012 8:58 AM
Hmm..I
've got a Portable Class Library in VS 2012 Pro running in Win 8 Pro (both no preview versions.. dreamspark premium)
while creating i checked: .net4.5 and .net for windows store apps (no silverlight, no phone)thats all..
here is the sample project: http://sdrv.ms/OBRvZu
Thanks
-
Tuesday, September 18, 2012 3:23 PM
For portable libraris you should still be able to use <Type>.GetType().IsEnum.
Tim Heuer | Program Manager, XAML | http://timheuer.com/blog | @timheuer
(if my post has answered your question, please consider using the 'mark as answer' feature in the forums to help others) -
Tuesday, September 18, 2012 4:36 PMnope.. nothing there..
i can see IsArray and so on, but no enum -
Tuesday, September 18, 2012 9:58 PMWeird, I just created a portable class library and did a this.GetType().IsEnum, no problem
Tim Heuer | Program Manager, XAML | http://timheuer.com/blog | @timheuer
(if my post has answered your question, please consider using the 'mark as answer' feature in the forums to help others) -
Wednesday, September 19, 2012 6:36 PMWhich platforms did you choose? maybe its because of the combo .net + store without phone and 360
-
Saturday, September 22, 2012 8:41 AM
I tested a view combinations..
the problem is because of the "store target" .. even if you create a class library for windows store (non portable) you don't have TypeInfo or IsEnum :(
Do you have any other idea?
Thanks!
-
Monday, September 24, 2012 4:03 AM
This works fine in a Store class library (non portable). You need to ensure you are using the extension method:
using System.Reflection; // to get the extension method for GetTypeInfo() var foo = this.GetType().GetTypeInfo().IsEnum;
Tim Heuer | Program Manager, XAML | http://timheuer.com/blog | @timheuer
(if my post has answered your question, please consider using the 'mark as answer' feature in the forums to help others) -
Monday, September 24, 2012 11:59 AM
works!
Thank you!


