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 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); }
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; }