public void UnknownLiteral_throws_when_unknown()
        {
            var ex = Assert.Throws <InvalidOperationException>(
                () => new CSharpHelper().UnknownLiteral(new object()));

            Assert.Equal(DesignCoreStrings.UnknownLiteral(typeof(object)), ex.Message);
        }
Example #2
0
        public virtual string UnknownLiteral([CanBeNull] object value)
        {
            if (value == null)
            {
                return("null");
            }

            var type = value.GetType().UnwrapNullableType();

            Func <CSharpHelper, object, string> literalFunc;

            if (_literalFuncs.TryGetValue(type, out literalFunc))
            {
                return(literalFunc(this, value));
            }

            var enumValue = value as Enum;

            if (enumValue != null)
            {
                return(Literal(enumValue));
            }

            throw new InvalidOperationException(DesignCoreStrings.UnknownLiteral(value.GetType()));
        }