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 IAccessor CreateSetter(IConstructLanguage language, string propertyName, IFieldDeclaration field)
        {
            string propertyChangedName = language.Name == LanguageNames.CSharp ? "OnPropertyChanged" : "RaisePropertyChangedEvent";

            IMethodInvocation onPropertyChanged = language.MethodInvocation(language.None<IExpression>(),
                language.Identifier(propertyChangedName),
                language.None<ITypeArguments>(),
                language.Arguments(
                    language.Argument(language.StringLiteral(propertyName))));

            IMemberAccess fieldUsage = language.MemberAccess(language.None<IExpression>(), field.Identifier);
            IExpression valueUsage = language.Expression("value");

            IStatement assignment = language.AssignmentStatement(fieldUsage, valueUsage);

            IIfStatement ifStatement =
                language.IfStatement(
                    language.BinaryExpression(fieldUsage,
                        Operator.NotEqual,
                        valueUsage),
                    language.Block(assignment, language.ExpressionStatement(onPropertyChanged)));

            IAccessor setter = language.Setter(language.Block(ifStatement));
            return setter;
        }
 private IFieldDeclaration CreateFieldToHoldWrappedClass(IConstructLanguage language, ITypeName typeName, IClassDeclaration classDeclaration)
 {
     IFieldDeclaration fieldDeclaration = language.Field(language.Modifiers(Modifiers.Private | Modifiers.Readonly), typeName);
     NamingPolicy fieldsNamingPolicy = fieldDeclaration.PrimaryNamingPolicy(classDeclaration.FileModel.UserSettings);
     string fieldName = fieldsNamingPolicy.ChangeNameAccordingToPolicy(classDeclaration.Identifier.Name, classDeclaration.SolutionModel);
     fieldDeclaration.Identifier = language.Identifier(fieldName);
     return fieldDeclaration;
 }
        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);
        }