Bladeren bron

[cs] Reflect.fields should only return the fields

Cauê Waneck 10 jaren geleden
bovenliggende
commit
f4e3e2982b
1 gewijzigde bestanden met toevoegingen van 16 en 1 verwijderingen
  1. 16 1
      std/cs/_std/Reflect.hx

+ 16 - 1
std/cs/_std/Reflect.hx

@@ -20,6 +20,7 @@
  * DEALINGS IN THE SOFTWARE.
  * DEALINGS IN THE SOFTWARE.
  */
  */
 import cs.internal.Function;
 import cs.internal.Function;
+import cs.system.reflection.*;
 /*
 /*
  * Copyright (c) 2005, The Haxe Project Contributors
  * Copyright (c) 2005, The Haxe Project Contributors
  * All rights reserved.
  * All rights reserved.
@@ -124,7 +125,7 @@ import cs.internal.Function;
 		} else if (o is System.Type) {
 		} else if (o is System.Type) {
 			return Type.getClassFields( (System.Type) o);
 			return Type.getClassFields( (System.Type) o);
 		} else {
 		} else {
-			return Type.getInstanceFields( (System.Type) o );
+			return instanceFields( (System.Type) o );
 		}
 		}
 	')
 	')
 	public static function fields( o : Dynamic ) : Array<String>
 	public static function fields( o : Dynamic ) : Array<String>
@@ -132,6 +133,20 @@ import cs.internal.Function;
 		return null;
 		return null;
 	}
 	}
 
 
+	private static function instanceFields( c : Class<Dynamic> ) : Array<String>
+	{
+		var c = cs.Lib.toNativeType(c);
+		var ret = [];
+		var bindingFlags:BindingFlags = cast cast(BindingFlags.Public, Int) | cast(BindingFlags.Instance, Int) | cast(BindingFlags.FlattenHierarchy,Int);
+		var mis = c.GetFields(bindingFlags);
+		for (i in 0...mis.Length)
+		{
+			var i = mis[i];
+			ret.push(i.Name);
+		}
+		return ret;
+	}
+
 	@:functionCode('
 	@:functionCode('
 		return f is haxe.lang.Function;
 		return f is haxe.lang.Function;
 	')
 	')