Browse files

Initial round of cleanup on Type class

  • Loading branch information...
1 parent b2889b6 commit a310499459995e73516766ae6f091cdffee2db63 @nikhilk committed Aug 26, 2012
Showing with 27 additions and 85 deletions.
  1. +3 −0 docs/History.txt
  2. +0 −61 src/Core/CoreLib/Type.cs
  3. +4 −24 src/Core/CoreScript/TypeSystem/Type.js
  4. +20 −0 tests/CoreLib/TestOOP.htm
View
3 docs/History.txt
@@ -11,6 +11,9 @@ v0.7.6
Window in Script.Web
- Moved SetTimeout, SetInterval and ClearTimeout, ClearInterval from
Window object to Script object in mscorlib.
+ - Removed some methods from Type as part of cleanup (AddHandler,
+ GetProperty, RemoveHandler, SetProperty, IsEnum, IsFlags, IsNamespace,
+ GetInterfaces, Parse)
- Removed window dependency in mscorlib.js
- Debug class now maps directly to console
View
61 src/Core/CoreLib/Type.cs
@@ -44,12 +44,6 @@ public sealed class Type {
}
}
- public static void AddHandler(object instance, string name, Delegate handler) {
- }
-
- public static void AddHandler(Type type, string name, Delegate handler) {
- }
-
public static object CreateInstance(Type type, params object[] arguments) {
return null;
}
@@ -68,22 +62,6 @@ public sealed class Type {
return null;
}
- public static object GetField(object instance, Enum name) {
- return null;
- }
-
- public Type[] GetInterfaces() {
- return null;
- }
-
- public static object GetProperty(object instance, string name) {
- return null;
- }
-
- public static object GetProperty(Type type, string name) {
- return null;
- }
-
public static string GetScriptType(object instance) {
return null;
}
@@ -108,14 +86,6 @@ public sealed class Type {
return false;
}
- public static bool HasProperty(object instance, string name) {
- return false;
- }
-
- public static bool HasProperty(Type type, string name) {
- return false;
- }
-
public static object InvokeMethod(object instance, string name, params object[] args) {
return null;
}
@@ -132,51 +102,20 @@ public sealed class Type {
return false;
}
- public static bool IsEnum(Type type) {
- return false;
- }
-
- public static bool IsFlags(Type type) {
- return false;
- }
-
public static bool IsInterface(Type type) {
return false;
}
- public static bool IsNamespace(object obj) {
- return false;
- }
-
public bool IsInstanceOfType(object instance) {
return false;
}
- public static Type Parse(string s) {
- return null;
- }
-
- public static void RemoveHandler(object instance, string name, Delegate handler) {
- }
-
- public static void RemoveHandler(Type type, string name, Delegate handler) {
- }
-
public static void SetField(object instance, string name, object value) {
}
- public static void SetField(object instance, Enum name, object value) {
- }
-
public static void SetField(Type type, string name, object value) {
}
- public static void SetProperty(object instance, string name, object value) {
- }
-
- public static void SetProperty(Type type, string name, object value) {
- }
-
[EditorBrowsable(EditorBrowsableState.Never)]
public static Type GetTypeFromHandle(RuntimeTypeHandle typeHandle) {
return null;
View
28 src/Core/CoreScript/TypeSystem/Type.js
@@ -139,10 +139,6 @@ Type.prototype.get_name = function#? DEBUG Type$get_name##() {
return fullName;
}
-Type.prototype.getInterfaces = function#? DEBUG Type$getInterfaces##() {
- return this.__interfaces;
-}
-
Type.prototype.isInstanceOfType = function#? DEBUG Type$isInstanceOfType##(instance) {
if (ss.isNullOrUndefined(instance)) {
return false;
@@ -186,24 +182,12 @@ Type.prototype.isAssignableFrom = function#? DEBUG Type$isAssignableFrom##(type)
return false;
}
-Type.isClass = function#? DEBUG Type$isClass##(type) {
- return (type.__class == true);
-}
-
-Type.isEnum = function#? DEBUG Type$isEnum##(type) {
- return (type.__enum == true);
-}
-
-Type.isFlags = function#? DEBUG Type$isFlags##(type) {
- return ((type.__enum == true) && (type.__flags == true));
-}
-
-Type.isInterface = function#? DEBUG Type$isInterface##(type) {
- return (type.__interface == true);
+Type.isClass = function#? DEBUG Type$isClass##(obj) {
+ return (obj.__class == true);
}
-Type.isNamespace = function#? DEBUG Type$isNamespace##(object) {
- return (object.__namespace == true);
+Type.isInterface = function#? DEBUG Type$isInterface##(obj) {
+ return (obj.__interface == true);
}
Type.canCast = function#? DEBUG Type$canCast##(instance, type) {
@@ -249,7 +233,3 @@ Type.getType = function#? DEBUG Type$getType##(typeName) {
}
return type;
}
-
-Type.parse = function#? DEBUG Type$parse##(typeName) {
- return Type.getType(typeName);
-}
View
20 tests/CoreLib/TestOOP.htm
@@ -24,6 +24,12 @@ <h2 id="qunit-userAgent"></h2>
QUnit.equal(Type.isClass(Test.More.Comic), true, 'Expectd Comic to be a class');
});
+test('isInteface', function() {
+ QUnit.equal(Type.isInterface(Test.Cat), false, 'Did not expect Cat to be an interface');
+ QUnit.equal(Type.isInterface(Test.IPet), true, 'Expected IPet to be an interface');
+ QUnit.equal(Type.isInterface(Test.More.Comic), false, 'Did not expect Comic to be an interface');
+});
+
test('isAssignableFrom', function() {
QUnit.equal(Test.Animal.isAssignableFrom(Test.Cat), true, 'Cat should be assignable to an Animal');
QUnit.equal(Test.IMammal.isAssignableFrom(Test.Cat), true, 'Cat should be assignable to an IMammal');
@@ -88,5 +94,19 @@ <h2 id="qunit-userAgent"></h2>
QUnit.equal(Type.getInstanceType(c).get_name(), 'Comic', "Expected 'Comic' for type name.");
QUnit.equal(Type.getInstanceType(c).get_fullName(), 'Test.More.Comic', "Expected 'Test.More.Comic' for type name.");
});
+
+test('getType', function() {
+ var t1 = Type.getType('String');
+ var t2 = Type.getType('ss.StringBuilder');
+ var t3 = Type.getType('Test.Garfield');
+ var t4 = Type.getType('Test.More.Comic');
+ var t5 = Type.getType('Test.Foo');
+
+ QUnit.equal(t1, String, "Expected String type.");
+ QUnit.equal(t2, ss.StringBuilder, "Expected StringBuilder type.");
+ QUnit.equal(t3, Test.Garfield, "Expected Garfield type.");
+ QUnit.equal(t4, Test.More.Comic, "Expected Comic type.");
+ QUnit.equal(t5, null, "Expected null type.");
+});
</script>
</html>

0 comments on commit a310499

Please sign in to comment.