Conflict of reference Google.api

3

I have a referral conflict problem in the Google API.

In my API classes I always rename it as follows: SiteTeste.APIS.Google.<Servico> , where service is, Gmail, Translate, Drive or whatever.

Google Translate I name it:

namespace SiteTeste.APIS.Google.Translate

The new API I'm using that's from GMAIL I've named:

namespace SiteTeste.APIS.Google.Gmail

The problem is in the Gmail API where I need to import some namespaces:

using Google.Apis.Auth.OAuth2;
using Google.Apis.Gmail.v1;
using Google.Apis.Gmail.v1.Data;
using Google.Apis.Services;
using Google.Apis.Util.Store;

If I call the following line in my code, the compiler says:

Google.Apis.Gmail.v1.Data.Message message = new Google.Apis.Gmail.v1.Data.Message();
  

Error CS0234 The type name or namespace "Apis" does not exist in the "SiteTest.APIS.Google" namespace

In other words, it is interpreting Google.Apis.Gmail.v1.Data.Message from "SiteTest.APIS.Google", I could solve this by renaming my APIS namespace and remove Google, but I believe there is another way to resolve this conflict. If anyone can give me a try to solve this problem ...

    
asked by anonymous 16.11.2017 / 20:40

1 answer

2

You do not need to rename namespaces, you can use aliases . An alias is a nickname that you give to a namespace . Just state it as follows:

using alias = namespacePropriamente dito.

Your code looks like this:

using FabricaDeChocolate = Google.Apis.Gmail.V1.Data;
using MinhasAPIs = SiteTeste.APIS.Google;

... // muito código
    FabricaDeChocolate.Message message = new FabricaDeChocolate.Message();

This should resolve any name resolution conflict problem between your API's and Chocolate Factory .

If this does not resolve because your code is within your API's namespace, do as Maniero pointed out in his comment. Declare the Google namespace like this:

using FabricaDeChocolate = global::Google.Apis.Gmail.v1.Data;
    
16.11.2017 / 20:57