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


C# ResolveContext.With方法代码示例

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


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

示例1: DoResolve

		protected override Expression DoResolve (ResolveContext ec)
		{
			constructor_method = Delegate.GetConstructor (type);

			var invoke_method = Delegate.GetInvokeMethod (type);

			if (!ec.HasSet (ResolveContext.Options.ConditionalAccessReceiver)) {
				if (method_group.HasConditionalAccess ()) {
					conditional_access_receiver = true;
					ec.Set (ResolveContext.Options.ConditionalAccessReceiver);
				}
			}

			Arguments arguments = CreateDelegateMethodArguments (ec, invoke_method.Parameters, invoke_method.Parameters.Types, loc);
			method_group = method_group.OverloadResolve (ec, ref arguments, this, OverloadResolver.Restrictions.CovariantDelegate);

			if (conditional_access_receiver)
				ec.With (ResolveContext.Options.ConditionalAccessReceiver, false);

			if (method_group == null)
				return null;

			var delegate_method = method_group.BestCandidate;
			
			if (delegate_method.DeclaringType.IsNullableType) {
				ec.Report.Error (1728, loc, "Cannot create delegate from method `{0}' because it is a member of System.Nullable<T> type",
					delegate_method.GetSignatureForError ());
				return null;
			}		
			
			if (!AllowSpecialMethodsInvocation)
				Invocation.IsSpecialMethodInvocation (ec, delegate_method, loc);

			ExtensionMethodGroupExpr emg = method_group as ExtensionMethodGroupExpr;
			if (emg != null) {
				method_group.InstanceExpression = emg.ExtensionExpression;
				TypeSpec e_type = emg.ExtensionExpression.Type;
				if (TypeSpec.IsValueType (e_type)) {
					ec.Report.Error (1113, loc, "Extension method `{0}' of value type `{1}' cannot be used to create delegates",
						delegate_method.GetSignatureForError (), e_type.GetSignatureForError ());
				}
			}

			TypeSpec rt = method_group.BestCandidateReturnType;
			if (rt.BuiltinType == BuiltinTypeSpec.Type.Dynamic)
				rt = ec.BuiltinTypes.Object;

			if (!Delegate.IsTypeCovariant (ec, rt, invoke_method.ReturnType)) {
				Expression ret_expr = new TypeExpression (delegate_method.ReturnType, loc);
				Error_ConversionFailed (ec, delegate_method, ret_expr);
			}

			if (method_group.IsConditionallyExcluded) {
				ec.Report.SymbolRelatedToPreviousError (delegate_method);
				MethodOrOperator m = delegate_method.MemberDefinition as MethodOrOperator;
				if (m != null && m.IsPartialDefinition) {
					ec.Report.Error (762, loc, "Cannot create delegate from partial method declaration `{0}'",
						delegate_method.GetSignatureForError ());
				} else {
					ec.Report.Error (1618, loc, "Cannot create delegate with `{0}' because it has a Conditional attribute",
						TypeManager.CSharpSignature (delegate_method));
				}
			}

			var expr = method_group.InstanceExpression;
			if (expr != null && (expr.Type.IsGenericParameter || !TypeSpec.IsReferenceType (expr.Type)))
				method_group.InstanceExpression = new BoxedCast (expr, ec.BuiltinTypes.Object);

			eclass = ExprClass.Value;
			return this;
		}
开发者ID:psni,项目名称:mono,代码行数:71,代码来源:delegate.cs

示例2: ImplicitStandardConversionExists

		//
		// Returns true if the body of lambda expression can be implicitly
		// converted to the delegate of type `delegate_type'
		//
		public bool ImplicitStandardConversionExists (ResolveContext ec, TypeSpec delegate_type)
		{
			using (ec.With (ResolveContext.Options.InferReturnType, false)) {
				using (ec.Set (ResolveContext.Options.ProbingMode)) {
					var prev = ec.Report.SetPrinter (TypeInferenceReportPrinter ?? new NullReportPrinter ());

					var res = Compatible (ec, delegate_type) != null;

					ec.Report.SetPrinter (prev);

					return res;
				}
			}
		}
开发者ID:rabink,项目名称:mono,代码行数:18,代码来源:anonymous.cs

示例3: ImplicitStandardConversionExists

		//
		// Returns true if the body of lambda expression can be implicitly
		// converted to the delegate of type `delegate_type'
		//
		public bool ImplicitStandardConversionExists (ResolveContext ec, TypeSpec delegate_type)
		{
			using (ec.With (ResolveContext.Options.InferReturnType, false)) {
				using (ec.Set (ResolveContext.Options.ProbingMode)) {
					return Compatible (ec, delegate_type) != null;
				}
			}
		}
开发者ID:nylen,项目名称:SharpDevelop,代码行数:12,代码来源:anonymous.cs

示例4: DoSimpleNameResolve

        /// <remarks>
        ///   7.5.2: Simple Names. 
        ///
        ///   Local Variables and Parameters are handled at
        ///   parse time, so they never occur as SimpleNames.
        ///
        ///   The `intermediate' flag is used by MemberAccess only
        ///   and it is used to inform us that it is ok for us to 
        ///   avoid the static check, because MemberAccess might end
        ///   up resolving the Name as a Type name and the access as
        ///   a static type access.
        ///
        ///   ie: Type Type; .... { Type.GetType (""); }
        ///
        ///   Type is both an instance variable and a Type;  Type.GetType
        ///   is the static method not an instance method of type.
        /// </remarks>
        Expression DoSimpleNameResolve(ResolveContext ec, Expression right_side, bool intermediate)
        {
            Expression e = null;

            //
            // Stage 1: Performed by the parser (binding to locals or parameters).
            //
            Block current_block = ec.CurrentBlock;
            if (current_block != null){
                LocalInfo vi = current_block.GetLocalInfo (Name);
                if (vi != null){
                    e = new LocalVariableReference (ec.CurrentBlock, Name, loc);

                    if (right_side != null) {
                        e = e.ResolveLValue (ec, right_side);
                    } else {
                        if (intermediate) {
                            using (ec.With (ResolveContext.Options.DoFlowAnalysis, false)) {
                                e = e.Resolve (ec, ResolveFlags.VariableOrValue);
                            }
                        } else {
                            e = e.Resolve (ec, ResolveFlags.VariableOrValue);
                        }
                    }

                    if (HasTypeArguments && e != null)
                        e.Error_TypeArgumentsCannotBeUsed (ec.Report, loc, null, 0);

                    return e;
                }

                e = current_block.Toplevel.GetParameterReference (Name, loc);
                if (e != null) {
                    if (right_side != null)
                        e = e.ResolveLValue (ec, right_side);
                    else
                        e = e.Resolve (ec);

                    if (HasTypeArguments && e != null)
                        e.Error_TypeArgumentsCannotBeUsed (ec.Report, loc, null, 0);

                    return e;
                }
            }

            //
            // Stage 2: Lookup members
            //
            int arity = HasTypeArguments ? Arity : -1;
            //			TypeSpec almost_matched_type = null;
            //			IList<MemberSpec> almost_matched = null;
            for (TypeSpec lookup_ds = ec.CurrentType; lookup_ds != null; lookup_ds = lookup_ds.DeclaringType) {
                e = MemberLookup (ec.Compiler, ec.CurrentType, lookup_ds, Name, arity, BindingRestriction.NoOverrides, loc);
                if (e != null) {
                    PropertyExpr pe = e as PropertyExpr;
                    if (pe != null) {
                        // since TypeManager.MemberLookup doesn't know if we're doing a lvalue access or not,
                        // it doesn't know which accessor to check permissions against
                        if (pe.PropertyInfo.Kind == MemberKind.Property && pe.IsAccessibleFrom (ec.CurrentType, right_side != null))
                            break;
                    } else if (e is EventExpr) {
                        if (((EventExpr) e).IsAccessibleFrom (ec.CurrentType))
                            break;
                    } else if (HasTypeArguments && e is TypeExpression) {
                        e = new GenericTypeExpr (e.Type, targs, loc).ResolveAsTypeStep (ec, false);
                        break;
                    } else {
                        break;
                    }
                    e = null;
                }
            /*
                if (almost_matched == null && almost_matched_members.Count > 0) {
                    almost_matched_type = lookup_ds;
                    almost_matched = new List<MemberSpec>(almost_matched_members);
                }
            */
            }

            if (e == null) {
            /*
                if (almost_matched == null && almost_matched_members.Count > 0) {
                    almost_matched_type = ec.CurrentType;
//.........这里部分代码省略.........
开发者ID:speier,项目名称:shake,代码行数:101,代码来源:ecore.cs

示例5: DoResolve

        Expression DoResolve(ResolveContext ec, bool lvalue_instance, bool out_access)
        {
            if (!IsStatic){
                if (InstanceExpression == null){
                    //
                    // This can happen when referencing an instance field using
                    // a fully qualified type expression: TypeName.InstanceField = xxx
                    //
                    SimpleName.Error_ObjectRefRequired (ec, loc, GetSignatureForError ());
                    return null;
                }

                // Resolve the field's instance expression while flow analysis is turned
                // off: when accessing a field "a.b", we must check whether the field
                // "a.b" is initialized, not whether the whole struct "a" is initialized.

                if (lvalue_instance) {
                    using (ec.With (ResolveContext.Options.DoFlowAnalysis, false)) {
                        Expression right_side =
                            out_access ? EmptyExpression.LValueMemberOutAccess : EmptyExpression.LValueMemberAccess;

                        if (InstanceExpression != EmptyExpression.Null)
                            InstanceExpression = InstanceExpression.ResolveLValue (ec, right_side);
                    }
                } else {
                    if (InstanceExpression != EmptyExpression.Null) {
                        using (ec.With (ResolveContext.Options.DoFlowAnalysis, false)) {
                            InstanceExpression = InstanceExpression.Resolve (ec, ResolveFlags.VariableOrValue);
                        }
                    }
                }

                if (InstanceExpression == null)
                    return null;

                using (ec.Set (ResolveContext.Options.OmitStructFlowAnalysis)) {
                    InstanceExpression.CheckMarshalByRefAccess (ec);
                }
            }

            if (!ec.IsObsolete) {
                ObsoleteAttribute oa = spec.GetAttributeObsolete ();
                if (oa != null)
                    AttributeTester.Report_ObsoleteMessage (oa, TypeManager.GetFullNameSignature (spec), loc, ec.Report);
            }

            var fb = spec as FixedFieldSpec;
            IVariableReference var = InstanceExpression as IVariableReference;

            if (fb != null) {
                IFixedExpression fe = InstanceExpression as IFixedExpression;
                if (!ec.HasSet (ResolveContext.Options.FixedInitializerScope) && (fe == null || !fe.IsFixed)) {
                    ec.Report.Error (1666, loc, "You cannot use fixed size buffers contained in unfixed expressions. Try using the fixed statement");
                }

                if (InstanceExpression.eclass != ExprClass.Variable) {
                    ec.Report.SymbolRelatedToPreviousError (spec);
                    ec.Report.Error (1708, loc, "`{0}': Fixed size buffers can only be accessed through locals or fields",
                        TypeManager.GetFullNameSignature (spec));
                } else if (var != null && var.IsHoisted) {
                    AnonymousMethodExpression.Error_AddressOfCapturedVar (ec, var, loc);
                }

                return new FixedBufferPtr (this, fb.ElementType, loc).Resolve (ec);
            }

            eclass = ExprClass.Variable;

            // If the instance expression is a local variable or parameter.
            if (var == null || var.VariableInfo == null)
                return this;

            VariableInfo vi = var.VariableInfo;
            if (!vi.IsFieldAssigned (ec, Name, loc))
                return null;

            variable_info = vi.GetSubStruct (Name);
            return this;
        }
开发者ID:speier,项目名称:shake,代码行数:79,代码来源:ecore.cs

示例6: DoResolve

		public override Expression DoResolve (ResolveContext ec)
		{
			using (ec.With (ResolveContext.Options.AllCheckStateFlags, false))
				Expr = Expr.Resolve (ec);

			if (Expr == null)
				return null;

			if (Expr is Constant || Expr is MethodGroupExpr || Expr is AnonymousMethodExpression || Expr is DefaultValueExpression)
				return Expr;
			
			eclass = Expr.eclass;
			type = Expr.Type;
			return this;
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:15,代码来源:expression.cs

示例7: CreateExpressionTree

		public override Expression CreateExpressionTree (ResolveContext ec)
		{
			using (ec.With (ResolveContext.Options.AllCheckStateFlags, false))
				return Expr.CreateExpressionTree (ec);
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:5,代码来源:expression.cs

示例8: Resolve

		public void Resolve (ResolveContext ec)
		{
			if (Expr == EmptyExpression.Null)
				return;

			using (ec.With (ResolveContext.Options.DoFlowAnalysis, true)) {
				// Verify that the argument is readable
				if (ArgType != AType.Out)
					Expr = Expr.Resolve (ec);

				// Verify that the argument is writeable
				if (Expr != null && IsByRef)
					Expr = Expr.ResolveLValue (ec, EmptyExpression.OutAccess);

				if (Expr == null)
					Expr = EmptyExpression.Null;
			}
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:18,代码来源:argument.cs


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