{"id":20806908,"url":"https://github.com/agentgill/reflection","last_synced_at":"2026-02-11T08:04:51.865Z","repository":{"id":152507044,"uuid":"177837711","full_name":"agentgill/reflection","owner":"agentgill","description":null,"archived":false,"fork":false,"pushed_at":"2018-07-27T13:35:44.000Z","size":2,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-18T13:38:35.837Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/agentgill.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-03-26T17:30:06.000Z","updated_at":"2020-03-08T21:26:36.000Z","dependencies_parsed_at":null,"dependency_job_id":"9ee109ab-3418-4452-be9b-ecd4a69641db","html_url":"https://github.com/agentgill/reflection","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agentgill%2Freflection","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agentgill%2Freflection/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agentgill%2Freflection/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agentgill%2Freflection/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/agentgill","download_url":"https://codeload.github.com/agentgill/reflection/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243152875,"owners_count":20244657,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-17T19:28:36.212Z","updated_at":"2026-02-11T08:04:46.841Z","avatar_url":"https://github.com/agentgill.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Apex Reflection Convention\n\nApex lacks native reflection, but it's still semi-possible with a shared convention. This is interesting for ISV and cross namespace applications. We can avoid extension packages and compile-time bindings on invoked code.\n\n### Goals\n\n- Be discoverable\n- Avoid package dependencies\n\n### Introducing StubProvider\n\nDevelopers can achieve cheap reflection in Apex by using the StubProvider system interface as a shared entry point.\n\n```c#\nObject handleMethodCall(\n    Object stub,\n    String method,\n    Type returnType,\n    List\u003cType\u003e argTypes,\n    List\u003cString\u003e argNames,\n    List\u003cObject\u003e argValues\n)\n```\n\nThe class to be executed is instrumented with `handleMethodCall` which delegates to methods made available.\n\n### Discovering Methods\n\n```c#\nType reflector = Type.forName('my_ns.Extension')\nStubProvider impl = (StubProvider)reflector.newInstance();\nList\u003cList\u003cObject\u003e\u003e supportedMethods = impl.handleMethodCall(impl, 'reflect', null, null, null, null);\n```\n\n### Invoking Methods\n\n```c#\nString result = impl.handleMethodCall(impl, 'exampleOne', null, null, null, null);\n```\n\n### Defining Methods\n\n```c#\nglobal class Extension implements StubProvider {\n    \n    /**\n     * Actual method\n     */\n    String exampleOne(String arg1)\n    {\n      return arg1 + arg1;\n    }\n\n    /**\n     * Actual method\n     */\n    Decimal exampleTwo(Decimal arg2)\n    {\n      return arg2 * arg2;\n    }\n\n    /**\n     * Advertises supported methods\n     */\n    List\u003cList\u003cObject\u003e\u003e reflect()\n    {\n        return new List\u003cList\u003cObject\u003e\u003e\n        {\n            new List\u003cObject\u003e{\n                'exampleOne',                 // method\n                String.class,                 // return type\n                new List\u003cType\u003e{String.class}, // arg types\n                new List\u003cString\u003e{'arg1'}      // arg names\n            },\n            new List\u003cObject\u003e{\n                'exampleTwo',                  // method\n                String.class,                  // return type\n                new List\u003cType\u003e{Decimal.class}, // arg types\n                new List\u003cString\u003e{'arg2'}       // arg names\n            }\n        }\n    }\n\n    /**\n     * Dispatches actual methods\n     */\n    global Object handleMethodCall(Object stub, String method, Type returnType, List\u003cType\u003e argTypes, List\u003cString\u003e argNames, List\u003cObject\u003e argValues)\n    {\n       if (method == 'reflect') return this.reflect();\n       if (method == 'exampleOne') return this.exampleOne((String)argValues[0]);\n       if (method == 'exampleTwo') return this.exampleTwo((Decimal)argValues[0]);\n       throw new StringException('method not implemented');\n    }\n    \n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fagentgill%2Freflection","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fagentgill%2Freflection","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fagentgill%2Freflection/lists"}