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));
        }
示例#2
0
 public static AbstractValue TypeError(string message)
 {
     throw RuntimeHelpers.SimpleTypeError(message);
     //return new AbstractValue(null, Exception, AbstractKind.Error, null);
 }