Autor Beitrag
Mitmischer 1703
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 754
Erhaltene Danke: 19

Win 7, Debian
Delphi Prism, Delphi 7, RAD Studio 2009 Academic, C#, C++, Java, HTML, PHP
BeitragVerfasst: Di 01.12.09 15:46 
ausblenden Delphi-Prism-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
namespace Extensions;

interface

uses
  System.Collections.Generic,
  System.Linq,
  System.Text,
  System.Runtime.CompilerServices;

type
  [Extension]
  DateTimeExtender = public static class
  protected
  public
    [Extension]
    class method GetTickCount(ExtendingdtTime : DateTime) : Integer;
  end;
  
implementation

class method DateTimeExtender.GetTickCount(ExtendingdtTime : DateTime) : Integer;
begin
  var Time := DateTime.Now;
  exit(Time.Hour*60*60*1000 + Time.Minute*60*1000 + Time.Second*1000 + Time.Millisecond);
end;

end.


Wie bekomme ich es hin, die Methode - praktisch wie DateTime.Now - aufrufen zu können, OHNE vorher eine Instanz erstellen zu müssen?

_________________
Die Lösung ist nicht siebzehn.
Ralf Jansen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 4700
Erhaltene Danke: 991


VS2010 Pro, VS2012 Pro, VS2013 Pro, VS2015 Pro, Delphi 7 Pro
BeitragVerfasst: Di 01.12.09 15:59 
Extension Methods funktionieren nur an Instanzen und man kann nur Methoden ~erweitern~ keine Properties. Dein Vergleich mit DateTime.Now scheitert also gleich 2 mal. Zumindest gilt das so in C#. Ich gehe mal davon aus das in Prism ebenso ist.
Mitmischer 1703 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 754
Erhaltene Danke: 19

Win 7, Debian
Delphi Prism, Delphi 7, RAD Studio 2009 Academic, C#, C++, Java, HTML, PHP
BeitragVerfasst: Di 01.12.09 16:14 
Properties sind also ohne Instanz aufrufbar?

_________________
Die Lösung ist nicht siebzehn.
Ralf Jansen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 4700
Erhaltene Danke: 991


VS2010 Pro, VS2012 Pro, VS2013 Pro, VS2015 Pro, Delphi 7 Pro
BeitragVerfasst: Di 01.12.09 16:57 
Wenn sie static (so heißt es in c# in Prism schreibt man glaube ich class davor) sind ja.