public static void ImportType(IScriptable scope, Type type) { if (!type.IsPublic) { return; } if (ScriptRuntime.IsNativeRuntimeType(type)) { return; } // Cannot define 'Object' if (type.Name == "Object") { return; } string [] ns = type.FullName.Split('.'); IScriptable parent = scope; for (int i = 0; i < ns.Length - 1; i++) { IScriptable obj = (parent.Get(ns [i], parent) as IScriptable); if (obj == null) { obj = new BuiltinObject(); parent.Put(ns [i], parent, obj); } parent = obj; } object thisObj = null; if (type.IsEnum) { thisObj = new CliEnum((Enum)Activator.CreateInstance(type)); } else { thisObj = CliType.GetNativeCliType(type); } // Define as toplevel object scope.Put(ns [ns.Length - 1], scope, thisObj); // Define as full qualified name parent.Put(ns [ns.Length - 1], parent, thisObj); }
public static void ImportType(IScriptable scope, Type type) { if (!type.IsPublic) return; if (ScriptRuntime.IsNativeRuntimeType (type)) return; // Cannot define 'Object' if (type.Name == "Object") return; string [] ns = type.FullName.Split ('.'); IScriptable parent = scope; for (int i = 0; i < ns.Length - 1; i++) { IScriptable obj = (parent.Get (ns [i], parent) as IScriptable); if (obj == null) { obj = new BuiltinObject (); parent.Put (ns [i], parent, obj); } parent = obj; } object thisObj = null; if (type.IsEnum) { thisObj = new CliEnum ((Enum)Activator.CreateInstance (type)); } else { thisObj = CliType.GetNativeCliType (type); } // Define as toplevel object scope.Put (ns [ns.Length - 1], scope, thisObj); // Define as full qualified name parent.Put (ns [ns.Length - 1], parent, thisObj); }