当前位置: 首页>>代码示例>>C#>>正文


C# Expression.Visit方法代码示例

本文整理汇总了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;
        }
开发者ID:ili,项目名称:linq2db,代码行数:64,代码来源:ExpressionTestGenerator.cs

示例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;
		}
开发者ID:Gremlin2,项目名称:bltoolkit,代码行数:73,代码来源:ExpressionTestGenerator.cs


注:本文中的System.Linq.Expressions.Expression.Visit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。