It sounds like it should be very simple, but I just don't see a way to make this work.
Type propType = propertyInfo.PropertyType; switch (propType) { case typeof(byte): // Can't do this, 'A constant value is expected' // Do something break; }
I also tried to do
private const byteType = typeof(byte);
and enable it, but this line of code does not compile for the same reason.
So the question is: how to enable the instance Type?
Type
Well, my original answer was wrong. You cannot do this in a type switch (without using when, as indicated, which is terrible for this using, in my opinion). The problem is that Typeit is not a constant, so you cannot use this on a switch.
when
, , Type. if.
if
switch, var when guard:
switch
var
Type propType = propertyInfo.PropertyType; switch (propType) { case var b when b == typeof(byte): // Do something break; }
switch Type, , , .
- TypeCode, :
TypeCode
switch (Type.GetTypeCode(propType)) { case TypeCode.Byte: // Do something break; }
, , TypeCode.
- :
switch (propType.FullName) { case "System.Byte": // Do something break; }
, , , , switch "" System.Byte (.. System.Byte, , .Net).
System.Byte
Source: https://habr.com/ru/post/1016747/More articles:PHP script is automatically called multiple times - javascriptInclude js file in Go template - jqueryIncorrect version of FSharp.Core in Xamarin.Forms project - f #Hibernate upgrade to 5.2 - Session Factory creating and replacing PersistentClass to get entity class properties - javaDrop-down list error, if you click too quickly, the options in the drop-down list remain visible - javascriptActiveRecord 5 всегда выполняет подзапросы отдельно от основного запроса - rubyClear List of Inaccessible Migrations (Symfony 3) - phpSave the video in the gallery and find the path to the video saved in the gallery - iosClient Side Paging Using Microsoft OneDrive API / SDK - office365How to access larvel.env variables inside yourself - phpAll Articles