소스 검색

[cs] Reflect.fields should only return the fields

Cauê Waneck 10 년 전
부모
커밋
f4e3e2982b
1개의 변경된 파일16개의 추가작업 그리고 1개의 파일을 삭제
  1. 16 1
      std/cs/_std/Reflect.hx

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

@@ -20,6 +20,7 @@
  * DEALINGS IN THE SOFTWARE.
  */
 import cs.internal.Function;
+import cs.system.reflection.*;
 /*
  * Copyright (c) 2005, The Haxe Project Contributors
  * All rights reserved.
@@ -124,7 +125,7 @@ import cs.internal.Function;
 		} else if (o is System.Type) {
 			return Type.getClassFields( (System.Type) o);
 		} else {
-			return Type.getInstanceFields( (System.Type) o );
+			return instanceFields( (System.Type) o );
 		}
 	')
 	public static function fields( o : Dynamic ) : Array<String>
@@ -132,6 +133,20 @@ import cs.internal.Function;
 		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('
 		return f is haxe.lang.Function;
 	')