Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introducing an abstract class implementing IRequest and ILocalizable #10

Open
SamHurne opened this issue Sep 19, 2015 · 1 comment
Open

Comments

@SamHurne
Copy link
Collaborator

[Moved from Codeplex: https://gw2dotnet.codeplex.com/workitem/1317]

Seeing that most of the time a implementation for a request looks like this:

public class ContinentRequest : IRequest, ILocalizable
{
    /// <summary>Gets or sets the locale.</summary>
    public CultureInfo Culture { get; set; }

    /// <summary>Gets the resource path.</summary>
    public string Resource
    {
        get
        {
            return "v2/continents";
        }
    }

    /// <summary>Gets the request parameters.</summary>
    /// <returns>A collection of parameters.</returns>
    public IEnumerable<KeyValuePair<string, string>> GetParameters()
    {
        // Get the 'lang' parameter
        if (this.Culture != null)
        {
            yield return new KeyValuePair<string, string>("lang", this.Culture.TwoLetterISOLanguageName);
        }
    }

    /// <summary>The get path segments.</summary>
    /// <returns>The <see cref="IEnumerable{T}"/>.</returns>
    public IEnumerable<string> GetPathSegments()
    {
        yield break;
    }
}

Wouldn't it make sense to implement an abstract class which has the following layout:

/// <summary>Represents a request, targeting any the v2/ endpoint.</summary>
public abstract class LocalizableRequest : IRequest, ILocalizable
{
    /// <summary>Gets or sets the locale.</summary>
    public CultureInfo Culture { get; set; }

    /// <summary>Gets the resource path.</summary>
    public abstract string Resource { get; }

    /// <summary>Gets the request parameters.</summary>
    /// <returns>A collection of parameters.</returns>
    public virtual IEnumerable<KeyValuePair<string, string>> GetParameters()
    {
        // Get the 'lang' parameter
        if (this.Culture != null)
        {
            yield return new KeyValuePair<string, string>("lang", this.Culture.TwoLetterISOLanguageName);
        }
    }

    /// <summary>The get path segments.</summary>
    /// <returns>The <see cref="IEnumerable{T}"/>.</returns>
    public virtual IEnumerable<string> GetPathSegments()
    {
        yield break;
    }
}

I went ahead and added this to the GW2.NET core library. However the only endpoint that uses this class is the continents endpoint which I am currently adding.

Thoughts?

@sliekens
Copy link
Collaborator

I remember trying to use the LocalizableRequest and running into problems with bulk expanded endpoints. A request class can't inherit both BulkRequest and LocalizableRequest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants