c# - Compiler directives for targeting several frameworks using .NET Core -


i have library targeting .net core , net45 @ point on code need use reflection this:

var type = obj.gettype(); var properties = type.getproperties().tolist();  if (type.isprimitive || type.isenum || properties.count == 0)     return new dictionary<string, object> { { unnamed, obj } }; 

now porting library support .net core made new .net core library project, project.json

{   "version": "1.0.0",   "dependencies": {     "wen.logging.abstractions": "1.0.0"   },   "frameworks": {     "net45": {       "frameworkassemblies": {         "system.reflection": "4.0.0.0"       },       "dependencies": {         "newtonsoft.json": "6.0.4",         "nlog": "4.3.5"       }     },     "netstandard1.6": {       "imports": "dnxcore50",       "dependencies": {         "netstandard.library": "1.6.0",         "system.reflection.typeextensions": "4.1.0",         "newtonsoft.json": "8.0.2",         "nlog": "4.4.0-*"       }     }   } } 

added classes , compiler complains type.isprimitive , types.isenum properties thought use compiler directives this:

var type = obj.gettype(); var properties = type.getproperties().tolist();  #if net45      if (type.isprimitive || type.isenum || properties.count == 0)     return new dictionary<string, object> { { unnamed, obj } };  #elif netstandard16  //... code  #endif 

once code inside net45 grayed out (i think because vs seeing .net core) no matter tag set between #elif , #endif grayed. have tried #else , can do:

var typeinfo = type.gettypeinfo(); if(typeinfo.isprimitive || typeinfo.isenum || properties.count == 0)     return new dictionary<string, object> { { unnamed, obj } }; 

however question remains:

what tags should use on code on compiler directives #if target several frameworks on same project/library?

while doing research on .net core came across this question , in accepted answer there in project.json file code caught eye, here snippet:

"frameworks": { "net46": {   "buildoptions": {     "define": [ "net46" ]   } }, 

as can see inside buildoptions there define: [ net46 ] tag can use along #if , #elif directives. if don't know (or there isn't) way refer versions of framework use own.


Comments

Popular posts from this blog

Combining PHP Registration and Login into one class with multiple functions in one PHP file -

Android volley - avoid multiple requests of the same kind to the server? -

magento2 - Magento 2 admin grid add filter to collection -