Developing RCaron modules
Getting started
Create a new class library project targeting .NET 7. This guide goes along with the name
ClassLibrary2
, so remember to change that from the examples.Install the
RCaron
andRCaron.LibrarySourceGenerator
packagesAdd a partial class that inherits from
RCaron.IRCaronModule
and has theModule
attribute:csharpusing RCaron;using RCaron.LibrarySourceGenerator;namespace ClassLibrary2;[Module("hello")]public partial class HelloModule : IRCaronModule{[Method("Hello")]public void Hello(Motor _, string name){Console.WriteLine($"Hello, {name}!");}}csharpusing RCaron;using RCaron.LibrarySourceGenerator;namespace ClassLibrary2;[Module("hello")]public partial class HelloModule : IRCaronModule{[Method("Hello")]public void Hello(Motor _, string name){Console.WriteLine($"Hello, {name}!");}}Build the project
Import the module in RCaron:
rcaron// importing is currently kind of hell$ass = #System.Reflection.Assembly:LoadFrom('/path/to/ClassLibrary2.dll');$current_motor.MainFileScope.Modules.Add(#ClassLibrary2.HelloModule:new());Hello 'World';rcaron// importing is currently kind of hell$ass = #System.Reflection.Assembly:LoadFrom('/path/to/ClassLibrary2.dll');$current_motor.MainFileScope.Modules.Add(#ClassLibrary2.HelloModule:new());Hello 'World';
Consuming pipeline input
To accept pipeline input, add a parameter with the FromPipeline
attribute:
csharp
[Method("Hello")]public void Hello(Motor _, [FromPipeline] string name){Console.WriteLine($"Hello, {name}!");}
csharp
[Method("Hello")]public void Hello(Motor _, [FromPipeline] string name){Console.WriteLine($"Hello, {name}!");}
rcaron
'pipelines' | Hello;
rcaron
'pipelines' | Hello;
If parameter is of type:
IEnumerable
- cannot be accepted from the pipeline, only as an object e.g./* IEnumerable */ | Hello;
IEnumerator
- accepts the pipeline's enumerator, which can also be the the IEnumerator returned by the left side of the pipelinePipeline
- receives the pipeline itself, note the GetEnumerator may be called only onceobject
or others - method is called for each item in the pipeline
Also see Native Pipelines(shell only) and Pipelines.