Browse Source

Interfaces for C#

Josh Engebretson 9 years ago
parent
commit
9da3d1df08

+ 12 - 0
Source/ToolCore/JSBind/CSharp/CSFunctionWriter.cpp

@@ -134,6 +134,18 @@ void CSFunctionWriter::WriteNativeFunction(String& source)
     {
     {
         JSBFunctionType* ftype = fparams[i];
         JSBFunctionType* ftype = fparams[i];
 
 
+        // Interface        
+        JSBClass* interface = 0;
+        if (ftype->type_->asClassType() && ftype->type_->asClassType()->class_->IsInterface())
+        {
+            // We need to downcast to the interface 
+            // TODO: this assumes Object* is in hierarchy, how do we validate this?
+            interface = ftype->type_->asClassType()->class_;
+            line = ToString("%s = dynamic_cast<%s*>((Object*)%s);\n", ftype->name_.CString(), interface->GetNativeName().CString(), ftype->name_.CString());
+            source += IndentLine(line);
+        }
+
+        // Vector
         JSBVectorType* vtype = ftype->type_->asVectorType();
         JSBVectorType* vtype = ftype->type_->asVectorType();
 
 
         if (!vtype)
         if (!vtype)

+ 5 - 1
Source/ToolCore/JSBind/CSharp/CSModuleWriter.cpp

@@ -131,7 +131,11 @@ void CSModuleWriter::GenerateNativeSource()
 
 
     WriteIncludes(source);
     WriteIncludes(source);
 
 
-    source += "\n#include <AtomicNET/NETNative/NETCore.h>\n";
+    // NOTE: We include Deserializer/Serializer here as they are interfaces
+    // If additional interfaces are introduced, consider generalizing this
+    source += "\n#include <Atomic/IO/Deserializer.h>\n";
+    source += "#include <Atomic/IO/Serializer.h>\n";
+    source += "#include <AtomicNET/NETNative/NETCore.h>\n";
 
 
     String ns = module_->GetPackage()->GetNamespace();
     String ns = module_->GetPackage()->GetNamespace();