CSScriptNativeApi.HostApp.CodeDomSamples.LoadCode_WithInterface C# (CSharp) Метод

LoadCode_WithInterface() публичный статический Метод

public static LoadCode_WithInterface ( HostApp host ) : void
host HostApp
Результат void
            public static void LoadCode_WithInterface(HostApp host)
            {
                // 1 - LoadCode compiles code and returns instance of a first class in the compiled assembly. 
                // 2 - The script class implements host app interface so the returned object can be type casted into it.
                // 3 - In this sample host object is passed into script routine.

                var calc = (ICalc)CSScript.LoadCode(@"using CSScriptNativeApi;
                                                      public class Script : ICalc
                                                      { 
                                                          public int Sum(int a, int b)
                                                          {
                                                              if(Host != null) 
                                                                  Host.Log(""Sum is invoked"");
                                                              return a + b;
                                                          }
                                                      
                                                          public HostApp Host { get; set; }
                                                      }")
                                          .CreateObject("*");
                calc.Host = host;
                int result = calc.Sum(1, 2);
            }