While writing library documentation I need to be able to reference (i.e. link to) methods from other classes (in the same library) but with the same method name (i.e. reference the delegating method from the docs of the one that is doing the work).
I have tried ClassName.method (does not work) and directly using the method (references the same class method).
Any ideas?
Thanks.
/// [B.someMethod] ..
/// [someMethod] ..
class A {
void someMethod() {
}
}
/// [A.someMethod]
/// [someMethod]
class B {
void someMethod() {
}
}
/// [A.someMethod]
void main() {
new A().someMethod();
}
All references in the doc comments work for me in this example, but sometimes DartEditor shows them only as links after a delay or after some other edits.
Its a docgen issue/bug - can be monitored here: https://code.google.com/p/dart/issues/detail?id=22144
Related
class Student {
static void getDetails() {
print('Get details method of Student class');
}
}
class DartStudent extends Student {
static void getDetails() {
print('Get details method of DartStudent class');
}
}
void main() {
DartStudent.getDetails();
}
Output : Get details method of DartStudent class
Expected : Error. static method cannot be overriden.. or something wrong..
what's wrong with me?
getDetails() in DartStudent class is not overriding parent class's method?
You can't override static methods.
The two static methods you declared there are in fact two different static methods, not the same, overriden one.
Answer for a different question, but related:
Dart doesn't inherit static methods to derived classes. So it makes no sense to create abstract static methods (without implementation).
Also check out Why shouldn't static methods be able to be overrideable?. It provides a thorough explanation of why static methods should not be overrideable in general.
I am little new to dart. I am trying to understand the difference between these two methods. Are both methods different or same? Where should I use one above another? Can someone explain it to me?
class A {
A.executor1() {
print('executor one is called');
}
static executor2() {
print('executor two is called');
}
}
Meanwhile neither of the method call is required to make a new instance? both are called using the class name.
void main() {
A.executor1(); // Will print "executor one is called"
A.executor2(); // Will print "executor two is called"
}
A.executor1() is a named constructor. static executor2() is a static method.
With an IDE (or dartpad.dev) you can see the different return types when you are placing the cursor over each method:
void main() {
A.executor1(); // (new) A A.executor1()
A.executor2(); // dynamic executor2()
}
static methods can be called without creating an instance of the class. executor1 will have access to this and so on because it's attached to an actual instance, but static methods will not because they aren't attached to anything.
Consider (in Javascript):
class Bicycle {
static numWheels = 2;
constructor(color) {
this.color = color;
}
static numberOfWheels() {
console.log(`Every bike has ${this.numWheels} wheels.`);
}
myColor() {
console.log(`This bike is ${this.color}.`);
}
}
// property of an instance
new Bicycle('red').myColor();
// available for anyone!
Bicycle.numberOfWheels();
We use the Ranorex Studio in our company for black-box testing. I am a newbie concerning black-box testing. For a very first automated test, I want to create two tests that use a number of methods from a file that was generated by adding a recording module and changing this to user code by clicking the items, pressing the right mouse button and selecting 'Convert to user code'.
The code has methods (where the names were refactored by me) of the form public void Mouse_Click_<something>(RepoItemInfo inputtagInfo, …). This means that whenever I want to call any such method, I should pass a RepoItemInfo object. How can I define the "proper" object to call this method? In other words: What to write on the right-hand side of info = ????????
According to the Ranorex help page, using RepoItemInfo
as arguments for user code actions enables a variety of possibilities
such as providing a framework of smart test actions, defining generic
technology independent get/set value actions, combining several
related actions to one user code action, implementing complex
validations and many more.
I have the following code:
namespace FirstTestProject
{
public partial class OpenIVMAndJobsite
{
private GoSearchJobsite gsj;
private RepoItemInfo info;
/// <summary>
/// This method gets called right after the recording has been started.
/// It can be used to execute recording specific initialization code.
/// </summary>
private void Init()
{
// Your recording-specific initialization code goes here.
gsj = new GoSearchJobsite();
info = ???????;
}
public void JobsiteSearch()
{
gsj.Mouse_Click_Country(info, Properties.EAustrianCountries.Wien);
}
public void Mouse_Click()
{
Report.Log(ReportLevel.Info, "Mouse", "Mouse Left Click at {X=0,Y=0}.");
Mouse.MoveTo(0, 0);
Mouse.Click(System.Windows.Forms.MouseButtons.Left);
}
}
[…]
public partial class GoAndSearchInJobsite
{
/// <summary>
/// This method gets called right after the recording has been started.
/// It can be used to execute recording specific initialization code.
/// </summary>
private void Init()
{
// Your recording specific initialization code goes here.
}
public void Mouse_Click_Country(RepoItemInfo atagInfo, string country)
{
Report.Log(ReportLevel.Info, "Mouse", "<" + country + ">\r\nMouse Left Click item 'atagInfo' at 16;8.", atagInfo);
atagInfo.FindAdapter<ATag>().Click("16;8");
}
[…]
}
/// <summary>
/// Description of Properties.
/// </summary>
public static class Properties
{
public enum EAustrianCountries
{
Alle,
Burgenland,
Kärnten,
Niederösterreich,
Oberösterreich,
Salzburg,
Steiermark,
Tirol,
Vorarlberg,
Wien
}
}
}
Each item in the repository will have a corresponding ReportItemInfo object as well.
For example, if you have a button as ButtonOK, you will also find ButtonOKInfo object. You can use it with repo.<window>.control mechanism.
If you are dealing with window itself, the object will be repo.<window>.selfInfo.
Hope it helps.
Thanks,
Manoj
I have a XAML page with WebView inside (for example MainPage.xaml). Also I have WinRT Component with class marked with [AllowForWeb] attribute. This component is referenced from project where MainPage.xaml located and in code-behind AddWebAllowedObject method is used. And I can't reference main project back because of circular dependency.
How to call MainPage.xaml.cs methods from component class? Very usual situation. Is there are some standard way to do it?
For example. I have a method inside RT component that could be called from JavaScript
public void ShowMessage(string message)
{
// I want to call here function from MainPage.xaml.cs
}
How to call MainPage.xaml.cs methods from component class? Very usual situation. Is there are some standard way to do it?
Yes, you can pass the method from MainPage.xaml.cs to Windows Runtime Component through delegate(Currently it's very limited to use delegate in Runtime Component using C#, see this case, so I use C++ as demo).
For Runtime Component Class MyClass.h:
public delegate Platform::String^ MyFunc(int a, int b);
public ref class MyClass sealed
{
public:
MyClass();
static Platform::String^ MyMethod(MyFunc^ func)
{
Platform::String^ abc=func(4, 5);
return abc;
}
};
And you can use the delegate in code behind like below:
using MyComponentCpp;
private void myBtn_Click(object sender, RoutedEventArgs e)
{
String abc=MyClass.MyMethod(MyMethod);
myTb.Text = abc;
}
private String MyMethod(int a, int b)
{
return (a.ToString() + b.ToString());//replace this line with your own logic.
}
And here is the complete Demo: TestProject.
Thankfully to #Elvis Xia who has gived me idea, I has found a solution how to do it without C++.
I have create a third project as Class Library. It doesn't has restrictions to use Action. This library I have referenced from main project and from WinRT component. Code of class inside library:
public class BridgeClass
{
public static event Action<string> MessageReceived;
public static void Broadcast(string message)
{
if (MessageReceived != null) MessageReceived(message);
}
}
Code inside main project with webview is:
// place somewhere
BridgeClass.MessageReceived += ShowMessage;
// ....... and add a method
void ShowMessage(string msg)
{
}
And now i can call this code from WinRT component:
public void ShowMessage(string message)
{
BridgeClass.Broadcast("lalala");
}
I often use this statement for extending class without needs of writing a whole separate file. Supposing ClassFromFramework is a class being part of a framework included in library.
public ClassFromFramework {
public String myMethod() {
// operations
}
//lot of other methods....
}
Then in my class I could do the following:
import com.framework.ClassFromFramework;
public MyClass {
public void method() {
ClassFromFramework m = new ClassFromFramework() {
#Override
public String myMethod() {
// do operations...
}
}
m.myMethod();
}
}
I wonder if I can achieve the same with Objective-c without declaring a new combination .h .m files and import in my using class.
You can make a new subclass, and override methods, but all new classes must be in their own .h & .m files. That's how Obj-C operates. In this case, it would make sense to have the additional files.
You can also call the parent method with the word super. This is done all the time when subclassing a ViewController, such as in viewDidLoad.