c# - Reimplementing Enum.HasFlag for use in Mono 2.6 -



c# - Reimplementing Enum.HasFlag for use in Mono 2.6 -

i'm trying convert jint utilize in mono 2.6. unfortunately mono 2.6 doesn't have enum.hasflag , that's utilize in jint. should add together i'm quite new c#.

according msdn page (http://msdn.microsoft.com/en-us/library/system.enum.hasflag(v=vs.110).aspx) implementation should

thisinstance , flag = flag

but doesn't seem create lot of sense. if these bitwise operations shouldn't more this?

thisinstance & flag == flag

so, line i'm trying modify

writable = !fieldinfo.attributes.hasflag(fieldattributes.initonly);

i've stuck in

var thisinstance = fieldinfo.attributes; var thisflag = fieldattributes.initonly; var hasflag1 = thisinstance & thisflag == thisflag; var hasflag2 = thisinstance , thisflag = thisflag; writable1 = !hasflag1; writable2 = !hasflag2;

and understandably compiler doesn't either of these. hasflag1 get

operator '&' cannot applied operands of type 'system.reflection.fieldattributes' , 'bool'

and hasflag2:

unexpected symbol 'and'

just want know if knows how meant done.

thanks!

it seems based on error of compiler == takes precedence on &. hence line evaluated this: var hasflag1 = thisinstance & (thisflag == thisflag);

what want this:

var hasflag1 = (thisinstance & thisflag) == thisflag;

so if add together parentheses, compiler error should go away.

most and vb equivalent of &

c#

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -