Skip to content

Commit

Permalink
Make typed property bag methods public (#32851)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshLove-msft authored Dec 2, 2022
1 parent fd1564a commit cd093d8
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 5 deletions.
2 changes: 2 additions & 0 deletions sdk/core/Azure.Core/api/Azure.Core.net461.cs
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,9 @@ public HttpMessage(Azure.Core.Request request, Azure.Core.ResponseClassifier res
public void Dispose() { }
public System.IO.Stream? ExtractResponseContent() { throw null; }
public void SetProperty(string name, object value) { }
public void SetProperty(System.Type type, object value) { }
public bool TryGetProperty(string name, out object? value) { throw null; }
public bool TryGetProperty(System.Type type, out object? value) { throw null; }
}
public enum HttpPipelinePosition
{
Expand Down
2 changes: 2 additions & 0 deletions sdk/core/Azure.Core/api/Azure.Core.net5.0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,9 @@ public HttpMessage(Azure.Core.Request request, Azure.Core.ResponseClassifier res
public void Dispose() { }
public System.IO.Stream? ExtractResponseContent() { throw null; }
public void SetProperty(string name, object value) { }
public void SetProperty(System.Type type, object value) { }
public bool TryGetProperty(string name, out object? value) { throw null; }
public bool TryGetProperty(System.Type type, out object? value) { throw null; }
}
public enum HttpPipelinePosition
{
Expand Down
2 changes: 2 additions & 0 deletions sdk/core/Azure.Core/api/Azure.Core.net6.0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,9 @@ public HttpMessage(Azure.Core.Request request, Azure.Core.ResponseClassifier res
public void Dispose() { }
public System.IO.Stream? ExtractResponseContent() { throw null; }
public void SetProperty(string name, object value) { }
public void SetProperty(System.Type type, object value) { }
public bool TryGetProperty(string name, out object? value) { throw null; }
public bool TryGetProperty(System.Type type, out object? value) { throw null; }
}
public enum HttpPipelinePosition
{
Expand Down
2 changes: 2 additions & 0 deletions sdk/core/Azure.Core/api/Azure.Core.netcoreapp2.1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,9 @@ public HttpMessage(Azure.Core.Request request, Azure.Core.ResponseClassifier res
public void Dispose() { }
public System.IO.Stream? ExtractResponseContent() { throw null; }
public void SetProperty(string name, object value) { }
public void SetProperty(System.Type type, object value) { }
public bool TryGetProperty(string name, out object? value) { throw null; }
public bool TryGetProperty(System.Type type, out object? value) { throw null; }
}
public enum HttpPipelinePosition
{
Expand Down
2 changes: 2 additions & 0 deletions sdk/core/Azure.Core/api/Azure.Core.netstandard2.0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,9 @@ public HttpMessage(Azure.Core.Request request, Azure.Core.ResponseClassifier res
public void Dispose() { }
public System.IO.Stream? ExtractResponseContent() { throw null; }
public void SetProperty(string name, object value) { }
public void SetProperty(System.Type type, object value) { }
public bool TryGetProperty(string name, out object? value) { throw null; }
public bool TryGetProperty(System.Type type, out object? value) { throw null; }
}
public enum HttpPipelinePosition
{
Expand Down
4 changes: 2 additions & 2 deletions sdk/core/Azure.Core/src/HttpMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public void SetProperty(string name, object value)
/// <param name="type">The property type.</param>
/// <param name="value">The property value.</param>
/// <returns><c>true</c> if property exists, otherwise. <c>false</c>.</returns>
internal bool TryGetInternalProperty(Type type, out object? value)
public bool TryGetProperty(Type type, out object? value)
{
value = null;
return _typeProperties?.TryGetValue(type, out value) == true;
Expand All @@ -173,7 +173,7 @@ internal bool TryGetInternalProperty(Type type, out object? value)
/// </summary>
/// <param name="type">The key for the value.</param>
/// <param name="value">The property value.</param>
internal void SetInternalProperty(Type type, object value)
public void SetProperty(Type type, object value)
{
_typeProperties ??= new Dictionary<Type, object>();
_typeProperties[type] = value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public TelemetryPolicy(TelemetryDetails telemetryDetails)

public override void OnSendingRequest(HttpMessage message)
{
if (message.TryGetInternalProperty(typeof(UserAgentValueKey), out var userAgent))
if (message.TryGetProperty(typeof(UserAgentValueKey), out var userAgent))
{
message.Request.Headers.Add(HttpHeader.Names.UserAgent, ((string)userAgent!));
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/Azure.Core/src/TelemetryDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public TelemetryDetails(Assembly assembly, string? applicationId = null)
/// <param name="message">The <see cref="HttpMessage"/> that will use this <see cref="TelemetryDetails"/>.</param>
public void Apply(HttpMessage message)
{
message.SetInternalProperty(typeof(UserAgentValueKey), ToString());
message.SetProperty(typeof(UserAgentValueKey), ToString());
}

internal static string GenerateUserAgentString(Assembly clientAssembly, string? applicationId = null)
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/Azure.Core/tests/TelemetryDetailsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void AppliesToMessage()

target.Apply(message);

message.TryGetInternalProperty(typeof(UserAgentValueKey), out var obj);
message.TryGetProperty(typeof(UserAgentValueKey), out var obj);
string actualValue = obj as string;

Assert.AreEqual(target.ToString(), actualValue);
Expand Down

0 comments on commit cd093d8

Please sign in to comment.