Esempio n. 1
0
        public void GetFields()
        {
            // Arrange
            ICommandConfiguration Configuration = this.mockRepository
                                                  .Of <ICommandConfiguration>()
                                                  .Where(x => x.TableName == "Persona")
                                                  .Where(x => x.PrimaryKeyTable == "Id")
                                                  .Where(x => x.IncludeId == true)
                                                  .First();

            IClassConfiguration ClassConfiguration = this.mockRepository
                                                     .Of <IClassConfiguration>()
                                                     .Where(x => x.FieldsInclude == true)
                                                     .Where(x => x.PropsInclude == false)
                                                     .First();

            Persona Entidad = GetPersona();

            // Act
            var result = SqlEntityUtil.GetKeysValues(
                ClassConfiguration,
                Configuration,
                Entidad);

            // Assert
            Assert.IsTrue(result.Count() == 1 && result["edad"] == "37");
        }
Esempio n. 2
0
        public void GetProps()
        {
            // Arrange
            ICommandConfiguration Configuration = this.mockRepository
                                                  .Of <ICommandConfiguration>()
                                                  .Where(x => x.TableName == "Persona")
                                                  .Where(x => x.PrimaryKeyTable == "Id")
                                                  .Where(x => x.IncludeId == true)
                                                  .First();

            IClassConfiguration ClassConfiguration = this.mockRepository
                                                     .Of <IClassConfiguration>()
                                                     .Where(x => x.FieldsInclude == false)
                                                     .Where(x => x.PropsInclude == true)
                                                     .First();

            Persona Entidad = GetPersona();

            // Act
            var result = SqlEntityUtil.GetKeysValues(
                ClassConfiguration,
                Configuration,
                Entidad);

            // Assert
            Assert.IsTrue(
                result.Count() == 4 &&
                result["Fecha"] == "'19820326 00:00'" &&
                result["Nombre"] == "N'Miguel Angel'" &&
                result["Id"] == "5" &&
                result["Saldo"] == "null"
                );
        }
Esempio n. 3
0
        private static FieldInfo GetFieldInfo(IFieldDescriptor fieldDescriptor, IClassConfiguration parent)
        {
            Type      t = Type.GetType(parent.ClassName);
            FieldInfo f = t.GetField(fieldDescriptor.FieldName,
                                     BindingFlags.NonPublic |
                                     BindingFlags.Public |
                                     BindingFlags.Instance);

            return(f);
        }
Esempio n. 4
0
 public void Visit(IClassConfiguration classConfiguration)
 {
     if (classConfiguration is XMLClassConfiguration)
     {
         foreach (IFieldDescriptor f in classConfiguration.FieldDesctiptors)
         {
             if (f is XMLFieldDescriptor)
             {
                 ((XMLFieldDescriptor)f).ParentClassConfiguration = (XMLClassConfiguration)classConfiguration;
             }
         }
     }
 }
Esempio n. 5
0
        public void Visit(IClassConfiguration classConfiguration)
        {
            if (classConfiguration.ClassName == null)
            {
                throw new ContextConfigurationException("IClassConfiguration without definition of 'ClassName' found");
            }
            Type t = Type.GetType(classConfiguration.ClassName);

            if (t == null)
            {
                throw new ContextConfigurationException("Type '" + classConfiguration.ClassName + "' not found");
            }
        }
Esempio n. 6
0
        public void Visit(IFieldDescriptor fieldDescriptor)
        {
            if (fieldDescriptor.FieldName == null)
            {
                throw new ContextConfigurationException("IFieldDescriptor without definition of 'FieldName' found");
            }

            IClassConfiguration parent = fieldDescriptor.ParentClassConfiguration;
            FieldInfo           f      = GetFieldInfo(fieldDescriptor, parent);

            if (f == null)
            {
                throw new ContextConfigurationException("Field '" + fieldDescriptor.FieldName + "' not found in class '" + parent.ClassName + "'");
            }
        }
Esempio n. 7
0
        public static IDictionary <string, string> GetKeysValues <T>(IClassConfiguration configuration, ICommandConfiguration commandConfiguration, T entity)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            var aSqlFields = new List <SqlField>();

            if (configuration.PropsInclude)
            {
                var props = typeof(T).GetProperties()
                            .Where(c => c.GetCustomAttributes(typeof(NonQuerable), false).Count() == 0)
                            .Select(x => new SqlField()
                {
                    name = x.Name, value = entity != null ? SqlValueUtil.GetValue(x.GetValue(entity)) : null
                });

                aSqlFields.AddRange(props);
            }

            if (configuration.FieldsInclude)
            {
                var fields = typeof(T).GetFields()
                             .Where(c => c.GetCustomAttributes(typeof(NonQuerable), false).Count() == 0)
                             .Select(x => new SqlField()
                {
                    name = x.Name, value = entity != null ? SqlValueUtil.GetValue(x.GetValue(entity)) : null
                });

                aSqlFields.AddRange(fields);
            }

            if (commandConfiguration != null)
            {
                if (!commandConfiguration.IncludeId)
                {
                    aSqlFields = aSqlFields
                                 .Where(x => x.name.ToUpper() != commandConfiguration.PrimaryKeyTable.ToUpper())
                                 .ToList();
                }
            }
            var Elementos = aSqlFields.ToDictionary(x => x.name, y => y.value);

            return(Elementos);
        }
 private void Init(IClassConfiguration configuration, SqlType SqlType)
 {
     this.ClassConfiguration = configuration ?? new SqlConfiguration <object>();
     this.SqlType            = SqlType;
 }
 public SqlParse(SqlType SqlType, IClassConfiguration configuration = null)
 {
     Init(configuration, SqlType.SqlServer);
 }
Esempio n. 10
0
 public static IEnumerable <string> GetValues <T>(IClassConfiguration Configuration, ICommandConfiguration CommandConfiguration, T Entidad)
 {
     return(GetKeysValues <T>(Configuration, CommandConfiguration, Entidad).Values.ToList());
 }
Esempio n. 11
0
 public static IEnumerable <string> GetKeys <T>(IClassConfiguration configuration, ICommandConfiguration commandConfiguration = null)
 {
     return(GetKeysValues <T>(configuration, commandConfiguration, default(T)).Keys.ToList());
 }
Esempio n. 12
0
        public static void Configure(IClassConfiguration conf, Object o)
        {
            Type type = Type.GetType(conf.ClassName);

            if (o.GetType() != type)
            {
                //dürfte nicht passieren ...
                throw new Exception();
            }



            foreach (IFieldDescriptor fd in conf.FieldDesctiptors)
            {
                FieldInfo fi = type.GetField(fd.FieldName,
                                             BindingFlags.NonPublic |
                                             BindingFlags.Public |
                                             BindingFlags.Instance);

                if (fi == null)
                {
                    throw new ContextRuntimeException("Field '" + fd.FieldName + "' not found in type '" + type.AssemblyQualifiedName + "'");
                }

                Object val = fi.GetValue(o);

                if (val == null)
                {
                    return;
                }

                foreach (ICustomAction ca in fd.CustomActions)
                {
                    String actionId = ca.ActionId;

                    IAction action = ActionRegistry.Instance.GetAction(actionId);

                    if (action == null)
                    {
                        throw new ContextRuntimeException("Action '" + actionId + "' not registered: type '" + type.AssemblyQualifiedName + "' -> field +'" + fd.FieldName + "'");
                    }

                    action.Perform(o, fi, val, ca.Parameter);
                }

                foreach (IInvokedMethod im in fd.InvokedMethods)
                {
                    PermissionLevel p = PolicyRegistry.Instance.GetInvocationPermissionLevel(val.GetType(), im.MethodName);
                    if (p != PermissionLevel.PERMITTED)
                    {
                        throw new Exception();
                    }

                    MethodInfo mi = val.GetType().GetMethod(im.MethodName);
                    if (mi == null)
                    {
                        throw new ContextRuntimeException("Method '" + im.MethodName + "' not found: type '" + type.AssemblyQualifiedName + "' -> field +'" + fd.FieldName + "'");
                    }

                    mi.Invoke(val, null);
                }

                foreach (IModifiedProperty mp in fd.ModifiedProperties)
                {
                    PermissionLevel p = PolicyRegistry.Instance.GetInvocationPermissionLevel(val.GetType(), mp.PropertyName);
                    if (p != PermissionLevel.PERMITTED)
                    {
                        throw new Exception();
                    }

                    PropertyInfo pi = val.GetType().GetProperty(mp.PropertyName);
                    if (pi == null)
                    {
                        throw new ContextRuntimeException("Property '" + mp.PropertyName + "' not found: type '" + type.AssemblyQualifiedName + "' -> field +'" + fd.FieldName + "'");
                    }

                    bool   parsed;
                    Object tmp = StringParserRegistry.Instance.ParseString(mp.Value, pi.PropertyType, out parsed);

                    if (!parsed)
                    {
                        throw new ContextRuntimeException("Could not convert parameter '" + mp.Value + "' to '" + pi.PropertyType.AssemblyQualifiedName + "': property '" + mp.PropertyName + "' of type '" + type.AssemblyQualifiedName + "' -> field +'" + fd.FieldName + "'");
                    }

                    pi.SetValue(val, tmp, null);
                }
            }


            if (o is ILayouted)
            {
                ((ILayouted)o).Layout.Pack();
            }
            //List<ILayout> ls = ContextManager.Instance.GetLayouts(o);
            //if (ls != null)
            //{
            //    foreach (ILayout l in ls)
            //    {
            //        l.Pack();
            //    }
            //}
        }
        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");
        }
        public IEnumerable<ZipEntry> Generate(IClassConfiguration configuration)
        {
            var files = new List<IFileConfiguration>();

            var initializeMethod = new CodeMemberMethod()
            {
                Name = "Initialize",
                Attributes = MemberAttributes.Public,
                ReturnType = new CodeTypeReference(typeof(void))
            };

            var testBaseClass = new CodeTypeDeclaration("Describe_" + configuration.Name)
            {
                Attributes = MemberAttributes.Public | MemberAttributes.Abstract,
                Members = { initializeMethod }
            };

            var classSpace = new CodeNamespace("Logics");
            classSpace.Imports.Add(new CodeNamespaceImport("System"));

            files.Add(new FileConfiguration(configuration.Name, classSpace));

            var targetClass = new CodeTypeDeclaration(configuration.Name)
            {
                IsClass = true,
                TypeAttributes = TypeAttributes.Public | TypeAttributes.Sealed
            };

            var targetInterface = new CodeTypeDeclaration("I" + configuration.Name)
            {
                IsInterface = true
            };

            targetClass.BaseTypes.Add(targetInterface.Name);

            var members = GenerateConstructor(configuration, classSpace, testBaseClass, files);

            targetClass.Members.AddRange(members.ToArray());
            targetInterface.Members.AddRange(members.ToArray());

            var methods = AddMethods(configuration, files);

            foreach (var method in methods)
            {
                targetClass.Members.Add(method);
                targetInterface.Members.Add(method);
            }

            foreach (var methodConfiguration in configuration.Methods.Where(m => m.MethodType == MethodTypes.Dependent))
            {
                var import = new CodeNamespaceImport("I" + methodConfiguration.Name + "Arguments = " + "I" + targetClass.Name + methodConfiguration.Name + "Arguments");

                classSpace.Imports.Add(import);
            }

            foreach (var methodConfiguration in configuration.Methods.Where(m => m.ReturnType.Type == ReturnTypes.Normal.Type))
            {
                var import = new CodeNamespaceImport("I" + methodConfiguration.Name + "Results = " + "I" + targetClass.Name + methodConfiguration.Name + "Results");

                classSpace.Imports.Add(import);

                import = new CodeNamespaceImport("I" + methodConfiguration.Name + "ResultsFactory = " + "I" + targetClass.Name + methodConfiguration.Name + "ResultsFactory");

                classSpace.Imports.Add(import);
            }

            if (configuration.ClassType == ClassTypes.Dependent)
                classSpace.Imports.Add(new CodeNamespaceImport("IDependencies = I" + configuration.Name + "Dependencies"));

            classSpace.Types.Add(targetInterface);
            classSpace.Types.Add(targetClass);

            var provider = CodeDomProvider.CreateProvider("CSharp");
            var options = new CodeGeneratorOptions { BracingStyle = "C" };

            foreach (var fileConfiguration in files)
            {
                var compileUnit = new CodeCompileUnit
                {
                    Namespaces = { fileConfiguration.Namespace }
                };

                var zipEntry = new ZipEntry
                {
                    FileName = fileConfiguration.Name + ".cs"
                };

                using (var writer = new StreamWriter(zipEntry.Stream))
                {
                    provider.GenerateCodeFromCompileUnit(compileUnit, writer, options);
                }

                yield return zipEntry;
            }
        }
        private ICollection<CodeMemberMethod> AddMethods(IClassConfiguration configuration, ICollection<IFileConfiguration> files)
        {
            var methods = new List<CodeMemberMethod>();

            foreach (var methodConfiguration in configuration.Methods)
            {
                var classMethod = GenerateMethod(configuration, methodConfiguration, files);

                methods.Add(classMethod);
            }

            return methods;
        }
 public void Visit(IClassConfiguration classConfiguration)
 {
     if (classConfiguration is XMLClassConfiguration)
     {
         foreach (IFieldDescriptor f in classConfiguration.FieldDesctiptors)
         {
             if (f is XMLFieldDescriptor)
             {
                 ((XMLFieldDescriptor)f).ParentClassConfiguration = (XMLClassConfiguration)classConfiguration;
             }
         }
     }
 }
        public static void Configure(IClassConfiguration conf, Object o)
        {
            Type type = Type.GetType(conf.ClassName);
            if (o.GetType() != type)
            {
                //dürfte nicht passieren ...
                throw new Exception();
            }

            foreach (IFieldDescriptor fd in conf.FieldDesctiptors)
            {
                FieldInfo fi = type.GetField(fd.FieldName,
                    BindingFlags.NonPublic |
                    BindingFlags.Public |
                    BindingFlags.Instance);

                if (fi == null)
                {
                    throw new ContextRuntimeException("Field '"+fd.FieldName+"' not found in type '"+type.AssemblyQualifiedName+"'");
                }

                Object val = fi.GetValue(o);

                if (val == null)
                {
                    return;
                }

                foreach (ICustomAction ca in fd.CustomActions)
                {
                    String actionId = ca.ActionId;

                    IAction action = ActionRegistry.Instance.GetAction(actionId);

                    if (action == null)
                    {
                        throw new ContextRuntimeException("Action '"+actionId+"' not registered: type '"+type.AssemblyQualifiedName+"' -> field +'"+fd.FieldName+"'");
                    }

                    action.Perform(o, fi, val, ca.Parameter);
                }

                foreach (IInvokedMethod im in fd.InvokedMethods)
                {
                    PermissionLevel p = PolicyRegistry.Instance.GetInvocationPermissionLevel(val.GetType(), im.MethodName);
                    if (p != PermissionLevel.PERMITTED)
                    {
                        throw new Exception();
                    }

                    MethodInfo mi = val.GetType().GetMethod(im.MethodName);
                    if (mi == null)
                    {
                        throw new ContextRuntimeException("Method '" + im.MethodName + "' not found: type '" + type.AssemblyQualifiedName + "' -> field +'" + fd.FieldName + "'");
                    }

                    mi.Invoke(val, null);
                }

                foreach (IModifiedProperty mp in fd.ModifiedProperties)
                {
                    PermissionLevel p = PolicyRegistry.Instance.GetInvocationPermissionLevel(val.GetType(), mp.PropertyName);
                    if (p != PermissionLevel.PERMITTED)
                    {
                        throw new Exception();
                    }

                    PropertyInfo pi = val.GetType().GetProperty(mp.PropertyName);
                    if (pi == null)
                    {
                        throw new ContextRuntimeException("Property '" + mp.PropertyName + "' not found: type '" + type.AssemblyQualifiedName + "' -> field +'" + fd.FieldName + "'");
                    }

                    bool parsed;
                    Object tmp = StringParserRegistry.Instance.ParseString(mp.Value, pi.PropertyType, out parsed);

                    if (!parsed)
                    {
                        throw new ContextRuntimeException("Could not convert parameter '"+mp.Value+"' to '"+pi.PropertyType.AssemblyQualifiedName+"': property '" + mp.PropertyName + "' of type '" + type.AssemblyQualifiedName + "' -> field +'" + fd.FieldName + "'");
                    }

                    pi.SetValue(val, tmp, null);
                }
            }

            if (o is ILayouted)
            {
                ((ILayouted)o).Layout.Pack();
            }
            //List<ILayout> ls = ContextManager.Instance.GetLayouts(o);
            //if (ls != null)
            //{
            //    foreach (ILayout l in ls)
            //    {
            //        l.Pack();
            //    }
            //}
        }
        private ICollection<CodeTypeMember> GenerateConstructor(IClassConfiguration classConfiguration, CodeNamespace classSpace, CodeTypeDeclaration testBaseClass, ICollection<IFileConfiguration> files)
        {
            var memberList = new List<CodeTypeMember>();

            var constructor = new CodeConstructor
            {
                Attributes = MemberAttributes.Public,
            };

            memberList.Add(constructor);

            if (classConfiguration.ClassType == ClassTypes.Data)
            {
                foreach (var propertyConfiguration in classConfiguration.Properties)
                {
                    var field = new CodeMemberField
                    {
                        Attributes = MemberAttributes.Private,
                        Name = "_" + propertyConfiguration.Name.ToPrivate(),
                        Type = new CodeTypeReference(propertyConfiguration.Type)
                    };

                    var expression = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), field.Name);

                    var returnStatement = new CodeMethodReturnStatement { Expression = expression };

                    var property = new CodeMemberProperty
                    {
                        Attributes = MemberAttributes.Public | MemberAttributes.Final,
                        Name = propertyConfiguration.Name,
                        Type = field.Type,
                        HasGet = true,
                        GetStatements = { returnStatement }
                    };

                    var parameter = new CodeParameterDeclarationExpression(field.Type, property.Name.ToPrivate());

                    constructor.Parameters.Add(parameter);

                    var referenceExpression = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), field.Name);

                    var constructorBody = new CodeAssignStatement(referenceExpression,
                                                                  new CodeArgumentReferenceExpression(parameter.Name));

                    constructor.Statements.Add(constructorBody);

                    memberList.Add(field);
                    memberList.Add(property);
                }

                return memberList;
            }

            if (classConfiguration.ClassType != ClassTypes.Dependent && classConfiguration.Methods.All(m => m.ReturnType.Type != ReturnTypes.Normal.Type))
                return memberList;

            var dependencyInterface = new CodeTypeDeclaration("I" + classConfiguration.Name + "Dependencies")
            {
                IsInterface = true
            };

            var dependencyConstructor = new CodeConstructor
            {
                Attributes = MemberAttributes.Public
            };

            var dependencyClass = new CodeTypeDeclaration(classConfiguration.Name + "Dependencies")
            {
                IsClass = true,
                BaseTypes = { dependencyInterface.Name },
                Members = { dependencyConstructor }
            };

            var dependencySpace = new CodeNamespace("Types")
            {
                Types = { dependencyInterface, dependencyClass }
            };

            var initializeMethod = (CodeMemberMethod)testBaseClass.Members[0];

            var dependencyMock = new CodeMemberField("Mock<" + dependencyInterface.Name + ">", "DependenciesMock")
            {
                Attributes = MemberAttributes.Family
            };

            testBaseClass.Members.Add(dependencyMock);

            var testReferenceExpression = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), dependencyMock.Name);

            var initializeBody = new CodeAssignStatement(testReferenceExpression, new CodeObjectCreateExpression(dependencyMock.Name));

            initializeMethod.Statements.Add(initializeBody);

            classSpace.Imports.Add(new CodeNamespaceImport(dependencySpace.Name));

            var dependencyFile = new FileConfiguration(dependencyClass.Name, dependencySpace);

            files.Add(dependencyFile);

            var constructorParameter = new CodeParameterDeclarationExpression("IDependencies",
                                                                   "dependencies");

            constructor.Parameters.Add(constructorParameter);

            foreach (var methodConfiguration in classConfiguration.Methods.Where(m => m.ReturnType.Type == ReturnTypes.Normal.Type))
            {
                var resultClassName = classConfiguration.Name + GetReturnName(classConfiguration, methodConfiguration);

                var resultInterface = new CodeTypeDeclaration("I" + resultClassName)
                {
                    IsInterface = true
                };

                var resultClass = new CodeTypeDeclaration(resultClassName)
                {
                    IsClass = true,
                    BaseTypes = { resultInterface.Name }
                };

                var resultSpace = new CodeNamespace("Types")
                {
                    Types = { resultInterface, resultClass }
                };

                var resultFile = new FileConfiguration(resultClassName, resultSpace);

                files.Add(resultFile);

                var resultFactoryName = GetReturnFactoryName(classConfiguration, methodConfiguration);

                var resultFactoryCreateExpression = new CodeObjectCreateExpression(resultClassName);

                var resultFactoryReturnStatement = new CodeMethodReturnStatement { Expression = resultFactoryCreateExpression };

                var factoryMethod = new CodeMemberMethod
                {
                    Attributes = MemberAttributes.Public | MemberAttributes.Final,
                    Name = "Produce",
                    ReturnType = new CodeTypeReference("I" + resultClassName),
                    Statements = { resultFactoryReturnStatement }
                };

                var resultFactoryInterface = new CodeTypeDeclaration("I" + classConfiguration.Name + resultFactoryName)
                {
                    IsInterface = true,
                    Members = { factoryMethod }
                };

                var resultFactoryClass = new CodeTypeDeclaration(classConfiguration.Name + resultFactoryName)
                {
                    IsClass = true,
                    BaseTypes = { resultFactoryInterface.Name },
                    Members = { factoryMethod }
                };

                var dependencyPrivateField = new CodeMemberField(resultFactoryInterface.Name, "_" + resultFactoryName.ToPrivate())
                {
                    Attributes = MemberAttributes.Private
                };

                var expression = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), dependencyPrivateField.Name);

                var returnStatement = new CodeMethodReturnStatement { Expression = expression };

                var dependencyProperty = new CodeMemberProperty
                {
                    Name = resultFactoryName,
                    Attributes = MemberAttributes.Public | MemberAttributes.Final,
                    Type = new CodeTypeReference(resultFactoryInterface.Name),
                    HasGet = true,
                    GetStatements = { returnStatement }
                };

                var classDependencyField = new CodeMemberField("I" + resultFactoryName, "_" + resultFactoryName.ToPrivate())
                {
                    Attributes = MemberAttributes.Private
                };

                var referenceExpression = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), classDependencyField.Name);

                var constructorBody = new CodeAssignStatement(referenceExpression,
                                                              new CodeArgumentReferenceExpression(constructorParameter.Name + "." + resultFactoryName));

                constructor.Statements.Add(constructorBody);

                memberList.Add(classDependencyField);

                dependencyInterface.Members.Add(dependencyProperty);
                dependencyClass.Members.Add(dependencyProperty);
                dependencyClass.Members.Add(dependencyPrivateField);

                var dependencyConstructorParameter = new CodeParameterDeclarationExpression(resultFactoryInterface.Name, resultFactoryName.ToPrivate());

                dependencyConstructor.Parameters.Add(dependencyConstructorParameter);

                var dependencyReferenceExpression = new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), dependencyPrivateField.Name);

                dependencyConstructor.Statements.Add(new CodeAssignStatement(dependencyReferenceExpression,
                                                                             new CodeArgumentReferenceExpression(
                                                                                 dependencyConstructorParameter.Name)));

                var resultFactorySpace = new CodeNamespace("Logics")
                {
                    Types = { resultFactoryInterface, resultFactoryClass }
                };

                var resultFactoryFile = new FileConfiguration(classConfiguration.Name + resultFactoryName, resultFactorySpace);

                files.Add(resultFactoryFile);
            }

            return memberList;
        }
 public void Visit(IClassConfiguration classConfiguration)
 {
     if(classConfiguration.ClassName == null)
     {
         throw new ContextConfigurationException("IClassConfiguration without definition of 'ClassName' found");
     }
     Type t = Type.GetType(classConfiguration.ClassName);
     if (t == null)
     {
         throw new ContextConfigurationException("Type '"+classConfiguration.ClassName+"' not found");
     }
 }
        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;
        }
 private static FieldInfo GetFieldInfo(IFieldDescriptor fieldDescriptor, IClassConfiguration parent)
 {
     Type t = Type.GetType(parent.ClassName);
     FieldInfo f = t.GetField(fieldDescriptor.FieldName,
         BindingFlags.NonPublic |
         BindingFlags.Public |
         BindingFlags.Instance);
     return f;
 }
 private string GetReturnName(IClassConfiguration classConfiguration, IMethodConfiguration methodConfiguration)
 {
     return methodConfiguration.Name + "Results";
 }
 private string selection(IClassConfiguration configuration, ICommandConfiguration commandConfiguration = null)
 {
     return
         (string.Join(",",
                      ExpressionToSQL.util.SqlEntityUtil.GetKeys <T>(configuration, commandConfiguration)));
 }