Skip to content

Commit e8ec7cb

Browse files
committed
Extend FromAssemblyContainingType
1 parent f4409ca commit e8ec7cb

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

src/Dibix.Http.Client/Client/HttpClientExtensions.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,14 @@ private sealed class HttpUserAgentSelectorExpression : IHttpUserAgentSelectorExp
4444
{
4545
public ProductInfoHeaderValue UserAgent { get; private set; }
4646

47-
public void FromAssembly(Assembly assembly, Func<string, string> productNameFormatter = null) => this.ResolveUserAgentFromAssembly(assembly, productNameFormatter);
47+
public void FromAssembly(Assembly assembly, Func<string, string> productNameFormatter = null) => ResolveUserAgentFromAssembly(assembly, productNameFormatter);
4848

49-
public void FromAssemblyContainingType<T>(Func<string, string> productNameFormatter = null) => this.ResolveUserAgentFromAssembly(typeof(T).Assembly, productNameFormatter);
49+
public void FromAssemblyContainingType<T>(Func<string, string> productNameFormatter = null) => FromAssemblyContainingType(typeof(T), productNameFormatter);
50+
public void FromAssemblyContainingType(Type type, Func<string, string> productNameFormatter = null) => ResolveUserAgentFromAssembly(type.Assembly, productNameFormatter);
5051

51-
public void FromEntryAssembly(Func<string, string> productNameFormatter = null) => this.ResolveUserAgentFromAssembly(ResolveEntryAssembly(), productNameFormatter);
52+
public void FromEntryAssembly(Func<string, string> productNameFormatter = null) => ResolveUserAgentFromAssembly(ResolveEntryAssembly(), productNameFormatter);
5253

53-
public void FromCurrentProcess(Func<string, string> productNameFormatter = null) => this.FromFile(ResolveCurrentProcessPath(), productNameFormatter);
54+
public void FromCurrentProcess(Func<string, string> productNameFormatter = null) => FromFile(ResolveCurrentProcessPath(), productNameFormatter);
5455

5556
public void FromFile(string path, Func<string, string> productNameFormatter)
5657
{
@@ -64,11 +65,11 @@ public void FromFile(string path, Func<string, string> productNameFormatter)
6465
if (productNameFormatter != null)
6566
userAgentProductName = productNameFormatter(userAgentProductName);
6667

67-
this.UserAgent = new ProductInfoHeaderValue(userAgentProductName, productVersion);
68+
UserAgent = new ProductInfoHeaderValue(userAgentProductName, productVersion);
6869
}
6970

7071
#pragma warning disable IL3000 // Avoid accessing Assembly file path when publishing as a single file
71-
private void ResolveUserAgentFromAssembly(Assembly assembly, Func<string, string> productNameFormatter) => this.FromFile(assembly.Location, productNameFormatter);
72+
private void ResolveUserAgentFromAssembly(Assembly assembly, Func<string, string> productNameFormatter) => FromFile(assembly.Location, productNameFormatter);
7273
#pragma warning restore IL3000 // Avoid accessing Assembly file path when publishing as a single file
7374

7475
private static Assembly ResolveEntryAssembly()

src/Dibix.Http.Client/Client/IHttpUserAgentSelectorExpression.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public interface IHttpUserAgentSelectorExpression
77
{
88
void FromAssembly(Assembly assembly, Func<string, string> productNameFormatter = null);
99
void FromAssemblyContainingType<T>(Func<string, string> productNameFormatter = null);
10+
void FromAssemblyContainingType(Type type, Func<string, string> productNameFormatter = null);
1011
void FromEntryAssembly(Func<string, string> productNameFormatter = null);
1112
void FromCurrentProcess(Func<string, string> productNameFormatter = null);
1213
void FromFile(string path, Func<string, string> productNameFormatter = null);

0 commit comments

Comments
 (0)