private bool AddConstructor(IClass cl)
        {
            RDomConstructor constructor = CreateRDomConstructor(cl);

            triviaManager.StoreStringWhitespace(constructor, LanguageElement.ParameterEndDelimiter, "", "\r\n");
            triviaManager.StoreStringWhitespace(constructor, LanguageElement.ConstructorInitializerPrefix, "       ", "");
            var properties  = cl.Properties.Where(x => x.CanSet && x.CanGet);
            var assignments = new List <IAssignmentStatement>();

            assignments.Add(new RDomAssignmentStatement(
                                RDom.CSharp.ParseExpression("NeedsFormatting"),
                                RDom.CSharp.ParseExpression("true")));
            triviaManager.StoreStringWhitespace(assignments.First(), LanguageElement.EndOfLine, "", "\r\n");
            var altConstructorPairs = new List <Tuple <RDomParameter, RDomParameter, RDomArgument> >();

            foreach (var prop in properties)
            {
                RDomParameter param = CreateParameter(assignments, altConstructorPairs, prop);
                constructor.Parameters.AddOrMove(param);
            }
            constructor.StatementsAll.AddOrMoveRange(assignments);
            if (altConstructorPairs.Any())
            {
                IConstructor altConstructor = CreateAlternateConstructor(constructor, altConstructorPairs);
                cl.InsertAfterInitialFields(altConstructor);
            }
            return(true);
        }
        private RDomParameter CreateParameter(List <IAssignmentStatement> assignments, List <Tuple <RDomParameter, RDomParameter, RDomArgument> > altConstructorPairs, IProperty prop)
        {
            var paramName = StringUtilities.CamelCase(prop.Name);
            var type      = prop.PropertyType.Copy();
            var param     = new RDomParameter(paramName, type);

            triviaManager.StoreStringWhitespace(param, LanguageElement.Identifier, "              ", "");
            triviaManager.StoreStringWhitespace(param, LanguageElement.EndOfLine, "", "\r\n");
            var newAssignment = new RDomAssignmentStatement(
                RDom.CSharp.ParseExpression(prop.Name),
                RDom.CSharp.ParseExpression(paramName));

            triviaManager.StoreStringWhitespace(newAssignment, LanguageElement.EndOfLine, "", "\r\n");
            assignments.Add(newAssignment);
            if (!(prop.Attributes.Any(x => x.Name == "Required")))
            {
                param.DefaultValue = GetDefaultValue(prop.PropertyType);
            }
            if (prop.PropertyType.Name == "IReferencedType")
            {
                var paramNewName = paramName + "Name";
                var paramNew     = new RDomParameter(paramName, "System.String");
                var argNew       = new RDomArgument(RDom.CSharp.ParseExpression(string.Format("new RDomReferencedType({0})", paramNewName)));
                altConstructorPairs.Add(Tuple.Create(param, paramNew, argNew));
            }

            return(param);
        }
        private RDomParameter CreateParameter(List<IAssignmentStatement> assignments, List<Tuple<RDomParameter, RDomParameter, RDomArgument>> altConstructorPairs, IProperty prop)
        {
            var paramName = StringUtilities.CamelCase(prop.Name);
             var type = prop.PropertyType.Copy();
             var param = new RDomParameter(paramName, type);
             triviaManager.StoreStringWhitespace(param, LanguageElement.Identifier, "              ", "");
             triviaManager.StoreStringWhitespace(param, LanguageElement.EndOfLine, "", "\r\n");
             var newAssignment = new RDomAssignmentStatement(
                  RDom.CSharp.ParseExpression(prop.Name),
                  RDom.CSharp.ParseExpression(paramName));
             triviaManager.StoreStringWhitespace(newAssignment, LanguageElement.EndOfLine, "", "\r\n");
             assignments.Add(newAssignment);
             if (!(prop.Attributes.Any(x => x.Name == "Required")))
             {
            param.DefaultValue = GetDefaultValue(prop.PropertyType);
             }
             if (prop.PropertyType.Name == "IReferencedType")
             {
            var paramNewName = paramName + "Name";
            var paramNew = new RDomParameter(paramName, "System.String");
            var argNew = new RDomArgument(RDom.CSharp.ParseExpression(string.Format("new RDomReferencedType({0})", paramNewName)));
            altConstructorPairs.Add(Tuple.Create(param, paramNew, argNew));
             }

             return param;
        }