I have a Xamarin.Android project. How can I use java class declared in java file from C# code? How can I reference to it?
That is what I did:
1) I've added java file to project,
2) set up build action to AndroidJavaSource
3) Compiled (and seen Foo.class in obj folder)
Foo.java
package x.y.z;
public class Foo{
}
How can I reference to Foo from C#?
var f = new Foo();
f.someFunction();
I've solved it!
Instance is created by
Java.Lang.Object obj = Java.Lang.Class.ForName("x.y.z.Foo").NewInstance();
You can cast Java.Lang.Object to a known ancestor if necessary.
Related
I'm trying to port a backend module from TYPO3 10 to TYPO3 11.
I have already made dependency injection working moving the repository variable from protected to public, but this way of working is already deprecated and will be removed in TYPO3 12
I used the guide here to define a repository variable in my controller and instantiate it:
class ModuleConfController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {
/**
* #var \Aip\Bit3\Domain\Repository\AbstractRepository
*
*/
private ?AbstractRepository $abstractRepository = null;
public function injectAbstractRepository(AbstractRepository $abstractRepository)
{
$this->$abstractRepository = $abstractRepository;
}
I have also defined a Services.yaml file with this content:
services:
_defaults:
autowire: true
autoconfigure: true
public: false
Aip\Bit3\:
resource: '../Classes/*'
exclude: '../Classes/Domain/Model/*'
The code seems to work since the inject injectAbstractRepository is called and the parameter is populated with an instance of the class AbstractRepository.
But instead of assinging the value to the class field it throws an exception
Object of class Aip\Bit3\Domain\Repository\AbstractRepository could not be converted to string
Can someone shed some light?
The comment made by Thomas Loffer solved the problem. I had improperly used cut and paste to write the wrong line and misled by the error message
I have to access to a private method in a Class. I created a library with inside the Class, imported it but it can't still recognize. I have the same problem also with private variables.
Example:
file buffer.dart:
library buflib;
class Buffer{
void _record(){
[...]
}
}
in the same folder: engine.dart
import 'buffer.dart';
class Engine {
Buffer _buff = Buffer()
[...]
void myMethod(){
[...]
this._buff._record();
}
}
I have this error:
The method '_record' isn't defined for the type 'Buffer'.
Try correcting the name to the name of an existing method, or defining >a method named '_record'.dartundefined_method
Any suggestions?
By default, each separate .dart file is a separate library. Since private identifiers are private to the library, they won't be visible to other .dart files.
You can use the library and part of directives to group multiple .dart files into the same library, but those directives aren't documented.
u cant call private methods or variables from out there classes .... u should change it to public by removing "under score"
I want to use some data type created by me(they are created in another project) in a new xtext project.
For example if I have some classes like the following:
//java project
class A {
int a;
String b;
// getters & setters
void f(){...}
}
In the xtext project I would like to use them as a type for some variables, but I would also like to use the primitive types as well (string, int, boolean).
So in the test file after launching the java eclipse app, I could be able to use them as the following
variable t = new A();
t.f()
t.getB()...
I have a following problem:
In my application, I have web and lib folders.
Lib folder is supposed to contain utility libraries.
Example:
lib/my_lib.dart
library my_lib;
part 'src/person.dart';
lib/my_lib1.dart
library my_lib1;
import 'my_lib.dart';
part 'src/other.dart';
In my_lib1, I want to use classes defined in my_lib
the classes are as follows:
lib/src/person.dart
part of my_lib;
class Person {
}
lib/src/other.dart
part of my_lib1;
class Other {
Person p;
Other(this.p) {
print(p);
}
}
Now, in web/testpackage.dart
import 'package:TestPackage/my_lib.dart';
import 'package:TestPackage/my_lib1.dart';
void main() {
Person p = new Person();
Other o = new Other(p);
}
Fails with:
Exception: type 'Person' is not a subtype of type 'Person' of 'p'.
Other.Other (package:testpackage/src/other.dart:7:14)
How should I structure my project to prevent that?
My libraries are local to the app, and I don't really want to develop them separately for my toy project.
Problem in that the your library my_lib is a publiclibrary and anyone (and you, of course) can use it elsewhere outside of lib directory.
In this case it must be imported (becuase it's a public library) always as the package library.
To solve this this problem you must change your source code.
From this lib/my_lib1.dart
library my_lib1;
import 'my_lib.dart';
part 'src/other.dart';
To this lib/my_lib1.dart
library my_lib1;
import 'package:TestPackage/my_lib.dart';
part 'src/other.dart';
Hi would like to know how to make the f# compiler to auto open a namespace automatically.
I have
namespace XXX
I have to add something here do(AutoOpen("XXX.YYY")) or something like that to make the XXX.YYY module to be opened when referencing the library from external projects.
[<AutoOpen>]
module YYY =
....
Thanks
In order to open a namespace/module without opening its parent first, you have to add the attribute on assembly level.
You can do this by adding an AssemblyInfo.fs file to your project:
In the case of the following code:
namespace Framework
module GlobalFunctions =
let Test () =
10.
You would for instance add the following code to AssemblyInfo.fs:
namespace Framework
[<assembly:AutoOpen("Framework.GlobalFunctions")>]
do()
And then you can call the code from a script (.fsx) file with:
#r #"C:\PathToAssembly\Assembly.dll"
let result = Test ()
Resulting in:
--> Referenced 'C:\PathToAssembly\Assembly.dll'
val result : float = 10.0
The AutoOpen attribute can be applied only to F# module, so you won't be able to add it to an entire namespace. However, since you can place all F# declarations inside a module, that may be enough for what you need. The syntax is:
[<AutoOpen>]
module MyGlobals =
// Declarations in the module
type Foo() =
member x.Bar = 10
When you reference the assembly, you should see Foo immediately. If the declaration is placed inside another namespace (i.e. MyLibrary), then you'll need to add open MyLibrary, but MyGlobals will be accessible automatically.