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 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 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);
        }
예제 #5
0
        public override void Execute(SolutionModel solutionModel, SelectionContext context)
        {
            FileModel fileModel;
            CodeSpan  selection;

            if (!solutionModel.IsEditorSelection(context, out fileModel, out selection))
            {
                return;
            }

            IConstructEnumerable <IFieldDeclaration> fields = FindFields(fileModel, selection);

            if (fields.Exist())
            {
                IConstructLanguage language = fields.Language;

                foreach (IFieldDeclaration field in fields)
                {
                    IPropertyDeclaration property = language.Property(
                        language.None <IDocComment>(),
                        language.None <IAttributes>(),
                        language.Modifiers(Modifiers.Public),
                        language.TypeName(field.TypeName.Type),
                        language.None <IIdentifier>());

                    NamingPolicy propertyNamingPolicy = property.PrimaryNamingPolicy(fileModel.UserSettings);
                    string       propertyName         = propertyNamingPolicy.MakeMemberNameUniqueInScope(field, field.Identifier.Name);

                    property.Identifier = language.Identifier(propertyName);

                    IAccessor getter = language.FieldGetter(field.Identifier);
                    IAccessor setter = CreateSetter(language, propertyName, field);

                    property.Accessors = language.Enumerable(new List <IAccessor>()
                    {
                        getter, setter
                    });

                    field.EnclosingClass.Insert(property);
                }
            }
        }
        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);
        }