/// <summary> /// Converts a SQL parameter into a MetaObject so that it can be serialized and displayed through a dynamic editor /// </summary> /// <param name="parameter">The parameter to convert</param> /// <returns>A Meta representation of the SQL parameter</returns> public static DbMetaObject ToMetaObject(this SQLParameterInfo parameter) { if (parameter is null) { throw new System.ArgumentNullException(nameof(parameter)); } System.Type PersistenceType = TypeConverter.ToNetType(parameter.DATA_TYPE); IMetaType thisType = new MetaTypeHolder(PersistenceType); DbMetaObject toReturn = new DbMetaObject() { Property = new DbMetaProperty() { Name = parameter.PARAMETER_NAME, Type = thisType }, Type = thisType, Value = parameter.HAS_DEFAULT ? parameter.DEFAULT : null }; if (PersistenceType == typeof(System.DateTime)) { IMetaAttribute rangeAttribute = new MetaAttributeHolder(new RangeAttribute(PersistenceType, SqlDateTime.MinValue.ToString(), SqlDateTime.MaxValue.ToString()), false); List <IMetaAttribute> existingAttributes = toReturn.Property.Attributes.ToList(); existingAttributes.Add(rangeAttribute); toReturn.Property.Attributes = existingAttributes; } return(toReturn); }
/// <summary> /// Casts a DataTable into list of MetaObjects /// </summary> /// <param name="dt">The data table to be used as a source</param> /// <returns>A list of MetaObjects representing the data</returns> public static List <DbMetaObject> ToMetaObject(this DataTable dt) { if (dt is null) { throw new System.ArgumentNullException(nameof(dt)); } List <DbMetaObject> MetaRows = new List <DbMetaObject>(); foreach (DataRow dr in dt.Rows) { DbMetaObject row = new DbMetaObject(); foreach (DataColumn dc in dt.Columns) { DbMetaObject item = new DbMetaObject(); MetaTypeHolder objectType = new MetaTypeHolder(dc.DataType); item.Type = objectType; item.Property = new DbMetaProperty() { Type = objectType, Name = dc.ColumnName }; item.Value = dr[dc]?.ToString(); row.Properties.Add(item); } row.Type = new DbMetaType("SqlRow", row.Properties) { CoreType = CoreType.Reference }; MetaRows.Add(row); } return(MetaRows); }