void CSClassWriter::GenerateManagedSource(String& sourceOut) { String source = ""; if (klass_->IsNumberArray()) return; Indent(); source += "\n"; String line; if (klass_->GetDocString().Length()) { // monodocer -assembly:NETCore.dll -path:en -pretty // mdoc export-html -o htmldocs en source += IndentLine("/// <summary>\n"); if (klass_->GetDocString().Contains('\n')) source += IndentLine("/* " + klass_->GetDocString() + "*/\n"); else source += IndentLine("/// " + klass_->GetDocString() + "\n"); source += IndentLine("/// </summary>\n"); } if (klass_->GetBaseClass()) { String baseString = klass_->GetBaseClass()->GetName(); const PODVector<JSBClass*>& interfaces = klass_->GetInterfaces(); if (interfaces.Size()) { StringVector baseStrings; baseStrings.Push(baseString); for (unsigned i = 0; i < interfaces.Size(); i++) { baseStrings.Push(interfaces.At(i)->GetName()); } baseString = String::Joined(baseStrings, ","); } line = ToString("public partial class %s%s : %s\n", klass_->GetName().CString(), klass_->IsGeneric() ? "<T>" : "", baseString.CString()); } else { String classString = "class"; if (klass_->IsInterface()) classString = "interface"; line = ToString("public partial %s %s%s\n", classString.CString(), klass_->GetName().CString(), klass_->IsGeneric() ? "<T>" : ""); } source += IndentLine(line); source += IndentLine("{\n"); Indent(); WriteManagedProperties(source); JSBPackage* package = klass_->GetPackage(); // CoreCLR has pinvoke security demand code commented out, so we do not (currently) need this optimization: // https://github.com/dotnet/coreclr/issues/1605 // line = "[SuppressUnmanagedCodeSecurity]\n"; // source += IndentLine(line); if (!klass_->IsInterface()) { line = "[DllImport (Constants.LIBNAME, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]\n"; source += IndentLine(line); line = ToString("public static extern IntPtr csb_%s_%s_GetClassIDStatic();\n", package->GetName().CString(), klass_->GetName().CString()); source += IndentLine(line); source += "\n"; } Dedent(); // managed functions CSFunctionWriter::SetWroteConstructor(false); for (unsigned i = 0; i < klass_->functions_.Size(); i++) { JSBFunction* function = klass_->functions_.At(i); if (function->Skip()) continue; if (klass_->IsInterface() && function->IsConstructor()) continue; if (function->IsDestructor()) continue; if (CSTypeHelper::OmitFunction(function)) continue; CSFunctionWriter fwriter(function); fwriter.GenerateManagedSource(source); } // There are some constructors being skipped (like HTTPRequest as it uses a vector of strings in args) // Make sure we have at least a IntPtr version if (!klass_->IsInterface() && !CSFunctionWriter::GetWroteConstructor() && klass_->GetName() != "RefCounted") { ATOMIC_LOGINFOF("WARNING: %s class didn't write a constructor, filling in generated native constructor", klass_->GetName().CString()); line = ToString("public %s (IntPtr native) : base (native)\n", klass_->GetName().CString()); source += IndentLine(line); source += IndentLine("{\n"); source += IndentLine("}\n\n"); } CSFunctionWriter::SetWroteConstructor(false); source += IndentLine("}\n"); Dedent(); sourceOut += source; }
void ShaderLibFile::SaveToFile(CoreLib::Basic::String fileName) { StreamWriter fwriter(fileName); fwriter.Write(ToString()); }