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


C# Context.ResolveLambda方法代码示例

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


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

示例1: resolveGetMember

        /// <summary>
        /// Resolves the method if the expression was a member getter (obj.field or type::field).
        /// </summary>
        private void resolveGetMember(Context ctx, GetMemberNode node)
        {
            _InvocationSource = node.Expression;
            var type = _InvocationSource != null
                ? _InvocationSource.Resolve(ctx)
                : ctx.ResolveType(node.StaticType);

            checkTypeInSafeMode(ctx, type);

            if (node.TypeHints != null && node.TypeHints.Count > 0)
                _TypeHints = node.TypeHints.Select(x => ctx.ResolveType(x, true)).ToArray();

            try
            {
                // resolve a normal method
                try
                {
                    _Method = ctx.ResolveMethod(
                        type,
                        node.MemberName,
                        _ArgTypes,
                        _TypeHints,
                        (idx, types) => ctx.ResolveLambda(Arguments[idx] as LambdaNode, types)
                    );

                    if (_Method.IsStatic)
                        _InvocationSource = null;

                    return;
                }
                catch (KeyNotFoundException)
                {
                    if (_InvocationSource == null)
                        throw;
                }

                // resolve a callable field
                try
                {
                    ctx.ResolveField(type, node.MemberName);
                    resolveExpression(ctx, node);
                    return;
                }
                catch (KeyNotFoundException) { }

                // resolve a callable property
                try
                {
                    ctx.ResolveProperty(type, node.MemberName);
                    resolveExpression(ctx, node);
                    return;
                }
                catch (KeyNotFoundException) { }

                Arguments = (Arguments[0] is UnitNode)
                    ? new List<NodeBase> {_InvocationSource}
                    : new[] {_InvocationSource}.Union(Arguments).ToList();

                var oldArgTypes = _ArgTypes;
                _ArgTypes = Arguments.Select(a => a.Resolve(ctx)).ToArray();
                _InvocationSource = null;

                try
                {
                    // resolve a local function that is implicitly used as an extension method
                    _Method = ctx.ResolveMethod(
                        ctx.MainType.TypeInfo,
                        node.MemberName,
                        _ArgTypes,
                        resolver: (idx, types) => ctx.ResolveLambda(Arguments[idx] as LambdaNode, types)
                    );

                    return;
                }
                catch (KeyNotFoundException) { }

                // resolve a declared extension method
                // most time-consuming operation, therefore is last checked
                try
                {
                    if(!ctx.Options.AllowExtensionMethods)
                        throw new KeyNotFoundException();

                    _Method = ctx.ResolveExtensionMethod(
                        type,
                        node.MemberName,
                        oldArgTypes,
                        _TypeHints,
                        (idx, types) => ctx.ResolveLambda(Arguments[idx] as LambdaNode, types)
                    );
                }
                catch (KeyNotFoundException)
                {
                    var msg = node.StaticType != null
                        ? CompilerMessages.TypeStaticMethodNotFound
                        : CompilerMessages.TypeMethodNotFound;

//.........这里部分代码省略.........
开发者ID:menozz,项目名称:lens,代码行数:101,代码来源:InvocationNode.cs

示例2: resolveGetIdentifier

        /// <summary>
        /// Resolves the method as a global function, imported property or a local variable with a delegate.
        /// </summary>
        private void resolveGetIdentifier(Context ctx, GetIdentifierNode node)
        {
            var nameInfo = ctx.Scope.FindLocal(node.Identifier);
            if (nameInfo != null)
            {
                resolveExpression(ctx, node);
                return;
            }

            try
            {
                _Method = ctx.ResolveMethod(
                    ctx.MainType.TypeInfo,
                    node.Identifier,
                    _ArgTypes,
                    resolver: (idx, types) => ctx.ResolveLambda(Arguments[idx] as LambdaNode, types)
                );

                if (_Method == null)
                    throw new KeyNotFoundException();

                if(_ArgTypes.Length == 0 && node.Identifier.IsAnyOf(EntityNames.RunMethodName, EntityNames.EntryPointMethodName))
                    error(CompilerMessages.ReservedFunctionInvocation, node.Identifier);
            }
            catch (KeyNotFoundException)
            {
                error(CompilerMessages.FunctionNotFound, node.Identifier);
            }
            catch (AmbiguousMatchException)
            {
                error(CompilerMessages.FunctionInvocationAmbiguous, node.Identifier);
            }
        }
开发者ID:menozz,项目名称:lens,代码行数:36,代码来源:InvocationNode.cs


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