Ejemplo n.º 1
0
 Action<IILGen> GenerateEnum2EnumConversion(Type from, Type to)
 {
     var fromcfg = new EnumFieldHandler.EnumConfiguration(from);
     var tocfg = new EnumFieldHandler.EnumConfiguration(to);
     if (fromcfg.IsSubsetOf(tocfg))
     {
         return GenerateConversion(from.GetEnumUnderlyingType(), to.GetEnumUnderlyingType());
     }
     return null;
 }
        public virtual Action <IILGen> GenerateConversion(Type from, Type to)
        {
            if (from == to)
            {
                return ilg => { }
            }
            ;
            if (!from.IsValueType && to == typeof(object))
            {
                return(i => i.Castclass(to));
            }
            if (from == typeof(object) && !to.IsValueType)
            {
                return(i => i.Isinst(to));
            }
            Action <IILGen> generator;

            if (_conversions.TryGetValue(new Tuple <Type, Type>(from, to), out generator))
            {
                return(generator);
            }
            if (from.IsEnum && to.IsEnum)
            {
                return(GenerateEnum2EnumConversion(from, to));
            }
            return(null);
        }

        Action <IILGen> GenerateEnum2EnumConversion(Type from, Type to)
        {
            var fromcfg = new EnumFieldHandler.EnumConfiguration(from);
            var tocfg   = new EnumFieldHandler.EnumConfiguration(to);

            if (fromcfg.IsSubsetOf(tocfg))
            {
                return(GenerateConversion(from.GetEnumUnderlyingType(), to.GetEnumUnderlyingType()));
            }
            return(null);
        }