{"action":"created","issue":{"url":"https://api.github.com/repos/RSuter/NSwag/issues/1656","repository_url":"https://api.github.com/repos/RSuter/NSwag","labels_url":"https://api.github.com/repos/RSuter/NSwag/issues/1656/labels{/name}","comments_url":"https://api.github.com/repos/RSuter/NSwag/issues/1656/comments","events_url":"https://api.github.com/repos/RSuter/NSwag/issues/1656/events","html_url":"https://github.com/RSuter/NSwag/issues/1656","id":367686055,"node_id":"MDU6SXNzdWUzNjc2ODYwNTU=","number":1656,"title":"Make generated C# client .NET 4.0 compatible","user":{"login":"Alexander8","id":2217403,"node_id":"MDQ6VXNlcjIyMTc0MDM=","avatar_url":"https://avatars2.githubusercontent.com/u/2217403?v=4","gravatar_id":"","url":"https://api.github.com/users/Alexander8","html_url":"https://github.com/Alexander8","followers_url":"https://api.github.com/users/Alexander8/followers","following_url":"https://api.github.com/users/Alexander8/following{/other_user}","gists_url":"https://api.github.com/users/Alexander8/gists{/gist_id}","starred_url":"https://api.github.com/users/Alexander8/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Alexander8/subscriptions","organizations_url":"https://api.github.com/users/Alexander8/orgs","repos_url":"https://api.github.com/users/Alexander8/repos","events_url":"https://api.github.com/users/Alexander8/events{/privacy}","received_events_url":"https://api.github.com/users/Alexander8/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-10-08T08:38:00Z","updated_at":"2018-10-31T16:01:56Z","closed_at":null,"author_association":"NONE","body":"Good day!\r\n\r\nI'm trying to use NSwag to generate C# client for desktop application written using .NET 4.0 framework.\r\n\r\nI've managed to do it with only one problem left: \r\n**ConvertToString** function => _if (value is System.Enum)_ branch.\r\n\r\nOriginally generated code can't be compiled against .NET 4.0 because of using not available classes:\r\n_System.Reflection.IntrospectionExtensions_ and _System.Reflection.CustomAttributeExtensions_.\r\n\r\nI've overcome that problem by modifying _Client.Class.ConvertToString.liquid_ template and applying it via _TemplateDirectory_ setting of swagger2csclient generator.\r\n\r\nHere is my _Client.Class.ConvertToString.liquid_ (I changed only _if (value is System.Enum)_ branch).\r\nI hope it may be useful for others or you could even modify the original template.\r\n\r\n```c#\r\nprivate string ConvertToString(object value, System.Globalization.CultureInfo cultureInfo)\r\n{\r\n    if (value is System.Enum)\r\n    {\r\n        string name = System.Enum.GetName(value.GetType(), value);\r\n        if (name != null)\r\n        {\r\n            System.Reflection.FieldInfo field = value.GetType().GetField(name);\r\n            if (field != null)\r\n            {\r\n                var attr = System.Attribute.GetCustomAttribute(field, typeof(System.Runtime.Serialization.EnumMemberAttribute)) \r\n                    as System.Runtime.Serialization.EnumMemberAttribute;\r\n                if (attr != null)\r\n                {\r\n                    return attr.Value;\r\n                }\r\n            }\r\n        }\r\n    }\r\n    else if (value is byte[])\r\n    {\r\n        return System.Convert.ToBase64String((byte[]) value);\r\n    }\r\n    else if (value != null && value.GetType().IsArray)\r\n    {\r\n        var array = System.Linq.Enumerable.OfType<object>((System.Array) value);\r\n        return string.Join(\",\", System.Linq.Enumerable.Select(array, o => ConvertToString(o, cultureInfo)));\r\n    }\r\n\r\n    return System.Convert.ToString(value, cultureInfo);\r\n}\r\n```\r\n\r\nThanks."},"comment":{"url":"https://api.github.com/repos/RSuter/NSwag/issues/comments/434745158","html_url":"https://github.com/RSuter/NSwag/issues/1656#issuecomment-434745158","issue_url":"https://api.github.com/repos/RSuter/NSwag/issues/1656","id":434745158,"node_id":"MDEyOklzc3VlQ29tbWVudDQzNDc0NTE1OA==","user":{"login":"RSuter","id":2603405,"node_id":"MDQ6VXNlcjI2MDM0MDU=","avatar_url":"https://avatars1.githubusercontent.com/u/2603405?v=4","gravatar_id":"","url":"https://api.github.com/users/RSuter","html_url":"https://github.com/RSuter","followers_url":"https://api.github.com/users/RSuter/followers","following_url":"https://api.github.com/users/RSuter/following{/other_user}","gists_url":"https://api.github.com/users/RSuter/gists{/gist_id}","starred_url":"https://api.github.com/users/RSuter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RSuter/subscriptions","organizations_url":"https://api.github.com/users/RSuter/orgs","repos_url":"https://api.github.com/users/RSuter/repos","events_url":"https://api.github.com/users/RSuter/events{/privacy}","received_events_url":"https://api.github.com/users/RSuter/received_events","type":"User","site_admin":false},"created_at":"2018-10-31T16:01:56Z","updated_at":"2018-10-31T16:01:56Z","author_association":"OWNER","body":"I think .NET 4.0 support will not be implemented as it is quite old. \r\n\r\nBut you can change templates: https://github.com/RSuter/NSwag/wiki/Templates\r\n\r\nAnd maybe there are compatiblity packages which the missing types...\r\n"}}
{"actor":{"display_login":"RSuter"}}