c# - How to enforce parameter with [CallerLineNumber] to be read only? -
[callerlinenumber]
great language feature. i'm using automatically order class properties declaration order. when user calls function or constructor parameter, user able feed value it, beats purpose of auto-generation. currently, have name parameter _donotset
, hint caller not set parameter.
how can forcefulness read only, or better, hide function signature?
the other thought had mark parameter [obsolete]
using compiler warn. unfortunately, obsoleteattribute
not targeted parameter, can't mark parameter so.
i surprised compiler doesn't override value passed in calling function. anyway, accepting unfortunate behavior don't think there going can guarantee no 1 break that.
as far aware, closest come have done. name _donotset
suggest _settingthisbreaksthetool
. depending on audience of code may plenty satisfy needs.
edit: link shows how determine if value supplied or not, unfortunately none of tactics supplied there going work you. suggest using known unlikely value (impossible in case since won't know line number or wouldn't care). or don't utilize default values , overload function. [callerlinenumber]
attribute needs parameter optional work. bugger.
come on microsoft... why
this goes how .net implements default values optional parameters. when specify parameter optional on function, , phone call function no value quite special happens during compilation. code not have value parameter replaced code does have value, default value.
i read few blog posts on awhile ago, this simplest understand basics.
i may making few jumps here guess [callerlinenumber]
attribute signals compiler utilize different value, namely line number. but compiler won't go through process inject values since there value in first place.
probably microsoft [callerlinenumber]
override value passed function, side impact of piggybacking default values caused them not able back upwards that. interesting see if roslyn project brings enhancements function.
c# .net
No comments:
Post a Comment