本文整理汇总了C#中System.Linq.Expressions.Expression.Visit方法的典型用法代码示例。如果您正苦于以下问题:C# Expression.Visit方法的具体用法?C# Expression.Visit怎么用?C# Expression.Visit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Linq.Expressions.Expression
的用法示例。
在下文中一共展示了Expression.Visit方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateSource
public string GenerateSource(Expression expr)
{
string fileName = null;
try
{
var tf = Windows.Storage.ApplicationData.Current.TemporaryFolder;
var dir = tf.CreateFolderAsync("linq2db", Windows.Storage.CreationCollisionOption.OpenIfExists).AsTask().Result;
var number = 0;//DateTime.Now.Ticks;
fileName = Path.Combine("ExpressionTest." + number + ".cs");
expr.Visit(new Action<Expression>(VisitMembers));
expr.Visit(new Action<Expression>(VisitTypes));
foreach (var type in _usedTypes.OrderBy(t => t.Namespace).ThenBy(t => t.Name))
BuildType(type);
expr.Visit(new Func<Expression,bool>(BuildExpression));
_exprBuilder.Replace("<>h__TransparentIdentifier", "tp");
var file = dir.CreateFileAsync(fileName, Windows.Storage.CreationCollisionOption.ReplaceExisting).AsTask().Result;
Windows.Storage.FileIO.WriteTextAsync(
file,
string.Format(@"//---------------------------------------------------------------------------------------------------
// This code was generated by LinqToDB.
//---------------------------------------------------------------------------------------------------
using System;
using System.Linq.Expressions;
using NUnit.Framework;
{0}
namespace Tests.UserTests
{{
[TestFixture]
public class UserTest : TestBase
{{
[Test]
public void Test([DataContexts] string context)
{{
// {1}
using (var db = GetDataContext(context))
{{
{2};
}}
}}
}}
}}
",
_typeBuilder,
expr,
_exprBuilder)).AsTask().RunSynchronously();
fileName = Path.Combine(dir.Name, fileName);
}
catch (Exception)
{
}
return fileName;
}
示例2: GenerateSource
public string GenerateSource(Expression expr)
{
string fileName = null;
StreamWriter sw = null;
try
{
var dir = Path.Combine(Path.GetTempPath(), "bltookit\\");
if (!Directory.Exists(dir))
Directory.CreateDirectory(dir);
var number = 0;//DateTime.Now.Ticks;
fileName = Path.Combine(dir, "ExpressionTest." + number + ".cs");
expr.Visit(new Action<Expression>(VisitMembers));
expr.Visit(new Action<Expression>(VisitTypes));
foreach (var type in _usedTypes.OrderBy(t => t.Namespace).ThenBy(t => t.Name))
BuildType(type);
expr.Visit(new Func<Expression,bool>(BuildExpression));
_exprBuilder.Replace("<>h__TransparentIdentifier", "tp");
sw = File.CreateText(fileName);
sw.WriteLine(@"//---------------------------------------------------------------------------------------------------
// This code was generated by BLToolkit.
//---------------------------------------------------------------------------------------------------
using System;
using System.Linq.Expressions;
using NUnit.Framework;
{0}
namespace Data.Linq
{{
[TestFixture]
public class UserTest : TestBase
{{
[Test]
public void Test()
{{
// {1}
ForEachProvider(db =>
{2});
}}
}}
}}
",
_typeBuilder,
expr,
_exprBuilder);
}
catch(Exception ex)
{
if (sw != null)
{
sw.WriteLine();
sw.WriteLine(ex.GetType());
sw.WriteLine(ex.Message);
sw.WriteLine(ex.StackTrace);
}
}
finally
{
if (sw != null)
sw.Close();
}
return fileName;
}