【问题标题】:Name variable "private" [duplicate]名称变量“私有”[重复]
【发布时间】:2020-07-13 19:57:02
【问题描述】:

我正在使用 .Net 核心开发一个项目,现在我有 Git hub 的存储库搜索 api,我需要将数据转换为 c# 对象。 使用 Json2Csharp (https://json2csharp.com/) 我得到了那个类:

public class Root    {
        public int id { get; set; } 
        public string node_id { get; set; } 
        public string name { get; set; } 
        public string full_name { get; set; } 
        public bool private { get; set; } 
        public Owner owner { get; set; } 
        public string html_url { get; set; } 
        public string description { get; set; } 
        public bool fork { get; set; } 
        public string url { get; set; } 
        public string forks_url { get; set; } 
        public string keys_url { get; set; } 
        public string collaborators_url { get; set; } 
        public string teams_url { get; set; } 
        public string hooks_url { get; set; } 
        public string issue_events_url { get; set; } 
        public string events_url { get; set; } 
        public string assignees_url { get; set; } 
        public string branches_url { get; set; } 
        public string tags_url { get; set; } 
        public string blobs_url { get; set; } 
        public string git_tags_url { get; set; } 
        public string git_refs_url { get; set; } 
        public string trees_url { get; set; } 
        public string statuses_url { get; set; } 
        public string languages_url { get; set; } 
        public string stargazers_url { get; set; } 
        public string contributors_url { get; set; } 
        public string subscribers_url { get; set; } 
        public string subscription_url { get; set; } 
        public string commits_url { get; set; } 
        public string git_commits_url { get; set; } 
        public string comments_url { get; set; } 
        public string issue_comment_url { get; set; } 
        public string contents_url { get; set; } 
        public string compare_url { get; set; } 
        public string merges_url { get; set; } 
        public string archive_url { get; set; } 
        public string downloads_url { get; set; } 
        public string issues_url { get; set; } 
        public string pulls_url { get; set; } 
        public string milestones_url { get; set; } 
        public string notifications_url { get; set; } 
        public string labels_url { get; set; } 
        public string releases_url { get; set; } 
        public string deployments_url { get; set; } 
        public DateTime created_at { get; set; } 
        public DateTime updated_at { get; set; } 
        public DateTime pushed_at { get; set; } 
        public string git_url { get; set; } 
        public string ssh_url { get; set; } 
        public string clone_url { get; set; } 
        public string svn_url { get; set; } 
        public string homepage { get; set; } 
        public int size { get; set; } 
        public int stargazers_count { get; set; } 
        public int watchers_count { get; set; } 
        public string language { get; set; } 
        public bool has_issues { get; set; } 
        public bool has_projects { get; set; } 
        public bool has_downloads { get; set; } 
        public bool has_wiki { get; set; } 
        public bool has_pages { get; set; } 
        public int forks_count { get; set; } 
        public object mirror_url { get; set; } 
        public bool archived { get; set; } 
        public bool disabled { get; set; } 
        public int open_issues_count { get; set; } 
        public License license { get; set; } 
        public int forks { get; set; } 
        public int open_issues { get; set; } 
        public int watchers { get; set; } 
        public string default_branch { get; set; } 
        public double score { get; set; } 
}

如您所见,有一个名为“private”的布尔变量,它一直在编译错误

Member modifier 'private' must precede the member type and name

我的问题是我可以覆盖“私有”名称或以某种方式忽略编译器错误吗?

【问题讨论】:

  • public bool @private,或遵循正常的 C# 命名约定 [JsonProperty("private")] public bool Private
  • 这能回答你的问题吗? C# keywords as a variable

标签: c# asp.net .net


【解决方案1】:

你必须使用 JsonPropertyAttribute

[JsonProperty("private")]
public string whatever{get;set;} //you can give any name, it will be translated as "private"

【讨论】:

    猜你喜欢
    • 2014-04-14
    • 1970-01-01
    • 2013-11-05
    • 2015-06-29
    • 1970-01-01
    • 1970-01-01
    • 2015-06-20
    • 2012-04-13
    • 2015-07-13
    相关资源
    最近更新 更多