public override string EscapeDefaultValue(string defaultValue, IType type)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            if (defaultValue != null)
            {
                if (type == PrimaryType.String)
                {
                    return(CodeNamer.QuoteValue(defaultValue));
                }
                else if (type == PrimaryType.Boolean)
                {
                    return(defaultValue);
                }
                else
                {
                    if (type == PrimaryType.Date ||
                        type == PrimaryType.DateTime ||
                        type == PrimaryType.DateTimeRfc1123 ||
                        type == PrimaryType.TimeSpan)
                    {
                        return("isodate.parse_date(\"" + defaultValue + "\")");
                    }

                    if (type == PrimaryType.ByteArray)
                    {
                        return("bytearray(\"" + defaultValue + "\", encoding=\"utf-8\")");
                    }
                }
            }
            return(defaultValue);
        }
        public override string EscapeDefaultValue(string defaultValue, IType type)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            if (defaultValue != null)
            {
                if (type == PrimaryType.String)
                {
                    return(CodeNamer.QuoteValue(defaultValue, quoteChar: "'"));
                }
                else if (type == PrimaryType.Boolean)
                {
                    return(defaultValue.ToLowerInvariant());
                }
                else
                {
                    if (type == PrimaryType.Date ||
                        type == PrimaryType.DateTime ||
                        type == PrimaryType.DateTimeRfc1123 ||
                        type == PrimaryType.TimeSpan)
                    {
                        return("Date.parse('" + defaultValue + "')");
                    }

                    if (type == PrimaryType.ByteArray)
                    {
                        return("'" + defaultValue + "'.bytes.to_a");
                    }
                }
            }
            return(defaultValue);
        }
Exemple #3
0
        public override string EscapeDefaultValue(string defaultValue, IType type)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            var primaryType = type as PrimaryType;

            if (defaultValue != null && primaryType != null)
            {
                if (primaryType.Type == KnownPrimaryType.String)
                {
                    return(CodeNamer.QuoteValue(defaultValue));
                }
                else if (primaryType.Type == KnownPrimaryType.Boolean)
                {
                    return(defaultValue.ToLowerInvariant());
                }
                else if (primaryType.Type == KnownPrimaryType.Long)
                {
                    return(defaultValue + "L");
                }
                else
                {
                    if (primaryType.Type == KnownPrimaryType.Date)
                    {
                        return("LocalDate.parse(\"" + defaultValue + "\")");
                    }
                    else if (primaryType.Type == KnownPrimaryType.DateTime ||
                             primaryType.Type == KnownPrimaryType.DateTimeRfc1123)
                    {
                        return("DateTime.parse(\"" + defaultValue + "\")");
                    }
                    else if (primaryType.Type == KnownPrimaryType.TimeSpan)
                    {
                        return("Period.parse(\"" + defaultValue + "\")");
                    }
                    else if (primaryType.Type == KnownPrimaryType.ByteArray)
                    {
                        return("\"" + defaultValue + "\".getBytes()");
                    }
                }
            }
            return(defaultValue);
        }
        public override string EscapeDefaultValue(string defaultValue, IType type)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            PrimaryType primaryType = type as PrimaryType;

            if (defaultValue != null)
            {
                if (type is CompositeType)
                {
                    return("new " + type.Name + "()");
                }
                else if (primaryType != null)
                {
                    if (primaryType.Type == KnownPrimaryType.String)
                    {
                        return(CodeNamer.QuoteValue(defaultValue));
                    }
                    else if (primaryType.Type == KnownPrimaryType.Boolean)
                    {
                        return(defaultValue.ToLowerInvariant());
                    }
                    else
                    {
                        if (primaryType.Type == KnownPrimaryType.Date ||
                            primaryType.Type == KnownPrimaryType.DateTime ||
                            primaryType.Type == KnownPrimaryType.DateTimeRfc1123 ||
                            primaryType.Type == KnownPrimaryType.TimeSpan ||
                            primaryType.Type == KnownPrimaryType.ByteArray ||
                            primaryType.Type == KnownPrimaryType.Base64Url ||
                            primaryType.Type == KnownPrimaryType.UnixTime)
                        {
                            return("Microsoft.Rest.Serialization.SafeJsonConvert.DeserializeObject<" + primaryType.Name.TrimEnd('?') +
                                   ">(" + CodeNamer.QuoteValue("\"" + defaultValue + "\"") + ", this.Client.SerializationSettings)");
                        }
                    }
                }
            }
            return(defaultValue);
        }
Exemple #5
0
        public override string EscapeDefaultValue(string defaultValue, IType type)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            PrimaryType primaryType = type as PrimaryType;

            if (defaultValue != null && primaryType != null)
            {
                if (primaryType.Type == KnownPrimaryType.String)
                {
                    return(CodeNamer.QuoteValue(defaultValue, quoteChar: "'"));
                }
                else if (primaryType.Type == KnownPrimaryType.Boolean)
                {
                    return(defaultValue.ToLowerInvariant());
                }
                else
                {
                    if (primaryType.Type == KnownPrimaryType.Date ||
                        primaryType.Type == KnownPrimaryType.DateTime ||
                        primaryType.Type == KnownPrimaryType.DateTimeRfc1123)
                    {
                        return("new Date('" + defaultValue + "')");
                    }
                    else if (primaryType.Type == KnownPrimaryType.TimeSpan)
                    {
                        return("moment.duration('" + defaultValue + "')");
                    }
                    else if (primaryType.Type == KnownPrimaryType.ByteArray)
                    {
                        return("new Buffer('" + defaultValue + "')");
                    }
                }
            }
            return(defaultValue);
        }
Exemple #6
0
        public override string EscapeDefaultValue(string defaultValue, IType type)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            PrimaryType primaryType = type as PrimaryType;

            if (defaultValue != null)
            {
                if (type is CompositeType)
                {
                    return(type.Name + "{}");
                }
                else if (primaryType != null)
                {
                    if (primaryType.Type == KnownPrimaryType.String ||
                        primaryType.Type == KnownPrimaryType.Uuid ||
                        primaryType.Type == KnownPrimaryType.TimeSpan)
                    {
                        return(CodeNamer.QuoteValue(defaultValue));
                    }
                    else if (primaryType.Type == KnownPrimaryType.Boolean)
                    {
                        return(defaultValue.ToLowerInvariant());
                    }
                    else if (primaryType.Type == KnownPrimaryType.ByteArray)
                    {
                        return("[]bytearray(\"" + defaultValue + "\")");
                    }
                    else
                    {
                        //TODO: handle imports for package types.
                    }
                }
            }
            return(defaultValue);
        }
        public override string EscapeDefaultValue(string defaultValue, IType type)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            var parsedDefault = PythonConstants.None;

            EnumType enumType = type as EnumType;

            if (defaultValue != null && enumType != null)
            {
                parsedDefault = CodeNamer.QuoteValue(defaultValue);
            }

            PrimaryType primaryType = type as PrimaryType;

            if (defaultValue != null && primaryType != null)
            {
                if (primaryType.Type == KnownPrimaryType.String || primaryType.Type == KnownPrimaryType.Uuid)
                {
                    parsedDefault = CodeNamer.QuoteValue(defaultValue);
                }
                else if (primaryType.Type == KnownPrimaryType.Boolean)
                {
                    if (defaultValue == "true")
                    {
                        parsedDefault = "True";
                    }
                    else
                    {
                        parsedDefault = "False";
                    }
                }
                else
                {
                    //TODO: Add support for default KnownPrimaryType.DateTimeRfc1123
                    //TODO: Default date objects can only be supported with an isodate import statement

                    //if (primaryType.Type == KnownPrimaryType.Date)
                    //{
                    //    parsedDefault = "isodate.parse_date(\"" + defaultValue + "\")";
                    //}

                    //else if (primaryType.Type == KnownPrimaryType.DateTime)
                    //{
                    //    parsedDefault = "isodate.parse_datetime(\"" + defaultValue + "\")";
                    //}

                    //else if (primaryType.Type == KnownPrimaryType.TimeSpan)
                    //{
                    //    parsedDefault = "isodate.parse_duration(\"" + defaultValue + "\")";
                    //}

                    if (primaryType.Type == KnownPrimaryType.ByteArray)
                    {
                        parsedDefault = "bytearray(\"" + defaultValue + "\", encoding=\"utf-8\")";
                    }

                    else if (primaryType.Type == KnownPrimaryType.Int ||
                             primaryType.Type == KnownPrimaryType.Long ||
                             primaryType.Type == KnownPrimaryType.Double)
                    {
                        parsedDefault = defaultValue;
                    }
                }
            }
            return(parsedDefault);
        }