コード例 #1
0
ファイル: Default.cs プロジェクト: laszlo-kiss/Dataphor
        public override Statement EmitDropStatement(EmitMode mode)
        {
            AlterScalarTypeStatement statement = new AlterScalarTypeStatement();

            statement.ScalarTypeName = Schema.Object.EnsureRooted(_scalarType.Name);
            statement.Default        = new D4.DropDefaultDefinition();
            return(statement);
        }
コード例 #2
0
ファイル: Constraint.cs プロジェクト: laszlo-kiss/Dataphor
        public override Statement EmitDropStatement(EmitMode mode)
        {
            AlterScalarTypeStatement statement = new AlterScalarTypeStatement();

            statement.ScalarTypeName = Schema.Object.EnsureRooted(_scalarType.Name);
            statement.DropConstraints.Add(new DropConstraintDefinition(Name));
            return(statement);
        }
コード例 #3
0
        private void GenerateSubclassType(Program program, Type type, string d4TypeName)
        {
            // create type <d4 type name> from class <native type name> is { <parent d4 type name> } { representation <d4 type name> { <properties> } };
            // foreach property:
            // <property name> : <d4 type name>
            var statement = new CreateScalarTypeStatement();

            statement.ScalarTypeName      = d4TypeName;
            statement.FromClassDefinition = new ClassDefinition(type.FullName);
            if (type.BaseType != null && !type.BaseType.Equals(typeof(System.Object)))
            {
                var scalarTypeSpecifier = GenerateType(program, type.BaseType) as ScalarTypeSpecifier;
                if (scalarTypeSpecifier == null)
                {
                    throw new InvalidOperationException(String.Format("Scalar type specifier expected: {0}.", type.BaseType.Name));
                }
                statement.ParentScalarTypes.Add(new ScalarTypeNameDefinition(scalarTypeSpecifier.ScalarTypeName));
            }
            else
            {
                // Add a default conveyor "System.BOPObjectConveyor"
                statement.ClassDefinition = new ClassDefinition("System.BOPObjectConveyor");
            }

            _statements.Statements.Add(statement);

            var defaultRepresentation = new RepresentationDefinition(d4TypeName);

            foreach (var property in type.GetProperties(BindingFlags.Public | BindingFlags.DeclaredOnly | BindingFlags.Instance))
            {
                if
                (
                    property.CanRead &&
                    property.CanWrite &&
                    property.GetGetMethod() != null &&
                    property.GetGetMethod().GetBaseDefinition().DeclaringType == type &&
                    property.GetSetMethod() != null &&
                    property.GetSetMethod().GetBaseDefinition().DeclaringType == type
                )
                {
                    defaultRepresentation.Properties.Add(new PropertyDefinition(property.Name, GenerateType(program, property.PropertyType)));
                }
            }

            foreach (var field in type.GetFields(BindingFlags.Public | BindingFlags.DeclaredOnly | BindingFlags.Instance))
            {
                defaultRepresentation.Properties.Add(new PropertyDefinition(field.Name, GenerateType(program, field.FieldType)));
            }

            if (defaultRepresentation.Properties.Count > 0)
            {
                var alterStatement = new AlterScalarTypeStatement();
                alterStatement.ScalarTypeName = d4TypeName;
                alterStatement.CreateRepresentations.Add(defaultRepresentation);
                _statements.Statements.Add(alterStatement);
            }
        }