예제 #1
0
        protected override Type ResolveInternal(Context ctx, bool mustReturn)
        {
            ResolveSelf(ctx);

            if (_type != null)
            {
                CheckTypeInSafeMode(ctx, _type);
            }

            if (Expression != null && Expression.Resolve(ctx).IsArray&& MemberName == "Length")
            {
                return(typeof(int));
            }

            if (_field != null)
            {
                return(_field.FieldType);
            }

            if (_property != null)
            {
                return(_property.PropertyType);
            }

            return(_method.ReturnType.IsVoid()
                ? FunctionalHelper.CreateActionType(_method.ArgumentTypes)
                : FunctionalHelper.CreateFuncType(_method.ReturnType, _method.ArgumentTypes));
        }
예제 #2
0
        public void CreateActionTypeTest()
        {
            Assert.AreEqual(
                typeof(Action <int, string, TimeSpan>),
                FunctionalHelper.CreateActionType(typeof(int), typeof(string), typeof(TimeSpan))
                );

            Assert.AreEqual(typeof(Action), FunctionalHelper.CreateActionType());

            Assert.Throws <LensCompilerException>(() => FunctionalHelper.CreateActionType(new Type[20]));
        }
예제 #3
0
        /// <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);
        }