-
unreachable code
hey all.
i got a problem here, im getting a cs0162 unreachable code
Using NET Framework 2.0.50727
here is the block its coming from,i commented on the line that is unreachable
Code:
public void LabelToAffix(Mobile to, int number, AffixType type, string affix, string args)
{
string message = StringList.CombineArguments(number, args);
MessageType label = MessageType.Label;
if ((type & AffixType.Append) != 0)
message += affix; //unreachable
else
message = affix + message;
if ((type & AffixType.System) != 0)
label = MessageType.System;
to.Send(new AsciiMessage(m_Serial, m_ItemID, label, 0x3B2, 3, "", message));
-
Re: unreachable code
What does AffixType.Append return?
It would appear that the compiler thinks it always returns 0.
Is that the case?
-
Re: unreachable code
If the AffixType is an enum, mark it with the [Flags] attribute and be sure the values are 2's compliment.
Code:
[Flags]
public enum AffixType
{
Append = 1,
System = 2,
Network = 4
}
-
Re: unreachable code
I am not sure if this will resolve your problem but since "&" operator works on "integral types" try casting your variables into one of those, i.e. try:
Code:
if (((int) type & (int) AffixType.Append) != 0)
instead of the if statement that you had before.
Let me know if it worked.
-
Re: unreachable code
You don't need to cast an enum (if that's what this is) to use bitwise operators on it. You don't eevn need to use the Flags attribute, you just need to make sure that each value is a power of 2.
-
Re: unreachable code
I think AffixType.Append = 0 (it could be if it is the first element of enum and you don't specify values like Arjay sugest), than anything & 0 is always 0, which cannot differ from zero, so the condition cannot be satisfied in any way.