How do I implement an InfoWindowAdapter interface in Xamarin? - interface

I am using Xamarin and I am wanting to create a CustomWindowAdapter that implements a GoogleMap.InfoWindowAdapter interface.
I have tried this so far:
public class CustomWindowAdapter : InfoWindowAdapter
{
}
I am getting this error:
Error CS0246: The type or namespace name 'InfoWindowAdapter' could not be found (are you missing a using directive or an assembly reference?)
Here is the documentation for the interface: https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/GoogleMap.InfoWindowAdapter
Can I please have some help?
What using statement do I need to use?
Thanks in advance

Step 1: Get Google Play Services component from Component Store
Step 2: Implement GoogleMap.IInfoWindowAdapter
using Android.Gms.Maps;
using Android.Gms.Maps.Model;
using Android.Views;
public class InfoWindow : Java.Lang.Object, GoogleMap.IInfoWindowAdapter
{
#region IInfoWindowAdapter implementation
public View GetInfoContents(Marker p0)
{
throw new NotImplementedException ();
}
public View GetInfoWindow(Marker p0)
{
throw new NotImplementedException ();
}
#endregion
}

Related

In which package, can I find "AlsoNotifyChangeFor" in .Net MAUI?

I'm using the package CommunityToolkit.Mvvm 8.0.0 in .Net MAUI.
I have a simple class as follows :
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.Mvvm.Collections;
using CommunityToolkit.Mvvm.DependencyInjection;
using CommunityToolkit.Mvvm.Messaging;
namespace My.ViewModels
{
public partial class BaseViewModel:ObservableObject
{
public BaseViewModel()
{
}
[ObservableProperty]
[AlsoNotifyChangeFor(nameof(IsNotBusy))] <<<< Compilation error here
bool isBusy;
[ObservableProperty]
string title;
public bool IsNotBusy => !isBusy;
}
}
This class raises a compilation error on the attribute AlsoNotifyChangeFor.
It says The type or namespace name could not be found for this attribute to be used.
Does anyone know please where can I find the right package to use this attribute ?
Thanks.
in the release notes, under breaking changes
[AlsoNotifyChangeFor] ---> [NotifyPropertyChangedFor]

C# 9 default implementations causing errors [duplicate]

Here is a my code inside a c# project that targets .NET Core 3.0 (so I should be in C# 8.0) with Visual Studio 2019 (16.3.9)
public interface IJsonAble
{
public string ToJson() => System.Text.Json.JsonSerializer.Serialize(this);
}
public class SumRequest : IJsonAble
{
public int X { get; set; }
public int Y { get; set; }
public void Tmp()
{
new SumRequest().ToJson(); //compile error
}
}
The compile error is:
CS1061 'SumRequest' does not contain a definition for 'ToJson' and no accessible extension method 'ToJson' accepting a first argument of type 'SumRequest' could be found (are you missing a using directive or an assembly reference?)
Can someone shed some light on this behavior ?
Methods are only available on the interface, not the class. So you can do this instead:
IJsonAble request = new SumRequest()
var result = request.ToJson();
Or:
((IJsonAble)new SumRequest()).ToJson();
The reason for this is it allows you to add to the interface without worrying about the downstream consequences. For example, the ToJson method may already exist in the SumRequest class, which would you expect to be called?
Try using (new SumRequest() as IJsonAble).ToJson(); to help the compiler a bit.
Anyway, I'm sure what you're after is (this as IJsonAble).ToJson(), assuming you want to apply ToJson on current SumRequest instance.

Can not access interface default implementation method from within derived class [duplicate]

Here is a my code inside a c# project that targets .NET Core 3.0 (so I should be in C# 8.0) with Visual Studio 2019 (16.3.9)
public interface IJsonAble
{
public string ToJson() => System.Text.Json.JsonSerializer.Serialize(this);
}
public class SumRequest : IJsonAble
{
public int X { get; set; }
public int Y { get; set; }
public void Tmp()
{
new SumRequest().ToJson(); //compile error
}
}
The compile error is:
CS1061 'SumRequest' does not contain a definition for 'ToJson' and no accessible extension method 'ToJson' accepting a first argument of type 'SumRequest' could be found (are you missing a using directive or an assembly reference?)
Can someone shed some light on this behavior ?
Methods are only available on the interface, not the class. So you can do this instead:
IJsonAble request = new SumRequest()
var result = request.ToJson();
Or:
((IJsonAble)new SumRequest()).ToJson();
The reason for this is it allows you to add to the interface without worrying about the downstream consequences. For example, the ToJson method may already exist in the SumRequest class, which would you expect to be called?
Try using (new SumRequest() as IJsonAble).ToJson(); to help the compiler a bit.
Anyway, I'm sure what you're after is (this as IJsonAble).ToJson(), assuming you want to apply ToJson on current SumRequest instance.

"DllAttribute could not be found": call a function in a .jslib file from unity

I tried to call a JavaScript Function from a .jslib file in Unity. I did it as described here
I have the .jslibe file in my assets/plugin folder. Now I tried to access it in the following code:
public class Prefab : MonoBehaviour
{
private string test = "test";
[DllImport("__Internal")]
private static extern void SendToJavscript(string test);
void Start()
{
SendToJavscript(this.test);
}
}
But it won´t compile and I get the error "The type or namespace name 'DllImportAttribute' could not be found (are you using directive or an assembly reference?)
Has anyone a idea what´s wrong here? I never got this error before..
At the top of your script add
using System.Runtime.InteropServices;

Class from Interface.cll

I'm trying to implement a class instance of an interface class. Exploring the interface (.NET DLL) with the project explorer, it says:
bool CreateInstance(SharedLibrary::MemoryArbiter^ pntMemory,
SharedLibrary::clsMessageQueue^ pntMessageQueue,
SharedLibrary::clsGPIO^ pntGPIO,
SharedLibrary::Types^ pntProgramSettings,
SharedLibrary::DisplayDriver^ pntDisplayDriver)
Member from Plugin_Interface::IPlugin
But if I write in my MyClass.h:
using namespace System;
using namespace System::ComponentModel;
using namespace SharedLibrary;
namespace MyCppPlugin {
[AttributeUsageAttribute(AttributeTargets::Class | AttributeTargets::Method |
AttributeTargets::Property | AttributeTargets::Field,
AllowMultiple = true, Inherited = false)]
ref class MyPlugin abstract : public Plugin_Interface::IPlugin
{
bool CreateInstance(SharedLibrary::MemoryArbiter^ pntMemory,
SharedLibrary::clsMessageQueue^ pntMessageQueue,
SharedLibrary::clsGPIO^ pntGPIO, SharedLibrary::Types^
pntProgramSettings, SharedLibrary::DisplayDriver^ pntDisplayDriver);
};
};
It says: "error C3766: Missing implementation of Plugin_Interface::IPlugin::CreateInstace(...)
What the heck do I do wrong?
EDIT:
Forgot the abstract statement.
And: Why is it saying "IntelliSense: Class can not implement interface member function "Plugin_Interface::IPlugin::CreateInstance" (declared in "Plugin_Interface.dll")"
???
You got a lot more diagnostic messages from this snippet, you are making several mistakes:
[AttributeUsage] is only valid on a class that derives from System::Attribute. You no doubt need to use some kind of attribute so that the plugin host can recognize your class as a valid plugin candidate, I can't guess what that attribute might be.
A method that implements an interface method should be public.
A method that implements an interface method must be virtual.
The method signature must be an exact match with the interface method declaration.
Just in case: you must actually implement the method, not just declare it.
The third and forth bullets are the chief reasons for the "must provide an implementation of the interface method" compile error. So proper code ought to resemble something like this:
[NoIdeaWhatAttribute]
public ref class MyPlugin : public Plugin_Interface::IPlugin {
public:
virtual bool CreateInstance(SharedLibrary::MemoryArbiter^% pntMemory,
SharedLibrary::clsMessageQueue^% pntMessageQueue,
SharedLibrary::clsGPIO^% pntGPIO,
SharedLibrary::Types^% pntProgramSettings,
SharedLibrary::DisplayDriver^% pntDisplayDriver)
{
// Todo...
return false;
}
};
I got it. Thanks to Hans Passant who gave me so many hints :)
To export the function it has to implement the Interface 1:1. The export statement has to be added over the class header:
[Export(IPlugin::typeid)]
public ref class MyPlugin : public Plugin_Interface::IPlugin
And: While VB.NET will compile to "Any CPU" and C++/CLI will compile to Win64/Win32 it will missfit. Both Projects have to have the same target - either 64bit OR 32bit.
Now it works.