Ejemplo n.º 1
0
        public static bool IsStrongBox(object target)
        {
            Type t = CompilerHelpers.GetType(target);

            return(IsStrongBox(t));
        }
Ejemplo n.º 2
0
        public override object Build(CodeContext context, object[] args)
        {
            object arg = args[Index];

            if (arg == null)
            {
                throw RuntimeHelpers.SimpleTypeError("expected StrongBox, but found null");
            }
            Type argType = arg.GetType();

            if (!argType.IsGenericType || argType.GetGenericTypeDefinition() != typeof(StrongBox <>))
            {
                throw RuntimeHelpers.SimpleTypeError("expected StrongBox<>");
            }
            if (argType.GetGenericArguments()[0] != _elementType)
            {
                throw RuntimeHelpers.SimpleTypeError(String.Format("Expected type {0}, got {1}", typeof(StrongBox <>).MakeGenericType(_elementType).FullName, CompilerHelpers.GetType(arg).FullName));
            }

            object value = ((IStrongBox)arg).Value;

            if (value == null)
            {
                return(null);
            }
            return(context.LanguageContext.Binder.Convert(value, _elementType));
        }