示例#1
0
        public static SchemaObjectBase CreateObject(string schemaTypeString)
        {
            ObjectSchemaSettings settings = ObjectSchemaSettings.GetConfig();

            ObjectSchemaConfigurationElement schemaElement = settings.Schemas[schemaTypeString];

            (schemaElement != null).FalseThrow <NotSupportedException>("不支持的对象类型: {0}", schemaTypeString);

            SchemaObjectBase result = null;

            if (schemaElement.GetTypeInfo() == typeof(SCGenericObject))
            {
                result = new SCGenericObject(schemaTypeString);
            }
            else
            {
                result = (SchemaObjectBase)schemaElement.CreateInstance(schemaTypeString);
                if (result.SchemaType != schemaTypeString)
                {
                    throw new SchemaObjectErrorCreationException(string.Format("无法根据指定的SchemaType {0} 创建对应的类型", schemaTypeString));
                }
            }

            return(result);
        }
        public void LoadFromDataReader(IDataReader reader)
        {
            Dictionary <string, ObjectSchemaConfigurationElement> schemaElements = new Dictionary <string, ObjectSchemaConfigurationElement>(StringComparer.OrdinalIgnoreCase);

            ObjectSchemaSettings settings = ObjectSchemaSettings.GetConfig();

            while (reader.Read())
            {
                string schemaType = (string)reader["SchemaType"];
                ObjectSchemaConfigurationElement schemaElement = null;

                if (schemaElements.TryGetValue(schemaType, out schemaElement) == false)
                {
                    schemaElement = settings.Schemas[schemaType];

                    schemaElements.Add(schemaType, schemaElement);
                }

                if (schemaElement != null)
                {
                    T obj = (T)schemaElement.CreateInstance(schemaType);

                    obj.FromString((string)reader["Data"]);

                    ORMapping.DataReaderToObject(reader, obj);

                    if (this.ContainsKey(obj.ID) == false)
                    {
                        this.Add(obj);
                    }
                }
            }
        }
示例#3
0
        public static DESchemaObjectBase CreateObject(string schemaTypeString)
        {
            ObjectSchemaSettings settings = ObjectSchemaSettings.GetConfig();

            ObjectSchemaConfigurationElement schemaElement = settings.Schemas[schemaTypeString];

            (schemaElement != null).FalseThrow <NotSupportedException>("不支持的对象类型: {0}", schemaTypeString);

            DESchemaObjectBase result = null;

            if (schemaElement.GetTypeInfo() == typeof(DEGenericObject))
            {
                result = new DEGenericObject(schemaTypeString);
            }
            else
            {
                result = (DESchemaObjectBase)schemaElement.CreateInstance();
            }

            return(result);
        }
        public void LoadFromDataView(DataView view, Action <DataRow, T> action)
        {
            Dictionary <string, ObjectSchemaConfigurationElement> schemaElements = new Dictionary <string, ObjectSchemaConfigurationElement>(StringComparer.OrdinalIgnoreCase);

            ObjectSchemaSettings settings = ObjectSchemaSettings.GetConfig();

            foreach (DataRowView drv in view)
            {
                string schemaType = (string)drv["SchemaType"];

                ObjectSchemaConfigurationElement schemaElement = null;

                if (schemaElements.TryGetValue(schemaType, out schemaElement) == false)
                {
                    schemaElement = settings.Schemas[schemaType];

                    schemaElements.Add(schemaType, schemaElement);
                }

                if (schemaElement != null)
                {
                    T obj = (T)schemaElement.CreateInstance(schemaType);

                    obj.FromString((string)drv["Data"]);

                    ORMapping.DataRowToObject(drv.Row, obj);

                    if (action != null)
                    {
                        action(drv.Row, obj);
                    }

                    if (this.ContainsKey(obj.ID) == false)
                    {
                        this.Add(obj);
                    }
                }
            }
        }