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

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

public static LoadCode_WithDuckTypedInterface ( HostApp host ) : void
host HostApp
Результат void
            public static void LoadCode_WithDuckTypedInterface(HostApp host)
            {
                // 1 - LoadCode compiles code and returns instance of a first class in the compiled assembly 
                // 2- The script class doesn't implement host app interface but it can still be aligned to 
                // one as long at it implements the  interface members
                // 3 - In this sample host object is passed into script routine.

                ICalc calc = 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("*")
                                     .AlignToInterface<ICalc>();
                calc.Host = host;
                int result = calc.Sum(1, 2);
            }