Exemple #1
0
        public override void Assign(CodeContext c, Expression source)
        {
            LocalBuilder local;
            int          parameter;

            if (c.Locals.TryGetValue(variablename, out local))
            {
                Type type = source.Evaluate(c);
                c.Convert(type, local.LocalType);
                c.IL.Emit(OpCodes.Stloc, local);
            }
            else if (c.Parameters.TryGetValue(variablename, out parameter))
            {
                Type type = source.Evaluate(c);
                c.Convert(type, c.ParameterTypes[parameter]);
                if (c.Method.IsStatic)
                {
                    c.IL.Emit(OpCodes.Starg, parameter);
                }
                else
                {
                    c.IL.Emit(OpCodes.Starg, parameter + 1);
                }
            }
            else
            {
                throw new ApplicationException();
            }
        }
Exemple #2
0
        public override void Assign(CodeContext c, Expression source)
        {
            Type       type   = Inner.Evaluate(c);
            MemberInfo member = GetMember(type, ScriptAccessType.Set);

            if (member.MemberType == MemberTypes.Field)
            {
                FieldInfo field = (FieldInfo)member;
                if (field.IsInitOnly || field.IsLiteral)
                {
                    throw new ApplicationException();
                }
                Type sourcetype = source.Evaluate(c);
                c.Convert(sourcetype, field.FieldType);
                c.IL.Emit(OpCodes.Stfld, field);
            }
            else if (member.MemberType == MemberTypes.Property)
            {
                PropertyInfo property = (PropertyInfo)member;
                if (!property.CanWrite)
                {
                    throw new ApplicationException();
                }
                Type sourcetype = source.Evaluate(c);
                c.Convert(sourcetype, property.PropertyType);
                c.IL.Emit(OpCodes.Callvirt, property.GetSetMethod());
            }
            else
            {
                throw new ApplicationException();
            }
        }
 public override void Assign(CodeContext c,Expression source)
 {
     LocalBuilder local;
     int parameter;
     if (c.Locals.TryGetValue(variablename,out local))
     {
         Type type = source.Evaluate(c);
         c.Convert(type,local.LocalType);
         c.IL.Emit(OpCodes.Stloc,local);
     }
     else if (c.Parameters.TryGetValue(variablename,out parameter))
     {
         Type type = source.Evaluate(c);
         c.Convert(type,c.ParameterTypes[parameter]);
         if (c.Method.IsStatic)
         {
             c.IL.Emit(OpCodes.Starg,parameter);
         }
         else
         {
             c.IL.Emit(OpCodes.Starg,parameter + 1);
         }
     }
     else
     {
         throw new ApplicationException();
     }
 }
 public override void Assign(CodeContext c,Expression source)
 {
     Type type = Inner.Evaluate(c);
     MemberInfo member = GetMember(type,ScriptAccessType.Set);
     if (member.MemberType == MemberTypes.Field)
     {
         FieldInfo field = (FieldInfo)member;
         if (field.IsInitOnly || field.IsLiteral)
         {
             throw new ApplicationException();
         }
         Type sourcetype = source.Evaluate(c);
         c.Convert(sourcetype,field.FieldType);
         c.IL.Emit(OpCodes.Stfld,field);
     }
     else if (member.MemberType == MemberTypes.Property)
     {
         PropertyInfo property = (PropertyInfo)member;
         if (!property.CanWrite)
         {
             throw new ApplicationException();
         }
         Type sourcetype = source.Evaluate(c);
         c.Convert(sourcetype,property.PropertyType);
         c.IL.Emit(OpCodes.Callvirt,property.GetSetMethod());
     }
     else
     {
         throw new ApplicationException();
     }
 }
Exemple #5
0
        public override Type Invoke(CodeContext c, Expression[] arguments)
        {
            Type       type   = Inner.Evaluate(c);
            MemberInfo member = GetMember(type, ScriptAccessType.Invoke);

            if (member.MemberType == MemberTypes.Method)
            {
                MethodInfo      method     = (MethodInfo)member;
                ParameterInfo[] parameters = method.GetParameters();
                if (parameters.Length != arguments.Length)
                {
                    throw new ApplicationException();
                }
                for (int i = 0; i < arguments.Length; i++)
                {
                    Type argumenttype = arguments[i].Evaluate(c);
                    c.Convert(argumenttype, parameters[i].ParameterType);
                }
                c.IL.Emit(OpCodes.Callvirt, method);
                return(method.ReturnType);
            }
            else
            {
                throw new ApplicationException();
            }
        }
Exemple #6
0
 public override void Compile(CodeContext c)
 {
     if (expression == null)
     {
         if (c.ReturnType != typeof(void))
         {
             throw new ApplicationException();
         }
         c.IL.Emit(OpCodes.Ret);
     }
     else if (expression != null)
     {
         if (c.ReturnType == typeof(void))
         {
             throw new ApplicationException();
         }
         Type type = expression.Evaluate(c);
         c.Convert(type, c.ReturnType);
         c.IL.Emit(OpCodes.Ret);
     }
 }
 public override void Compile(CodeContext c)
 {
     if (expression == null)
     {
         if (c.ReturnType != typeof(void))
         {
             throw new ApplicationException();
         }
         c.IL.Emit(OpCodes.Ret);
     }
     else if (expression != null)
     {
         if (c.ReturnType == typeof(void))
         {
             throw new ApplicationException();
         }
         Type type = expression.Evaluate(c);
         c.Convert(type,c.ReturnType);
         c.IL.Emit(OpCodes.Ret);
     }
 }
 public override Type Invoke(CodeContext c,Expression[] arguments)
 {
     Type type = Inner.Evaluate(c);
     MemberInfo member = GetMember(type,ScriptAccessType.Invoke);
     if (member.MemberType == MemberTypes.Method)
     {
         MethodInfo method = (MethodInfo)member;
         ParameterInfo[] parameters = method.GetParameters();
         if (parameters.Length != arguments.Length)
         {
             throw new ApplicationException();
         }
         for (int i = 0;i < arguments.Length;i++)
         {
             Type argumenttype = arguments[i].Evaluate(c);
             c.Convert(argumenttype,parameters[i].ParameterType);
         }
         c.IL.Emit(OpCodes.Callvirt,method);
         return method.ReturnType;
     }
     else
     {
         throw new ApplicationException();
     }
 }