Skip to content

Cannot convert type 'System.Collections.Generic.List<CodeGenerator.Models.ColumnInfo>' to 'System.Collections.Generic.List<CodeGenerator.Models.ColumnInfo>' #154

Description

@lianyitj

Hi, @foreach (var col in ((List<ColumnInfo>)Model.FormFields).Where(c => !c.IsIdentity))

err:
Cannot convert type 'System.Collections.Generic.List<CodeGenerator.Models.ColumnInfo>' to 'System.Collections.Generic.List<CodeGenerator.Models.ColumnInfo>'

What is the reason for this? I only know a little English. Sorry about that.

ColumnInfo: as follow:

`using System.Text.Json.Serialization;

namespace CodeGenerator.Models;

public class ColumnInfo
{
[JsonPropertyName("name")]
public string Name { get; set; } = "";

[JsonPropertyName("description")]
public string Description { get; set; } = "";

[JsonPropertyName("dataType")]
public string DataType { get; set; } = "";

[JsonPropertyName("isNullable")]
public bool IsNullable { get; set; }

[JsonPropertyName("isPrimaryKey")]
public bool IsPrimaryKey { get; set; }

[JsonPropertyName("isIdentity")]
public bool IsIdentity { get; set; }

[JsonPropertyName("maxLength")]
public int MaxLength { get; set; }

[JsonPropertyName("decimalPlaces")]
public int DecimalPlaces { get; set; }

[JsonPropertyName("vueComponentType")]
public VueComponentType VueComponentType { get; set; } = VueComponentType.ElInput;

[JsonPropertyName("sortOrder")]
public int SortOrder { get; set; }

[JsonPropertyName("isHidden")]
public bool IsHidden { get; set; }

[JsonPropertyName("width")]
public string Width { get; set; } = "auto";

[JsonPropertyName("align")]
public AlignType Align { get; set; } = AlignType.Left;

[JsonPropertyName("isSearchField")]
public bool IsSearchField { get; set; }

[JsonPropertyName("isRequired")]
public bool IsRequired { get; set; }

[JsonPropertyName("placeholder")]
public string Placeholder { get; set; } = "";

[JsonPropertyName("defaultValue")]
public string DefaultValue { get; set; } = "";

[JsonPropertyName("format")]
public string Format { get; set; } = "";

[JsonPropertyName("options")]
public List<OptionItem> Options { get; set; } = new();

[JsonIgnore]
public string DisplayName => string.IsNullOrEmpty(Description) ? Name : Description;

[JsonIgnore]
public string PascalCaseName => ToPascalCase(Name);

[JsonIgnore]
public string CamelCaseName => ToCamelCase(Name);

private static string ToPascalCase(string input)
{
    if (string.IsNullOrEmpty(input)) return input;
    var parts = input.Split('_', '-', ' ');
    return string.Concat(parts.Select(p => char.ToUpper(p[0]) + p[1..].ToLower()));
}

private static string ToCamelCase(string input)
{
    var pascal = ToPascalCase(input);
    if (string.IsNullOrEmpty(pascal)) return pascal;
    return char.ToLower(pascal[0]) + pascal[1..];
}

}

public class OptionItem
{
[JsonPropertyName("label")]
public string Label { get; set; } = "";

[JsonPropertyName("value")]
public string Value { get; set; } = "";

}
`

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions