Exemple #1
0
        public static Sigil.NonGeneric.Emit Box(this Sigil.NonGeneric.Emit emitter, Type typeFrom, bool castIfRefType)
        {
            if (typeFrom.IsByRef)
            {
                var baseType = typeFrom.GetElementType();

                if (baseType.IsPrimitive)
                {
                    return(emitter.LoadIndirect(baseType).Box(baseType));
                }

                if (baseType.IsValueType)
                {
                    return(emitter.LoadObject(baseType).Box(baseType));
                }

                if (!baseType.IsValueType)
                {
                    return(emitter.LoadIndirect(baseType));
                }

                throw new NotSupportedException(typeFrom.FullName + " not supported in this context");
            }

            if (!typeFrom.IsValueType)
            {
                return(emitter.CastClass(typeFrom));
            }

            return(emitter.Box(typeFrom));
        }
Exemple #2
0
        public static Sigil.NonGeneric.Emit Unbox(this Sigil.NonGeneric.Emit emitter, Type typeTo, bool castIfRefType)
        {
            if (!typeTo.IsValueType)
            {
                return(emitter.CastClass(typeTo));
            }

            return(emitter.Unbox(typeTo));
        }