示例#1
0
        public string RequiredPropertiesSettersForInitParameters()
        {
            var indented   = new IndentedStringBuilder("    ");
            var properties = Properties.Cast <PropertySwift>().ToList();

            if (BaseModelType != null)
            {
                indented.Append(((CompositeTypeSwift)BaseModelType).FieldWriter.RequiredPropertiesSettersForInitParameters());
            }

            foreach (var property in properties)
            {
                if (property.ModelType == null)
                {
                    continue;
                }

                if (property.IsPolymorphicDiscriminator)
                {
                    continue;
                }

                var propName  = property.VariableName;
                var modelType = property.ModelType;
                if (modelType is PrimaryTypeSwift)
                {
                    ((PrimaryTypeSwift)modelType).IsRequired = property.IsRequired;
                }

                var modelDeclaration = modelType.Name;
                if (modelType is PrimaryTypeSwift)
                {
                    modelDeclaration = SwiftNameHelper.getTypeName(modelType.Name, property.IsRequired);
                }
                else if (modelType is IVariableType &&
                         !string.IsNullOrEmpty(((IVariableType)modelType).VariableTypeDeclaration(property.IsRequired)))
                {
                    modelDeclaration = ((IVariableType)modelType).VariableTypeDeclaration(property.IsRequired);
                }

                if (property.IsRequired)
                {
                    indented.Append($"self.{propName} = {propName}\r\n");
                }
            }

            return(indented.ToString());
        }
示例#2
0
        public string RequiredPropertiesForInitParameters(bool forMethodCall = false)
        {
            var indented   = new IndentedStringBuilder("    ");
            var properties = Properties.Cast <PropertySwift>().ToList();
            var seperator  = "";

            if (BaseModelType != null)
            {
                indented.Append(((CompositeTypeSwift)BaseModelType).FieldWriter.RequiredPropertiesForInitParameters(forMethodCall));
                if (indented.ToString().Length > 0)
                {
                    seperator = ", ";
                }
            }

            // Emit each property, except for named Enumerated types, as a pointer to the type
            foreach (var property in properties)
            {
                if (property.ModelType == null)
                {
                    continue;
                }

                if (property.IsPolymorphicDiscriminator)
                {
                    continue;
                }

                var modelType = property.ModelType;
                if (modelType is PrimaryTypeSwift)
                {
                    ((PrimaryTypeSwift)modelType).IsRequired = property.IsRequired;
                }

                var modelDeclaration = modelType.Name;
                if (modelType is PrimaryTypeSwift)
                {
                    modelDeclaration = SwiftNameHelper.getTypeName(modelType.Name, property.IsRequired);
                }
                else if (modelType is IVariableType &&
                         !string.IsNullOrEmpty(((IVariableType)modelType).VariableTypeDeclaration(property.IsRequired)))
                {
                    modelDeclaration = ((IVariableType)modelType).VariableTypeDeclaration(property.IsRequired);
                }

                var output   = string.Empty;
                var propName = property.VariableName;

                if (property.IsRequired)
                {
                    if (forMethodCall)
                    {
                        indented.Append($"{seperator}{propName}: {propName}");
                    }
                    else
                    {
                        indented.Append($"{seperator}{propName}: {modelDeclaration}");
                    }

                    seperator = ", ";
                }
            }

            return(indented.ToString());
        }
示例#3
0
        public string FieldsAsString(bool forInterface = false)
        {
            var indented   = new IndentedStringBuilder("    ");
            var properties = Properties.Cast <PropertySwift>().ToList();

            if (BaseModelType != null && !forInterface)
            {
                indented.Append(((CompositeTypeSwift)BaseModelType).FieldWriter.FieldsAsString(forInterface));
            }

            // Emit each property, except for named Enumerated types, as a pointer to the type
            foreach (var property in properties)
            {
                if (property.ModelType == null)
                {
                    continue;
                }

                var modelType = property.ModelType;
                if (property.IsPolymorphicDiscriminator)
                {
                    continue;
                }

                if (modelType is PrimaryTypeSwift)
                {
                    ((PrimaryTypeSwift)modelType).IsRequired = property.IsRequired;
                }

                var modelDeclaration = modelType.Name;
                if (modelType is PrimaryTypeSwift)
                {
                    modelDeclaration = SwiftNameHelper.getTypeName(modelType.Name, property.IsRequired);
                }
                else if (modelType is IVariableType)
                {
                    modelDeclaration = ((IVariableType)modelType).VariableTypeDeclaration(property.IsRequired);
                }

                var output   = string.Empty;
                var propName = property.VariableName;
                var modifier = forInterface ? "" : "public";
                //TODO: need to handle flatten property case.
                output = string.Format("{2} var {0}: {1}",
                                       propName,
                                       modelDeclaration,
                                       modifier);

                if (forInterface)
                {
                    output += " { get set }\n";
                }
                else
                {
                    output += "\n";
                }

                indented.Append(output);
            }

            return(indented.ToString());
        }
示例#4
0
        public string FieldDecodingString()
        {
            var indented   = new IndentedStringBuilder("    ");
            var properties = Properties.Cast <PropertySwift>().ToList();

            if (BaseModelType != null)
            {
                indented.Append(((CompositeTypeSwift)BaseModelType).FieldWriter.FieldDecodingString());
            }

            // Emit each property, except for named Enumerated types, as a pointer to the type
            foreach (var property in properties)
            {
                if (property.ModelType == null)
                {
                    continue;
                }

                if (property.IsPolymorphicDiscriminator)
                {
                    continue;
                }

                var propName  = property.VariableName;
                var modelType = property.ModelType;
                if (modelType is PrimaryTypeSwift)
                {
                    ((PrimaryTypeSwift)modelType).IsRequired = property.IsRequired;
                }

                var modelDeclaration = modelType.Name;
                if (modelType is PrimaryTypeSwift)
                {
                    modelDeclaration = SwiftNameHelper.getTypeName(modelType.Name, property.IsRequired);
                }
                else if (modelType is IVariableType &&
                         !string.IsNullOrEmpty(((IVariableType)modelType).DecodeTypeDeclaration(property.IsRequired)))
                {
                    modelDeclaration = ((IVariableType)modelType).DecodeTypeDeclaration(property.IsRequired);
                }

                if (property.IsRequired)
                {
                    if (modelType is PrimaryTypeSwift &&
                        "Date".Equals(modelType.Name))
                    {
                        this.compositeType.SetDecodeDate(propName, property, indented);
                    }
                    else
                    {
                        indented.Append($"self.{propName} = try container.decode({modelDeclaration}.self, forKey: .{propName})\r\n");
                    }
                }
                else
                {
                    indented.Append($"if container.contains(.{propName}) {{\r\n");
                    if (modelType is PrimaryTypeSwift &&
                        "Date".Equals(modelType.Name))
                    {
                        this.compositeType.SetDecodeDate(propName, property, indented);
                    }
                    else
                    {
                        indented.Append($"    self.{propName} = try container.decode({modelDeclaration}.self, forKey: .{propName})\r\n");
                    }
                    indented.Append($"}}\r\n");
                }
            }

            return(indented.ToString());
        }