protected override void AddBaseTypes(CodeTypeDeclaration type, TableImportArgumentsViewModel args)
        {
            base.AddBaseTypes(type, args);
            var primaryKeyType = args.GetPrimaryKeyType();

            if (args.SelectedBaseRepositoryType == typeof(ICRUDRepository <,>))
            {
                type.BaseTypes.Add(new CodeTypeReference(typeof(CRUDRESTRepositoryBase <,>).Name, new CodeTypeReference(args.ModelName), new CodeTypeReference(primaryKeyType)));
            }
            else if (args.SelectedBaseRepositoryType == typeof(IReadOnlyRepository <,>))
            {
                type.BaseTypes.Add(new CodeTypeReference(typeof(ReadOnlyRESTRepositoryBase <,>).Name, new CodeTypeReference(args.ModelName), new CodeTypeReference(primaryKeyType)));
            }
            else
            {
                type.BaseTypes.Add(new CodeTypeReference(typeof(RESTRepositoryBase <,>).Name, new CodeTypeReference(args.ModelName), new CodeTypeReference(primaryKeyType)));
            }

            var interfaceName = $"I{args.SingularName}Repository";

            type.BaseTypes.Add(new CodeTypeReference(interfaceName));

            var attr = new CodeAttributeDeclaration(new CodeTypeReference(typeof(RepositoryAttribute)));

            attr.Arguments.Add(new CodeAttributeArgument(new CodeTypeOfExpression(interfaceName)));
            type.CustomAttributes.Add(attr);

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

            constructor.BaseConstructorArgs.Add(new CodePrimitiveExpression(args.SingularName));
            type.Members.Add(constructor);
        }
 protected override void AddBaseTypes(CodeTypeDeclaration type, TableImportArgumentsViewModel args)
 {
     base.AddBaseTypes(type, args);
     var primaryKeyType = args.GetPrimaryKeyType();
     if (primaryKeyType != null)
         type.BaseTypes.Add(new CodeTypeReference(args.SelectedBaseRepositoryType.Name, new CodeTypeReference(args.ModelName), new CodeTypeReference(primaryKeyType)));
 }
Exemple #3
0
        protected override void AddBaseTypes(CodeTypeDeclaration type, TableImportArgumentsViewModel args)
        {
            base.AddBaseTypes(type, args);
            var primaryKeyType = args.GetPrimaryKeyType();
            var dbmlClass      = Path.GetFileName(_solution.DatabaseConfigurations.DbmlPath) + "DataContext";
            var dbClass        = $"DB.{args.SingularName}";

            if (dbClass.EndsWith("Status"))
            {
                dbClass = dbClass.Replace("Status", "Statuse");
            }

            if (args.SelectedBaseRepositoryType == typeof(ICRUDRepository <,>))
            {
                if (_solution.LinqProjectConfiguration.UseCutomCrudBase)
                {
                    type.BaseTypes.Add(new CodeTypeReference(_solution.LinqProjectConfiguration.SelectedLinqCrudBase, new CodeTypeReference(dbClass), new CodeTypeReference(args.ModelName), new CodeTypeReference(primaryKeyType)));
                }
                else
                {
                    type.BaseTypes.Add(new CodeTypeReference(typeof(CRUDLinqRepositoryBase <, , ,>).Name, new CodeTypeReference($"DB.{dbmlClass}"), new CodeTypeReference(dbClass), new CodeTypeReference(args.ModelName), new CodeTypeReference(primaryKeyType)));
                }
            }
            else if (args.SelectedBaseRepositoryType == typeof(IReadOnlyRepository <,>))
            {
                if (_solution.LinqProjectConfiguration.UseCutomCrudBase)
                {
                    type.BaseTypes.Add(new CodeTypeReference(_solution.LinqProjectConfiguration.SelectedLinqReadBase, new CodeTypeReference(dbClass), new CodeTypeReference(args.ModelName), new CodeTypeReference(primaryKeyType)));
                }
                else
                {
                    type.BaseTypes.Add(new CodeTypeReference(typeof(ReadOnlyLinqRepositoryBase <, , ,>).Name, new CodeTypeReference($"DB.{dbmlClass}"), new CodeTypeReference(dbClass), new CodeTypeReference(args.ModelName), new CodeTypeReference(primaryKeyType)));
                }
            }
            else
            {
                type.BaseTypes.Add(new CodeTypeReference(typeof(LinqRepositoryBase <, , ,>).Name, new CodeTypeReference($"DB.{dbmlClass}"), new CodeTypeReference(dbClass), new CodeTypeReference(args.ModelName), new CodeTypeReference(primaryKeyType)));
            }

            var interfaceName = $"I{args.SingularName}Repository";

            type.BaseTypes.Add(new CodeTypeReference(interfaceName));

            var attr = new CodeAttributeDeclaration(new CodeTypeReference(typeof(RepositoryAttribute)));

            attr.Arguments.Add(new CodeAttributeArgument(new CodeTypeOfExpression(interfaceName)));
            type.CustomAttributes.Add(attr);
        }