init
This commit is contained in:
37
Program.fs
Normal file
37
Program.fs
Normal file
@@ -0,0 +1,37 @@
|
||||
// Learn more about F# at http://fsharp.org
|
||||
|
||||
open System
|
||||
open Newtonsoft.Json
|
||||
open System.Xml
|
||||
open System.IO
|
||||
type Tommy =
|
||||
{
|
||||
mutable Name: string
|
||||
mutable Age: int
|
||||
}
|
||||
type Step() =
|
||||
member val Name = "" with get,set
|
||||
member val Age = 0 with get,set
|
||||
|
||||
// {
|
||||
// mutable Name: string
|
||||
// mutable Desc: string
|
||||
// }
|
||||
|
||||
[<EntryPoint>]
|
||||
let main argv =
|
||||
let xml = " <Step>
|
||||
<Name>Tommy</Name>
|
||||
<Age>27</Age>
|
||||
</Step>"
|
||||
let serializer = System.Xml.Serialization.XmlSerializer(typeof<Step>);
|
||||
use memory = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(xml))
|
||||
let rez = (serializer.Deserialize(memory) :?> Step)
|
||||
printf "my name is %s and I'm %i" rez.Name rez.Age
|
||||
let result = JsonConvert.DeserializeObject<Tommy>("{\"Name\": \"Tommy Parnell\", \"Age\": 27}")
|
||||
if isNull(box result)
|
||||
then
|
||||
Console.WriteLine "its null"
|
||||
else
|
||||
printfn "my name is %s and my age is %i" result.Name result.Age
|
||||
0 // return an integer exit code
|
||||
14
fjson.fsproj
Normal file
14
fjson.fsproj
Normal file
@@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.fs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="newtonsoft.json" Version="10.0.3" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
Reference in New Issue
Block a user