Repository navigation
Expand file tree
/
Copy pathCSharpFactory.fs
More file actions
65 lines (48 loc) · 2.62 KB
/
Copy pathCSharpFactory.fs
File metadata and controls
65 lines (48 loc) · 2.62 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
namespace PowerShellModule
open System.Collections.Generic
open System.Management.Automation
open Generator
open System
module CasingConstants =
[<Literal>]
let Pascal = "Pascal"
[<Literal>]
let Camel = "Camel"
[<Literal>]
let None = "None"
/// <summary>
/// The ConvertFrom-Json command.
/// This command converts a Json string representation to a CSharp string.
/// </summary>
[<Cmdlet(VerbsCommon.New, "CSharpModel")>]
type CSharpFactory() =
inherit PSCmdlet()
[<ValidateNotNullOrEmpty>]
[<Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true, HelpMessage = "The JSON.")>]
member val InputObject: string = "" with get, set
[<ValidateSet(CasingConstants.Camel, CasingConstants.Pascal, CasingConstants.None)>]
[<Parameter(Mandatory = false, Position = 1, HelpMessage = "Sets the casing rules for class names.")>]
member val ClassCasing: string = CasingConstants.Pascal with get, set
[<ValidateSet(CasingConstants.Camel, CasingConstants.Pascal, CasingConstants.None)>]
[<Parameter(Mandatory = false, Position = 2, HelpMessage = "Sets the casing rules for property names.")>]
member val PropertyCasing: string = CasingConstants.Pascal with get, set
[<ValidateNotNullOrEmpty>]
[<Parameter(Mandatory = false, Position = 3, HelpMessage = "Sets the name of the namespace.")>]
member val NameSpace: string = "" with get, set
[<ValidateNotNullOrEmpty>]
[<Parameter(Mandatory = false, Position = 4, HelpMessage = "Sets the name of the root object.")>]
member val ObjectName: string = "Root" with get, set
[<Parameter(Mandatory = false, Position = 5, HelpMessage = "Sets a prefix for the class names.")>]
member val Prefix: string = "" with get, set
[<Parameter(Mandatory = false, Position = 6, HelpMessage = "Suffix a prefix for the class names.")>]
member val Suffix: string = "" with get, set
member val private Buffer: List<string> = List<string>()
override x.ProcessRecord() = x.Buffer.Add(x.InputObject)
override x.EndProcessing() =
let settings =
CSharpSettings
(PropertyCasing = x.PropertyCasing, ClassCasing = x.ClassCasing, NameSpace = x.NameSpace,
ClassPrefix = x.Prefix, ClassSuffix = x.Suffix, RootObjectName = x.ObjectName)
// TODO add proper support like https://github.com/PowerShell/PowerShell/blob/master/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/ConvertFromJsonCommand.cs
let json = String.Join(Environment.NewLine, x.Buffer)
(Factory.ConfiguredCSharpFromJson json settings).Match((fun x -> x), raise) |> x.WriteObject