Exemple #1
0
        private ClassType CreateClass(DatabaseTable table)
        {
            var name = textFormatter.FormatText(table.Name);

            ClassType classType = ClassAlreadyExists(name);

            if (classType != null)
            {
                return(classType);
            }

            classType = diagram.AddClass();
            classType.AccessModifier = AccessModifier.Public;
            classType.Modifier       = ClassModifier.None;
            classType.Name           = name;

            if (CodeGenerator.Settings.Default.GenerateNHibernateMapping)
            {
                if (CodeGenerator.Settings.Default.UseUnderscoreAndLowercaseInDB)
                {
                    classType.NHMTableName = new LowercaseAndUnderscoreTextFormatter().FormatText(table.Name);
                }
                else
                {
                    classType.NHMTableName = table.Name;
                }

                classType.IdGenerator = Enum.GetName(typeof(CodeGenerator.IdentityGeneratorType), CodeGenerator.Settings.Default.DefaultIdentityGenerator);
            }

            foreach (var column in table.Columns)
            {
                Property property = classType.AddProperty();
                property.InitFromString(CreateProperty(column, classType));

                if (CodeGenerator.Settings.Default.GenerateNHibernateMapping)
                {
                    if (CodeGenerator.Settings.Default.UseUnderscoreAndLowercaseInDB)
                    {
                        property.NHMColumnName = new LowercaseAndUnderscoreTextFormatter().FormatText(column.Name);
                    }
                    else
                    {
                        property.NHMColumnName = column.Name;
                    }

                    property.IsIdentity = column.IsPrimaryKey;

                    if (column.IsForeignKey)
                    {
                        property.ManyToOne = textFormatter.FormatText(column.ForeignKeyTableName);
                    }

                    property.IsUnique  = column.IsUniqueKey;
                    property.IsNotNull = !column.Nullable;
                }
            }

            return(classType);
        }
        private ClassType CreateClass(DatabaseTable table)
        {
            var name = textFormatter.FormatText(table.Name);

            ClassType classType = ClassAlreadyExists(name);

            if (classType != null)
            {
                return(classType);
            }

            classType = diagram.AddClass();
            classType.AccessModifier = AccessModifier.Public;
            classType.Modifier       = ClassModifier.None;
            classType.Name           = name;

            foreach (var column in table.Columns)
            {
                classType.AddProperty().InitFromString(CreateProperty(column, classType));
            }

            return(classType);
        }
Exemple #3
0
    ClassType FillIn(ClassType t, System.Type type)
    {
        foreach (System.Type x in type.GetNestedTypes(flags))
        {
            GetType(x);
        }
        foreach (FieldInfo x in type.GetFields(BindingFlags.Instance | BindingFlags.Static | flags))
        {
            Field f = t.AddField(new InputElement(x.Name), msg);
            f.Modifiers = GetFieldModifiers(x);
            f.Type      = GetType(x.FieldType);
        }
        foreach (ConstructorInfo x in type.GetConstructors(BindingFlags.Instance | BindingFlags.Static | flags))
        {
            GetMethod(t.AddConstructor(new InputElement(t.Name), msg), x);
        }
        foreach (MethodInfo x in type.GetMethods(BindingFlags.Instance | BindingFlags.Static | flags))
        {
            if (x.Name == "get_Item" || x.Name == "set_Item" ||
                type.FullName == "System.String" && x.Name == "get_Chars")
            {
                GetMethod(t, x.Name, x);                        // indexer
            }
            else if (x.Name.StartsWith("get_") || x.Name.StartsWith("set_"))
            {
                string   name = x.Name.Substring(4);
                Property p    = t.members[name] as Property;
                if (p == null)
                {
                    p = t.AddProperty(new InputElement(name), msg);
                }
                p.Modifiers = GetMethodModifiers(x);
                Method m;
                if (x.Name.StartsWith("get_"))
                {
                    m      = p.AddGet(new InputElement(name));
                    p.Type = GetType(x.ReturnType);
                }
                else
                {
                    m      = p.AddSet(new InputElement(name));
                    m.Type = global.Types.Void;
                    p.Type = GetType(x.GetParameters()[0].ParameterType);
                }
            }
            else
            {
                GetMethod(t, x.Name, x);
            }
        }
        t.Modifiers = GetTypeModifiers(type);
        IList baseinterfaces;

        if (type.BaseType != null)
        {
            t.baseClass    = (ClassType)GetType(type.BaseType);
            baseinterfaces = type.BaseType.GetInterfaces();
        }
        else
        {
            baseinterfaces = new System.Type[0];
        }
        if (type.DeclaringType != null)
        {
            t.enclosingType = (ClassType)GetType(type.DeclaringType);
        }
        foreach (System.Type x in type.GetInterfaces())
        {
            if (!baseinterfaces.Contains(x))
            {
                t.interfaces.Add((InterfaceType)GetType(x));
            }
        }
        return(t);
    }
Exemple #4
0
 ClassType FillIn(ClassType t, MetaDataTypeDefinition d, string path)
 {
     foreach (MetaDataTypeDefinition x in d.NestedClasses)
     {
         GetSymbol(x, path);
     }
     foreach (MetaDataField x in d.Fields)
     {
         Field f = t.AddField(new InputElement(x.Name), msg);
         f.Modifiers = GetFieldModifiers(x);
         f.Type      = GetType(x.Signature.FieldType, path);
     }
     foreach (MetaDataMethod x in d.Methods)
     {
         if (x.Name == "get_Item" || x.Name == "set_Item" ||
             d.FullName == "System.String" && x.Name == "get_Chars")
         {
             GetMethod(t, x.Name, x, path);  // indexer
         }
         else if (x.Name.StartsWith("get_") || x.Name.StartsWith("set_"))
         {
             Property p;
             string   name = x.Name.Substring(4);
             if (t.members.Contains(name))
             {
                 p = (Property)t.members[name];
             }
             else
             {
                 p = t.AddProperty(new InputElement(name), msg);
             }
             p.Modifiers = GetMethodModifiers(x);
             Method m;
             if (x.Name.StartsWith("get_"))
             {
                 m      = p.AddGet(new InputElement(name));
                 m.Type = GetType(x.Signature.ReturnType, path);
             }
             else
             {
                 m      = p.AddSet(new InputElement(name));
                 p.Type = GetType(x.Signature.Parameters[0].Type, path);
                 m.Type = global.Types.Void;
             }
             m.Modifiers = p.Modifiers;
         }
         else if (x.Name == ".ctor")
         {
             GetMethod(t.AddConstructor(new InputElement(t.Name), msg), x, path);
         }
         else if (x.Name == ".cctor")
         {
             Constructor m = new Constructor(new InputElement(t.Name), t.members);
             GetMethod(m, x, path);
         }
         else
         {
             GetMethod(t, x.Name, x, path);
         }
     }
     t.Modifiers     = GetTypeModifiers(d);
     t.baseClass     = (ClassType)ResolveTypeRef(d.Extends, path);
     t.enclosingType = (ClassType)ResolveTypeRef(d.EnclosingClass, path);
     foreach (MetaDataObject x in d.Interfaces)
     {
         InterfaceType f = ResolveTypeRef(x, path) as InterfaceType;
         if (f != null)
         {
             t.interfaces.Add(f);
         }
     }
     return(t);
 }