BadScript 2
Loading...
Searching...
No Matches
Program.cs
Go to the documentation of this file.
10
12
13[BadInteropObject("Person")]
14public class Person
15{
16 public Person(string name, int age)
17 {
18 Name = name;
19 Age = age;
20 }
21 [BadProperty]
22 public string Name { get; set; }
23 [BadProperty]
24 public int Age { get; set; }
25
26 [BadMethod]
27 public virtual string PrintInfo()
28 {
29 return $"{Name} is {Age} years old";
30 }
31}
32
33[BadInteropObject("Employee", typeof(PersonWrapper))]
34public class Employee : Person
35{
36 public Employee(string name, int age, string job, int employeeId) : base(name, age)
37 {
38 Job = job;
39 EmployeeId = employeeId;
40 }
41 [BadProperty]
42 public string Job { get; set; }
43 [BadProperty]
44 public int EmployeeId { get; set; }
45
46 public override string PrintInfo()
47 {
48 return base.PrintInfo() + " and works as " + Job + " with EmployeeId " + EmployeeId;
49 }
50}
51
52
53[BadInteropApi("TestApi")]
54internal partial class Program
55{
56 private string m_Name = "World";
57
58 [BadMethod("Hello", "Says Hello")]
59 private void SayHello()
60 {
61 Console.WriteLine("Hello");
62 }
63
64 [BadMethod(description: "Returns the Greeting String")]
65 [return: BadReturn("Hello {name}")]
66 private string GetGreeting()
67 {
68 return $"Hello {m_Name}";
69 }
70
71 [BadMethod(description: "Sets the Name")]
72 private void SetName([BadParameter(description: "The Name to be set.")] string name = "World")
73 {
74 m_Name = name;
75 }
76
77 [BadMethod(description: "Gets the Name")]
78 [return: BadReturn("The Name")]
79 private string GetName()
80 {
81 return m_Name;
82 }
83
84 [BadMethod(description: "Greets a list of users")]
85 private void ParamsTest(params string[] names)
86 {
87 foreach (string name in names)
88 {
89 SetName(name);
90 Greet();
91 }
92 }
93
94 [BadMethod(description: "Greets a list of users and resets the name")]
95 private void ParamsTest2(string resetName, params string[] names)
96 {
97 ParamsTest(names);
98 SetName(resetName);
99 }
100
101 [BadMethod(description: "Greets the User")]
102 private void Greet()
103 {
104 Console.WriteLine(GetGreeting());
105 }
106
107 private static void Main()
108 {
109 BadRuntime runtime = new BadRuntime()
110 .UseCommonInterop()
111 .UseApi(new Program());
112 BadObject obj = (PersonWrapper)new Person("John", 42);
113
114 BadNativeClassBuilder.AddNative(PersonWrapper.Prototype);
115 BadNativeClassBuilder.AddNative(EmployeeWrapper.Prototype);
116
117 runtime.RunInteractive(Enumerable.Empty<string>());
118 }
119}
Exposes the BadScript Runtime Functionality to Consumers.
Definition BadRuntime.cs:30
BadRuntime UseApi(BadInteropApi api, bool replace=false)
Adds or Replaces a specified API.
override string PrintInfo()
Definition Program.cs:46
Employee(string name, int age, string job, int employeeId)
Definition Program.cs:36
virtual string PrintInfo()
Definition Program.cs:27
Person(string name, int age)
Definition Program.cs:16
void SetName([BadParameter(description:"The Name to be set.")] string name="World")
Definition Program.cs:72
void ParamsTest(params string[] names)
Definition Program.cs:85
void ParamsTest2(string resetName, params string[] names)
Definition Program.cs:95
Implements an Interop API for the BS2 Language.
The Base Class for all BadScript Objects.
Definition BadObject.cs:14
Helper Class that Builds a Native Class from a Prototype.
static void AddNative(BadClassPrototype native)
Adds a native Type.
Contains the interactive console Implementation.
Contains Common Interop Extensions and APIs for the BadScript2 Runtime.
Contains the Interop Libraries for BadScript2.
Contains the Interop Function Classes for the BadScript2 Language.
Contains the Interop Abstractions and Implementations for the BadScript2 Language.
Contains the Native Runtime Objects.
Definition BadBoolean.cs:6
Contains the Runtime Objects.
Definition BadArray.cs:10
Contains the Runtime Implementation.