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


C# Context.ResolveField方法代码示例

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


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

示例1: emitGetClosuredRemote

        /// <summary>
        /// Gets a closured variable that has been imported from outer scopes.
        /// </summary>
        private void emitGetClosuredRemote(Context ctx, Local name)
        {
            var gen = ctx.CurrentMethod.Generator;

            gen.EmitLoadArgument(0);

            var dist = name.ClosureDistance;
            var type = (Type)ctx.CurrentType.TypeBuilder;
            while (dist > 1)
            {
                var rootField = ctx.ResolveField(type, EntityNames.ParentScopeFieldName);
                gen.EmitLoadField(rootField.FieldInfo);

                type = rootField.FieldType;
                dist--;
            }

            var clsField = ctx.ResolveField(type, name.ClosureFieldName);
            gen.EmitLoadField(clsField.FieldInfo, PointerRequired || RefArgumentRequired);
        }
开发者ID:menozz,项目名称:lens,代码行数:23,代码来源:GetIdentifierNode.cs

示例2: emitSetClosuredLocal

        /// <summary>
        /// Assigns a closured variable that is declared in current scope.
        /// </summary>
        private void emitSetClosuredLocal(Context ctx, Local name)
        {
            var gen = ctx.CurrentMethod.Generator;

            gen.EmitLoadLocal(ctx.Scope.ActiveClosure.ClosureVariable);

            Expr.Cast(Value, name.Type).Emit(ctx, true);

            var clsType = ctx.Scope.ActiveClosure.ClosureType.TypeInfo;
            var clsField = ctx.ResolveField(clsType, name.ClosureFieldName);
            gen.EmitSaveField(clsField.FieldInfo);
        }
开发者ID:menozz,项目名称:lens,代码行数:15,代码来源:SetIdentifierNode.cs

示例3: 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

示例4: assignClosuredLocal

        /// <summary>
        /// Assigns a closured variable that is declared in current scope.
        /// </summary>
        private void assignClosuredLocal(Context ctx, LocalName name)
        {
            var gen = ctx.CurrentILGenerator;

            gen.EmitLoadLocal(ctx.CurrentScope.ClosureVariable);

            Expr.Cast(Value, name.Type).Compile(ctx, true);

            var clsType = ctx.CurrentScope.ClosureType.TypeInfo;
            var clsField = ctx.ResolveField(clsType, name.ClosureFieldName);
            gen.EmitSaveField(clsField.FieldInfo);
        }
开发者ID:TrickyCat,项目名称:lens,代码行数:15,代码来源:SetIdentifierNode.cs

示例5: assignClosuredRemote

        /// <summary>
        /// Assigns a closured variable that has been imported from outer scopes.
        /// </summary>
        private void assignClosuredRemote(Context ctx, LocalName name)
        {
            var gen = ctx.CurrentILGenerator;

            gen.EmitLoadArgument(0);

            var dist = name.ClosureDistance;
            var type = (Type)ctx.CurrentType.TypeBuilder;
            while (dist > 1)
            {
                var rootField = ctx.ResolveField(type, EntityNames.ParentScopeFieldName);
                gen.EmitLoadField(rootField.FieldInfo);

                type = rootField.FieldType;
                dist--;
            }

            Expr.Cast(Value, name.Type).Compile(ctx, true);

            var clsField = ctx.ResolveField(type, name.ClosureFieldName);
            gen.EmitSaveField(clsField.FieldInfo);
        }
开发者ID:TrickyCat,项目名称:lens,代码行数:25,代码来源:SetIdentifierNode.cs

示例6: resolveGetMember

        private void resolveGetMember(Context ctx, GetMemberNode node)
        {
            m_InvocationSource = node.Expression;
            var type = m_InvocationSource != null
                ? m_InvocationSource.GetExpressionType(ctx)
                : ctx.ResolveType(node.StaticType);

            SafeModeCheckType(ctx, type);

            if (node.TypeHints.Any())
                m_TypeHints = node.TypeHints.Select(x => x.FullSignature == "_" ? null : ctx.ResolveType(x)).ToArray();

            try
            {
                // resolve a normal method
                try
                {
                    m_Method = ctx.ResolveMethod(type, node.MemberName, m_ArgTypes, m_TypeHints);

                    if (m_Method.IsStatic)
                        m_InvocationSource = null;

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

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

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

                // resolve a local function that is implicitly used as an extension method
                // move invocation source to arguments
                if (Arguments[0] is UnitNode)
                    Arguments[0] = m_InvocationSource;
                else
                    Arguments.Insert(0, m_InvocationSource);

                var oldArgTypes = m_ArgTypes;
                m_ArgTypes = Arguments.Select(a => a.GetExpressionType(ctx)).ToArray();
                m_InvocationSource = null;

                try
                {
                    m_Method = ctx.ResolveMethod(ctx.MainType.TypeInfo, node.MemberName, m_ArgTypes);
                }
                catch (KeyNotFoundException)
                {
                    // resolve a declared extension method
                    // most time-consuming operation, therefore is last checked
                    if(ctx.Options.AllowExtensionMethods)
                        m_Method = ctx.ResolveExtensionMethod(type, node.MemberName, oldArgTypes, m_TypeHints);
                }
            }
            catch (AmbiguousMatchException)
            {
                Error(CompilerMessages.TypeMethodInvocationAmbiguous, type, node.MemberName);
            }
            catch (KeyNotFoundException)
            {
                var msg = node.StaticType != null
                    ? CompilerMessages.TypeStaticMethodNotFound
                    : CompilerMessages.TypeMethodNotFound;

                Error(msg, type, node.MemberName);
            }
        }
开发者ID:TrickyCat,项目名称:lens,代码行数:84,代码来源:InvocationNode.cs

示例7: resolveSelf

        /// <summary>
        /// Attempts to resolve current node and sets either of the following fields:
        /// _Field, _Method, _Property
        /// 
        /// The following fields are also set:
        /// _Type, _Static
        /// </summary>
        private void resolveSelf(Context ctx)
        {
            Action check = () =>
            {
                if (Expression == null && !_IsStatic)
                    error(CompilerMessages.DynamicMemberFromStaticContext, _Type, MemberName);

                if (_Method == null && TypeHints.Count > 0)
                    error(CompilerMessages.TypeArgumentsForNonMethod, _Type, MemberName);
            };

            _Type = StaticType != null
                ? ctx.ResolveType(StaticType)
                : Expression.Resolve(ctx);

            // special case: array length
            if (_Type.IsArray && MemberName == "Length")
            {
                check();
                return;
            }

            // check for field
            try
            {
                _Field = ctx.ResolveField(_Type, MemberName);
                _IsStatic = _Field.IsStatic;

                check();
                return;
            }
            catch (KeyNotFoundException) { }

            // check for property
            try
            {
                _Property = ctx.ResolveProperty(_Type, MemberName);

                if(!_Property.CanGet)
                    error(CompilerMessages.PropertyNoGetter, _Type, MemberName);

                _IsStatic = _Property.IsStatic;

                check();
                return;
            }
            catch (KeyNotFoundException) { }

            // check for event: events are only allowed at the left side of += and -=
            try
            {
                ctx.ResolveEvent(_Type, MemberName);
                error(CompilerMessages.EventAsExpr);
            }
            catch (KeyNotFoundException) { }

            // find method
            var argTypes = TypeHints.Select(t => t.FullSignature == "_" ? null : ctx.ResolveType(t)).ToArray();
            var methods = ctx.ResolveMethodGroup(_Type, MemberName).Where(m => checkMethodArgs(argTypes, m)).ToArray();

            if (methods.Length == 0)
                error(argTypes.Length == 0 ? CompilerMessages.TypeIdentifierNotFound : CompilerMessages.TypeMethodNotFound, _Type.Name, MemberName);

            if (methods.Length > 1)
                error(CompilerMessages.TypeMethodAmbiguous, _Type.Name, MemberName);

            _Method = methods[0];
            if (_Method.ArgumentTypes.Length > 16)
                error(CompilerMessages.CallableTooManyArguments);

            _IsStatic = _Method.IsStatic;

            check();
        }
开发者ID:menozz,项目名称:lens,代码行数:81,代码来源:GetMemberNode.cs

示例8: resolveSelf

        /// <summary>
        /// Attempts to resolve member reference to a field or a property.
        /// </summary>
        private void resolveSelf(Context ctx)
        {
            var type = StaticType != null
                ? ctx.ResolveType(StaticType)
                : Expression.Resolve(ctx);

            checkTypeInSafeMode(ctx, type);

            // check for field
            try
            {
                _Field = ctx.ResolveField(type, MemberName);
                _IsStatic = _Field.IsStatic;
                if (Expression == null && !_IsStatic)
                    error(CompilerMessages.DynamicMemberFromStaticContext, type, MemberName);
            }
            catch (KeyNotFoundException)
            {
                try
                {
                    _Property = ctx.ResolveProperty(type, MemberName);
                    if (!_Property.CanSet)
                        error(CompilerMessages.PropertyNoSetter, MemberName, type);

                    _IsStatic = _Property.IsStatic;
                    if (Expression == null && !_IsStatic)
                        error(CompilerMessages.DynamicMemberFromStaticContext, type, MemberName);
                }
                catch (KeyNotFoundException)
                {
                    error(CompilerMessages.TypeSettableIdentifierNotFound, type, MemberName);
                }
            }

            var destType = _Field != null ? _Field.FieldType : _Property.PropertyType;
            ensureLambdaInferred(ctx, Value, destType);

            var valType = Value.Resolve(ctx);
            ctx.CheckTypedExpression(Value, valType, true);

            if (!destType.IsExtendablyAssignableFrom(valType))
                error(CompilerMessages.ImplicitCastImpossible, valType, destType);
        }
开发者ID:menozz,项目名称:lens,代码行数:46,代码来源:SetMemberNode.cs

示例9: resolve

        private void resolve(Context ctx)
        {
            Action check = () =>
            {
                if (Expression == null && !m_IsStatic)
                    Error(CompilerMessages.DynamicMemberFromStaticContext, MemberName);

                if(m_Method == null && TypeHints.Count > 0)
                    Error(CompilerMessages.TypeArgumentsForNonMethod, m_Type, MemberName);

                m_IsResolved = true;
            };

            m_Type = StaticType != null
                ? ctx.ResolveType(StaticType)
                : Expression.GetExpressionType(ctx);

            // special case: array length
            if (m_Type.IsArray && MemberName == "Length")
            {
                check();
                return;
            }

            // check for field
            try
            {
                m_Field = ctx.ResolveField(m_Type, MemberName);
                m_IsStatic = m_Field.IsStatic;

                check();
                return;
            }
            catch (KeyNotFoundException) { }

            // check for property
            try
            {
                m_Property = ctx.ResolveProperty(m_Type, MemberName);

                if(!m_Property.CanGet)
                    Error(CompilerMessages.PropertyNoGetter, m_Type, MemberName);

                m_IsStatic = m_Property.IsStatic;

                check();
                return;
            }
            catch (KeyNotFoundException)
            { }

            var argTypes = TypeHints.Select(t => t.FullSignature == "_" ? null : ctx.ResolveType(t)).ToArray();
            var methods = ctx.ResolveMethodGroup(m_Type, MemberName).Where(m => checkMethodArgs(ctx, argTypes, m)).ToArray();

            if (methods.Length == 0)
                Error(argTypes.Length == 0 ? CompilerMessages.TypeIdentifierNotFound : CompilerMessages.TypeMethodNotFound, m_Type.Name, MemberName);

            if (methods.Length > 1)
                Error(CompilerMessages.TypeMethodAmbiguous, m_Type.Name, MemberName);

            m_Method = methods[0];
            if (m_Method.ArgumentTypes.Length > 16)
                Error(CompilerMessages.CallableTooManyArguments);

            m_IsStatic = m_Method.IsStatic;

            check();
        }
开发者ID:TrickyCat,项目名称:lens,代码行数:68,代码来源:GetMemberNode.cs

示例10: resolve

        private void resolve(Context ctx)
        {
            var type = StaticType != null
                ? ctx.ResolveType(StaticType)
                : Expression.GetExpressionType(ctx);

            SafeModeCheckType(ctx, type);

            // check for field
            try
            {
                m_Field = ctx.ResolveField(type, MemberName);
                m_IsStatic = m_Field.IsStatic;
                if (Expression == null && !m_IsStatic)
                    Error(CompilerMessages.DynamicMemberFromStaticContext, type, MemberName);

                return;
            }
            catch (KeyNotFoundException) { }

            try
            {
                m_Property = ctx.ResolveProperty(type, MemberName);
                if(!m_Property.CanSet)
                    Error(CompilerMessages.PropertyNoSetter, MemberName, type);

                m_IsStatic = m_Property.IsStatic;
                if (Expression == null && !m_IsStatic)
                    Error(CompilerMessages.DynamicMemberFromStaticContext, MemberName, type);
            }
            catch (KeyNotFoundException)
            {
                Error(CompilerMessages.TypeSettableIdentifierNotFound, type, MemberName);
            }
        }
开发者ID:TrickyCat,项目名称:lens,代码行数:35,代码来源:SetMemberNode.cs


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