{"id":28287788,"url":"https://github.com/li-xiaoyao/simplestring","last_synced_at":"2026-04-29T08:33:53.857Z","repository":{"id":40044945,"uuid":"507338967","full_name":"LI-XIAOYAO/SimpleString","owner":"LI-XIAOYAO","description":"通过XML注释或指定特性转换成字符串输出。","archived":false,"fork":false,"pushed_at":"2024-04-18T03:38:21.000Z","size":62,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-21T22:14:27.119Z","etag":null,"topics":["csharp","dotnet","dotnetcore","netcore"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LI-XIAOYAO.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-06-25T14:53:52.000Z","updated_at":"2022-11-26T13:55:40.000Z","dependencies_parsed_at":"2022-06-26T10:03:07.299Z","dependency_job_id":null,"html_url":"https://github.com/LI-XIAOYAO/SimpleString","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/LI-XIAOYAO/SimpleString","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LI-XIAOYAO%2FSimpleString","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LI-XIAOYAO%2FSimpleString/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LI-XIAOYAO%2FSimpleString/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LI-XIAOYAO%2FSimpleString/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LI-XIAOYAO","download_url":"https://codeload.github.com/LI-XIAOYAO/SimpleString/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LI-XIAOYAO%2FSimpleString/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260494366,"owners_count":23017688,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","dotnet","dotnetcore","netcore"],"created_at":"2025-05-21T22:14:26.245Z","updated_at":"2026-04-29T08:33:53.850Z","avatar_url":"https://github.com/LI-XIAOYAO.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SimpleString\n通过XML注释或指定特性转换成字符串输出。\n\n\u003c!--TOC--\u003e\n- [安装](#安装)\n- [配置](#配置)\n- [特性](#特性)\n- [使用](#使用)\n- [示例](#示例)\n\u003c!--/TOC--\u003e\n---\n\n#### 安装\n\u003e `Install-Package SimpleString`\n\n#### 配置\n\n\u003e 基础配置\n\n````c#\nvar config = new Config\n{\n    AttributeType = typeof(DescriptionAttribute), // 解析的特性，默认DescriptionAttribute（HandleType.Attribute时生效）\n    Name = nameof(DescriptionAttribute.Description), // 解析的特性属性，默认DescriptionAttribute.Description（HandleType.Attribute时生效）\n    HandleOptions = HandleOptions.Attribute, // 处理方式 Attribute|XML（默认）\n    HandCustomType = true, // 自定义类型处理，默认调用 ToString() 否则 ToSimpleString().\n    IgnoreLoopReference = true, // 忽略循环引用（存在相同引用只输出一次否则为空），默认false.\n    Operator = \"= \", // 间隔符号，默认“ = ”\n}.AddXml(\"xxx.xml\"); // XML文档路径，类必须添加注释否则不会解析\n````\n\n\u003e 自定义配置\n\n````c#\n// 自定义配置只需要继承基础配置也可设置默认值\npublic class ENConfig : Config\n{\n    public ENConfig()\n    {\n        AttributeType = typeof(ENAttribute);\n        Name = nameof(ENAttribute.ENName);\n        IgnoreLoopReference = true;\n    }\n}\n\n// 自定义特性\n[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property)]\npublic class ENAttribute : Attribute\n{\n    public ENAttribute(string eNName)\n    {\n        ENName = eNName;\n    }\n\n    public string ENName { get; set; }\n}\n````\n\n#### 特性\n\n\u003e  忽略：`[IgnoreSimpleString]`\n\n#### 使用\n\n\u003e 通用\n\n```c#\n // 初始化，默认全局\nSimpleString.Config(c =\u003e\n{\n    // 默认使用XML解析 需要指定XML文档\n    c.AddXml(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, \"xxx.xml\"));\n});\n\n// 直接调用\nvar str = new Test().ToSimpleString();\n\n// 重写类ToString()方法（推荐）\nvar str = new Test().ToString();\n\n// 创建实例调用\nvar str = new SimpleString(new Config\n{\n    HandleOptions = HandleOptions.Attribute,\n    Operator = \": \"\n}).ToSimpleString(test);\n```\n\n\u003e 注入使用\n\n````c#\n// 默认静态全局注入\nservices.AddSimpleString(c =\u003e\n{\n    // 默认XML 需要指定XML文档\n    c.AddXml(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, \"xxx.xml\"));\n});\n// 指定特性配置注入\nservices.AddSimpleString\u003cConfig\u003e();\n// 指定特性配置注入\nservices.AddSimpleString\u003cENConfig\u003e(c =\u003e\n{\n    c.Operator = \": \";\n});\n\n// 构造函数注入调用\nprivate readonly SimpleString\u003cConfig\u003e _simpleString;\nprivate readonly SimpleString\u003cENConfig\u003e _enSimpleString;\n\npublic HomeController(ILogger\u003cHomeController\u003e logger, SimpleString\u003cConfig\u003e simpleString, SimpleString\u003cENConfig\u003e enSimpleString)\n{\n    this._logger = logger;\n    this._simpleString = simpleString;\n    this._enSimpleString = enSimpleString;\n}\n\nvar str = _simpleString.ToSimpleString(test);\nvar str = _enSimpleString.ToSimpleString(test);\n\n````\n\n#### 示例\n\n````c#\n/// \u003csummary\u003e\n/// 测试 （XML解析时类注释必须添加）\n/// \u003c/summary\u003e\npublic class Test\n{\n    /// \u003csummary\u003e\n    /// XML属性1\n    /// \u003c/summary\u003e\n    [EN(\"MyProperty1\")]\n    [Description(\"属性1\")]\n    public int MyProperty1 { get; set; }\n\n    /// \u003csummary\u003e\n    /// XML属性2\n    /// \u003c/summary\u003e\n    [EN(\"MyProperty2\")]\n    [Description(\"属性2\")]\n    public string MyProperty2 { get; set; }\n\n    /// \u003csummary\u003e\n    /// XML属性3\n    /// \u003c/summary\u003e\n    [IgnoreSimpleString]\n    [EN(\"MyProperty3\")]\n    [Description(\"属性3\")]\n    public string MyProperty3 { get; set; }\n\n    /// \u003csummary\u003e\n    /// XML属性4\n    /// \u003c/summary\u003e\n    [EN(\"MyProperty4\")]\n    [Description(\"属性4\")]\n    public string MyProperty4 { get; set; }\n\n    /// \u003csummary\u003e\n    /// XML属性5\n    /// \u003c/summary\u003e\n    [EN(\"MyProperty5\")]\n    [Description(\"属性5\")]\n    public string MyProperty5 { get; set; }\n\n    /// \u003csummary\u003e\n    /// XML属性6\n    /// \u003c/summary\u003e\n    [EN(\"MyProperty6\")]\n    [Description(\"属性6\")]\n    public string MyProperty6 { get; set; }\n\n    /// \u003csummary\u003e\n    /// XML属性7\n    /// \u003c/summary\u003e\n    [EN(\"MyProperty7\")]\n    [Description(\"属性7\")]\n    public string MyProperty7 { get; set; }\n\n    /// \u003csummary\u003e\n    /// 重写ToString 调用默认全局转换\n    /// \u003c/summary\u003e\n    /// \u003creturns\u003e\u003c/returns\u003e\n    public override string ToString() =\u003e this.ToSimpleString();\n}\n\nvar test = new Test\n{\n    MyProperty1 = 1,\n    MyProperty2 = \"2\",\n    MyProperty3 = \"33\",\n    MyProperty4 = \"444\",\n    MyProperty5 = \"5555\",\n    MyProperty6 = \"66666\"\n};\n\nvar str1 = test.ToString();\nvar str2 = test.ToSimpleString();\nvar str3 = _simpleString.ToSimpleString(test);\nvar str4 = _enSimpleString.ToSimpleString(test);\nvar str5 = new SimpleString(new Config\n{\n    HandleOptions = HandleOptions.Attribute,\n    Operator = \": \"\n}).ToSimpleString(test);\n\n// 输出\nstr1:[XML属性1 = 1, XML属性2 = 2, XML属性4 = 444, XML属性5 = 5555, XML属性6 = 66666, XML属性7 = ]\nstr2:[XML属性1 = 1, XML属性2 = 2, XML属性4 = 444, XML属性5 = 5555, XML属性6 = 66666, XML属性7 = ]\nstr3:[属性1 = 1, 属性2 = 2, 属性4 = 444, 属性5 = 5555, 属性6 = 66666, 属性7 = ]\nstr4:[MyProperty1: 1, MyProperty2: 2, MyProperty4: 444, MyProperty5: 5555, MyProperty6: 66666, MyProperty7: ]\nstr5:[属性1: 1, 属性2: 2, 属性4: 444, 属性5: 5555, 属性6: 66666, 属性7: ]\n````\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fli-xiaoyao%2Fsimplestring","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fli-xiaoyao%2Fsimplestring","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fli-xiaoyao%2Fsimplestring/lists"}