Structure (enum?) like EndOfLine

How would you create something that works in a manner like EndOfLine does?

I mean… it basically has two syntax

  • x=EndOfLine – returns a value based on platform
  • x=EndOfLine.xxx - returns a designated value

EndOf Line is a lot of misdirection :slight_smile:
There seems to be a global function, EndOfLine, that returns an instance of the EndOfLine Class
The EndOfLine class has an operator_convert TO method on it and also ones for OSX, Unix, Windows, and Macintosh line endings.
Something like

Module GlobalFunctions
     Global Function EndOfLine() As EndOfLine

Class EndOfLine
	Public Shared Property Macintosh As String
	Public Shared Property OSX As String
	Public Shared Property UNIX As String
	Public Shared Property Windows As String

	Public Function Operator_Add(value As String) As String	
	Public Function Operator_AddRight(value As String) As String
	Public Function Operator_Compare(value As String) As Integer
	Public Function Operator_Convert() As String
End Class

introspection can be useful :slight_smile:

Dim eol As New EndOfLine

Dim tinfo As Xojo.Introspection.TypeInfo = xojo.Introspection.GetType(eol)

Dim pInfo() As Xojo.Introspection.PropertyInfo = tInfo.Properties

For Each prop As Xojo.Introspection.PropertyInfo In pInfo
  Dim typeInfo As Xojo.Introspection.TypeInfo = prop.PropertyType
  
  System.DebugLog prop.Name + " as " + typeInfo.Name
  
Next

Dim mInfo() As Xojo.Introspection.MethodInfo = tInfo.Methods

For Each meth As Xojo.Introspection.MethodInfo In mInfo
  
  Dim typeInfo As Xojo.Introspection.TypeInfo = meth.ReturnType
  
  System.DebugLog meth.Name + "() as " + typeInfo.Name
  
Next

EDIT : for those wondering how I know EndOfLine has to be both a class AND a method as described here’s how. ( I’m not “hacking the framework” or anything like that) Code like

dim s as string = "foo " + EndOfLine + "bar"

would not compile IF endofline were just a class. I would get an error. The global method is required to make such a line work.
Reasoning & experimentation tell me it MUST be this way as I can make a version of this work in my own code (renamed EndOfLine as myEndOfLine) and the code

dim s as string = "foo " + myEndOfLine + "bar"

works

EDIT 2 : here’s the sample in Xojo

1 Like