mgusmano / sharpkit

Automatically exported from code.google.com/p/sharpkit
0 stars 0 forks source link

Default values for enum members not set from constructor #162

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

Given this enum and class:

public enum Manufacturer {Audi,BMW};
public class Car
{
   public Manufacturer Manufacturer {get;set;}
}

I run this code
var car = new Car();
var result = car.Manufacturer == Manufacturer.Audi;

The manufacturer should be audi by default but it is undefined.

Please use labels and text to provide additional information.

Original issue reported on code.google.com by mmuur...@gmail.com on 29 Jun 2012 at 9:56

GoogleCodeExporter commented 8 years ago

Original comment by DanelK...@gmail.com on 30 Jun 2012 at 11:08

GoogleCodeExporter commented 8 years ago
There's a similar issue if you use the default() keyword

[JsType(JsMode.Clr, Filename = "res/Default.js")]
enum Values
{
   First,
   Second,
   Third
}
var valuesDefault = default(Values);
var valuesFirst = Values.First;
var intDefault = default(int);

new jQuery("body").append("valuesDefault " + valuesDefault + "<br/>");
new jQuery("body").append("valuesFirst " + valuesFirst + "<br/>");
new jQuery("body").append("intDefault " + intDefault + "<br/>");

Which results in:

valuesDefault null
valuesFirst First
intDefault 0

If you're deep into generic code it's useful to be able to default up values 
and hard to work around in a generic manner.

/*Generated by SharpKit 5 v5.01.0000*/

Original comment by co...@gravill.com on 3 May 2013 at 3:05

GoogleCodeExporter commented 8 years ago
From my test, it seems that enum values are generated in constructors, is the 
first issue still relevant?

Original comment by DanelK...@gmail.com on 3 May 2013 at 3:17

GoogleCodeExporter commented 8 years ago
The default keyword with enum bug is confirmed, it's a parser issue, I'll try 
to patch it in the meantime

Original comment by DanelK...@gmail.com on 3 May 2013 at 3:26

GoogleCodeExporter commented 8 years ago
I didn't test the constructor, just tagged on my own issue which looked similar.

Original comment by co...@gravill.com on 3 May 2013 at 3:31

GoogleCodeExporter commented 8 years ago
Ok, issue is fixed, but it's best to always open new issues, we can merge them 
afterwards if they're exactly the same. :-)

Original comment by DanelK...@gmail.com on 3 May 2013 at 3:32