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


C# Context.ResolveConstructor方法代码示例

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


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

示例1: compile

        protected override void compile(Context ctx, bool mustReturn)
        {
            var gen = ctx.CurrentILGenerator;

            // find constructor
            var type = FunctionalHelper.CreateDelegateType(Body.GetExpressionType(ctx), _Method.ArgumentTypes);
            var ctor = ctx.ResolveConstructor(type, new[] {typeof (object), typeof (IntPtr)});

            var closureInstance = ctx.CurrentScope.ClosureVariable;
            gen.EmitLoadLocal(closureInstance);
            gen.EmitLoadFunctionPointer(_Method.MethodBuilder);
            gen.EmitCreateObject(ctor.ConstructorInfo);
        }
开发者ID:TrickyCat,项目名称:lens,代码行数:13,代码来源:LambdaNode.cs

示例2: compile

        protected override void compile(Context ctx, bool mustReturn)
        {
            var gen = ctx.CurrentILGenerator;

            var type = GetExpressionType(ctx);
            if(type.IsVoid())
                Error(CompilerMessages.VoidTypeDefault);

            if(type.IsAbstract)
                Error(CompilerMessages.TypeAbstract, TypeSignature.FullSignature);

            if(Arguments.Count == 0)
                Error(CompilerMessages.ParameterlessConstructorParens);

            var isParameterless = Arguments.Count == 1 && Arguments[0].GetExpressionType(ctx) == typeof (Unit);

            var argTypes = isParameterless
                ? Type.EmptyTypes
                : Arguments.Select(a => a.GetExpressionType(ctx)).ToArray();

            try
            {
                var ctor = ctx.ResolveConstructor(type, argTypes);

                if (!isParameterless)
                {
                    var destTypes = ctor.ArgumentTypes;
                    for (var idx = 0; idx < Arguments.Count; idx++)
                        Expr.Cast(Arguments[idx], destTypes[idx]).Compile(ctx, true);
                }

                gen.EmitCreateObject(ctor.ConstructorInfo);
            }
            catch (AmbiguousMatchException)
            {
                Error(CompilerMessages.TypeConstructorAmbiguos, TypeSignature.FullSignature);
            }
            catch (KeyNotFoundException)
            {
                if (!isParameterless || !type.IsValueType)
                    Error(CompilerMessages.TypeConstructorNotFound, TypeSignature.FullSignature);

                var castExpr = Expr.Default(TypeSignature);
                castExpr.Compile(ctx, true);
            }
        }
开发者ID:TrickyCat,项目名称:lens,代码行数:46,代码来源:NewObjectNode.cs

示例3: emitCode

        protected override void emitCode(Context ctx, bool mustReturn)
        {
            var resultType = Resolve(ctx);

            var gen = ctx.CurrentMethod.Generator;

            // local name is not cached because it can be closured.
            // if the identifier is actually a local constant, the 'compile' method is not invoked at all
            var local = Local ?? ctx.Scope.FindLocal(Identifier);
            if (local != null)
            {
                if(local.IsImmutable && RefArgumentRequired)
                    error(CompilerMessages.ConstantByRef);

                if (local.IsClosured)
                {
                    if (local.ClosureDistance == 0)
                        emitGetClosuredLocal(ctx, local);
                    else
                        emitGetClosuredRemote(ctx, local);
                }
                else
                {
                    emitGetLocal(ctx, local);
                }

                return;
            }

            // load pointer to global function
            if (_Method != null)
            {
                var ctor = ctx.ResolveConstructor(resultType, new[] {typeof (object), typeof (IntPtr)});

                gen.EmitNull();
                gen.EmitLoadFunctionPointer(_Method.MethodInfo);
                gen.EmitCreateObject(ctor.ConstructorInfo);

                return;
            }

            // get a property value
            if (_Property != null)
            {
                var id = _Property.PropertyId;
                if(!_Property.HasGetter)
                    error(CompilerMessages.GlobalPropertyNoGetter, Identifier);

                var type = _Property.PropertyType;
                if (_Property.GetterMethod != null)
                {
                    gen.EmitCall(_Property.GetterMethod.MethodInfo);
                }
                else
                {
                    var method = typeof (GlobalPropertyHelper).GetMethod("Get").MakeGenericMethod(type);
                    gen.EmitConstant(ctx.ContextId);
                    gen.EmitConstant(id);
                    gen.EmitCall(method);
                }
                return;
            }

            error(CompilerMessages.IdentifierNotFound, Identifier);
        }
开发者ID:menozz,项目名称:lens,代码行数:65,代码来源:GetIdentifierNode.cs

示例4: castDelegate

        private void castDelegate(Context ctx, Type from, Type to)
        {
            var gen = ctx.CurrentILGenerator;

            var toCtor = ctx.ResolveConstructor(to, new[] {typeof (object), typeof (IntPtr)});
            var fromMethod = ctx.ResolveMethod(from, "Invoke");
            var toMethod = ctx.ResolveMethod(to, "Invoke");

            var fromArgs = fromMethod.ArgumentTypes;
            var toArgs = toMethod.ArgumentTypes;

            if(fromArgs.Length != toArgs.Length || toArgs.Select((ta, id) => !ta.IsExtendablyAssignableFrom(fromArgs[id], true)).Any(x => x))
                Error(CompilerMessages.CastDelegateArgTypesMismatch, from, to);

            if(!toMethod.ReturnType.IsExtendablyAssignableFrom(fromMethod.ReturnType, true))
                Error(CompilerMessages.CastDelegateReturnTypesMismatch, from, to);

            if (fromMethod.IsStatic)
                gen.EmitNull();
            else
                Expression.Compile(ctx, true);

            if (from.IsGenericType && to.IsGenericType && from.GetGenericTypeDefinition() == to.GetGenericTypeDefinition())
                return;

            gen.EmitLoadFunctionPointer(fromMethod.MethodInfo);
            gen.EmitCreateObject(toCtor.ConstructorInfo);
        }
开发者ID:TrickyCat,项目名称:lens,代码行数:28,代码来源:CastOperatorNode.cs

示例5: resolve

        protected override Type resolve(Context ctx, bool mustReturn)
        {
            base.resolve(ctx, true);

            var type = Type ?? ctx.ResolveType(TypeSignature);

            if (type.IsVoid())
                error(CompilerMessages.VoidTypeDefault);

            if (type.IsAbstract)
                error(CompilerMessages.TypeAbstract, TypeSignature.FullSignature);

            if (type.IsInterface)
                error(CompilerMessages.TypeInterface, TypeSignature.FullSignature);

            if (Arguments.Count == 0)
                error(CompilerMessages.ParameterlessConstructorParens);

            try
            {
                _Constructor = ctx.ResolveConstructor(type, _ArgTypes);
            }
            catch (AmbiguousMatchException)
            {
                error(CompilerMessages.TypeConstructorAmbiguos, TypeSignature.FullSignature);
            }
            catch (KeyNotFoundException)
            {
                if (_ArgTypes.Length > 0 || !type.IsValueType)
                    error(CompilerMessages.TypeConstructorNotFound, TypeSignature.FullSignature);

                _IsDefault = true;
                return type;
            }

            applyLambdaArgTypes(ctx);

            return resolvePartial(_Constructor, type, _ArgTypes);
        }
开发者ID:menozz,项目名称:lens,代码行数:39,代码来源:NewObjectNode.cs

示例6: compileComposition

        private void compileComposition(Context ctx)
        {
            var gen = ctx.CurrentILGenerator;

            // find constructor
            var type = FunctionalHelper.CreateDelegateType(_Method.ReturnType, _Method.ArgumentTypes);
            var ctor = ctx.ResolveConstructor(type, new[] { typeof(object), typeof(IntPtr) });

            var closureInstance = ctx.CurrentScope.ClosureVariable;
            gen.EmitLoadLocal(closureInstance);
            gen.EmitLoadFunctionPointer(_Method.MethodBuilder);
            gen.EmitCreateObject(ctor.ConstructorInfo);
        }
开发者ID:TrickyCat,项目名称:lens,代码行数:13,代码来源:ShiftOperatorNode.cs

示例7: emitMethod

        /// <summary>
        /// Emits code for getting the method as a delegate instance.
        /// </summary>
        private void emitMethod(Context ctx, ILGenerator gen)
        {
            if (RefArgumentRequired)
                error(CompilerMessages.MethodRef);

            if (_IsStatic)
                gen.EmitNull();

            var retType = _Method.ReturnType;
            var type = retType.IsVoid()
                ? FunctionalHelper.CreateActionType(_Method.ArgumentTypes)
                : FunctionalHelper.CreateFuncType(retType, _Method.ArgumentTypes);

            var ctor = ctx.ResolveConstructor(type, new [] { typeof(object), typeof(IntPtr) });
            gen.EmitLoadFunctionPointer(_Method.MethodInfo);
            gen.EmitCreateObject(ctor.ConstructorInfo);
        }
开发者ID:menozz,项目名称:lens,代码行数:20,代码来源:GetMemberNode.cs

示例8: castNumeric

        private void castNumeric(Context ctx, Type from, Type to)
        {
            var gen = ctx.CurrentMethod.Generator;

            Expression.Emit(ctx, true);

            if (to == typeof (decimal))
            {
                var ctor = ctx.ResolveConstructor(typeof (decimal), new[] { from });
                if (ctor == null)
                {
                    ctor = ctx.ResolveConstructor(typeof(decimal), new[] { typeof(int) });
                    gen.EmitConvert(typeof(int));
                }

                gen.EmitCreateObject(ctor.ConstructorInfo);
            }
            else
            {
                gen.EmitConvert(to);
            }
        }
开发者ID:menozz,项目名称:lens,代码行数:22,代码来源:CastOperatorNode.cs


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