рдЗрдиреНрдлреНрд░рд╛рд╕реНрдЯреНрд░рдХреНрдЪрд░ред рдиреЗрдЯ рдореЗрдВ рдмрд┐рд▓реНрдЯ-рдЗрди рдХреЛрдб рдЬреЗрдирд░реЗрд╢рди (рдСрди-рдж-рдлреНрд▓рд╛рдИ рдХреЛрдб рдЬреЗрдирд░реЗрд╢рди) рд╣реЛрддрд╛ рд╣реИред рдпрд╣ .Net рдХрд╛рд░реНрдпрдХреНрд░рдо рдХреЛ рдЗрд╕рдХреЗ рдирд┐рд╖реНрдкрд╛рджрди рдХреЗ рд╕рдордп рд╕реНрд╡рддрдВрддреНрд░ рд░реВрдк рд╕реЗ (рдкреНрд░реЛрдЧреНрд░рд╛рдорд░ рдХреА рднрд╛рдЧреАрджрд╛рд░реА рдХреЗ рдмрд┐рдирд╛) рдХрд┐рд╕реА рднреА рдкреНрд░реЛрдЧреНрд░рд╛рдорд┐рдВрдЧ рднрд╛рд╖рд╛ рдореЗрдВ рд▓рд┐рдЦреЗ рдЧрдП рдкрд╛рда рдХреЛ рд╕рдВрдХрд▓рд┐рдд рдХрд░рдиреЗ рдФрд░ рдкрд░рд┐рдгрд╛рдореА рдХреЛрдб рдХреЛ рдирд┐рд╖реНрдкрд╛рджрд┐рдд рдХрд░рдиреЗ рдХреА рдЕрдиреБрдорддрд┐ рджреЗрддрд╛ рд╣реИред рдпрд╣ рдЕрдкреЗрдХреНрд╖рд╛ рдХрд░рдирд╛ рддрд░реНрдХрд╕рдВрдЧрдд рд╣реЛрдЧрд╛ рдХрд┐ рдорд╛рдирдХ .Net рдкреБрд╕реНрддрдХрд╛рд▓рдп рдореЗрдВ рдЗрди рдХрд╛рд░реНрдпреЛрдВ рдХреЗ рдХрд╛рд░реНрдпрд╛рдиреНрд╡рдпрди рдХреЗ рд▓рд┐рдП рд╕рдВрдмрдВрдзрд┐рдд рд╡рд░реНрдЧ рдХреА рд╕рдмрд╕реЗ рд╕рд░рд▓ рд╡рд┐рдзрд┐ рдкреНрд░рджрд╛рди рдХреА рдЬрд╛рддреА рд╣реИред рд▓реЗрдХрд┐рди рджреБрд░реНрднрд╛рдЧреНрдп рд╕реЗ рдРрд╕рд╛ рдирд╣реАрдВ рд╣реИред Microsoft, .рдиреЗрдЯ рд╡рд╛рддрд╛рд╡рд░рдг рдореЗрдВ рдХреЛрдб рдЬрдирд░реЗрд╢рди рдЯреВрд▓реНрд╕ рдХреЛ рдПрдореНрдмреЗрдб рдХрд░рдиреЗ рдХреЗ рд▓рд┐рдП рдПрдХ рд▓рдВрдмрд╛ рд░рд╛рд╕реНрддрд╛ рддрдп рдХрд░ рд░рд╣рд╛ рд╣реИ, рдЬрд┐рд╕рдиреЗ рдкреНрд░реЛрдЧреНрд░рд╛рдорд░ рдХреА рд╕рд░рд▓рддрдо рдЬрд░реВрд░рддреЛрдВ рдХреА рджрд┐рд╢рд╛ рдореЗрдВ рдмрд╣реБрдд рдЕрдВрддрд┐рдо рдХрджрдо рдирд╣реАрдВ рдЙрдард╛рдпрд╛ рд╣реИред рддреЛ, рдЖрдкрдХреЛ рдпрд╣ рдХрджрдо рдЦреБрдж рдЙрдард╛рдирд╛ рд╣реЛрдЧрд╛ред
Microsoft рджреНрд╡рд╛рд░рд╛ рд╡рд░реНрдгрд┐рдд рд╕рдорд╕реНрдпрд╛ рдХреЛ рд╣рд▓ рдХрд░рдиреЗ рдХрд╛ рд╕рдмрд╕реЗ рд╕рд░рд▓ рдЙрдкрдХрд░рдг CSharpCodeProvider рд╡рд░реНрдЧ рд╣реИ, рдЬреЛ рдорд╛рдирдХ .Net рд▓рд╛рдЗрдмреНрд░реЗрд░реА рдХрд╛ рд╣рд┐рд╕реНрд╕рд╛ рд╣реИред рдЗрд╕ рд╡рд░реНрдЧ рдХрд╛ рдЙрдкрдпреЛрдЧ рдХрд░рдирд╛ рдмрд╣реБрдд рдореБрд╢реНрдХрд┐рд▓ рдХрд╛рдо рдирд╣реАрдВ рд╣реИ, рд▓реЗрдХрд┐рди рдлрд┐рд░ рднреА рдпрд╣ рдПрдХ рдЙрдкрдХрд░рдг рдХреЗ рд▓рд┐рдП рдЙрдкрдпреЛрдЧреА рд╣реЛрдЧрд╛ рдЬреЛ рдСрди-рдж-рдлреНрд▓рд╛рдИ рдЬрдирд░реЗрдЯ рдХреЛрдб рдХреЗ рдЙрдкрдпреЛрдЧ рдХреЛ рдПрдХ рддреБрдЪреНрдЫ рдХрд╛рд░реНрдп рдореЗрдВ рдмрджрд▓ рджреЗрддрд╛ рд╣реИред
рдкрд░рд┐рдгрд╛рдо рдХрдХреНрд╖рд╛рдУрдВ рдХрд╛ рдПрдХ рдЫреЛрдЯрд╛ рд╕рд╛ рд╕реЗрдЯ рд╣реИ, рдЬрд┐рд╕рдХрд╛ рдХреЗрдВрджреНрд░
Tech.DynamicCoding.CodeGenerator
ред рд╣рдо рдПрдХ рд╕рд╛рдзрд╛рд░рдг рдЙрдкрдпреЛрдЧ рдХреЗ рдорд╛рдорд▓реЗ рдХреЗ рд╕рд╛рде рдЕрдкрдирд╛ рд╡рд┐рд╡рд░рдг рд╢реБрд░реВ рдХрд░рддреЗ рд╣реИрдВред (рдкреБрд╕реНрддрдХрд╛рд▓рдп рдХреЗ рдЧреНрд░рдВрде рдФрд░ рдЙрджрд╛рд╣рд░рдг
рд╕рдВрдЧреНрд░рд╣ рдореЗрдВ рд╣реИрдВ )ред
рд╕рд░рд▓ рдХреЛрдб рдкреАрдврд╝реА
рдорд╛рди рд▓реЗрдВ рдХрд┐ рдЖрдкрдХреЛ рдкрд╛рда рд░реВрдк рдореЗрдВ рджрд┐рдП рдЧрдП рд╕рдВрдЦреНрдпрд╛рддреНрдордХ рдЕрднрд┐рд╡реНрдпрдХреНрддрд┐ рдХреЗ рдореВрд▓реНрдп рдХреА рдЧрдгрдирд╛ рдХрд░рдиреЗ рдХреА рдЖрд╡рд╢реНрдпрдХрддрд╛ рд╣реИред рдЙрджрд╛рд╣рд░рдг рдХреЗ рд▓рд┐рдП, рдпрд╣рд╛рдВ "12345678 * 9 + 9" рд╣реИред рдЗрд╕ рдорд╛рдорд▓реЗ рдореЗрдВ, рдЖрдкрдХреЛ рдмрд╕ рдирд┐рдореНрдирд▓рд┐рдЦрд┐рдд рд▓рд┐рдЦрдиреЗ рдХреА рдЖрд╡рд╢реНрдпрдХрддрд╛ рд╣реИ:
var result = CodeGenerator.ExecuteCode<int>("return 12345678 * 9 + 9;");
рд╕рдмрд╕реЗ рдкрд╣рд▓реЗ, рдЖрдк рдПрдХ C # рдХреЛрдб рдХрд╛ рдПрдХ рдЯреБрдХрдбрд╝рд╛ рдмрдирд╛рддреЗ рд╣реИрдВ рдФрд░ рдЗрд╕реЗ
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
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