it's seem not support cs enum?

Jul 3, 2014 at 1:01 PM
Edited Jul 3, 2014 at 1:02 PM
it's seem not support cs enum?

only can redefine in Js ?

I just Test in unity3d,but when I add some code
  engine.SetGlobalValue("PrimitiveType", typeof(PrimitiveType));
and js like
GameObject.CreatePrimitive(PrimitiveType.Cube);
and uinity will auto quit..
Feb 4, 2016 at 8:19 PM
Edited Feb 5, 2016 at 2:49 AM
I hope Paul is checking the discussions. In order for the above enum to be exposed in JS, a slight modification have to be made in the ClrStaticTypeWrapper.PopulateMembers method. I propose the following code for handling MemberTypes.Field:
                    case MemberTypes.Field:
                        FieldInfo field = (FieldInfo)member;

                        if ( field.FieldType.IsEnum )
                        {   // enum.
                            target.DefineProperty( field.Name, new PropertyDescriptor( Convert.ToInt32( field.GetValue( null ) ), PropertyAttributes.Enumerable ), false );
                        }
                        else
                        {
                            ClrFunction fieldGetter = new ClrFunction( target.Engine.Function.InstancePrototype, new FieldGetterBinder( field ) );
                            ClrFunction fieldSetter = new ClrFunction( target.Engine.Function.InstancePrototype, new FieldSetterBinder( field ) );
                            target.DefineProperty( field.Name, new PropertyDescriptor( fieldGetter, fieldSetter, PropertyAttributes.NonEnumerable ), false );
                        }

                        break;
Coordinator
Feb 5, 2016 at 2:22 AM
This doesn't look quite right. In your code sample, modifying a non-enum field from JS changes the field value, but modifying an enum field from JS doesn't.
Feb 5, 2016 at 2:38 AM
paulbartrum wrote:
This doesn't look quite right. In your code sample, modifying a non-enum field from JS changes the field value, but modifying an enum field from JS doesn't.
Paul,

Your observation is spot on. The enum is not exactly field, but a constant. Do you have better idea how enums could be supported in JS? I found interesting related post here.
Feb 5, 2016 at 2:50 AM
Paul,

I have made slight fix to the code above. Now the field is no longer allowed to be modified.