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


C# Expression.Resolve方法代码示例

本文整理汇总了C#中Expression.Resolve方法的典型用法代码示例。如果您正苦于以下问题:C# Expression.Resolve方法的具体用法?C# Expression.Resolve怎么用?C# Expression.Resolve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Expression的用法示例。


在下文中一共展示了Expression.Resolve方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateAggregator

		public override IAggregator CreateAggregator(Type inputType)
		{
			if (inputType == null)
				throw ExceptionBuilder.ArgumentNull("inputType");

			// Create an expression to determine the type of inputType + inputType

			Expression<object> addExpr = new Expression<object>();
			addExpr.Parameters.Add("@Left", inputType);
			addExpr.Parameters.Add("@Right", inputType);
			addExpr.Text = "@Left + @Right";

			Type sumType;
			try
			{
				sumType = addExpr.Resolve();
			}
			catch (CompilationException)
			{
				return null;
			}

			// Now change the type of the first argument to the result type of 'inputType + inputType'

			addExpr.Parameters.Clear();
			ParameterBinding leftParam = addExpr.Parameters.Add("@Left", sumType);
			ParameterBinding rightParam = addExpr.Parameters.Add("@Right", inputType);
			addExpr.Text = "@Left + @Right";

			try
			{
				Type newSumType = addExpr.Resolve();
				if (newSumType != sumType)
					return null;
			}
			catch (CompilationException)
			{
				return null;
			}

			// Conversion from inputType to sumType

			Expression<object> convertInputToSumExpr = new Expression<object>();
			convertInputToSumExpr.Parameters.Add("@Input", inputType);
			convertInputToSumExpr.Text = "@Input";
			convertInputToSumExpr.TargetType = sumType;

			try
			{
				convertInputToSumExpr.Resolve();
			}
			catch (CompilationException)
			{
				return null;
			}

			return new SumAggregator(addExpr, leftParam, rightParam, convertInputToSumExpr);
		}
开发者ID:chenzuo,项目名称:nquery,代码行数:58,代码来源:SumAggregateBinding.cs

示例2: CreateAggregator

		public override IAggregator CreateAggregator(Type inputType)
		{
			if (inputType == null)
				throw ExceptionBuilder.ArgumentNull("inputType");

			SumAggregateBinding sumAggregate = new SumAggregateBinding(String.Empty);
			IAggregator sumAggregator = sumAggregate.CreateAggregator(inputType);
			if (sumAggregator == null)
				return null;

			Expression<object> avgExpression = new Expression<object>();
			ParameterBinding sumParam = avgExpression.Parameters.Add("@Sum", sumAggregator.ReturnType);
			ParameterBinding countParam = avgExpression.Parameters.Add("@Count", typeof(int));
			avgExpression.Text = "@Sum / @Count";

			try
			{
				avgExpression.Resolve();
			}
			catch (CompilationException)
			{
				return null;
			}

			return new AverageAggregator(sumAggregator, avgExpression, sumParam, countParam);
		}
开发者ID:chenzuo,项目名称:nquery,代码行数:26,代码来源:AverageAggregateBinding.cs

示例3: ConstantFoldingDoesPreserveType

        public void ConstantFoldingDoesPreserveType()
        {
            DataTable dataTable = new DataTable();
            dataTable.Columns.Add("NonNullInt", typeof (int));
            dataTable.Columns.Add("NullInt", typeof (int));

            DataRow dataRow = dataTable.NewRow();
            dataRow["NonNullInt"] = 1;
            dataTable.Rows.Add(dataRow);
            
            DataColumnPropertyBinding[] dataRowProperties = DataRowPropertyProvider.GetProperties(dataTable);
            
            DataContext dataContext = new DataContext();
            dataContext.Constants.Add("DataRow", dataRow, dataRowProperties);

			Expression<object> exprWithNonNullInt = new Expression<object>();
            exprWithNonNullInt.DataContext = dataContext;
            exprWithNonNullInt.Text = "DataRow.NonNullInt";
            Assert.AreEqual(typeof(int), exprWithNonNullInt.Resolve());
            Assert.AreEqual(1, exprWithNonNullInt.Evaluate());

			Expression<object> exprWithNullInt = new Expression<object>();
            exprWithNullInt.DataContext = dataContext;
            exprWithNullInt.Text = "DataRow.NullInt";
            Assert.AreEqual(typeof(int), exprWithNullInt.Resolve());
            Assert.AreEqual(null, exprWithNullInt.Evaluate());
        }
开发者ID:chenzuo,项目名称:nquery,代码行数:27,代码来源:ConstantFoldingTests.cs

示例4: GetExpressionTypeCode

        private static string GetExpressionTypeCode(Expression Expression)
        {
            var resolvedElement = Expression.Resolve(ParserServices.SourceTreeResolver);
            ITypeReferenceExpression typeRef = resolvedElement as ITypeReferenceExpression;
            var simpleName = CodeRush.Language.GetSimpleTypeName(resolvedElement.FullName);

            var Code = CodeRush.CodeMod.GenerateCode(SourceModelUtils.CreateTypeReferenceExpression(resolvedElement));

            //var Code = CodeRush.CodeMod.GenerateCode(new TypeReferenceExpression(simpleName), true);
            return CodeRush.Language.GetSimpleTypeName(Code);
        }
开发者ID:modulexcite,项目名称:CR_CorrectReturnType,代码行数:11,代码来源:PlugIn1.cs

示例5: SumAggregator

        public SumAggregator(Expression<object> addExpression, ParameterBinding leftParameter, ParameterBinding rightParameter, Expression<object> convertInputToSumExpression)
        {
            if (addExpression == null)
                throw ExceptionBuilder.ArgumentNull("addExpr");

            if (leftParameter == null)
                throw ExceptionBuilder.ArgumentNull("leftParam");

            if (rightParameter == null)
                throw ExceptionBuilder.ArgumentNull("rightParam");

            if (convertInputToSumExpression == null)
                throw ExceptionBuilder.ArgumentNull("convertInputToSumExpr)");

            _addExpression = addExpression;
            _returnType = addExpression.Resolve();
            _leftParameter = leftParameter;
            _rightParameter = rightParameter;
            _convertInputToSumExpression = convertInputToSumExpression;
        }
开发者ID:chenzuo,项目名称:nquery,代码行数:20,代码来源:SumAggregator.cs

示例6: AverageAggregator

        public AverageAggregator(IAggregator sumAggregator, Expression<object> avgExpression, ParameterBinding sumParameter, ParameterBinding countParameter)
        {
            if (sumAggregator == null)
                throw ExceptionBuilder.ArgumentNull("sumAggregator");

            if (avgExpression == null)
                throw ExceptionBuilder.ArgumentNull("avgExpression");

            if (sumParameter == null)
                throw ExceptionBuilder.ArgumentNull("sumParam");

            if (countParameter == null)
                throw ExceptionBuilder.ArgumentNull("countParam");

            _sumAggregator = sumAggregator;
            _avgExpression = avgExpression;
            _returnType = avgExpression.Resolve();
            _sumParameter = sumParameter;
            _countParameter = countParameter;
        }
开发者ID:chenzuo,项目名称:nquery,代码行数:20,代码来源:AverageAggregator.cs

示例7: DictionaryPropertiesConstantWithNullPropValue

		public void DictionaryPropertiesConstantWithNullPropValue()
		{
			Hashtable hashtable = new Hashtable();
			hashtable["EmployeeID"] = -1;
			hashtable["FirstName"] = "Immo";
			hashtable["DOB"] = new DateTime(1981, 10, 19);
			
			PropertyBinding[] customProps = DictionaryPropertyProvider.GetProperties(hashtable);
			hashtable["FirstName"] = null;

			Expression<object> expr = new Expression<object>();	
			expr.DataContext.Constants.Add(new ConstantBinding("Constant", hashtable, customProps));
			expr.Text = "Constant.FirstName = 'Immo'";
			
			Assert.AreEqual(typeof(bool), expr.Resolve());
			Assert.AreEqual(null, expr.Evaluate());
		}
开发者ID:chenzuo,项目名称:nquery,代码行数:17,代码来源:CustomPropertiesTest.cs

示例8: DictionaryPropertiesParameterNullValue

		public void DictionaryPropertiesParameterNullValue()
		{
			Hashtable hashtable = new Hashtable();
			hashtable["EmployeeID"] = -1;
			hashtable["FirstName"] = "Immo";
			hashtable["DOB"] = new DateTime(1981, 10, 19);
			
			PropertyBinding[] customProps = DictionaryPropertyProvider.GetProperties(hashtable);

			Expression<object> expr = new Expression<object>();	
			expr.Parameters.Add(new ParameterBinding("@Parameter", typeof(IDictionary), customProps));
			expr.Parameters["@Parameter"].Value = null;
			
			expr.Text = "@Parameter.FirstName = 'Immo'";
			
			Assert.AreEqual(typeof(bool), expr.Resolve());
			Assert.AreEqual(null, expr.Evaluate());
		}
开发者ID:chenzuo,项目名称:nquery,代码行数:18,代码来源:CustomPropertiesTest.cs

示例9: IsValidReferenceAndQualifier

    private bool IsValidReferenceAndQualifier(LanguageElement activeRerence, out ITypeElement callerType, out Expression qualifier)
    {
      qualifier = null;
      callerType = null;
      if (!(activeRerence is IHasQualifier))
        return false;

      // should be undeclared....
      IElement declaration = activeRerence.GetDeclaration(false);
      if (declaration != null)
        return false;


      qualifier = (activeRerence as IHasQualifier).Qualifier;
      if (qualifier is MethodReferenceExpression)
        qualifier = (qualifier as MethodReferenceExpression).Qualifier;
      if (qualifier == null)
        return false;

      callerType = qualifier.Resolve(ParserServices.SourceTreeResolver) as ITypeElement;
      if (callerType == null)
        return false;

      return true;
    }
开发者ID:kevinmiles,项目名称:dxcorecommunityplugins,代码行数:25,代码来源:PlugIn1.cs

示例10: DoResolve

		protected override Expression DoResolve (ResolveContext rc)
		{
			var sn = expr as SimpleName;
			const ResolveFlags flags = ResolveFlags.VariableOrValue | ResolveFlags.Type;

			if (sn != null) {
				expr = sn.LookupNameExpression (rc, MemberLookupRestrictions.ReadAccess | MemberLookupRestrictions.ExactArity);

				//
				// Resolve expression which does have type set as we need expression type
				// with disable flow analysis as we don't know whether left side expression
				// is used as variable or type
				//
				if (expr is VariableReference || expr is ConstantExpr || expr is Linq.TransparentMemberAccess) {
					expr = expr.Resolve (rc);
				} else if (expr is TypeParameterExpr) {
					expr.Error_UnexpectedKind (rc, flags, sn.Location);
					expr = null;
				}
			} else {
				expr = expr.Resolve (rc, flags);
			}

			if (expr == null)
				return null;

			TypeSpec expr_type = expr.Type;
			if (expr_type.IsPointer || expr_type.Kind == MemberKind.Void || expr_type == InternalType.NullLiteral || expr_type == InternalType.AnonymousMethod) {
				expr.Error_OperatorCannotBeApplied (rc, loc, ".", expr_type);
				return null;
			}

			if (targs != null) {
				if (!targs.Resolve (rc, true))
					return null;
			}

			var results = new List<string> ();
			var nexpr = expr as NamespaceExpression;
			if (nexpr != null) {
				string namespaced_partial;

				if (partial_name == null)
					namespaced_partial = nexpr.Namespace.Name;
				else
					namespaced_partial = nexpr.Namespace.Name + "." + partial_name;

				rc.CurrentMemberDefinition.GetCompletionStartingWith (namespaced_partial, results);
				if (partial_name != null)
					results = results.Select (l => l.Substring (partial_name.Length)).ToList ();
			} else {
				var r = MemberCache.GetCompletitionMembers (rc, expr_type, partial_name).Select (l => l.Name);
				AppendResults (results, partial_name, r);
			}

			throw new CompletionResult (partial_name == null ? "" : partial_name, results.Distinct ().ToArray ());
		}
开发者ID:furesoft,项目名称:NRefactory,代码行数:57,代码来源:complete.cs


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