Tech.DynamicCoding.CodeGenerator
is Tech.DynamicCoding.CodeGenerator
. Let's begin its description with the simplest example of use. (Texts of the library and examples are in the archive ). var result = CodeGenerator.ExecuteCode<int>("return 12345678 * 9 + 9;");
CodeGenerator.ExecuteCode. - . , . ? ?
. " ", " " ExecuteCode . , , , , . , , , . , , , , .
, . .
var result = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 9876543.21), CodeParameter.Create("b", 9), CodeParameter.Create("c", -0.01)); var result2 = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 12345678.9), CodeParameter.Create("b", 8), CodeParameter.Create("c", 0.9));
, , . ExecuteCode , , . C#-, , , ExecuteCode .
. , .
var code = CodeGenerator.CreateCode<DateTime>( "return StartDate.AddDays(Duration);", new CodeParameter("StartDate", typeof(DateTime)), new CodeParameter("Duration", typeof(int))); var result1 = code.Execute(DateTime.Parse("2013-01-01"), 256); var result2 = code.Execute(DateTime.Parse("2013-10-13"), 131);
. C#-, , . . .
. .
. , , . , - . , . , .
- . , . (, ). , .
, (AppDomain) - "" (sandbox). , . , , .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, "return (int)(DateTime.Now - StartDate).TotalDays;", new CodeParameter("StartDate", typeof(DateTime))); var result = code.Execute(DateTime.Parse("1962-09-17")); }
Sandbox
, AppDomain. . .
, , . - .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(@"c:\temp\a.txt"); // SecurityException }
, . .
const string FILE_PATH = @"c:\temp\a.txt"; using (var sandbox = new Sandbox( new FileIOPermission(FileIOPermissionAccess.AllAccess, FILE_PATH))) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(FILE_PATH); }
,
. , . , .. .
, . , MarshalByRefObject. .Net Remoting, .
. :
public class AirConditioner : MarshalByRefObject { public bool Working { get; set; } } [Serializable] public struct Climate { public double Temperature { get; set; } }
, / , .
const string controlAlgorithm = @" IF Climate.Temperature > 26 THEN Unit.Working = TRUE IF Climate.Temperature < 22 THEN Unit.Working = FALSE"; var unit = new AirConditioner(); var limate = new Climate { Temperature = 28 }; using (var sandbox = new Sandbox()) { var controlCode = CodeGenerator.CreateCode<int>(sandbox, VB.Compiler, controlAlgorithm, null, null, CodeParameter.Create("Unit", unit), CodeParameter.Create("Climate", limate)); while (!Console.KeyAvailable) { Console.WriteLine("t={0}°C", limate.Temperature); controlCode.Execute(unit, limate); Thread.Sleep(300); limate.Temperature += unit.Working ? -1 : 1; } }
, , MarshalByRefObject, Climate [Serializable].
.
1. #- System
, , . C# using'. . , , . .
2. System.dll mscorlib.dll, . , . , .
, , . .
3. C#. . VB.Net. . ( .)
, , . . .
, . , , -, . , - (plugin modules).
. , . , .

, , , .
C#
C# " "
CS-Script - The C# Script Engine
Security and On-the-Fly Code Generation
How to: Run Partially Trusted Code in a Sandbox
Metaprogramming in .NET. EBook
Debugging a generated .NET assembly from within the application that generated it
method CodeGenerator.ExecuteCode. - . , . ? ?
. " ", " " ExecuteCode . , , , , . , , , . , , , , .
, . .
var result = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 9876543.21), CodeParameter.Create("b", 9), CodeParameter.Create("c", -0.01)); var result2 = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 12345678.9), CodeParameter.Create("b", 8), CodeParameter.Create("c", 0.9));
, , . ExecuteCode , , . C#-, , , ExecuteCode .
. , .
var code = CodeGenerator.CreateCode<DateTime>( "return StartDate.AddDays(Duration);", new CodeParameter("StartDate", typeof(DateTime)), new CodeParameter("Duration", typeof(int))); var result1 = code.Execute(DateTime.Parse("2013-01-01"), 256); var result2 = code.Execute(DateTime.Parse("2013-10-13"), 131);
. C#-, , . . .
. .
. , , . , - . , . , .
- . , . (, ). , .
, (AppDomain) - "" (sandbox). , . , , .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, "return (int)(DateTime.Now - StartDate).TotalDays;", new CodeParameter("StartDate", typeof(DateTime))); var result = code.Execute(DateTime.Parse("1962-09-17")); }
Sandbox
, AppDomain. . .
, , . - .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(@"c:\temp\a.txt"); // SecurityException }
, . .
const string FILE_PATH = @"c:\temp\a.txt"; using (var sandbox = new Sandbox( new FileIOPermission(FileIOPermissionAccess.AllAccess, FILE_PATH))) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(FILE_PATH); }
,
. , . , .. .
, . , MarshalByRefObject. .Net Remoting, .
. :
public class AirConditioner : MarshalByRefObject { public bool Working { get; set; } } [Serializable] public struct Climate { public double Temperature { get; set; } }
, / , .
const string controlAlgorithm = @" IF Climate.Temperature > 26 THEN Unit.Working = TRUE IF Climate.Temperature < 22 THEN Unit.Working = FALSE"; var unit = new AirConditioner(); var limate = new Climate { Temperature = 28 }; using (var sandbox = new Sandbox()) { var controlCode = CodeGenerator.CreateCode<int>(sandbox, VB.Compiler, controlAlgorithm, null, null, CodeParameter.Create("Unit", unit), CodeParameter.Create("Climate", limate)); while (!Console.KeyAvailable) { Console.WriteLine("t={0}°C", limate.Temperature); controlCode.Execute(unit, limate); Thread.Sleep(300); limate.Temperature += unit.Working ? -1 : 1; } }
, , MarshalByRefObject, Climate [Serializable].
.
1. #- System
, , . C# using'. . , , . .
2. System.dll mscorlib.dll, . , . , .
, , . .
3. C#. . VB.Net. . ( .)
, , . . .
, . , , -, . , - (plugin modules).
. , . , .

, , , .
C#
C# " "
CS-Script - The C# Script Engine
Security and On-the-Fly Code Generation
How to: Run Partially Trusted Code in a Sandbox
Metaprogramming in .NET. EBook
Debugging a generated .NET assembly from within the application that generated it
CodeGenerator.ExecuteCode. - . , . ? ?
. " ", " " ExecuteCode
. , , , , . , , , . , , , , .
, . .
var result = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 9876543.21), CodeParameter.Create("b", 9), CodeParameter.Create("c", -0.01)); var result2 = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 12345678.9), CodeParameter.Create("b", 8), CodeParameter.Create("c", 0.9));
, , . ExecuteCode , , . C#-, , , ExecuteCode .
. , .
var code = CodeGenerator.CreateCode<DateTime>( "return StartDate.AddDays(Duration);", new CodeParameter("StartDate", typeof(DateTime)), new CodeParameter("Duration", typeof(int))); var result1 = code.Execute(DateTime.Parse("2013-01-01"), 256); var result2 = code.Execute(DateTime.Parse("2013-10-13"), 131);
. C#-, , . . .
. .
. , , . , - . , . , .
- . , . (, ). , .
, (AppDomain) - "" (sandbox). , . , , .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, "return (int)(DateTime.Now - StartDate).TotalDays;", new CodeParameter("StartDate", typeof(DateTime))); var result = code.Execute(DateTime.Parse("1962-09-17")); }
Sandbox
, AppDomain. . .
, , . - .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(@"c:\temp\a.txt"); // SecurityException }
, . .
const string FILE_PATH = @"c:\temp\a.txt"; using (var sandbox = new Sandbox( new FileIOPermission(FileIOPermissionAccess.AllAccess, FILE_PATH))) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(FILE_PATH); }
,
. , . , .. .
, . , MarshalByRefObject. .Net Remoting, .
. :
public class AirConditioner : MarshalByRefObject { public bool Working { get; set; } } [Serializable] public struct Climate { public double Temperature { get; set; } }
, / , .
const string controlAlgorithm = @" IF Climate.Temperature > 26 THEN Unit.Working = TRUE IF Climate.Temperature < 22 THEN Unit.Working = FALSE"; var unit = new AirConditioner(); var limate = new Climate { Temperature = 28 }; using (var sandbox = new Sandbox()) { var controlCode = CodeGenerator.CreateCode<int>(sandbox, VB.Compiler, controlAlgorithm, null, null, CodeParameter.Create("Unit", unit), CodeParameter.Create("Climate", limate)); while (!Console.KeyAvailable) { Console.WriteLine("t={0}°C", limate.Temperature); controlCode.Execute(unit, limate); Thread.Sleep(300); limate.Temperature += unit.Working ? -1 : 1; } }
, , MarshalByRefObject, Climate [Serializable].
.
1. #- System
, , . C# using'. . , , . .
2. System.dll mscorlib.dll, . , . , .
, , . .
3. C#. . VB.Net. . ( .)
, , . . .
, . , , -, . , - (plugin modules).
. , . , .

, , , .
C#
C# " "
CS-Script - The C# Script Engine
Security and On-the-Fly Code Generation
How to: Run Partially Trusted Code in a Sandbox
Metaprogramming in .NET. EBook
Debugging a generated .NET assembly from within the application that generated it
CodeGenerator.ExecuteCode. - . , . ? ?
. " ", " " ExecuteCode . , , , , . , , , . , , , , .
, . .
var result = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 9876543.21), CodeParameter.Create("b", 9), CodeParameter.Create("c", -0.01)); var result2 = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 12345678.9), CodeParameter.Create("b", 8), CodeParameter.Create("c", 0.9));
, , . ExecuteCode , , . C#-, , , ExecuteCode .
. , .
var code = CodeGenerator.CreateCode<DateTime>( "return StartDate.AddDays(Duration);", new CodeParameter("StartDate", typeof(DateTime)), new CodeParameter("Duration", typeof(int))); var result1 = code.Execute(DateTime.Parse("2013-01-01"), 256); var result2 = code.Execute(DateTime.Parse("2013-10-13"), 131);
. C#-, , . . .
. .
. , , . , - . , . , .
- . , . (, ). , .
, (AppDomain) - "" (sandbox). , . , , .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, "return (int)(DateTime.Now - StartDate).TotalDays;", new CodeParameter("StartDate", typeof(DateTime))); var result = code.Execute(DateTime.Parse("1962-09-17")); }
Sandbox
, AppDomain. . .
, , . - .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(@"c:\temp\a.txt"); // SecurityException }
, . .
const string FILE_PATH = @"c:\temp\a.txt"; using (var sandbox = new Sandbox( new FileIOPermission(FileIOPermissionAccess.AllAccess, FILE_PATH))) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(FILE_PATH); }
,
. , . , .. .
, . , MarshalByRefObject. .Net Remoting, .
. :
public class AirConditioner : MarshalByRefObject { public bool Working { get; set; } } [Serializable] public struct Climate { public double Temperature { get; set; } }
, / , .
const string controlAlgorithm = @" IF Climate.Temperature > 26 THEN Unit.Working = TRUE IF Climate.Temperature < 22 THEN Unit.Working = FALSE"; var unit = new AirConditioner(); var limate = new Climate { Temperature = 28 }; using (var sandbox = new Sandbox()) { var controlCode = CodeGenerator.CreateCode<int>(sandbox, VB.Compiler, controlAlgorithm, null, null, CodeParameter.Create("Unit", unit), CodeParameter.Create("Climate", limate)); while (!Console.KeyAvailable) { Console.WriteLine("t={0}°C", limate.Temperature); controlCode.Execute(unit, limate); Thread.Sleep(300); limate.Temperature += unit.Working ? -1 : 1; } }
, , MarshalByRefObject, Climate [Serializable].
.
1. #- System
, , . C# using'. . , , . .
2. System.dll mscorlib.dll, . , . , .
, , . .
3. C#. . VB.Net. . ( .)
, , . . .
, . , , -, . , - (plugin modules).
. , . , .

, , , .
C#
C# " "
CS-Script - The C# Script Engine
Security and On-the-Fly Code Generation
How to: Run Partially Trusted Code in a Sandbox
Metaprogramming in .NET. EBook
Debugging a generated .NET assembly from within the application that generated it
CodeGenerator.ExecuteCode. - . , . ? ?
. " ", " " ExecuteCode
. , , , , . , , , . , , , , .
, . .
var result = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 9876543.21), CodeParameter.Create("b", 9), CodeParameter.Create("c", -0.01)); var result2 = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 12345678.9), CodeParameter.Create("b", 8), CodeParameter.Create("c", 0.9));
, , . ExecuteCode , , . C#-, , , ExecuteCode .
. , .
var code = CodeGenerator.CreateCode<DateTime>( "return StartDate.AddDays(Duration);", new CodeParameter("StartDate", typeof(DateTime)), new CodeParameter("Duration", typeof(int))); var result1 = code.Execute(DateTime.Parse("2013-01-01"), 256); var result2 = code.Execute(DateTime.Parse("2013-10-13"), 131);
. C#-, , . . .
. .
. , , . , - . , . , .
- . , . (, ). , .
, (AppDomain) - "" (sandbox). , . , , .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, "return (int)(DateTime.Now - StartDate).TotalDays;", new CodeParameter("StartDate", typeof(DateTime))); var result = code.Execute(DateTime.Parse("1962-09-17")); }
Sandbox
, AppDomain. . .
, , . - .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(@"c:\temp\a.txt"); // SecurityException }
, . .
const string FILE_PATH = @"c:\temp\a.txt"; using (var sandbox = new Sandbox( new FileIOPermission(FileIOPermissionAccess.AllAccess, FILE_PATH))) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(FILE_PATH); }
,
. , . , .. .
, . , MarshalByRefObject. .Net Remoting, .
. :
public class AirConditioner : MarshalByRefObject { public bool Working { get; set; } } [Serializable] public struct Climate { public double Temperature { get; set; } }
, / , .
const string controlAlgorithm = @" IF Climate.Temperature > 26 THEN Unit.Working = TRUE IF Climate.Temperature < 22 THEN Unit.Working = FALSE"; var unit = new AirConditioner(); var limate = new Climate { Temperature = 28 }; using (var sandbox = new Sandbox()) { var controlCode = CodeGenerator.CreateCode<int>(sandbox, VB.Compiler, controlAlgorithm, null, null, CodeParameter.Create("Unit", unit), CodeParameter.Create("Climate", limate)); while (!Console.KeyAvailable) { Console.WriteLine("t={0}°C", limate.Temperature); controlCode.Execute(unit, limate); Thread.Sleep(300); limate.Temperature += unit.Working ? -1 : 1; } }
, , MarshalByRefObject, Climate [Serializable].
.
1. #- System
, , . C# using'. . , , . .
2. System.dll mscorlib.dll, . , . , .
, , . .
3. C#. . VB.Net. . ( .)
, , . . .
, . , , -, . , - (plugin modules).
. , . , .

, , , .
C#
C# " "
CS-Script - The C# Script Engine
Security and On-the-Fly Code Generation
How to: Run Partially Trusted Code in a Sandbox
Metaprogramming in .NET. EBook
Debugging a generated .NET assembly from within the application that generated it
CodeGenerator.ExecuteCode. - . , . ? ?
. " ", " " ExecuteCode
. , , , , . , , , . , , , , .
, . .
var result = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 9876543.21), CodeParameter.Create("b", 9), CodeParameter.Create("c", -0.01)); var result2 = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 12345678.9), CodeParameter.Create("b", 8), CodeParameter.Create("c", 0.9));
, , . ExecuteCode , , . C#-, , , ExecuteCode .
. , .
var code = CodeGenerator.CreateCode<DateTime>( "return StartDate.AddDays(Duration);", new CodeParameter("StartDate", typeof(DateTime)), new CodeParameter("Duration", typeof(int))); var result1 = code.Execute(DateTime.Parse("2013-01-01"), 256); var result2 = code.Execute(DateTime.Parse("2013-10-13"), 131);
. C#-, , . . .
. .
. , , . , - . , . , .
- . , . (, ). , .
, (AppDomain) - "" (sandbox). , . , , .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, "return (int)(DateTime.Now - StartDate).TotalDays;", new CodeParameter("StartDate", typeof(DateTime))); var result = code.Execute(DateTime.Parse("1962-09-17")); }
Sandbox
, AppDomain. . .
, , . - .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(@"c:\temp\a.txt"); // SecurityException }
, . .
const string FILE_PATH = @"c:\temp\a.txt"; using (var sandbox = new Sandbox( new FileIOPermission(FileIOPermissionAccess.AllAccess, FILE_PATH))) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(FILE_PATH); }
,
. , . , .. .
, . , MarshalByRefObject. .Net Remoting, .
. :
public class AirConditioner : MarshalByRefObject { public bool Working { get; set; } } [Serializable] public struct Climate { public double Temperature { get; set; } }
, / , .
const string controlAlgorithm = @" IF Climate.Temperature > 26 THEN Unit.Working = TRUE IF Climate.Temperature < 22 THEN Unit.Working = FALSE"; var unit = new AirConditioner(); var limate = new Climate { Temperature = 28 }; using (var sandbox = new Sandbox()) { var controlCode = CodeGenerator.CreateCode<int>(sandbox, VB.Compiler, controlAlgorithm, null, null, CodeParameter.Create("Unit", unit), CodeParameter.Create("Climate", limate)); while (!Console.KeyAvailable) { Console.WriteLine("t={0}°C", limate.Temperature); controlCode.Execute(unit, limate); Thread.Sleep(300); limate.Temperature += unit.Working ? -1 : 1; } }
, , MarshalByRefObject, Climate [Serializable].
.
1. #- System
, , . C# using'. . , , . .
2. System.dll mscorlib.dll, . , . , .
, , . .
3. C#. . VB.Net. . ( .)
, , . . .
, . , , -, . , - (plugin modules).
. , . , .
, , , .
C#
C# " "
CS-Script - The C# Script Engine
Security and On-the-Fly Code Generation
How to: Run Partially Trusted Code in a Sandbox
Metaprogramming in .NET. EBook
Debugging a generated .NET assembly from within the application that generated it
CodeGenerator.ExecuteCode. - . , . ? ?
. " ", " " ExecuteCode
. , , , , . , , , . , , , , .
, . .
var result = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 9876543.21), CodeParameter.Create("b", 9), CodeParameter.Create("c", -0.01)); var result2 = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 12345678.9), CodeParameter.Create("b", 8), CodeParameter.Create("c", 0.9));
, , . ExecuteCode , , . C#-, , , ExecuteCode .
. , .
var code = CodeGenerator.CreateCode<DateTime>( "return StartDate.AddDays(Duration);", new CodeParameter("StartDate", typeof(DateTime)), new CodeParameter("Duration", typeof(int))); var result1 = code.Execute(DateTime.Parse("2013-01-01"), 256); var result2 = code.Execute(DateTime.Parse("2013-10-13"), 131);
. C#-, , . . .
. .
. , , . , - . , . , .
- . , . (, ). , .
, (AppDomain) - "" (sandbox). , . , , .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, "return (int)(DateTime.Now - StartDate).TotalDays;", new CodeParameter("StartDate", typeof(DateTime))); var result = code.Execute(DateTime.Parse("1962-09-17")); }
Sandbox
, AppDomain. . .
, , . - .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(@"c:\temp\a.txt"); // SecurityException }
, . .
const string FILE_PATH = @"c:\temp\a.txt"; using (var sandbox = new Sandbox( new FileIOPermission(FileIOPermissionAccess.AllAccess, FILE_PATH))) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(FILE_PATH); }
,
. , . , .. .
, . , MarshalByRefObject. .Net Remoting, .
. :
public class AirConditioner : MarshalByRefObject { public bool Working { get; set; } } [Serializable] public struct Climate { public double Temperature { get; set; } }
, / , .
const string controlAlgorithm = @" IF Climate.Temperature > 26 THEN Unit.Working = TRUE IF Climate.Temperature < 22 THEN Unit.Working = FALSE"; var unit = new AirConditioner(); var limate = new Climate { Temperature = 28 }; using (var sandbox = new Sandbox()) { var controlCode = CodeGenerator.CreateCode<int>(sandbox, VB.Compiler, controlAlgorithm, null, null, CodeParameter.Create("Unit", unit), CodeParameter.Create("Climate", limate)); while (!Console.KeyAvailable) { Console.WriteLine("t={0}°C", limate.Temperature); controlCode.Execute(unit, limate); Thread.Sleep(300); limate.Temperature += unit.Working ? -1 : 1; } }
, , MarshalByRefObject, Climate [Serializable].
.
1. #- System
, , . C# using'. . , , . .
2. System.dll mscorlib.dll, . , . , .
, , . .
3. C#. . VB.Net. . ( .)
, , . . .
, . , , -, . , - (plugin modules).
. , . , .

, , , .
C#
C# " "
CS-Script - The C# Script Engine
Security and On-the-Fly Code Generation
How to: Run Partially Trusted Code in a Sandbox
Metaprogramming in .NET. EBook
Debugging a generated .NET assembly from within the application that generated it
CodeGenerator.ExecuteCode. - . , . ? ?
. " ", " " ExecuteCode
. , , , , . , , , . , , , , .
, . .
var result = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 9876543.21), CodeParameter.Create("b", 9), CodeParameter.Create("c", -0.01)); var result2 = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 12345678.9), CodeParameter.Create("b", 8), CodeParameter.Create("c", 0.9));
, , . ExecuteCode , , . C#-, , , ExecuteCode .
. , .
var code = CodeGenerator.CreateCode<DateTime>( "return StartDate.AddDays(Duration);", new CodeParameter("StartDate", typeof(DateTime)), new CodeParameter("Duration", typeof(int))); var result1 = code.Execute(DateTime.Parse("2013-01-01"), 256); var result2 = code.Execute(DateTime.Parse("2013-10-13"), 131);
. C#-, , . . .
. .
. , , . , - . , . , .
- . , . (, ). , .
, (AppDomain) - "" (sandbox). , . , , .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, "return (int)(DateTime.Now - StartDate).TotalDays;", new CodeParameter("StartDate", typeof(DateTime))); var result = code.Execute(DateTime.Parse("1962-09-17")); }
Sandbox
, AppDomain. . .
, , . - .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(@"c:\temp\a.txt"); // SecurityException }
, . .
const string FILE_PATH = @"c:\temp\a.txt"; using (var sandbox = new Sandbox( new FileIOPermission(FileIOPermissionAccess.AllAccess, FILE_PATH))) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(FILE_PATH); }
,
. , . , .. .
, . , MarshalByRefObject. .Net Remoting, .
. :
public class AirConditioner : MarshalByRefObject { public bool Working { get; set; } } [Serializable] public struct Climate { public double Temperature { get; set; } }
, / , .
const string controlAlgorithm = @" IF Climate.Temperature > 26 THEN Unit.Working = TRUE IF Climate.Temperature < 22 THEN Unit.Working = FALSE"; var unit = new AirConditioner(); var limate = new Climate { Temperature = 28 }; using (var sandbox = new Sandbox()) { var controlCode = CodeGenerator.CreateCode<int>(sandbox, VB.Compiler, controlAlgorithm, null, null, CodeParameter.Create("Unit", unit), CodeParameter.Create("Climate", limate)); while (!Console.KeyAvailable) { Console.WriteLine("t={0}°C", limate.Temperature); controlCode.Execute(unit, limate); Thread.Sleep(300); limate.Temperature += unit.Working ? -1 : 1; } }
, , MarshalByRefObject, Climate [Serializable].
.
1. #- System
, , . C# using'. . , , . .
2. System.dll mscorlib.dll, . , . , .
, , . .
3. C#. . VB.Net. . ( .)
, , . . .
, . , , -, . , - (plugin modules).
. , . , .

, , , .
C#
C# " "
CS-Script - The C# Script Engine
Security and On-the-Fly Code Generation
How to: Run Partially Trusted Code in a Sandbox
Metaprogramming in .NET. EBook
Debugging a generated .NET assembly from within the application that generated it
CodeGenerator.ExecuteCode. - . , . ? ?
. " ", " " ExecuteCode
. , , , , . , , , . , , , , .
, . .
var result = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 9876543.21), CodeParameter.Create("b", 9), CodeParameter.Create("c", -0.01)); var result2 = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 12345678.9), CodeParameter.Create("b", 8), CodeParameter.Create("c", 0.9));
, , . ExecuteCode , , . C#-, , , ExecuteCode .
. , .
var code = CodeGenerator.CreateCode<DateTime>( "return StartDate.AddDays(Duration);", new CodeParameter("StartDate", typeof(DateTime)), new CodeParameter("Duration", typeof(int))); var result1 = code.Execute(DateTime.Parse("2013-01-01"), 256); var result2 = code.Execute(DateTime.Parse("2013-10-13"), 131);
. C#-, , . . .
. .
. , , . , - . , . , .
- . , . (, ). , .
, (AppDomain) - "" (sandbox). , . , , .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, "return (int)(DateTime.Now - StartDate).TotalDays;", new CodeParameter("StartDate", typeof(DateTime))); var result = code.Execute(DateTime.Parse("1962-09-17")); }
Sandbox
, AppDomain. . .
, , . - .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(@"c:\temp\a.txt"); // SecurityException }
, . .
const string FILE_PATH = @"c:\temp\a.txt"; using (var sandbox = new Sandbox( new FileIOPermission(FileIOPermissionAccess.AllAccess, FILE_PATH))) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(FILE_PATH); }
,
. , . , .. .
, . , MarshalByRefObject. .Net Remoting, .
. :
public class AirConditioner : MarshalByRefObject { public bool Working { get; set; } } [Serializable] public struct Climate { public double Temperature { get; set; } }
, / , .
const string controlAlgorithm = @" IF Climate.Temperature > 26 THEN Unit.Working = TRUE IF Climate.Temperature < 22 THEN Unit.Working = FALSE"; var unit = new AirConditioner(); var limate = new Climate { Temperature = 28 }; using (var sandbox = new Sandbox()) { var controlCode = CodeGenerator.CreateCode<int>(sandbox, VB.Compiler, controlAlgorithm, null, null, CodeParameter.Create("Unit", unit), CodeParameter.Create("Climate", limate)); while (!Console.KeyAvailable) { Console.WriteLine("t={0}°C", limate.Temperature); controlCode.Execute(unit, limate); Thread.Sleep(300); limate.Temperature += unit.Working ? -1 : 1; } }
, , MarshalByRefObject, Climate [Serializable].
.
1. #- System
, , . C# using'. . , , . .
2. System.dll mscorlib.dll, . , . , .
, , . .
3. C#. . VB.Net. . ( .)
, , . . .
, . , , -, . , - (plugin modules).
. , . , .

, , , .
C#
C# " "
CS-Script - The C# Script Engine
Security and On-the-Fly Code Generation
How to: Run Partially Trusted Code in a Sandbox
Metaprogramming in .NET. EBook
Debugging a generated .NET assembly from within the application that generated it
CodeGenerator.ExecuteCode. - . , . ? ?
. " ", " " ExecuteCode
. , , , , . , , , . , , , , .
, . .
var result = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 9876543.21), CodeParameter.Create("b", 9), CodeParameter.Create("c", -0.01)); var result2 = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 12345678.9), CodeParameter.Create("b", 8), CodeParameter.Create("c", 0.9));
, , . ExecuteCode , , . C#-, , , ExecuteCode .
. , .
var code = CodeGenerator.CreateCode<DateTime>( "return StartDate.AddDays(Duration);", new CodeParameter("StartDate", typeof(DateTime)), new CodeParameter("Duration", typeof(int))); var result1 = code.Execute(DateTime.Parse("2013-01-01"), 256); var result2 = code.Execute(DateTime.Parse("2013-10-13"), 131);
. C#-, , . . .
. .
. , , . , - . , . , .
- . , . (, ). , .
, (AppDomain) - "" (sandbox). , . , , .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, "return (int)(DateTime.Now - StartDate).TotalDays;", new CodeParameter("StartDate", typeof(DateTime))); var result = code.Execute(DateTime.Parse("1962-09-17")); }
Sandbox
, AppDomain. . .
, , . - .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(@"c:\temp\a.txt"); // SecurityException }
, . .
const string FILE_PATH = @"c:\temp\a.txt"; using (var sandbox = new Sandbox( new FileIOPermission(FileIOPermissionAccess.AllAccess, FILE_PATH))) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(FILE_PATH); }
,
. , . , .. .
, . , MarshalByRefObject. .Net Remoting, .
. :
public class AirConditioner : MarshalByRefObject { public bool Working { get; set; } } [Serializable] public struct Climate { public double Temperature { get; set; } }
, / , .
const string controlAlgorithm = @" IF Climate.Temperature > 26 THEN Unit.Working = TRUE IF Climate.Temperature < 22 THEN Unit.Working = FALSE"; var unit = new AirConditioner(); var limate = new Climate { Temperature = 28 }; using (var sandbox = new Sandbox()) { var controlCode = CodeGenerator.CreateCode<int>(sandbox, VB.Compiler, controlAlgorithm, null, null, CodeParameter.Create("Unit", unit), CodeParameter.Create("Climate", limate)); while (!Console.KeyAvailable) { Console.WriteLine("t={0}°C", limate.Temperature); controlCode.Execute(unit, limate); Thread.Sleep(300); limate.Temperature += unit.Working ? -1 : 1; } }
, , MarshalByRefObject, Climate [Serializable].
.
1. #- System
, , . C# using'. . , , . .
2. System.dll mscorlib.dll, . , . , .
, , . .
3. C#. . VB.Net. . ( .)
, , . . .
, . , , -, . , - (plugin modules).
. , . , .
, , , .
C#
C# " "
CS-Script - The C# Script Engine
Security and On-the-Fly Code Generation
How to: Run Partially Trusted Code in a Sandbox
Metaprogramming in .NET. EBook
Debugging a generated .NET assembly from within the application that generated it
CodeGenerator.ExecuteCode. - . , . ? ?
. " ", " " ExecuteCode
. , , , , . , , , . , , , , .
, . .
var result = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 9876543.21), CodeParameter.Create("b", 9), CodeParameter.Create("c", -0.01)); var result2 = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 12345678.9), CodeParameter.Create("b", 8), CodeParameter.Create("c", 0.9));
, , . ExecuteCode , , . C#-, , , ExecuteCode .
. , .
var code = CodeGenerator.CreateCode<DateTime>( "return StartDate.AddDays(Duration);", new CodeParameter("StartDate", typeof(DateTime)), new CodeParameter("Duration", typeof(int))); var result1 = code.Execute(DateTime.Parse("2013-01-01"), 256); var result2 = code.Execute(DateTime.Parse("2013-10-13"), 131);
. C#-, , . . .
. .
. , , . , - . , . , .
- . , . (, ). , .
, (AppDomain) - "" (sandbox). , . , , .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, "return (int)(DateTime.Now - StartDate).TotalDays;", new CodeParameter("StartDate", typeof(DateTime))); var result = code.Execute(DateTime.Parse("1962-09-17")); }
Sandbox
, AppDomain. . .
, , . - .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(@"c:\temp\a.txt"); // SecurityException }
, . .
const string FILE_PATH = @"c:\temp\a.txt"; using (var sandbox = new Sandbox( new FileIOPermission(FileIOPermissionAccess.AllAccess, FILE_PATH))) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(FILE_PATH); }
,
. , . , .. .
, . , MarshalByRefObject. .Net Remoting, .
. :
public class AirConditioner : MarshalByRefObject { public bool Working { get; set; } } [Serializable] public struct Climate { public double Temperature { get; set; } }
, / , .
const string controlAlgorithm = @" IF Climate.Temperature > 26 THEN Unit.Working = TRUE IF Climate.Temperature < 22 THEN Unit.Working = FALSE"; var unit = new AirConditioner(); var limate = new Climate { Temperature = 28 }; using (var sandbox = new Sandbox()) { var controlCode = CodeGenerator.CreateCode<int>(sandbox, VB.Compiler, controlAlgorithm, null, null, CodeParameter.Create("Unit", unit), CodeParameter.Create("Climate", limate)); while (!Console.KeyAvailable) { Console.WriteLine("t={0}°C", limate.Temperature); controlCode.Execute(unit, limate); Thread.Sleep(300); limate.Temperature += unit.Working ? -1 : 1; } }
, , MarshalByRefObject, Climate [Serializable].
.
1. #- System
, , . C# using'. . , , . .
2. System.dll mscorlib.dll, . , . , .
, , . .
3. C#. . VB.Net. . ( .)
, , . . .
, . , , -, . , - (plugin modules).
. , . , .

, , , .
C#
C# " "
CS-Script - The C# Script Engine
Security and On-the-Fly Code Generation
How to: Run Partially Trusted Code in a Sandbox
Metaprogramming in .NET. EBook
Debugging a generated .NET assembly from within the application that generated it
CodeGenerator.ExecuteCode. - . , . ? ?
. " ", " " ExecuteCode
. , , , , . , , , . , , , , .
, . .
var result = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 9876543.21), CodeParameter.Create("b", 9), CodeParameter.Create("c", -0.01)); var result2 = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 12345678.9), CodeParameter.Create("b", 8), CodeParameter.Create("c", 0.9));
, , . ExecuteCode , , . C#-, , , ExecuteCode .
. , .
var code = CodeGenerator.CreateCode<DateTime>( "return StartDate.AddDays(Duration);", new CodeParameter("StartDate", typeof(DateTime)), new CodeParameter("Duration", typeof(int))); var result1 = code.Execute(DateTime.Parse("2013-01-01"), 256); var result2 = code.Execute(DateTime.Parse("2013-10-13"), 131);
. C#-, , . . .
. .
. , , . , - . , . , .
- . , . (, ). , .
, (AppDomain) - "" (sandbox). , . , , .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, "return (int)(DateTime.Now - StartDate).TotalDays;", new CodeParameter("StartDate", typeof(DateTime))); var result = code.Execute(DateTime.Parse("1962-09-17")); }
Sandbox
, AppDomain. . .
, , . - .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(@"c:\temp\a.txt"); // SecurityException }
, . .
const string FILE_PATH = @"c:\temp\a.txt"; using (var sandbox = new Sandbox( new FileIOPermission(FileIOPermissionAccess.AllAccess, FILE_PATH))) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(FILE_PATH); }
,
. , . , .. .
, . , MarshalByRefObject. .Net Remoting, .
. :
public class AirConditioner : MarshalByRefObject { public bool Working { get; set; } } [Serializable] public struct Climate { public double Temperature { get; set; } }
, / , .
const string controlAlgorithm = @" IF Climate.Temperature > 26 THEN Unit.Working = TRUE IF Climate.Temperature < 22 THEN Unit.Working = FALSE"; var unit = new AirConditioner(); var limate = new Climate { Temperature = 28 }; using (var sandbox = new Sandbox()) { var controlCode = CodeGenerator.CreateCode<int>(sandbox, VB.Compiler, controlAlgorithm, null, null, CodeParameter.Create("Unit", unit), CodeParameter.Create("Climate", limate)); while (!Console.KeyAvailable) { Console.WriteLine("t={0}°C", limate.Temperature); controlCode.Execute(unit, limate); Thread.Sleep(300); limate.Temperature += unit.Working ? -1 : 1; } }
, , MarshalByRefObject, Climate [Serializable].
.
1. #- System
, , . C# using'. . , , . .
2. System.dll mscorlib.dll, . , . , .
, , . .
3. C#. . VB.Net. . ( .)
, , . . .
, . , , -, . , - (plugin modules).
. , . , .

, , , .
C#
C# " "
CS-Script - The C# Script Engine
Security and On-the-Fly Code Generation
How to: Run Partially Trusted Code in a Sandbox
Metaprogramming in .NET. EBook
Debugging a generated .NET assembly from within the application that generated it
CodeGenerator.ExecuteCode. - . , . ? ?
. " ", " " ExecuteCode
. , , , , . , , , . , , , , .
, . .
var result = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 9876543.21), CodeParameter.Create("b", 9), CodeParameter.Create("c", -0.01)); var result2 = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 12345678.9), CodeParameter.Create("b", 8), CodeParameter.Create("c", 0.9));
, , . ExecuteCode , , . C#-, , , ExecuteCode .
. , .
var code = CodeGenerator.CreateCode<DateTime>( "return StartDate.AddDays(Duration);", new CodeParameter("StartDate", typeof(DateTime)), new CodeParameter("Duration", typeof(int))); var result1 = code.Execute(DateTime.Parse("2013-01-01"), 256); var result2 = code.Execute(DateTime.Parse("2013-10-13"), 131);
. C#-, , . . .
. .
. , , . , - . , . , .
- . , . (, ). , .
, (AppDomain) - "" (sandbox). , . , , .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, "return (int)(DateTime.Now - StartDate).TotalDays;", new CodeParameter("StartDate", typeof(DateTime))); var result = code.Execute(DateTime.Parse("1962-09-17")); }
Sandbox
, AppDomain. . .
, , . - .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(@"c:\temp\a.txt"); // SecurityException }
, . .
const string FILE_PATH = @"c:\temp\a.txt"; using (var sandbox = new Sandbox( new FileIOPermission(FileIOPermissionAccess.AllAccess, FILE_PATH))) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(FILE_PATH); }
,
. , . , .. .
, . , MarshalByRefObject. .Net Remoting, .
. :
public class AirConditioner : MarshalByRefObject { public bool Working { get; set; } } [Serializable] public struct Climate { public double Temperature { get; set; } }
, / , .
const string controlAlgorithm = @" IF Climate.Temperature > 26 THEN Unit.Working = TRUE IF Climate.Temperature < 22 THEN Unit.Working = FALSE"; var unit = new AirConditioner(); var limate = new Climate { Temperature = 28 }; using (var sandbox = new Sandbox()) { var controlCode = CodeGenerator.CreateCode<int>(sandbox, VB.Compiler, controlAlgorithm, null, null, CodeParameter.Create("Unit", unit), CodeParameter.Create("Climate", limate)); while (!Console.KeyAvailable) { Console.WriteLine("t={0}°C", limate.Temperature); controlCode.Execute(unit, limate); Thread.Sleep(300); limate.Temperature += unit.Working ? -1 : 1; } }
, , MarshalByRefObject, Climate [Serializable].
.
1. #- System
, , . C# using'. . , , . .
2. System.dll mscorlib.dll, . , . , .
, , . .
3. C#. . VB.Net. . ( .)
, , . . .
, . , , -, . , - (plugin modules).
. , . , .

, , , .
C#
C# " "
CS-Script - The C# Script Engine
Security and On-the-Fly Code Generation
How to: Run Partially Trusted Code in a Sandbox
Metaprogramming in .NET. EBook
Debugging a generated .NET assembly from within the application that generated it
CodeGenerator.ExecuteCode. - . , . ? ?
. " ", " " ExecuteCode
. , , , , . , , , . , , , , .
, . .
var result = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 9876543.21), CodeParameter.Create("b", 9), CodeParameter.Create("c", -0.01)); var result2 = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 12345678.9), CodeParameter.Create("b", 8), CodeParameter.Create("c", 0.9));
, , . ExecuteCode , , . C#-, , , ExecuteCode .
. , .
var code = CodeGenerator.CreateCode<DateTime>( "return StartDate.AddDays(Duration);", new CodeParameter("StartDate", typeof(DateTime)), new CodeParameter("Duration", typeof(int))); var result1 = code.Execute(DateTime.Parse("2013-01-01"), 256); var result2 = code.Execute(DateTime.Parse("2013-10-13"), 131);
. C#-, , . . .
. .
. , , . , - . , . , .
- . , . (, ). , .
, (AppDomain) - "" (sandbox). , . , , .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, "return (int)(DateTime.Now - StartDate).TotalDays;", new CodeParameter("StartDate", typeof(DateTime))); var result = code.Execute(DateTime.Parse("1962-09-17")); }
Sandbox
, AppDomain. . .
, , . - .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(@"c:\temp\a.txt"); // SecurityException }
, . .
const string FILE_PATH = @"c:\temp\a.txt"; using (var sandbox = new Sandbox( new FileIOPermission(FileIOPermissionAccess.AllAccess, FILE_PATH))) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(FILE_PATH); }
,
. , . , .. .
, . , MarshalByRefObject. .Net Remoting, .
. :
public class AirConditioner : MarshalByRefObject { public bool Working { get; set; } } [Serializable] public struct Climate { public double Temperature { get; set; } }
, / , .
const string controlAlgorithm = @" IF Climate.Temperature > 26 THEN Unit.Working = TRUE IF Climate.Temperature < 22 THEN Unit.Working = FALSE"; var unit = new AirConditioner(); var limate = new Climate { Temperature = 28 }; using (var sandbox = new Sandbox()) { var controlCode = CodeGenerator.CreateCode<int>(sandbox, VB.Compiler, controlAlgorithm, null, null, CodeParameter.Create("Unit", unit), CodeParameter.Create("Climate", limate)); while (!Console.KeyAvailable) { Console.WriteLine("t={0}°C", limate.Temperature); controlCode.Execute(unit, limate); Thread.Sleep(300); limate.Temperature += unit.Working ? -1 : 1; } }
, , MarshalByRefObject, Climate [Serializable].
.
1. #- System
, , . C# using'. . , , . .
2. System.dll mscorlib.dll, . , . , .
, , . .
3. C#. . VB.Net. . ( .)
, , . . .
, . , , -, . , - (plugin modules).
. , . , .
, , , .
C#
C# " "
CS-Script - The C# Script Engine
Security and On-the-Fly Code Generation
How to: Run Partially Trusted Code in a Sandbox
Metaprogramming in .NET. EBook
Debugging a generated .NET assembly from within the application that generated it
CodeGenerator.ExecuteCode. - . , . ? ?
. " ", " " ExecuteCode
. , , , , . , , , . , , , , .
, . .
var result = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 9876543.21), CodeParameter.Create("b", 9), CodeParameter.Create("c", -0.01)); var result2 = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 12345678.9), CodeParameter.Create("b", 8), CodeParameter.Create("c", 0.9));
, , . ExecuteCode , , . C#-, , , ExecuteCode .
. , .
var code = CodeGenerator.CreateCode<DateTime>( "return StartDate.AddDays(Duration);", new CodeParameter("StartDate", typeof(DateTime)), new CodeParameter("Duration", typeof(int))); var result1 = code.Execute(DateTime.Parse("2013-01-01"), 256); var result2 = code.Execute(DateTime.Parse("2013-10-13"), 131);
. C#-, , . . .
. .
. , , . , - . , . , .
- . , . (, ). , .
, (AppDomain) - "" (sandbox). , . , , .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, "return (int)(DateTime.Now - StartDate).TotalDays;", new CodeParameter("StartDate", typeof(DateTime))); var result = code.Execute(DateTime.Parse("1962-09-17")); }
Sandbox
, AppDomain. . .
, , . - .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(@"c:\temp\a.txt"); // SecurityException }
, . .
const string FILE_PATH = @"c:\temp\a.txt"; using (var sandbox = new Sandbox( new FileIOPermission(FileIOPermissionAccess.AllAccess, FILE_PATH))) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(FILE_PATH); }
,
. , . , .. .
, . , MarshalByRefObject. .Net Remoting, .
. :
public class AirConditioner : MarshalByRefObject { public bool Working { get; set; } } [Serializable] public struct Climate { public double Temperature { get; set; } }
, / , .
const string controlAlgorithm = @" IF Climate.Temperature > 26 THEN Unit.Working = TRUE IF Climate.Temperature < 22 THEN Unit.Working = FALSE"; var unit = new AirConditioner(); var limate = new Climate { Temperature = 28 }; using (var sandbox = new Sandbox()) { var controlCode = CodeGenerator.CreateCode<int>(sandbox, VB.Compiler, controlAlgorithm, null, null, CodeParameter.Create("Unit", unit), CodeParameter.Create("Climate", limate)); while (!Console.KeyAvailable) { Console.WriteLine("t={0}°C", limate.Temperature); controlCode.Execute(unit, limate); Thread.Sleep(300); limate.Temperature += unit.Working ? -1 : 1; } }
, , MarshalByRefObject, Climate [Serializable].
.
1. #- System
, , . C# using'. . , , . .
2. System.dll mscorlib.dll, . , . , .
, , . .
3. C#. . VB.Net. . ( .)
, , . . .
, . , , -, . , - (plugin modules).
. , . , .

, , , .
C#
C# " "
CS-Script - The C# Script Engine
Security and On-the-Fly Code Generation
How to: Run Partially Trusted Code in a Sandbox
Metaprogramming in .NET. EBook
Debugging a generated .NET assembly from within the application that generated it
CodeGenerator.ExecuteCode. - . , . ? ?
. " ", " " ExecuteCode
. , , , , . , , , . , , , , .
, . .
var result = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 9876543.21), CodeParameter.Create("b", 9), CodeParameter.Create("c", -0.01)); var result2 = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 12345678.9), CodeParameter.Create("b", 8), CodeParameter.Create("c", 0.9));
, , . ExecuteCode , , . C#-, , , ExecuteCode .
. , .
var code = CodeGenerator.CreateCode<DateTime>( "return StartDate.AddDays(Duration);", new CodeParameter("StartDate", typeof(DateTime)), new CodeParameter("Duration", typeof(int))); var result1 = code.Execute(DateTime.Parse("2013-01-01"), 256); var result2 = code.Execute(DateTime.Parse("2013-10-13"), 131);
. C#-, , . . .
. .
. , , . , - . , . , .
- . , . (, ). , .
, (AppDomain) - "" (sandbox). , . , , .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, "return (int)(DateTime.Now - StartDate).TotalDays;", new CodeParameter("StartDate", typeof(DateTime))); var result = code.Execute(DateTime.Parse("1962-09-17")); }
Sandbox
, AppDomain. . .
, , . - .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(@"c:\temp\a.txt"); // SecurityException }
, . .
const string FILE_PATH = @"c:\temp\a.txt"; using (var sandbox = new Sandbox( new FileIOPermission(FileIOPermissionAccess.AllAccess, FILE_PATH))) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(FILE_PATH); }
,
. , . , .. .
, . , MarshalByRefObject. .Net Remoting, .
. :
public class AirConditioner : MarshalByRefObject { public bool Working { get; set; } } [Serializable] public struct Climate { public double Temperature { get; set; } }
, / , .
const string controlAlgorithm = @" IF Climate.Temperature > 26 THEN Unit.Working = TRUE IF Climate.Temperature < 22 THEN Unit.Working = FALSE"; var unit = new AirConditioner(); var limate = new Climate { Temperature = 28 }; using (var sandbox = new Sandbox()) { var controlCode = CodeGenerator.CreateCode<int>(sandbox, VB.Compiler, controlAlgorithm, null, null, CodeParameter.Create("Unit", unit), CodeParameter.Create("Climate", limate)); while (!Console.KeyAvailable) { Console.WriteLine("t={0}°C", limate.Temperature); controlCode.Execute(unit, limate); Thread.Sleep(300); limate.Temperature += unit.Working ? -1 : 1; } }
, , MarshalByRefObject, Climate [Serializable].
.
1. #- System
, , . C# using'. . , , . .
2. System.dll mscorlib.dll, . , . , .
, , . .
3. C#. . VB.Net. . ( .)
, , . . .
, . , , -, . , - (plugin modules).
. , . , .

, , , .
C#
C# " "
CS-Script - The C# Script Engine
Security and On-the-Fly Code Generation
How to: Run Partially Trusted Code in a Sandbox
Metaprogramming in .NET. EBook
Debugging a generated .NET assembly from within the application that generated it
CodeGenerator.ExecuteCode. - . , . ? ?
. " ", " " ExecuteCode
. , , , , . , , , . , , , , .
, . .
var result = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 9876543.21), CodeParameter.Create("b", 9), CodeParameter.Create("c", -0.01)); var result2 = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 12345678.9), CodeParameter.Create("b", 8), CodeParameter.Create("c", 0.9));
, , . ExecuteCode , , . C#-, , , ExecuteCode .
. , .
var code = CodeGenerator.CreateCode<DateTime>( "return StartDate.AddDays(Duration);", new CodeParameter("StartDate", typeof(DateTime)), new CodeParameter("Duration", typeof(int))); var result1 = code.Execute(DateTime.Parse("2013-01-01"), 256); var result2 = code.Execute(DateTime.Parse("2013-10-13"), 131);
. C#-, , . . .
. .
. , , . , - . , . , .
- . , . (, ). , .
, (AppDomain) - "" (sandbox). , . , , .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, "return (int)(DateTime.Now - StartDate).TotalDays;", new CodeParameter("StartDate", typeof(DateTime))); var result = code.Execute(DateTime.Parse("1962-09-17")); }
Sandbox
, AppDomain. . .
, , . - .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(@"c:\temp\a.txt"); // SecurityException }
, . .
const string FILE_PATH = @"c:\temp\a.txt"; using (var sandbox = new Sandbox( new FileIOPermission(FileIOPermissionAccess.AllAccess, FILE_PATH))) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(FILE_PATH); }
,
. , . , .. .
, . , MarshalByRefObject. .Net Remoting, .
. :
public class AirConditioner : MarshalByRefObject { public bool Working { get; set; } } [Serializable] public struct Climate { public double Temperature { get; set; } }
, / , .
const string controlAlgorithm = @" IF Climate.Temperature > 26 THEN Unit.Working = TRUE IF Climate.Temperature < 22 THEN Unit.Working = FALSE"; var unit = new AirConditioner(); var limate = new Climate { Temperature = 28 }; using (var sandbox = new Sandbox()) { var controlCode = CodeGenerator.CreateCode<int>(sandbox, VB.Compiler, controlAlgorithm, null, null, CodeParameter.Create("Unit", unit), CodeParameter.Create("Climate", limate)); while (!Console.KeyAvailable) { Console.WriteLine("t={0}°C", limate.Temperature); controlCode.Execute(unit, limate); Thread.Sleep(300); limate.Temperature += unit.Working ? -1 : 1; } }
, , MarshalByRefObject, Climate [Serializable].
.
1. #- System
, , . C# using'. . , , . .
2. System.dll mscorlib.dll, . , . , .
, , . .
3. C#. . VB.Net. . ( .)
, , . . .
, . , , -, . , - (plugin modules).
. , . , .

, , , .
C#
C# " "
CS-Script - The C# Script Engine
Security and On-the-Fly Code Generation
How to: Run Partially Trusted Code in a Sandbox
Metaprogramming in .NET. EBook
Debugging a generated .NET assembly from within the application that generated it
CodeGenerator.ExecuteCode. - . , . ? ?
. " ", " " ExecuteCode
. , , , , . , , , . , , , , .
, . .
var result = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 9876543.21), CodeParameter.Create("b", 9), CodeParameter.Create("c", -0.01)); var result2 = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 12345678.9), CodeParameter.Create("b", 8), CodeParameter.Create("c", 0.9));
, , . ExecuteCode , , . C#-, , , ExecuteCode .
. , .
var code = CodeGenerator.CreateCode<DateTime>( "return StartDate.AddDays(Duration);", new CodeParameter("StartDate", typeof(DateTime)), new CodeParameter("Duration", typeof(int))); var result1 = code.Execute(DateTime.Parse("2013-01-01"), 256); var result2 = code.Execute(DateTime.Parse("2013-10-13"), 131);
. C#-, , . . .
. .
. , , . , - . , . , .
- . , . (, ). , .
, (AppDomain) - "" (sandbox). , . , , .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, "return (int)(DateTime.Now - StartDate).TotalDays;", new CodeParameter("StartDate", typeof(DateTime))); var result = code.Execute(DateTime.Parse("1962-09-17")); }
Sandbox
, AppDomain. . .
, , . - .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(@"c:\temp\a.txt"); // SecurityException }
, . .
const string FILE_PATH = @"c:\temp\a.txt"; using (var sandbox = new Sandbox( new FileIOPermission(FileIOPermissionAccess.AllAccess, FILE_PATH))) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(FILE_PATH); }
,
. , . , .. .
, . , MarshalByRefObject. .Net Remoting, .
. :
public class AirConditioner : MarshalByRefObject { public bool Working { get; set; } } [Serializable] public struct Climate { public double Temperature { get; set; } }
, / , .
const string controlAlgorithm = @" IF Climate.Temperature > 26 THEN Unit.Working = TRUE IF Climate.Temperature < 22 THEN Unit.Working = FALSE"; var unit = new AirConditioner(); var limate = new Climate { Temperature = 28 }; using (var sandbox = new Sandbox()) { var controlCode = CodeGenerator.CreateCode<int>(sandbox, VB.Compiler, controlAlgorithm, null, null, CodeParameter.Create("Unit", unit), CodeParameter.Create("Climate", limate)); while (!Console.KeyAvailable) { Console.WriteLine("t={0}°C", limate.Temperature); controlCode.Execute(unit, limate); Thread.Sleep(300); limate.Temperature += unit.Working ? -1 : 1; } }
, , MarshalByRefObject, Climate [Serializable].
.
1. #- System
, , . C# using'. . , , . .
2. System.dll mscorlib.dll, . , . , .
, , . .
3. C#. . VB.Net. . ( .)
, , . . .
, . , , -, . , - (plugin modules).
. , . , .
, , , .
C#
C# " "
CS-Script - The C# Script Engine
Security and On-the-Fly Code Generation
How to: Run Partially Trusted Code in a Sandbox
Metaprogramming in .NET. EBook
Debugging a generated .NET assembly from within the application that generated it
CodeGenerator.ExecuteCode. - . , . ? ?
. " ", " " ExecuteCode
. , , , , . , , , . , , , , .
, . .
var result = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 9876543.21), CodeParameter.Create("b", 9), CodeParameter.Create("c", -0.01)); var result2 = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 12345678.9), CodeParameter.Create("b", 8), CodeParameter.Create("c", 0.9));
, , . ExecuteCode , , . C#-, , , ExecuteCode .
. , .
var code = CodeGenerator.CreateCode<DateTime>( "return StartDate.AddDays(Duration);", new CodeParameter("StartDate", typeof(DateTime)), new CodeParameter("Duration", typeof(int))); var result1 = code.Execute(DateTime.Parse("2013-01-01"), 256); var result2 = code.Execute(DateTime.Parse("2013-10-13"), 131);
. C#-, , . . .
. .
. , , . , - . , . , .
- . , . (, ). , .
, (AppDomain) - "" (sandbox). , . , , .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, "return (int)(DateTime.Now - StartDate).TotalDays;", new CodeParameter("StartDate", typeof(DateTime))); var result = code.Execute(DateTime.Parse("1962-09-17")); }
Sandbox
, AppDomain. . .
, , . - .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(@"c:\temp\a.txt"); // SecurityException }
, . .
const string FILE_PATH = @"c:\temp\a.txt"; using (var sandbox = new Sandbox( new FileIOPermission(FileIOPermissionAccess.AllAccess, FILE_PATH))) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(FILE_PATH); }
,
. , . , .. .
, . , MarshalByRefObject. .Net Remoting, .
. :
public class AirConditioner : MarshalByRefObject { public bool Working { get; set; } } [Serializable] public struct Climate { public double Temperature { get; set; } }
, / , .
const string controlAlgorithm = @" IF Climate.Temperature > 26 THEN Unit.Working = TRUE IF Climate.Temperature < 22 THEN Unit.Working = FALSE"; var unit = new AirConditioner(); var limate = new Climate { Temperature = 28 }; using (var sandbox = new Sandbox()) { var controlCode = CodeGenerator.CreateCode<int>(sandbox, VB.Compiler, controlAlgorithm, null, null, CodeParameter.Create("Unit", unit), CodeParameter.Create("Climate", limate)); while (!Console.KeyAvailable) { Console.WriteLine("t={0}°C", limate.Temperature); controlCode.Execute(unit, limate); Thread.Sleep(300); limate.Temperature += unit.Working ? -1 : 1; } }
, , MarshalByRefObject, Climate [Serializable].
.
1. #- System
, , . C# using'. . , , . .
2. System.dll mscorlib.dll, . , . , .
, , . .
3. C#. . VB.Net. . ( .)
, , . . .
, . , , -, . , - (plugin modules).
. , . , .

, , , .
C#
C# " "
CS-Script - The C# Script Engine
Security and On-the-Fly Code Generation
How to: Run Partially Trusted Code in a Sandbox
Metaprogramming in .NET. EBook
Debugging a generated .NET assembly from within the application that generated it
CodeGenerator.ExecuteCode. - . , . ? ?
. " ", " " ExecuteCode
. , , , , . , , , . , , , , .
, . .
var result = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 9876543.21), CodeParameter.Create("b", 9), CodeParameter.Create("c", -0.01)); var result2 = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 12345678.9), CodeParameter.Create("b", 8), CodeParameter.Create("c", 0.9));
, , . ExecuteCode , , . C#-, , , ExecuteCode .
. , .
var code = CodeGenerator.CreateCode<DateTime>( "return StartDate.AddDays(Duration);", new CodeParameter("StartDate", typeof(DateTime)), new CodeParameter("Duration", typeof(int))); var result1 = code.Execute(DateTime.Parse("2013-01-01"), 256); var result2 = code.Execute(DateTime.Parse("2013-10-13"), 131);
. C#-, , . . .
. .
. , , . , - . , . , .
- . , . (, ). , .
, (AppDomain) - "" (sandbox). , . , , .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, "return (int)(DateTime.Now - StartDate).TotalDays;", new CodeParameter("StartDate", typeof(DateTime))); var result = code.Execute(DateTime.Parse("1962-09-17")); }
Sandbox
, AppDomain. . .
, , . - .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(@"c:\temp\a.txt"); // SecurityException }
, . .
const string FILE_PATH = @"c:\temp\a.txt"; using (var sandbox = new Sandbox( new FileIOPermission(FileIOPermissionAccess.AllAccess, FILE_PATH))) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(FILE_PATH); }
,
. , . , .. .
, . , MarshalByRefObject. .Net Remoting, .
. :
public class AirConditioner : MarshalByRefObject { public bool Working { get; set; } } [Serializable] public struct Climate { public double Temperature { get; set; } }
, / , .
const string controlAlgorithm = @" IF Climate.Temperature > 26 THEN Unit.Working = TRUE IF Climate.Temperature < 22 THEN Unit.Working = FALSE"; var unit = new AirConditioner(); var limate = new Climate { Temperature = 28 }; using (var sandbox = new Sandbox()) { var controlCode = CodeGenerator.CreateCode<int>(sandbox, VB.Compiler, controlAlgorithm, null, null, CodeParameter.Create("Unit", unit), CodeParameter.Create("Climate", limate)); while (!Console.KeyAvailable) { Console.WriteLine("t={0}°C", limate.Temperature); controlCode.Execute(unit, limate); Thread.Sleep(300); limate.Temperature += unit.Working ? -1 : 1; } }
, , MarshalByRefObject, Climate [Serializable].
.
1. #- System
, , . C# using'. . , , . .
2. System.dll mscorlib.dll, . , . , .
, , . .
3. C#. . VB.Net. . ( .)
, , . . .
, . , , -, . , - (plugin modules).
. , . , .
, , , .
C#
C# " "
CS-Script - The C# Script Engine
Security and On-the-Fly Code Generation
How to: Run Partially Trusted Code in a Sandbox
Metaprogramming in .NET. EBook
Debugging a generated .NET assembly from within the application that generated it
CodeGenerator.ExecuteCode. - . , . ? ?
. " ", " " ExecuteCode
. , , , , . , , , . , , , , .
, . .
var result = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 9876543.21), CodeParameter.Create("b", 9), CodeParameter.Create("c", -0.01)); var result2 = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 12345678.9), CodeParameter.Create("b", 8), CodeParameter.Create("c", 0.9));
, , . ExecuteCode , , . C#-, , , ExecuteCode .
. , .
var code = CodeGenerator.CreateCode<DateTime>( "return StartDate.AddDays(Duration);", new CodeParameter("StartDate", typeof(DateTime)), new CodeParameter("Duration", typeof(int))); var result1 = code.Execute(DateTime.Parse("2013-01-01"), 256); var result2 = code.Execute(DateTime.Parse("2013-10-13"), 131);
. C#-, , . . .
. .
. , , . , - . , . , .
- . , . (, ). , .
, (AppDomain) - "" (sandbox). , . , , .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, "return (int)(DateTime.Now - StartDate).TotalDays;", new CodeParameter("StartDate", typeof(DateTime))); var result = code.Execute(DateTime.Parse("1962-09-17")); }
Sandbox
, AppDomain. . .
, , . - .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(@"c:\temp\a.txt"); // SecurityException }
, . .
const string FILE_PATH = @"c:\temp\a.txt"; using (var sandbox = new Sandbox( new FileIOPermission(FileIOPermissionAccess.AllAccess, FILE_PATH))) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(FILE_PATH); }
,
. , . , .. .
, . , MarshalByRefObject. .Net Remoting, .
. :
public class AirConditioner : MarshalByRefObject { public bool Working { get; set; } } [Serializable] public struct Climate { public double Temperature { get; set; } }
, / , .
const string controlAlgorithm = @" IF Climate.Temperature > 26 THEN Unit.Working = TRUE IF Climate.Temperature < 22 THEN Unit.Working = FALSE"; var unit = new AirConditioner(); var limate = new Climate { Temperature = 28 }; using (var sandbox = new Sandbox()) { var controlCode = CodeGenerator.CreateCode<int>(sandbox, VB.Compiler, controlAlgorithm, null, null, CodeParameter.Create("Unit", unit), CodeParameter.Create("Climate", limate)); while (!Console.KeyAvailable) { Console.WriteLine("t={0}°C", limate.Temperature); controlCode.Execute(unit, limate); Thread.Sleep(300); limate.Temperature += unit.Working ? -1 : 1; } }
, , MarshalByRefObject, Climate [Serializable].
.
1. #- System
, , . C# using'. . , , . .
2. System.dll mscorlib.dll, . , . , .
, , . .
3. C#. . VB.Net. . ( .)
, , . . .
, . , , -, . , - (plugin modules).
. , . , .

, , , .
C#
C# " "
CS-Script - The C# Script Engine
Security and On-the-Fly Code Generation
How to: Run Partially Trusted Code in a Sandbox
Metaprogramming in .NET. EBook
Debugging a generated .NET assembly from within the application that generated it
CodeGenerator.ExecuteCode. - . , . ? ?
. " ", " " ExecuteCode
. , , , , . , , , . , , , , .
, . .
var result = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 9876543.21), CodeParameter.Create("b", 9), CodeParameter.Create("c", -0.01)); var result2 = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 12345678.9), CodeParameter.Create("b", 8), CodeParameter.Create("c", 0.9));
, , . ExecuteCode , , . C#-, , , ExecuteCode .
. , .
var code = CodeGenerator.CreateCode<DateTime>( "return StartDate.AddDays(Duration);", new CodeParameter("StartDate", typeof(DateTime)), new CodeParameter("Duration", typeof(int))); var result1 = code.Execute(DateTime.Parse("2013-01-01"), 256); var result2 = code.Execute(DateTime.Parse("2013-10-13"), 131);
. C#-, , . . .
. .
. , , . , - . , . , .
- . , . (, ). , .
, (AppDomain) - "" (sandbox). , . , , .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, "return (int)(DateTime.Now - StartDate).TotalDays;", new CodeParameter("StartDate", typeof(DateTime))); var result = code.Execute(DateTime.Parse("1962-09-17")); }
Sandbox
, AppDomain. . .
, , . - .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(@"c:\temp\a.txt"); // SecurityException }
, . .
const string FILE_PATH = @"c:\temp\a.txt"; using (var sandbox = new Sandbox( new FileIOPermission(FileIOPermissionAccess.AllAccess, FILE_PATH))) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(FILE_PATH); }
,
. , . , .. .
, . , MarshalByRefObject. .Net Remoting, .
. :
public class AirConditioner : MarshalByRefObject { public bool Working { get; set; } } [Serializable] public struct Climate { public double Temperature { get; set; } }
, / , .
const string controlAlgorithm = @" IF Climate.Temperature > 26 THEN Unit.Working = TRUE IF Climate.Temperature < 22 THEN Unit.Working = FALSE"; var unit = new AirConditioner(); var limate = new Climate { Temperature = 28 }; using (var sandbox = new Sandbox()) { var controlCode = CodeGenerator.CreateCode<int>(sandbox, VB.Compiler, controlAlgorithm, null, null, CodeParameter.Create("Unit", unit), CodeParameter.Create("Climate", limate)); while (!Console.KeyAvailable) { Console.WriteLine("t={0}°C", limate.Temperature); controlCode.Execute(unit, limate); Thread.Sleep(300); limate.Temperature += unit.Working ? -1 : 1; } }
, , MarshalByRefObject, Climate [Serializable].
.
1. #- System
, , . C# using'. . , , . .
2. System.dll mscorlib.dll, . , . , .
, , . .
3. C#. . VB.Net. . ( .)
, , . . .
, . , , -, . , - (plugin modules).
. , . , .

, , , .
C#
C# " "
CS-Script - The C# Script Engine
Security and On-the-Fly Code Generation
How to: Run Partially Trusted Code in a Sandbox
Metaprogramming in .NET. EBook
Debugging a generated .NET assembly from within the application that generated it
CodeGenerator.ExecuteCode. - . , . ? ?
. " ", " " ExecuteCode
. , , , , . , , , . , , , , .
, . .
var result = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 9876543.21), CodeParameter.Create("b", 9), CodeParameter.Create("c", -0.01)); var result2 = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 12345678.9), CodeParameter.Create("b", 8), CodeParameter.Create("c", 0.9));
, , . ExecuteCode , , . C#-, , , ExecuteCode .
. , .
var code = CodeGenerator.CreateCode<DateTime>( "return StartDate.AddDays(Duration);", new CodeParameter("StartDate", typeof(DateTime)), new CodeParameter("Duration", typeof(int))); var result1 = code.Execute(DateTime.Parse("2013-01-01"), 256); var result2 = code.Execute(DateTime.Parse("2013-10-13"), 131);
. C#-, , . . .
. .
. , , . , - . , . , .
- . , . (, ). , .
, (AppDomain) - "" (sandbox). , . , , .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, "return (int)(DateTime.Now - StartDate).TotalDays;", new CodeParameter("StartDate", typeof(DateTime))); var result = code.Execute(DateTime.Parse("1962-09-17")); }
Sandbox
, AppDomain. . .
, , . - .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(@"c:\temp\a.txt"); // SecurityException }
, . .
const string FILE_PATH = @"c:\temp\a.txt"; using (var sandbox = new Sandbox( new FileIOPermission(FileIOPermissionAccess.AllAccess, FILE_PATH))) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(FILE_PATH); }
,
. , . , .. .
, . , MarshalByRefObject. .Net Remoting, .
. :
public class AirConditioner : MarshalByRefObject { public bool Working { get; set; } } [Serializable] public struct Climate { public double Temperature { get; set; } }
, / , .
const string controlAlgorithm = @" IF Climate.Temperature > 26 THEN Unit.Working = TRUE IF Climate.Temperature < 22 THEN Unit.Working = FALSE"; var unit = new AirConditioner(); var limate = new Climate { Temperature = 28 }; using (var sandbox = new Sandbox()) { var controlCode = CodeGenerator.CreateCode<int>(sandbox, VB.Compiler, controlAlgorithm, null, null, CodeParameter.Create("Unit", unit), CodeParameter.Create("Climate", limate)); while (!Console.KeyAvailable) { Console.WriteLine("t={0}°C", limate.Temperature); controlCode.Execute(unit, limate); Thread.Sleep(300); limate.Temperature += unit.Working ? -1 : 1; } }
, , MarshalByRefObject, Climate [Serializable].
.
1. #- System
, , . C# using'. . , , . .
2. System.dll mscorlib.dll, . , . , .
, , . .
3. C#. . VB.Net. . ( .)
, , . . .
, . , , -, . , - (plugin modules).
. , . , .

, , , .
C#
C# " "
CS-Script - The C# Script Engine
Security and On-the-Fly Code Generation
How to: Run Partially Trusted Code in a Sandbox
Metaprogramming in .NET. EBook
Debugging a generated .NET assembly from within the application that generated it
CodeGenerator.ExecuteCode. - . , . ? ?
. " ", " " ExecuteCode
. , , , , . , , , . , , , , .
, . .
var result = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 9876543.21), CodeParameter.Create("b", 9), CodeParameter.Create("c", -0.01)); var result2 = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 12345678.9), CodeParameter.Create("b", 8), CodeParameter.Create("c", 0.9));
, , . ExecuteCode , , . C#-, , , ExecuteCode .
. , .
var code = CodeGenerator.CreateCode<DateTime>( "return StartDate.AddDays(Duration);", new CodeParameter("StartDate", typeof(DateTime)), new CodeParameter("Duration", typeof(int))); var result1 = code.Execute(DateTime.Parse("2013-01-01"), 256); var result2 = code.Execute(DateTime.Parse("2013-10-13"), 131);
. C#-, , . . .
. .
. , , . , - . , . , .
- . , . (, ). , .
, (AppDomain) - "" (sandbox). , . , , .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, "return (int)(DateTime.Now - StartDate).TotalDays;", new CodeParameter("StartDate", typeof(DateTime))); var result = code.Execute(DateTime.Parse("1962-09-17")); }
Sandbox
, AppDomain. . .
, , . - .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(@"c:\temp\a.txt"); // SecurityException }
, . .
const string FILE_PATH = @"c:\temp\a.txt"; using (var sandbox = new Sandbox( new FileIOPermission(FileIOPermissionAccess.AllAccess, FILE_PATH))) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(FILE_PATH); }
,
. , . , .. .
, . , MarshalByRefObject. .Net Remoting, .
. :
public class AirConditioner : MarshalByRefObject { public bool Working { get; set; } } [Serializable] public struct Climate { public double Temperature { get; set; } }
, / , .
const string controlAlgorithm = @" IF Climate.Temperature > 26 THEN Unit.Working = TRUE IF Climate.Temperature < 22 THEN Unit.Working = FALSE"; var unit = new AirConditioner(); var limate = new Climate { Temperature = 28 }; using (var sandbox = new Sandbox()) { var controlCode = CodeGenerator.CreateCode<int>(sandbox, VB.Compiler, controlAlgorithm, null, null, CodeParameter.Create("Unit", unit), CodeParameter.Create("Climate", limate)); while (!Console.KeyAvailable) { Console.WriteLine("t={0}°C", limate.Temperature); controlCode.Execute(unit, limate); Thread.Sleep(300); limate.Temperature += unit.Working ? -1 : 1; } }
, , MarshalByRefObject, Climate [Serializable].
.
1. #- System
, , . C# using'. . , , . .
2. System.dll mscorlib.dll, . , . , .
, , . .
3. C#. . VB.Net. . ( .)
, , . . .
, . , , -, . , - (plugin modules).
. , . , .
, , , .
C#
C# " "
CS-Script - The C# Script Engine
Security and On-the-Fly Code Generation
How to: Run Partially Trusted Code in a Sandbox
Metaprogramming in .NET. EBook
Debugging a generated .NET assembly from within the application that generated it
CodeGenerator.ExecuteCode. - . , . ? ?
. " ", " " ExecuteCode
. , , , , . , , , . , , , , .
, . .
var result = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 9876543.21), CodeParameter.Create("b", 9), CodeParameter.Create("c", -0.01)); var result2 = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 12345678.9), CodeParameter.Create("b", 8), CodeParameter.Create("c", 0.9));
, , . ExecuteCode , , . C#-, , , ExecuteCode .
. , .
var code = CodeGenerator.CreateCode<DateTime>( "return StartDate.AddDays(Duration);", new CodeParameter("StartDate", typeof(DateTime)), new CodeParameter("Duration", typeof(int))); var result1 = code.Execute(DateTime.Parse("2013-01-01"), 256); var result2 = code.Execute(DateTime.Parse("2013-10-13"), 131);
. C#-, , . . .
. .
. , , . , - . , . , .
- . , . (, ). , .
, (AppDomain) - "" (sandbox). , . , , .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, "return (int)(DateTime.Now - StartDate).TotalDays;", new CodeParameter("StartDate", typeof(DateTime))); var result = code.Execute(DateTime.Parse("1962-09-17")); }
Sandbox
, AppDomain. . .
, , . - .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(@"c:\temp\a.txt"); // SecurityException }
, . .
const string FILE_PATH = @"c:\temp\a.txt"; using (var sandbox = new Sandbox( new FileIOPermission(FileIOPermissionAccess.AllAccess, FILE_PATH))) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(FILE_PATH); }
,
. , . , .. .
, . , MarshalByRefObject. .Net Remoting, .
. :
public class AirConditioner : MarshalByRefObject { public bool Working { get; set; } } [Serializable] public struct Climate { public double Temperature { get; set; } }
, / , .
const string controlAlgorithm = @" IF Climate.Temperature > 26 THEN Unit.Working = TRUE IF Climate.Temperature < 22 THEN Unit.Working = FALSE"; var unit = new AirConditioner(); var limate = new Climate { Temperature = 28 }; using (var sandbox = new Sandbox()) { var controlCode = CodeGenerator.CreateCode<int>(sandbox, VB.Compiler, controlAlgorithm, null, null, CodeParameter.Create("Unit", unit), CodeParameter.Create("Climate", limate)); while (!Console.KeyAvailable) { Console.WriteLine("t={0}°C", limate.Temperature); controlCode.Execute(unit, limate); Thread.Sleep(300); limate.Temperature += unit.Working ? -1 : 1; } }
, , MarshalByRefObject, Climate [Serializable].
.
1. #- System
, , . C# using'. . , , . .
2. System.dll mscorlib.dll, . , . , .
, , . .
3. C#. . VB.Net. . ( .)
, , . . .
, . , , -, . , - (plugin modules).
. , . , .

, , , .
C#
C# " "
CS-Script - The C# Script Engine
Security and On-the-Fly Code Generation
How to: Run Partially Trusted Code in a Sandbox
Metaprogramming in .NET. EBook
Debugging a generated .NET assembly from within the application that generated it
CodeGenerator.ExecuteCode. - . , . ? ?
. " ", " " ExecuteCode
. , , , , . , , , . , , , , .
, . .
var result = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 9876543.21), CodeParameter.Create("b", 9), CodeParameter.Create("c", -0.01)); var result2 = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 12345678.9), CodeParameter.Create("b", 8), CodeParameter.Create("c", 0.9));
, , . ExecuteCode , , . C#-, , , ExecuteCode .
. , .
var code = CodeGenerator.CreateCode<DateTime>( "return StartDate.AddDays(Duration);", new CodeParameter("StartDate", typeof(DateTime)), new CodeParameter("Duration", typeof(int))); var result1 = code.Execute(DateTime.Parse("2013-01-01"), 256); var result2 = code.Execute(DateTime.Parse("2013-10-13"), 131);
. C#-, , . . .
. .
. , , . , - . , . , .
- . , . (, ). , .
, (AppDomain) - "" (sandbox). , . , , .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, "return (int)(DateTime.Now - StartDate).TotalDays;", new CodeParameter("StartDate", typeof(DateTime))); var result = code.Execute(DateTime.Parse("1962-09-17")); }
Sandbox
, AppDomain. . .
, , . - .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(@"c:\temp\a.txt"); // SecurityException }
, . .
const string FILE_PATH = @"c:\temp\a.txt"; using (var sandbox = new Sandbox( new FileIOPermission(FileIOPermissionAccess.AllAccess, FILE_PATH))) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(FILE_PATH); }
,
. , . , .. .
, . , MarshalByRefObject. .Net Remoting, .
. :
public class AirConditioner : MarshalByRefObject { public bool Working { get; set; } } [Serializable] public struct Climate { public double Temperature { get; set; } }
, / , .
const string controlAlgorithm = @" IF Climate.Temperature > 26 THEN Unit.Working = TRUE IF Climate.Temperature < 22 THEN Unit.Working = FALSE"; var unit = new AirConditioner(); var limate = new Climate { Temperature = 28 }; using (var sandbox = new Sandbox()) { var controlCode = CodeGenerator.CreateCode<int>(sandbox, VB.Compiler, controlAlgorithm, null, null, CodeParameter.Create("Unit", unit), CodeParameter.Create("Climate", limate)); while (!Console.KeyAvailable) { Console.WriteLine("t={0}°C", limate.Temperature); controlCode.Execute(unit, limate); Thread.Sleep(300); limate.Temperature += unit.Working ? -1 : 1; } }
, , MarshalByRefObject, Climate [Serializable].
.
1. #- System
, , . C# using'. . , , . .
2. System.dll mscorlib.dll, . , . , .
, , . .
3. C#. . VB.Net. . ( .)
, , . . .
, . , , -, . , - (plugin modules).
. , . , .
, , , .
C#
C# " "
CS-Script - The C# Script Engine
Security and On-the-Fly Code Generation
How to: Run Partially Trusted Code in a Sandbox
Metaprogramming in .NET. EBook
Debugging a generated .NET assembly from within the application that generated it
CodeGenerator.ExecuteCode. - . , . ? ?
. " ", " " ExecuteCode
. , , , , . , , , . , , , , .
, . .
var result = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 9876543.21), CodeParameter.Create("b", 9), CodeParameter.Create("c", -0.01)); var result2 = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 12345678.9), CodeParameter.Create("b", 8), CodeParameter.Create("c", 0.9));
, , . ExecuteCode , , . C#-, , , ExecuteCode .
. , .
var code = CodeGenerator.CreateCode<DateTime>( "return StartDate.AddDays(Duration);", new CodeParameter("StartDate", typeof(DateTime)), new CodeParameter("Duration", typeof(int))); var result1 = code.Execute(DateTime.Parse("2013-01-01"), 256); var result2 = code.Execute(DateTime.Parse("2013-10-13"), 131);
. C#-, , . . .
. .
. , , . , - . , . , .
- . , . (, ). , .
, (AppDomain) - "" (sandbox). , . , , .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, "return (int)(DateTime.Now - StartDate).TotalDays;", new CodeParameter("StartDate", typeof(DateTime))); var result = code.Execute(DateTime.Parse("1962-09-17")); }
Sandbox
, AppDomain. . .
, , . - .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(@"c:\temp\a.txt"); // SecurityException }
, . .
const string FILE_PATH = @"c:\temp\a.txt"; using (var sandbox = new Sandbox( new FileIOPermission(FileIOPermissionAccess.AllAccess, FILE_PATH))) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(FILE_PATH); }
,
. , . , .. .
, . , MarshalByRefObject. .Net Remoting, .
. :
public class AirConditioner : MarshalByRefObject { public bool Working { get; set; } } [Serializable] public struct Climate { public double Temperature { get; set; } }
, / , .
const string controlAlgorithm = @" IF Climate.Temperature > 26 THEN Unit.Working = TRUE IF Climate.Temperature < 22 THEN Unit.Working = FALSE"; var unit = new AirConditioner(); var limate = new Climate { Temperature = 28 }; using (var sandbox = new Sandbox()) { var controlCode = CodeGenerator.CreateCode<int>(sandbox, VB.Compiler, controlAlgorithm, null, null, CodeParameter.Create("Unit", unit), CodeParameter.Create("Climate", limate)); while (!Console.KeyAvailable) { Console.WriteLine("t={0}°C", limate.Temperature); controlCode.Execute(unit, limate); Thread.Sleep(300); limate.Temperature += unit.Working ? -1 : 1; } }
, , MarshalByRefObject, Climate [Serializable].
.
1. #- System
, , . C# using'. . , , . .
2. System.dll mscorlib.dll, . , . , .
, , . .
3. C#. . VB.Net. . ( .)
, , . . .
, . , , -, . , - (plugin modules).
. , . , .

, , , .
C#
C# " "
CS-Script - The C# Script Engine
Security and On-the-Fly Code Generation
How to: Run Partially Trusted Code in a Sandbox
Metaprogramming in .NET. EBook
Debugging a generated .NET assembly from within the application that generated it
CodeGenerator.ExecuteCode. - . , . ? ?
. " ", " " ExecuteCode
. , , , , . , , , . , , , , .
, . .
var result = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 9876543.21), CodeParameter.Create("b", 9), CodeParameter.Create("c", -0.01)); var result2 = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 12345678.9), CodeParameter.Create("b", 8), CodeParameter.Create("c", 0.9));
, , . ExecuteCode , , . C#-, , , ExecuteCode .
. , .
var code = CodeGenerator.CreateCode<DateTime>( "return StartDate.AddDays(Duration);", new CodeParameter("StartDate", typeof(DateTime)), new CodeParameter("Duration", typeof(int))); var result1 = code.Execute(DateTime.Parse("2013-01-01"), 256); var result2 = code.Execute(DateTime.Parse("2013-10-13"), 131);
. C#-, , . . .
. .
. , , . , - . , . , .
- . , . (, ). , .
, (AppDomain) - "" (sandbox). , . , , .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, "return (int)(DateTime.Now - StartDate).TotalDays;", new CodeParameter("StartDate", typeof(DateTime))); var result = code.Execute(DateTime.Parse("1962-09-17")); }
Sandbox
, AppDomain. . .
, , . - .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(@"c:\temp\a.txt"); // SecurityException }
, . .
const string FILE_PATH = @"c:\temp\a.txt"; using (var sandbox = new Sandbox( new FileIOPermission(FileIOPermissionAccess.AllAccess, FILE_PATH))) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(FILE_PATH); }
,
. , . , .. .
, . , MarshalByRefObject. .Net Remoting, .
. :
public class AirConditioner : MarshalByRefObject { public bool Working { get; set; } } [Serializable] public struct Climate { public double Temperature { get; set; } }
, / , .
const string controlAlgorithm = @" IF Climate.Temperature > 26 THEN Unit.Working = TRUE IF Climate.Temperature < 22 THEN Unit.Working = FALSE"; var unit = new AirConditioner(); var limate = new Climate { Temperature = 28 }; using (var sandbox = new Sandbox()) { var controlCode = CodeGenerator.CreateCode<int>(sandbox, VB.Compiler, controlAlgorithm, null, null, CodeParameter.Create("Unit", unit), CodeParameter.Create("Climate", limate)); while (!Console.KeyAvailable) { Console.WriteLine("t={0}°C", limate.Temperature); controlCode.Execute(unit, limate); Thread.Sleep(300); limate.Temperature += unit.Working ? -1 : 1; } }
, , MarshalByRefObject, Climate [Serializable].
.
1. #- System
, , . C# using'. . , , . .
2. System.dll mscorlib.dll, . , . , .
, , . .
3. C#. . VB.Net. . ( .)
, , . . .
, . , , -, . , - (plugin modules).
. , . , .

, , , .
C#
C# " "
CS-Script - The C# Script Engine
Security and On-the-Fly Code Generation
How to: Run Partially Trusted Code in a Sandbox
Metaprogramming in .NET. EBook
Debugging a generated .NET assembly from within the application that generated it
CodeGenerator.ExecuteCode. - . , . ? ?
. " ", " " ExecuteCode
. , , , , . , , , . , , , , .
, . .
var result = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 9876543.21), CodeParameter.Create("b", 9), CodeParameter.Create("c", -0.01)); var result2 = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 12345678.9), CodeParameter.Create("b", 8), CodeParameter.Create("c", 0.9));
, , . ExecuteCode , , . C#-, , , ExecuteCode .
. , .
var code = CodeGenerator.CreateCode<DateTime>( "return StartDate.AddDays(Duration);", new CodeParameter("StartDate", typeof(DateTime)), new CodeParameter("Duration", typeof(int))); var result1 = code.Execute(DateTime.Parse("2013-01-01"), 256); var result2 = code.Execute(DateTime.Parse("2013-10-13"), 131);
. C#-, , . . .
. .
. , , . , - . , . , .
- . , . (, ). , .
, (AppDomain) - "" (sandbox). , . , , .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, "return (int)(DateTime.Now - StartDate).TotalDays;", new CodeParameter("StartDate", typeof(DateTime))); var result = code.Execute(DateTime.Parse("1962-09-17")); }
Sandbox
, AppDomain. . .
, , . - .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(@"c:\temp\a.txt"); // SecurityException }
, . .
const string FILE_PATH = @"c:\temp\a.txt"; using (var sandbox = new Sandbox( new FileIOPermission(FileIOPermissionAccess.AllAccess, FILE_PATH))) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(FILE_PATH); }
,
. , . , .. .
, . , MarshalByRefObject. .Net Remoting, .
. :
public class AirConditioner : MarshalByRefObject { public bool Working { get; set; } } [Serializable] public struct Climate { public double Temperature { get; set; } }
, / , .
const string controlAlgorithm = @" IF Climate.Temperature > 26 THEN Unit.Working = TRUE IF Climate.Temperature < 22 THEN Unit.Working = FALSE"; var unit = new AirConditioner(); var limate = new Climate { Temperature = 28 }; using (var sandbox = new Sandbox()) { var controlCode = CodeGenerator.CreateCode<int>(sandbox, VB.Compiler, controlAlgorithm, null, null, CodeParameter.Create("Unit", unit), CodeParameter.Create("Climate", limate)); while (!Console.KeyAvailable) { Console.WriteLine("t={0}°C", limate.Temperature); controlCode.Execute(unit, limate); Thread.Sleep(300); limate.Temperature += unit.Working ? -1 : 1; } }
, , MarshalByRefObject, Climate [Serializable].
.
1. #- System
, , . C# using'. . , , . .
2. System.dll mscorlib.dll, . , . , .
, , . .
3. C#. . VB.Net. . ( .)
, , . . .
, . , , -, . , - (plugin modules).
. , . , .

, , , .
C#
C# " "
CS-Script - The C# Script Engine
Security and On-the-Fly Code Generation
How to: Run Partially Trusted Code in a Sandbox
Metaprogramming in .NET. EBook
Debugging a generated .NET assembly from within the application that generated it
CodeGenerator.ExecuteCode. - . , . ? ?
. " ", " " ExecuteCode
. , , , , . , , , . , , , , .
, . .
var result = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 9876543.21), CodeParameter.Create("b", 9), CodeParameter.Create("c", -0.01)); var result2 = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 12345678.9), CodeParameter.Create("b", 8), CodeParameter.Create("c", 0.9));
, , . ExecuteCode , , . C#-, , , ExecuteCode .
. , .
var code = CodeGenerator.CreateCode<DateTime>( "return StartDate.AddDays(Duration);", new CodeParameter("StartDate", typeof(DateTime)), new CodeParameter("Duration", typeof(int))); var result1 = code.Execute(DateTime.Parse("2013-01-01"), 256); var result2 = code.Execute(DateTime.Parse("2013-10-13"), 131);
. C#-, , . . .
. .
. , , . , - . , . , .
- . , . (, ). , .
, (AppDomain) - "" (sandbox). , . , , .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, "return (int)(DateTime.Now - StartDate).TotalDays;", new CodeParameter("StartDate", typeof(DateTime))); var result = code.Execute(DateTime.Parse("1962-09-17")); }
Sandbox
, AppDomain. . .
, , . - .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(@"c:\temp\a.txt"); // SecurityException }
, . .
const string FILE_PATH = @"c:\temp\a.txt"; using (var sandbox = new Sandbox( new FileIOPermission(FileIOPermissionAccess.AllAccess, FILE_PATH))) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(FILE_PATH); }
,
. , . , .. .
, . , MarshalByRefObject. .Net Remoting, .
. :
public class AirConditioner : MarshalByRefObject { public bool Working { get; set; } } [Serializable] public struct Climate { public double Temperature { get; set; } }
, / , .
const string controlAlgorithm = @" IF Climate.Temperature > 26 THEN Unit.Working = TRUE IF Climate.Temperature < 22 THEN Unit.Working = FALSE"; var unit = new AirConditioner(); var limate = new Climate { Temperature = 28 }; using (var sandbox = new Sandbox()) { var controlCode = CodeGenerator.CreateCode<int>(sandbox, VB.Compiler, controlAlgorithm, null, null, CodeParameter.Create("Unit", unit), CodeParameter.Create("Climate", limate)); while (!Console.KeyAvailable) { Console.WriteLine("t={0}°C", limate.Temperature); controlCode.Execute(unit, limate); Thread.Sleep(300); limate.Temperature += unit.Working ? -1 : 1; } }
, , MarshalByRefObject, Climate [Serializable].
.
1. #- System
, , . C# using'. . , , . .
2. System.dll mscorlib.dll, . , . , .
, , . .
3. C#. . VB.Net. . ( .)
, , . . .
, . , , -, . , - (plugin modules).
. , . , .

, , , .
C#
C# " "
CS-Script - The C# Script Engine
Security and On-the-Fly Code Generation
How to: Run Partially Trusted Code in a Sandbox
Metaprogramming in .NET. EBook
Debugging a generated .NET assembly from within the application that generated it
CodeGenerator.ExecuteCode. - . , . ? ?
. " ", " " ExecuteCode
. , , , , . , , , . , , , , .
, . .
var result = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 9876543.21), CodeParameter.Create("b", 9), CodeParameter.Create("c", -0.01)); var result2 = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 12345678.9), CodeParameter.Create("b", 8), CodeParameter.Create("c", 0.9));
, , . ExecuteCode , , . C#-, , , ExecuteCode .
. , .
var code = CodeGenerator.CreateCode<DateTime>( "return StartDate.AddDays(Duration);", new CodeParameter("StartDate", typeof(DateTime)), new CodeParameter("Duration", typeof(int))); var result1 = code.Execute(DateTime.Parse("2013-01-01"), 256); var result2 = code.Execute(DateTime.Parse("2013-10-13"), 131);
. C#-, , . . .
. .
. , , . , - . , . , .
- . , . (, ). , .
, (AppDomain) - "" (sandbox). , . , , .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, "return (int)(DateTime.Now - StartDate).TotalDays;", new CodeParameter("StartDate", typeof(DateTime))); var result = code.Execute(DateTime.Parse("1962-09-17")); }
Sandbox
, AppDomain. . .
, , . - .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(@"c:\temp\a.txt"); // SecurityException }
, . .
const string FILE_PATH = @"c:\temp\a.txt"; using (var sandbox = new Sandbox( new FileIOPermission(FileIOPermissionAccess.AllAccess, FILE_PATH))) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(FILE_PATH); }
,
. , . , .. .
, . , MarshalByRefObject. .Net Remoting, .
. :
public class AirConditioner : MarshalByRefObject { public bool Working { get; set; } } [Serializable] public struct Climate { public double Temperature { get; set; } }
, / , .
const string controlAlgorithm = @" IF Climate.Temperature > 26 THEN Unit.Working = TRUE IF Climate.Temperature < 22 THEN Unit.Working = FALSE"; var unit = new AirConditioner(); var limate = new Climate { Temperature = 28 }; using (var sandbox = new Sandbox()) { var controlCode = CodeGenerator.CreateCode<int>(sandbox, VB.Compiler, controlAlgorithm, null, null, CodeParameter.Create("Unit", unit), CodeParameter.Create("Climate", limate)); while (!Console.KeyAvailable) { Console.WriteLine("t={0}°C", limate.Temperature); controlCode.Execute(unit, limate); Thread.Sleep(300); limate.Temperature += unit.Working ? -1 : 1; } }
, , MarshalByRefObject, Climate [Serializable].
.
1. #- System
, , . C# using'. . , , . .
2. System.dll mscorlib.dll, . , . , .
, , . .
3. C#. . VB.Net. . ( .)
, , . . .
, . , , -, . , - (plugin modules).
. , . , .

, , , .
C#
C# " "
CS-Script - The C# Script Engine
Security and On-the-Fly Code Generation
How to: Run Partially Trusted Code in a Sandbox
Metaprogramming in .NET. EBook
Debugging a generated .NET assembly from within the application that generated it
CodeGenerator.ExecuteCode. - . , . ? ?
. " ", " " ExecuteCode
. , , , , . , , , . , , , , .
, . .
var result = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 9876543.21), CodeParameter.Create("b", 9), CodeParameter.Create("c", -0.01)); var result2 = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 12345678.9), CodeParameter.Create("b", 8), CodeParameter.Create("c", 0.9));
, , . ExecuteCode , , . C#-, , , ExecuteCode .
. , .
var code = CodeGenerator.CreateCode<DateTime>( "return StartDate.AddDays(Duration);", new CodeParameter("StartDate", typeof(DateTime)), new CodeParameter("Duration", typeof(int))); var result1 = code.Execute(DateTime.Parse("2013-01-01"), 256); var result2 = code.Execute(DateTime.Parse("2013-10-13"), 131);
. C#-, , . . .
. .
. , , . , - . , . , .
- . , . (, ). , .
, (AppDomain) - "" (sandbox). , . , , .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, "return (int)(DateTime.Now - StartDate).TotalDays;", new CodeParameter("StartDate", typeof(DateTime))); var result = code.Execute(DateTime.Parse("1962-09-17")); }
Sandbox
, AppDomain. . .
, , . - .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(@"c:\temp\a.txt"); // SecurityException }
, . .
const string FILE_PATH = @"c:\temp\a.txt"; using (var sandbox = new Sandbox( new FileIOPermission(FileIOPermissionAccess.AllAccess, FILE_PATH))) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(FILE_PATH); }
,
. , . , .. .
, . , MarshalByRefObject. .Net Remoting, .
. :
public class AirConditioner : MarshalByRefObject { public bool Working { get; set; } } [Serializable] public struct Climate { public double Temperature { get; set; } }
, / , .
const string controlAlgorithm = @" IF Climate.Temperature > 26 THEN Unit.Working = TRUE IF Climate.Temperature < 22 THEN Unit.Working = FALSE"; var unit = new AirConditioner(); var limate = new Climate { Temperature = 28 }; using (var sandbox = new Sandbox()) { var controlCode = CodeGenerator.CreateCode<int>(sandbox, VB.Compiler, controlAlgorithm, null, null, CodeParameter.Create("Unit", unit), CodeParameter.Create("Climate", limate)); while (!Console.KeyAvailable) { Console.WriteLine("t={0}°C", limate.Temperature); controlCode.Execute(unit, limate); Thread.Sleep(300); limate.Temperature += unit.Working ? -1 : 1; } }
, , MarshalByRefObject, Climate [Serializable].
.
1. #- System
, , . C# using'. . , , . .
2. System.dll mscorlib.dll, . , . , .
, , . .
3. C#. . VB.Net. . ( .)
, , . . .
, . , , -, . , - (plugin modules).
. , . , .

, , , .
C#
C# " "
CS-Script - The C# Script Engine
Security and On-the-Fly Code Generation
How to: Run Partially Trusted Code in a Sandbox
Metaprogramming in .NET. EBook
Debugging a generated .NET assembly from within the application that generated it
CodeGenerator.ExecuteCode. - . , . ? ?
. " ", " " ExecuteCode
. , , , , . , , , . , , , , .
, . .
var result = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 9876543.21), CodeParameter.Create("b", 9), CodeParameter.Create("c", -0.01)); var result2 = CodeGenerator.ExecuteCode<double>("return a * b + c;", CodeParameter.Create("a", 12345678.9), CodeParameter.Create("b", 8), CodeParameter.Create("c", 0.9));
, , . ExecuteCode , , . C#-, , , ExecuteCode .
. , .
var code = CodeGenerator.CreateCode<DateTime>( "return StartDate.AddDays(Duration);", new CodeParameter("StartDate", typeof(DateTime)), new CodeParameter("Duration", typeof(int))); var result1 = code.Execute(DateTime.Parse("2013-01-01"), 256); var result2 = code.Execute(DateTime.Parse("2013-10-13"), 131);
. C#-, , . . .
. .
. , , . , - . , . , .
- . , . (, ). , .
, (AppDomain) - "" (sandbox). , . , , .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, "return (int)(DateTime.Now - StartDate).TotalDays;", new CodeParameter("StartDate", typeof(DateTime))); var result = code.Execute(DateTime.Parse("1962-09-17")); }
Sandbox
, AppDomain. . .
, , . - .
using (var sandbox = new Sandbox()) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(@"c:\temp\a.txt"); // SecurityException }
, . .
const string FILE_PATH = @"c:\temp\a.txt"; using (var sandbox = new Sandbox( new FileIOPermission(FileIOPermissionAccess.AllAccess, FILE_PATH))) { var code = CodeGenerator.CreateCode<int>(sandbox, @"System.IO.File.Delete(filePath);", new CodeParameter("filePath", typeof(string))); code.Execute(FILE_PATH); }
,
. , . , .. .
, . , MarshalByRefObject. .Net Remoting, .
. :
public class AirConditioner : MarshalByRefObject { public bool Working { get; set; } } [Serializable] public struct Climate { public double Temperature { get; set; } }
, / , .
const string controlAlgorithm = @" IF Climate.Temperature > 26 THEN Unit.Working = TRUE IF Climate.Temperature < 22 THEN Unit.Working = FALSE"; var unit = new AirConditioner(); var limate = new Climate { Temperature = 28 }; using (var sandbox = new Sandbox()) { var controlCode = CodeGenerator.CreateCode<int>(sandbox, VB.Compiler, controlAlgorithm, null, null, CodeParameter.Create("Unit", unit), CodeParameter.Create("Climate", limate)); while (!Console.KeyAvailable) { Console.WriteLine("t={0}°C", limate.Temperature); controlCode.Execute(unit, limate); Thread.Sleep(300); limate.Temperature += unit.Working ? -1 : 1; } }
, , MarshalByRefObject, Climate [Serializable].
.
1. #- System
, , . C# using'. . , , . .
2. System.dll mscorlib.dll, . , . , .
, , . .
3. C#. . VB.Net. . ( .)
, , . . .
, . , , -, . , - (plugin modules).
. , . , .

, , , .
C#
C# " "
CS-Script - The C# Script Engine
Security and On-the-Fly Code Generation
How to: Run Partially Trusted Code in a Sandbox
Metaprogramming in .NET. EBook
Debugging a generated .NET assembly from within the application that generated it
Source: https://habr.com/ru/post/199266/
All Articles