~mandel/wadlsharp/refactor_code_serialization

« back to all changes in this revision

Viewing changes to LpNet.WadlSharp.Common/Generator/LpClass.cs

  • Committer: Manuel de la Pena
  • Date: 2010-09-17 15:26:59 UTC
  • Revision ID: mandel@themacaque.com-20100917152659-3w3ttzyufwvkq2wj
Modified the code to allow the users to fix the casing of the generated code to follow naming conventions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
 ********************************************************************/
27
27
 
28
28
 
 
29
using System;
 
30
 
29
31
namespace LpNet.WadlSharp.Common.Generator
30
32
{
31
33
    using System.CodeDom;
36
38
 
37
39
    public class LpClass : IClass
38
40
    {
 
41
        #region Variables
 
42
 
 
43
        private readonly Func<string, string> _createIdentifier;
 
44
 
 
45
        #endregion
 
46
 
 
47
        #region Constructors
 
48
 
 
49
        /// <summary>
 
50
        /// Creates a new instance of the class that will be use the 
 
51
        /// basic identifier generator.
 
52
        /// </summary>
 
53
        public LpClass()
 
54
            : this(WadlSharpUtils.CreateIdentifier)
 
55
        {
 
56
 
 
57
        }
 
58
 
 
59
        /// <summary>
 
60
        /// Creates a new instance of the class with the given identifier generator.
 
61
        /// </summary>
 
62
        /// <param name="createIdentifier">The generator that will create 
 
63
        /// the identifiers used in the generated class.</param>
 
64
        public LpClass(Func<string, string> createIdentifier)
 
65
        {
 
66
            _createIdentifier = createIdentifier;
 
67
        }
 
68
 
 
69
        #endregion
 
70
 
39
71
        #region IClass Members
40
72
 
41
73
        /// <summary>
47
79
        /// <returns>Instance of CodeTypeDeclaration</returns>
48
80
        public CodeTypeDeclaration Create(representation_type repType, HashSet<string> nameSpaces, CodeNamespace ns)
49
81
        {
50
 
            CodeTypeDeclaration cdDec= new CodeTypeDeclaration();
51
 
 
52
 
            cdDec.Name = WadlSharpUtils.CreateIdentifier(repType.id);
53
 
            cdDec.IsClass = true;
54
 
            cdDec.Attributes = MemberAttributes.Public | MemberAttributes.Static;
55
 
            cdDec.IsPartial = true;
 
82
            CodeTypeDeclaration cdDec= new CodeTypeDeclaration
 
83
            {
 
84
                Name = _createIdentifier(repType.id),
 
85
                IsClass = true,
 
86
                Attributes = MemberAttributes.Public | MemberAttributes.Static,
 
87
                IsPartial = true
 
88
            };
56
89
 
57
90
            #region Namespaces Import
58
91
 
85
118
                    if (param.option != null)
86
119
                    {
87
120
                        paramName = string.Format("{0}_{1}", cdDec.Name,
88
 
                                                         WadlSharpUtils.CreateIdentifier(param.name));
 
121
                                                         _createIdentifier(param.name));
89
122
 
90
123
                        CodeTypeMember existingEnum = LpMethod.CheckEnumExists(ns, param, paramName);
91
124
                        if (existingEnum == null)
92
125
                        {
93
 
                            string enumName = WadlSharpUtils.CreateIdentifier(param.name);
 
126
                            string enumName = _createIdentifier(param.name);
94
127
 
95
128
                            IEnum paramEnum = new LpEnum();
96
129
                            CodeTypeDeclaration memberEnum = paramEnum.Create(paramName, param.option, nameSpaces);
104
137
 
105
138
                    CodeMemberField field;
106
139
 
107
 
                    IProperty property = new LpProperty();
 
140
                    IProperty property = new LpProperty(_createIdentifier);
108
141
                    CodeMemberProperty prop = property.Create(param, out field, nameSpaces, ns, paramName);
109
142
 
110
143
                    propertiesList.Add(prop);
139
172
 
140
173
            #region The Class Definition and Properties
141
174
 
142
 
            typeDeclaration.Name = WadlSharpUtils.CreateIdentifier(resourceType.id);
 
175
            typeDeclaration.Name = _createIdentifier(resourceType.id);
143
176
            typeDeclaration.IsClass = true;
144
177
            typeDeclaration.Attributes = MemberAttributes.Public | MemberAttributes.Static;
145
178
            typeDeclaration.IsPartial = true;
177
210
 
178
211
                foreach (method method in resourceType.method)
179
212
                {
180
 
                    IMethod lpmethod = new LpMethod();
 
213
                    IMethod lpmethod = new LpMethod(_createIdentifier);
181
214
                    CodeMemberMethod memberMethod;
182
215
 
183
216
                    if (method.request != null && method.request.representation != null)
206
239
            {
207
240
                foreach (param param in resourceType.param)
208
241
                {
209
 
                    IProperty paramInst = new LpProperty();
 
242
                    IProperty paramInst = new LpProperty(_createIdentifier);
210
243
                    CodeMemberField field;
211
244
 
212
245
                    CodeMemberProperty prop = paramInst.Create(param, out field, nameSpaces, ns, string.Empty);