Beispiel #1
0
        public void Parse(IList <string> args)
        {
            Options = new OptionSet()
            {
                // SQLMetal compatible
                { "c|conn=",
                  "Database {CONNECTION STRING}. Cannot be used with /server, "
                  + "/user or /password options.",
                  conn => Conn = conn },
                // SQLMetal compatible
                { "u|user="******"Login user {NAME}.",
                  name => User = name },
                // SQLMetal compatible
                { "p|password="******"Login {PASSWORD}.",
                  password => Password = password },
                // SQLMetal compatible
                { "s|server=",
                  "Database server {NAME}.",
                  name => Server = name },
                // SQLMetal compatible
                { "d|database=",
                  "Database catalog {NAME} on server.",
                  name => Database = name },
                { "provider=",
                  "Specify {PROVIDER}. May be Ingres, MySql, Oracle, OracleODP, PostgreSql or Sqlite.",
                  provider => Provider = provider },
                { "with-schema-loader=",
                  "ISchemaLoader implementation {TYPE}.",
                  type => DbLinqSchemaLoaderProvider = type },
                { "with-dbconnection=",
                  "IDbConnection implementation {TYPE}.",
                  type => DatabaseConnectionProvider = type },
                { "with-sql-dialect=",
                  "IVendor implementation {TYPE}.",
                  type => SqlDialectType = type },
                // SQLMetal compatible
                { "code=",
                  "Output as source code to {FILE}. Cannot be used with /dbml option.",
                  file => Code = file },
                // SQLMetal compatible
                { "dbml=",
                  "Output as dbml to {FILE}. Cannot be used with /map option.",
                  file => Dbml = file },
                // SQLMetal compatible
                { "language=",
                  "Language {NAME} for source code: C#, C#2 or VB "
                  + "(default: derived from extension on code file name).",
                  name => Language = name },
                { "aliases=",
                  "Use mapping {FILE}.",
                  file => Aliases = file },
                { "schema",
                  "Generate schema in code files (default: enabled).",
                  v => Schema = v != null },
                // SQLMetal compatible
                { "namespace=",
                  "Namespace {NAME} of generated code (default: no namespace).",
                  name => Namespace = name },
                // SQLMetal compatible
                { "entitybase=",
                  "Base {TYPE} of entity classes in the generated code "
                  + "(default: entities have no base class).",
                  type => EntityBase = type },
                { "member-attribute=",
                  "{ATTRIBUTE} for entity members in the generated code, "
                  + "can be specified multiple times.",
                  attribute => MemberAttributes.Add(attribute) },
                { "generate-type=",
                  "Generate only the {TYPE} selected, can be specified multiple times "
                  + "and does not prevent references from being generated (default: "
                  + "generate a DataContex subclass and all the entities in the schema).",
                  type => GenerateTypes.Add(type) },
                { "generate-equals-hash",
                  "Generates overrides for Equals() and GetHashCode() methods.",
                  v => GenerateEqualsHash = v != null },
                // SQLMetal compatible
                { "sprocs",
                  "Extract stored procedures.",
                  v => Sprocs = v != null },
                // SQLMetal compatible
                { "pluralize",
                  "Automatically pluralize or singularize class and member names "
                  + "using specified culture rules.",
                  v => Pluralize = v != null },
                { "culture=",
                  "Specify {CULTURE} for word recognition and pluralization (default: \"en\").",
                  culture => Culture = culture },
                { "case=",
                  "Transform names with the indicated {STYLE} "
                  + "(default: net; may be: leave, pascal, camel, net).",
                  style => Case = style },
                { "generate-timestamps",
                  "Generate timestampes in the generated code (default: enabled).",
                  v => GenerateTimestamps = v != null },
                { "readline",
                  "Wait for a key to be pressed after processing.",
                  v => Readline = v != null },
                { "debug",
                  "Enables additional information to help with debugging, " +
                  "such as full stack traces in error messages.",
                  v => Debug = v != null },
                { "h|?|help",
                  "Show this help",
                  v => Help = v != null }
            };

            Extra = Options.Parse(args);
        }
Beispiel #2
0
        protected IEntity ReadObject(XmlReader reader, ObjectDescription ObjectType)
        {
            IEntity ob = ObjectType.CreateInstance();

            //foreach (string propName in ObjectType.Properties.Keys)
            //{
            if (reader.Name == ObjectType.ObjectType.Name)
            {
                ob.Id   = int.Parse(reader.GetAttribute("Id"));
                ob.Name = reader.GetAttribute("Name");
                do
                {
                    SkipWhiteSpace(reader);
                    if (reader.Name == ObjectType.TableName &&
                        reader.NodeType == XmlNodeType.EndElement)
                    {
                        break;                        // The entuty have been read
                    }
                    string propName = reader.Name;
                    if (ObjectType.PropertyExists(propName))                       //   != null)
                    {
                        bool     doRead = true;
                        object[] attrs  = ObjectType.GetProperty(propName).GetCustomAttributes(true);
                        if (attrs != null && attrs.Length != 0)
                        {
                            foreach (object attr in attrs)
                            {
                                if (attr is NonPersistentAttribute)
                                {
                                    doRead = false;
                                }
                                if (attr is ReferenceAttribute)
                                {
                                    if (reader.MoveToFirstAttribute())
                                    {
                                        MemberAttributes attribs = new MemberAttributes();
                                        do
                                        {
                                            //reader.ReadAttributeValue();
                                            attribs.Add(reader.Name, reader.Value);
                                        } while (reader.MoveToNextAttribute());
                                        reader.MoveToElement();
                                        ob.Attributes.Add(propName, attribs);
                                    }
                                }
                            }
                        }
                        if (!doRead)
                        {
                            reader.Read();
                            continue;
                        }
                        if (ObjectType.GetProperty(propName).PropertyType.IsArray)
                        {
                            ReadArrayProp(ref ob, ObjectType.GetProperty(propName), reader);
                            reader.Read();
                            continue;
                        }
                        object value = reader.ReadElementContentAs(ObjectType.GetProperty(propName).PropertyType, null);
                        ObjectType.SetReadPropertyValue(propName, ob, value);
                    }
                } while (reader.Name != ObjectType.TableName && reader.NodeType != XmlNodeType.EndElement);
            }
            //}
            return(ob);
        }