Skip to content

Commit

Permalink
improve UserAgent for csharp
Browse files Browse the repository at this point in the history
  • Loading branch information
JacksonTian committed Jun 28, 2024
1 parent 2110c48 commit a74ecf7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ java/.classpath
cc/*.o
python/**/__pycache__/
cache/
csharp/tests/coverage.xml
9 changes: 2 additions & 7 deletions csharp/core/Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public static string ToFormString(Dictionary<string, object> map)
return result.ToString();
}

public static string ToJSONString(Object value)
public static string ToJSONString(object value)
{
if (value is string)
{
Expand Down Expand Up @@ -458,15 +458,10 @@ public static Stream AssertAsReadable(object a)

internal static string GetDefaultUserAgent()
{
string defaultUserAgent = string.Empty;
string OSVersion = Environment.OSVersion.ToString();
string ClientVersion = GetRuntimeRegexValue(RuntimeEnvironment.GetRuntimeDirectory());
string CoreVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
defaultUserAgent = "Alibaba Cloud (" + OSVersion + ") ";
defaultUserAgent += ClientVersion;
defaultUserAgent += " Core/" + CoreVersion;
defaultUserAgent += " TeaDSL/1";
return defaultUserAgent;
return string.Format("AlibabaCloud ({0}) {1} Core/{2} TeaDSL/1", OSVersion, ClientVersion, CoreVersion);
}

internal static string GetRuntimeRegexValue(string value)
Expand Down
4 changes: 4 additions & 0 deletions csharp/tests/CommonTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,10 @@ public void Test_GetUserAgent()
{
Assert.NotNull(Common.GetUserAgent(null));

string ua = Common.GetUserAgent("").Trim();
Assert.StartsWith("AlibabaCloud (", ua);
Assert.EndsWith("TeaDSL/1", ua);

Assert.Contains("test", Common.GetUserAgent("test"));
}

Expand Down

0 comments on commit a74ecf7

Please sign in to comment.