Exemplo n.º 1
0
        private IConstructorDeclaration CreateConstructor(IClassDeclaration classDeclaration, IIdentifier fieldIdentifier, ITypeName typeName)
        {
            IConstructLanguage language = classDeclaration.Language;

            IParameter   parameter             = language.Parameter(typeName);
            NamingPolicy parameterNamingPolicy = parameter.PrimaryNamingPolicy(classDeclaration.FileModel.UserSettings);
            string       parameterName         = parameterNamingPolicy.ChangeNameAccordingToPolicy(classDeclaration.Identifier.Name, classDeclaration.SolutionModel);

            parameter.Identifier = language.Identifier(parameterName);
            Modifiers constructorModifiers = Modifiers.Public;
            Modifiers visibility           = classDeclaration.Modifiers.Modifiers.GetVisibility();

            if (visibility == Modifiers.None || visibility.IsInternal())
            {
                constructorModifiers = Modifiers.Internal;
            }

            IConstructorDeclaration constructor = language.Constructor(language.None <IDocComment>(),
                                                                       language.None <IAttributes>(),
                                                                       language.Modifiers(constructorModifiers),
                                                                       language.Parameters(parameter),
                                                                       language.None <IConstructorInitializer>(),
                                                                       language.Block(
                                                                           language.AssignmentStatement(
                                                                               language.MemberAccess(language.This(), fieldIdentifier),
                                                                               language.VariableAccess(parameter.Identifier))));

            return(constructor);
        }