Ejemplo n.º 1
0
 /// <summary>
 /// Gets a array of constructor arguments to build an object with
 /// </summary>
 /// <param name="dstore">The datastore.</param>
 /// <param name="parminfo">The parms for the constructor.</param>
 /// <param name="ti">The type info</param>
 /// <param name="row">The row in the result set to use</param>
 /// <param name="dt">The query result set</param>
 /// <returns></returns>
 public static object[] SetConstructorArguments(this IDataStore dstore, ParameterInfo[] parminfo, DatabaseTypeInfo ti, IQueryRow dt)
 {
     object[] toReturn = new object[parminfo.Length];
     for (int i = 0; i < parminfo.Length; i++)
     {
         ParameterInfo curr = parminfo[i];
         if (ti.IsCompilerGenerated)
         {
             if (curr.ParameterType.IsSystemType())
             {
                 toReturn[i] = dstore.Connection.CLRConverter.ConvertToType(dt.GetDataForRowField(curr.Name), parminfo[i].ParameterType);
             }
             else
             {
                 toReturn[i] = BuildObject(dstore, dt, dstore.Connection.CommandGenerator.TypeParser.GetTypeInfo(curr.ParameterType));
             }
         }
         else
         {
             //most system classes are handled just nicely by the type converter, only interested in user defined classes
             if (dt.FieldHasMapping(ti.DataFields[i].FieldName) && curr.ParameterType.IsSystemType())
             {
                 toReturn[i] = dstore.Connection.CLRConverter.ConvertToType(dt.GetDataForRowField(parminfo[i].Name), parminfo[i].ParameterType);
             }
             else
             {
                 toReturn[i] = BuildObject(dstore, dt, dstore.Connection.CommandGenerator.TypeParser.GetTypeInfo(curr.ParameterType));
             }
         }
     }
     return(toReturn);
 }
Ejemplo n.º 2
0
        private void AddColumn(IDataStore dstore, IQueryRow columns, DBObject t)
        {
            Column toAdd = new Column();

            toAdd.ColumnLength = ((string)CLRConverter.ConvertToType(columns.GetDataForRowField("COLUMN_SIZE"), typeof(string))).Trim();
            toAdd.DataType     = ((string)CLRConverter.ConvertToType(columns.GetDataForRowField("TYPE_NAME"), typeof(string))).Trim();
            toAdd.DefaultValue = null;
            toAdd.IsPrimaryKey = false;
            toAdd.Name         = ((string)CLRConverter.ConvertToType(columns.GetDataForRowField("COLUMN_NAME"), typeof(string))).Trim();

            t.Columns.Add(toAdd);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Sets the fields on an object
        /// </summary>
        /// <param name="dstore">The datastore.</param>
        /// <param name="info">The information for the type</param>
        /// <param name="row">The row to pull from</param>
        /// <param name="dataItem">The object to set the data on</param>
        public static void SetFieldData(this IDataStore dstore, DatabaseTypeInfo info, IQueryRow row, object dataItem)
        {
            foreach (DataFieldInfo dfi in info.DataFields)
            {
                object item = row.GetDataForRowField(dfi.FieldName);
                if (item != null)
                {
                    if (dfi.PropertyType.IsAssignableFrom(item.GetType()))
                    {
                        dfi.Setter(dataItem, item);
                    }
                    else
                    {
                        try
                        {
                            if (!dfi.PropertyType.IsSystemType() && !dfi.PropertyType.IsEnum)
                            {
                                dfi.Setter(dataItem, BuildObject(dstore, row, dstore.Connection.CommandGenerator.TypeParser.GetTypeInfo(dfi.PropertyType)));
                            }
                            else
                            {
                                object fieldValue = dstore.Connection.CLRConverter.ConvertToType(item, dfi.PropertyType);
                                if (fieldValue == null)
                                {//if the value comes back null, lets use the default for the property type (null, zero, whatever)
                                    SetDefaultValue(dataItem, dfi);
                                }
                                else
                                {
                                    dfi.Setter(dataItem, fieldValue);
                                }
                            }
                        }
                        catch
                        {//attempt to set to default
                            SetDefaultValue(dataItem, dfi);
                        }
                    }
                }
                else
                {
                    int i = 1;
                    i++;
                }
            }

            if (info.AdditionalInit != null)
            {
                info.AdditionalInit.ForEach(R => R.Invoke(dstore, dataItem));
            }
        }