Skip to content

TypeBinder.Deserialize<T> should have new() constraint #40718

Open
@Arithmomaniac

Description

@Arithmomaniac

public T Deserialize<T>(TExchange source)
{
if (_isPrimitive)
{
if (!_binderImplementation.TryGet(null, source, out T result))
{
throw new InvalidOperationException($"Unable to deserialize into a primitive type {typeof(T)}");
}
return result;
}
T o = Activator.CreateInstance<T>();

This method should have a new() constraint, as it can only handle primitive types or types with a parameterless constructor. Propagating the resulting new() constraints s up the call chain (such as to Azure.Monitor.Query.LogsQueryClient.QueryWorkspaceAsync<T>) would prevent runtime errors that could be caught at compile time instead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Azure.CoreClientThis issue points to a problem in the data-plane of the library.customer-reportedIssues that are reported by GitHub users external to the Azure organization.feature-requestThis issue requires a new behavior in the product in order be resolved.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions