Xbasic

FILE.TO_PROPERTY Function

Syntax

Property_Data as C = FILE.To_property(C Filename,P data)

Arguments

FilenameCharacter

The name of the file containing the formatted property data.

dataPointer

A pointer variable to contain the new property data.

Returns

Property_DataCharacter

The property data as formatted in the property file.

Description

Reads a file to a in dot variable - returns file contents as string.

Discussion

The FILE.TO_PROPERTY() method reads a file created by the FILE.FROM_PROPERTY() method and returns its contents as a string. Use PROPERTY_FROM_STRING() to convert the string into a dot variable.

Example

dim b as P
dim cc as C
dim b.foo as C = ""

cc = FILE.to_property("c:\my_property.txt", b)
? cc
= <[1]<name="Fred">
<city="Boston">
<age=23>
>
<[2]<name="Tom">
<city="NY">
<age=35>
>

File.to_property() Function can automatically de-serialize a file that was serialized using property_to_string(), property_to_blob() or json_generate(). Example:

dim src.fname as c = "john"
dim src.lname as c = "public"
FILE.From_string("c:\data\sample.txt",property_to_string(src))
FILE.From_string("c:\data\sample.json",json_generate(src))
FILE.From_blob("c:\data\sample.dat",property_to_blob(src))


dim p1 as p
FILE.to_property("c:\data\sample.txt",p1)
? p1
= fname = "john"
lname = "public"


dim p2 as p
FILE.to_property("c:\data\sample.txt",p2)
? p2
= fname = "john"
lname = "public"

dim p3 as p
FILE.to_property("c:\data\sample.dat",p3)
? p3
= fname = "john"
lname = "public"

See Also