Skip to content

C# loader: class support - failing test first (TDD) #123 - #858

Open
G00dS0ul wants to merge 3 commits into
metacall:developfrom
G00dS0ul:feature/cs-class-support
Open

C# loader: class support - failing test first (TDD) #123#858
G00dS0ul wants to merge 3 commits into
metacall:developfrom
G00dS0ul:feature/cs-class-support

Conversation

@G00dS0ul

Copy link
Copy Markdown
Contributor

Description

First step toward class support in the C# loader (part of #123 — make the C# loader production-ready). This is a Draft / TDD red-first PR: it adds a failing test only, no loader implementation yet, so we can agree on the test shape before I build the reflection layer. CI is expected to fail on the legs that have DotNET.

The new test metacall_csharp_class_test mirrors the non-static class section of metacall_java_test, using the file layout of metacall_csharp_static_class_test. It adds a small class.cs (Counter) that exercises the four things class support needs:

  • constructor — new Counter(5)
  • instance attribute — count == 5
  • instance method — Add(7) == 12
  • static method — Counter.Twice(21) == 42

It goes red because cs_loader_impl_discover() currently registers only top-level functions and never builds a klass, so metacall_class("Counter") returns NULL.

Follow-up PRs (kept intentionally small): interfaces (blocked on the core templates/generics work) and inheritance.

Part of #123 — first of several PRs, so I've deliberately avoided a closing keyword.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality) — red test scaffolding only in this PR
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Documentation update

Checklist:

  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.
  • My changes generate no new warnings.
  • I have added tests/screenshots (if any) that prove my fix is effective or that my feature works.
  • I have tested the tests implicated (if any) by my own code and they pass (make test or ctest -VV -R ). — the new test fails as intended (TDD red); it will pass in the follow-up implementation PR.
  • If my change is significant or breaking, I have passed all tests with ./docker-compose.sh test &> output and attached the output.
  • I have tested my code with OPTION_BUILD_ADDRESS_SANITIZER or ./docker-compose.sh test-address-sanitizer &> output and OPTION_TEST_MEMORYCHECK.
  • I have tested my code with OPTION_BUILD_THREAD_SANITIZER or ./docker-compose.sh test-thread-sanitizer &> output.
  • I have tested with Helgrind in case my code works with threading.
  • I have run make clang-format in order to format my code and my code follows the style guidelines.

@G00dS0ul G00dS0ul changed the title [WIP] C# loader: class support - failing test first (TDD) #123 C# loader: class support - failing test first (TDD) #123 Aug 22, 2026
@@ -0,0 +1,20 @@
public class Counter
{
public int count; // attribute

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static attribute is also needed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in 0065cd4 Counter now has public static int total and the test exercises metacall_class_static_set

/* C# Netcore */
#if defined(OPTION_BUILD_LOADERS_CS)
{
const char* cs_scripts[] = {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you may need to run make clang-format for formatting the c/c++ code

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you use vscode you can add clang plugins to automatically format it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you may need to run make clang-format for formatting the c/c++ code

Done in ffca761 scoped the run to just the two new test sources (clang-format -i on main.cpp and metacall_csharp_class_test.cpp), didn't use make clang-format, to avoid the repo-wide diff

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants