Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StatusEnum comparison fails because it is not actually an Enum. #376

Closed
jhurdlow opened this issue Jun 30, 2017 · 2 comments
Closed

StatusEnum comparison fails because it is not actually an Enum. #376

jhurdlow opened this issue Jun 30, 2017 · 2 comments

Comments

@jhurdlow
Copy link

Version: 5.5.1

Code Snippet

// This check fails, even when the call status is 'completed':
var incomingCall = CallResource.Fetch(call.CallSid);

if (incomingCall.Status == CallResource.StatusEnum.Completed)) {
	// call is completed
}

// This works:
var incomingCall = CallResource.Fetch(call.CallSid);

if (incomingCall.Status.Equals(CallResource.StatusEnum.Completed)) {
	// call is completed
}

Explanation

One would expect this to work if normal C# enum types were used (value types), the so-called "enums" in this library are actually classes, and thus "==" does a reference comparison. Fetch is creating the .Status value on its result in a way that does not reference the same instance of Status.Enum.Completed exposed by the library; so the camparison fails. While I would prefer to see actual C# enum types used rather than these custom classes, this problematic issue can be worked around by adding '==' and '!=' operators to the StringEnum class. C# developers expect something named 'enum' to be a value type, and this could cause problems in production code (which is how I found the problem).

I have made the appropriate modification, with associated test, if someone is willing to accept a pull request (or I can paste in the code here if you'd prefer).

@jingming
Copy link
Contributor

@jhurdlow Thanks for bringing this up. We have a PR here: #378

@codejudas
Copy link
Contributor

@jhurdlow This is fixed in 5.5.2 and 5.5.3-alpha1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants