private static IMethodDeclaration CreateVBInvocator(IEventDeclaration eventDeclaration, IModifiers modifiers,
                                                            IList <IArgument> arguments, IList <IParameter> parameters, IConstructLanguage language)
        {
            IEventInvocation eventInvocation = language.New <IEventInvocation>();

            eventInvocation.DelegateInvocation =
                language.DelegateInvocation(
                    language.VariableAccess(eventDeclaration.Identifier),
                    language.Arguments(arguments));

            IMethodDeclaration method = language.Method(
                language.None <IDocComment>(),
                language.None <IAttributes>(),
                modifiers,
                language.TypeName(eventDeclaration.VoidTypeAtThisLocation()),
                language.None <IMethodTypeParameters>(),
                language.Parameters(parameters),
                language.Block(
                    language.ExpressionStatement(eventInvocation)));

            NamingPolicy methodsNamingPolicy = method.PrimaryNamingPolicy(eventDeclaration.FileModel.UserSettings);
            string       methodName          = methodsNamingPolicy.ChangeNameAccordingToPolicy("Raise" + eventDeclaration.Identifier.Name + "Event",
                                                                                               eventDeclaration.SolutionModel);

            method.Identifier = language.Identifier(methodName);

            return(method);
        }
예제 #2
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);
        }
        private static void GenerateSecondParameterAndArgument(IEventDeclaration eventDeclaration, IParameter parameter, IConstructLanguage language, FileModel fileModel, IList <IArgument> arguments, IList <IParameter> parameters)
        {
            NamingPolicy parametersNamingPolicy = language.PrimaryNamingPolicyFor <IParameter>(fileModel.UserSettings);
            IType        parameterType          = eventDeclaration.TypeName.Type.As <IDelegateType>().ReplaceParameterTypesIn(parameter.Type);

            IParameter newParameter = language.Parameter(
                parameter.IsRef,
                parameter.IsOut,
                parameter.IsParams,
                language.TypeName(eventDeclaration.StringTypeAtThisLocation()),
                parameter.DefaultValue);

            string parameterName = parametersNamingPolicy.ChangeNameAccordingToPolicy("propertyName", parameter.SolutionModel);

            newParameter.Identifier = language.Identifier(parameterName);

            IObjectCreation objectCreation = language.ObjectCreation(
                language.TypeName(parameterType), language.Arguments(
                    language.Argument(
                        language.VariableAccess(newParameter.Identifier))));

            arguments.Add(
                language.Argument(
                    objectCreation));

            parameters.Add(newParameter);
        }
        private static IMethodDeclaration CreateCSInvocator(IEventDeclaration eventDeclaration, IModifiers modifiers, IList<IArgument> arguments,
            IList<IParameter> parameters, IConstructLanguage language)
        {
            IVariableDeclaration variable = language.Variable(
                eventDeclaration.TypeName,
                language.VariableAccess(eventDeclaration.Identifier));

            NamingPolicy variablesNamingPolicy = variable.PrimaryNamingPolicy(eventDeclaration.FileModel.UserSettings);
            string variableName = variablesNamingPolicy.ChangeNameAccordingToPolicy("on" + eventDeclaration.Identifier.Name,
                eventDeclaration.SolutionModel);

            variable.Identifier = language.Identifier(variableName);

            IIfStatement ifStatement = language.IfStatement(
                language.BinaryExpression(
                    language.VariableAccess(variable.Identifier),
                    Operator.NotEqual,
                    language.New<INull>()),
                language.Block(
                    language.ExpressionStatement(
                        language.DelegateInvocation(
                            language.VariableAccess(variable.Identifier),
                            language.Arguments(arguments)))));

            IMethodDeclaration method = language.Method(
                language.None<IDocComment>(),
                language.None<IAttributes>(),
                modifiers,
                language.TypeName(eventDeclaration.VoidTypeAtThisLocation()),
                language.None<IMethodTypeParameters>(),
                language.Parameters(parameters),
                language.Block(
                    variable,
                    ifStatement));

            NamingPolicy methodsNamingPolicy = method.PrimaryNamingPolicy(eventDeclaration.FileModel.UserSettings);
            string methodName = methodsNamingPolicy.ChangeNameAccordingToPolicy("on" + eventDeclaration.Identifier.ToUpperFirstLetter().Name,
                eventDeclaration.SolutionModel);

            method.Identifier = language.Identifier(methodName);

            return method;
        }
        private static IMethodDeclaration CreateCSInvocator(IEventDeclaration eventDeclaration, IModifiers modifiers, IList <IArgument> arguments,
                                                            IList <IParameter> parameters, IConstructLanguage language)
        {
            IVariableDeclaration variable = language.Variable(
                eventDeclaration.TypeName,
                language.VariableAccess(eventDeclaration.Identifier));

            NamingPolicy variablesNamingPolicy = variable.PrimaryNamingPolicy(eventDeclaration.FileModel.UserSettings);
            string       variableName          = variablesNamingPolicy.ChangeNameAccordingToPolicy("on" + eventDeclaration.Identifier.Name,
                                                                                                   eventDeclaration.SolutionModel);

            variable.Identifier = language.Identifier(variableName);

            IIfStatement ifStatement = language.IfStatement(
                language.BinaryExpression(
                    language.VariableAccess(variable.Identifier),
                    Operator.NotEqual,
                    language.New <INull>()),
                language.Block(
                    language.ExpressionStatement(
                        language.DelegateInvocation(
                            language.VariableAccess(variable.Identifier),
                            language.Arguments(arguments)))));

            IMethodDeclaration method = language.Method(
                language.None <IDocComment>(),
                language.None <IAttributes>(),
                modifiers,
                language.TypeName(eventDeclaration.VoidTypeAtThisLocation()),
                language.None <IMethodTypeParameters>(),
                language.Parameters(parameters),
                language.Block(
                    variable,
                    ifStatement));

            NamingPolicy methodsNamingPolicy = method.PrimaryNamingPolicy(eventDeclaration.FileModel.UserSettings);
            string       methodName          = methodsNamingPolicy.ChangeNameAccordingToPolicy("on" + eventDeclaration.Identifier.ToUpperFirstLetter().Name,
                                                                                               eventDeclaration.SolutionModel);

            method.Identifier = language.Identifier(methodName);

            return(method);
        }
        private static IMethodDeclaration CreateVBInvocator(IEventDeclaration eventDeclaration, IModifiers modifiers,
            IList<IArgument> arguments, IList<IParameter> parameters, IConstructLanguage language)
        {
            IEventInvocation eventInvocation = language.New<IEventInvocation>();
            eventInvocation.DelegateInvocation =
                language.DelegateInvocation(
                    language.VariableAccess(eventDeclaration.Identifier),
                    language.Arguments(arguments));

            IMethodDeclaration method = language.Method(
                    language.None<IDocComment>(),
                    language.None<IAttributes>(),
                    modifiers,
                    language.TypeName(eventDeclaration.VoidTypeAtThisLocation()),
                    language.None<IMethodTypeParameters>(),
                    language.Parameters(parameters),
                    language.Block(
                        language.ExpressionStatement(eventInvocation)));

            NamingPolicy methodsNamingPolicy = method.PrimaryNamingPolicy(eventDeclaration.FileModel.UserSettings);
            string methodName = methodsNamingPolicy.ChangeNameAccordingToPolicy("Raise" + eventDeclaration.Identifier.Name + "Event",
                eventDeclaration.SolutionModel);

            method.Identifier = language.Identifier(methodName);

            return method;
        }
        private static void GenerateSecondParameterAndArgument(IEventDeclaration eventDeclaration, IParameter parameter, IConstructLanguage language, FileModel fileModel, IList<IArgument> arguments, IList<IParameter> parameters)
        {
            NamingPolicy parametersNamingPolicy = language.PrimaryNamingPolicyFor<IParameter>(fileModel.UserSettings);
            IType parameterType = eventDeclaration.TypeName.Type.As<IDelegateType>().ReplaceParameterTypesIn(parameter.Type);

            IParameter newParameter = language.Parameter(
                parameter.IsRef,
                parameter.IsOut,
                parameter.IsParams,
                language.TypeName(eventDeclaration.StringTypeAtThisLocation()),
                parameter.DefaultValue);

            string parameterName = parametersNamingPolicy.ChangeNameAccordingToPolicy("propertyName", parameter.SolutionModel);
            newParameter.Identifier = language.Identifier(parameterName);

            IObjectCreation objectCreation = language.ObjectCreation(
                language.TypeName(parameterType), language.Arguments(
                    language.Argument(
                        language.VariableAccess(newParameter.Identifier))));

            arguments.Add(
                language.Argument(
                    objectCreation));

            parameters.Add(newParameter);
        }