Exemplo n.º 1
0
        //public static void CallDynamic(ILGenerator il, MethodInfo method)
        //{
        //il.Emit(OpCodes.Callvirt, method);

        /*if (method.IsAbstract || method.IsVirtual)
         * {
         *  il.Emit(OpCodes.Callvirt, method);
         * }
         * else
         * {
         *  il.Emit(OpCodes.Call, method);
         * }*/
        /* Console.WriteLine(string.Format("{0} IsStatic:{1}", method.Name, method.IsStatic));
         * if (method.IsStatic)
         * {
         *   il.Emit(OpCodes.Call, method);
         * }
         * else
         * {
         *   il.Emit(OpCodes.Callvirt, method);
         * }
         * }*/
        /*
         * public static void CallDynamic(ILGenerator il, MethodInfo method,Type objType)
         * {
         *  if (objType == method.DeclaringType)
         *      il.Emit(OpCodes.Call, method);
         *  else
         *      il.Emit(OpCodes.Callvirt, method);
         * }*/

        public static bool EmitSymbolGet(ILGenerator il, SymbolInfo symbol)
        {
            if (symbol is SymbolVar)
            {
                var symbolVar = symbol as SymbolVar;
                EmitHelper.LoadVar(il, symbolVar.VarBuilder);
            }
            else if (symbol is SymbolArg)
            {
                SymbolArg argsymbol = (symbol as SymbolArg);
                il.Emit(OpCodes.Ldarg, argsymbol.ArgIndex);
            }
            else if (symbol is SymbolEnumItem)
            {
                SymbolEnumItem eisymbol = (symbol as SymbolEnumItem);
                EmitHelper.LoadInt(il, (int)eisymbol.EnumValue);
            }
            else if (symbol is SymbolPropertyDirect)
            {
                SymbolPropertyDirect prsymbol  = symbol as SymbolPropertyDirect;
                MethodInfo           getMethod = prsymbol.ExProperty.Property.GetGetMethod();
                EmitHelper.CallDynamic(il, getMethod, prsymbol.ExProperty.IsSelf);
            }
            else if (symbol is SymbolFieldDirect)
            {
                SymbolFieldDirect fymbol = symbol as SymbolFieldDirect;
                EmitHelper.LoadField(il, fymbol.ExField.Field);
            }
            else if (symbol is SymbolDefProperty)
            {
                SymbolDefProperty prsymbol = (symbol as SymbolDefProperty);
                if (!prsymbol.IsStatic)
                {
                    il.Emit(OpCodes.Ldarg_0);
                }
                MethodInfo getMethod = prsymbol.GetProperty().GetGetMethod();
                EmitHelper.CallDynamic(il, getMethod, true);
            }
            else if (symbol is SymbolDefField)
            {
                SymbolDefField prsymbol = (symbol as SymbolDefField);
                if (!prsymbol.IsStatic)
                {
                    il.Emit(OpCodes.Ldarg_0);
                }
                //il.Emit(OpCodes.Ldfld, prsymbol.Builder);
                EmitHelper.LoadField(il, prsymbol.GetField());
            }
            else if (symbol is SymbolDefClass)
            {
                return(true);
            }
            else
            {
                return(false);
            }
            return(true);
        }
Exemplo n.º 2
0
 public static bool EmitSet_Storm(ILGenerator il, SymbolInfo symbol)
 {
     if (symbol is SymbolVar)
     {
         EmitHelper.StormVar(il, (symbol as SymbolVar).VarBuilder);
     }
     else if (symbol is SymbolArg)
     {
         EmitHelper.StormArg(il, (symbol as SymbolArg).ArgIndex);
     }
     else if (symbol is SymbolPropertyDirect)
     {
         SymbolPropertyDirect prsymbol  = symbol as SymbolPropertyDirect;
         MethodInfo           setMethod = prsymbol.ExProperty.Property.GetSetMethod();
         EmitHelper.CallDynamic(il, setMethod, prsymbol.ExProperty.IsSelf);
     }
     else if (symbol is SymbolDefProperty)
     {
         SymbolDefProperty prsymbol  = (symbol as SymbolDefProperty);
         MethodInfo        setMethod = prsymbol.GetProperty().GetSetMethod();
         EmitHelper.CallDynamic(il, setMethod, true);
     }
     else if (symbol is SymbolDefField)
     {
         SymbolDefField prsymbol = (symbol as SymbolDefField);
         EmitHelper.StormField(il, prsymbol.GetField());
     }
     else if (symbol is SymbolFieldDirect)
     {
         SymbolFieldDirect fymbol = symbol as SymbolFieldDirect;
         EmitHelper.StormField(il, fymbol.ExField.Field);
     }
     else
     {
         return(false);
     }
     return(true);
 }