/// <summary> /// Adds the given element to the collection /// </summary> /// <param name="item">The item to add</param> public override void Add(IModelElement item) { IMethodConfiguration methodConfigurationsCasted = item.As <IMethodConfiguration>(); if ((methodConfigurationsCasted != null)) { this._parent.MethodConfigurations.Add(methodConfigurationsCasted); } }
/// <summary> /// Removes the given item from the collection /// </summary> /// <returns>True, if the item was removed, otherwise False</returns> /// <param name="item">The item that should be removed</param> public override bool Remove(IModelElement item) { IMethodConfiguration methodConfigurationItem = item.As <IMethodConfiguration>(); if (((methodConfigurationItem != null) && this._parent.MethodConfigurations.Remove(methodConfigurationItem))) { return(true); } return(false); }
private CodeParameterDeclarationExpression GenerateMethodArgument(IClassConfiguration classConfiguration, IMethodConfiguration methodConfiguration, ICollection<IFileConfiguration> files) { var className = classConfiguration.Name + methodConfiguration.Name + "Arguments"; var argumentinterface = new CodeTypeDeclaration("I" + className) { IsInterface = true }; var argumentsClass = new CodeTypeDeclaration(className) { IsClass = true, BaseTypes = { argumentinterface.Name } }; var argumentSpace = new CodeNamespace("Types") { Types = { argumentinterface, argumentsClass } }; var argumentFile = new FileConfiguration(className, argumentSpace); files.Add(argumentFile); var argumentFactoryName = className + "Factory"; var expression = new CodeObjectCreateExpression(className); var returnStatement = new CodeMethodReturnStatement { Expression = expression }; var factoryMethod = new CodeMemberMethod() { Name = "Produce", Attributes = MemberAttributes.Public | MemberAttributes.Final, ReturnType = new CodeTypeReference(argumentinterface.Name), Statements = { returnStatement } }; var argumentFactoryInterface = new CodeTypeDeclaration("I" + argumentFactoryName) { IsInterface = true, Members = { factoryMethod } }; var argumentFactoryClass = new CodeTypeDeclaration(argumentFactoryName) { IsClass = true, BaseTypes = { argumentFactoryInterface.Name }, Members = { factoryMethod } }; var argumentFactorySpace = new CodeNamespace("Logics") { Types = { argumentFactoryInterface, argumentFactoryClass } }; var argumentFactoryFile = new FileConfiguration(argumentFactoryClass.Name, argumentFactorySpace); files.Add(argumentFactoryFile); return new CodeParameterDeclarationExpression("I" + methodConfiguration.Name + "Arguments", "argument"); }
private string GetReturnName(IClassConfiguration classConfiguration, IMethodConfiguration methodConfiguration) { return methodConfiguration.Name + "Results"; }
private CodeMemberMethod GenerateMethod(IClassConfiguration classConfiguration, IMethodConfiguration methodConfiguration, ICollection<IFileConfiguration> files) { var classMethod = new CodeMemberMethod { Attributes = MemberAttributes.Public | MemberAttributes.Final, Name = methodConfiguration.Name, //Parameters = { GenerateMethodArgument(classConfiguration, methodConfiguration, files) }, ReturnType = new CodeTypeReference(typeof(void)) }; if (methodConfiguration.MethodType == MethodTypes.Dependent) classMethod.Parameters.Add(GenerateMethodArgument(classConfiguration, methodConfiguration, files)); if (methodConfiguration.ReturnType.Type == ReturnTypes.Void.Type) return classMethod; classMethod.ReturnType = new CodeTypeReference(methodConfiguration.ReturnType.Type); if (methodConfiguration.ReturnType.Type != ReturnTypes.Normal.Type) { var typedBody = GenerateTypedMethodBody(methodConfiguration.ReturnType); classMethod.Statements.Add(typedBody); return classMethod; } var returnInterfaceResultName = GetReturnName(classConfiguration, methodConfiguration); classMethod.ReturnType = new CodeTypeReference("I" + returnInterfaceResultName); var privateFactoryName = GetReturnFactoryName(classConfiguration, methodConfiguration) .ToPrivate(); var body = GenerateNormalMethodBody("_" + privateFactoryName); classMethod.Statements.Add(body); return classMethod; }