Beispiel #1
0
        /// <summary>
        /// Convert collection to dataset.
        /// </summary>
        /// <returns>DataSet</returns>
        public System.Data.DataSet ToDataSet()
        {
            System.Data.DataSet ds = new System.Data.DataSet();

            for (int i = 0; i < ContainsType.Length; i++)
            {
                ds.Tables.Add(new System.Data.DataTable(ContainsType[i].Name));
                System.Data.DataTable dt = ds.Tables[i];
                for (int j = 0; j < this.InnerList.Count; j++)
                {
                    if (this.InnerList[j].GetType() == ContainsType[i])
                    {
                        OrcaLogic.Reflection.PropertyTable pt = OrcaLogic.Reflection.ReflectionHelper.GetProperties(InnerList[j]);
                        PropertyInfo[] propertyInfo           = pt.GetSimpleMembers();
                        if (dt.Columns.Count == 0)
                        {
                            BuildColumnCollection(propertyInfo, dt);
                        }

                        System.Data.DataRow dr = dt.NewRow();
                        dr.ItemArray = this.GetItemArray(propertyInfo, this.InnerList[j]);
                        dt.Rows.Add(dr);
                    }
                }
            }

            ds.AcceptChanges();

            return(ds);
        }
        /// <summary>
        /// Gets a property hash table for quick lookup for any object.
        /// </summary>
        /// <param name="any">Any object to get a property table for.</param>
        /// <returns>A property table or null if unable to obtain a table.</returns>
        public static PropertyTable GetProperties(object any)
        {
            PropertyTable match = null;

            lock(_proptable.SyncRoot)
            {
                // attempt to get a match
                match = _proptable[any.GetType()] as PropertyTable;
                // return it if we have one
                if (match != null) return match;
                // reflect the object into a new property table
                match = new PropertyTable(any);
                // cache it for future usage
                _proptable[any.GetType()] = match;
            }

            // return the match
            return match;
        }
Beispiel #3
0
        /// <summary>
        /// Sets the attributes of the class element with its own attributes.
        /// </summary>
        /// <param name="classElement">The class element to set attributes for.</param>
        /// <param name="any">Any object.</param>
        private static void SetAttributes(XmlElement classElement, object any)
        {
            // attemp to convert the generic object to a factory element
            IXmlFactoryElement factoryelement = any as IXmlFactoryElement;

            PropertyTable properties = new PropertyTable(any, BindingFlags.Instance | BindingFlags.Public);
            PropertyInfo pinfo = null;
            bool continueprocessing = false;

            // add any additional attributes that can not be extracted from the object
            if (factoryelement != null)
            {
                System.Collections.Specialized.NameValueCollection additionalattribs = factoryelement.AdditionalAttributes;
                if (additionalattribs != null && additionalattribs.Count > 0)
                {
                    for(int i = 0; i<additionalattribs.Count; i++)
                    {
                        classElement.SetAttribute(string.Format("{0}", additionalattribs.Keys[i]), string.Format("{0}", additionalattribs[additionalattribs.Keys[i]]));
                    }
                }
            }

            System.Collections.DictionaryEntry dentry;

            // process all the property members
            foreach(string membername in properties.MemberNames)
            {
                dentry = new System.Collections.DictionaryEntry(membername, null);
                pinfo = properties[membername];
                if (pinfo != null)
                {
                    try
                    {
                        dentry.Value = pinfo.GetValue(any, null);
                    }
                    catch
                    {
                        dentry.Value = null;
                    }
                    if (factoryelement != null)
                        continueprocessing = factoryelement.ProcessAttribute(ref dentry);
                    else
                        continueprocessing = true; // just keep going without constraints

                    // if there is no reason to quit processing then set attributes.
                    if (continueprocessing)
                        classElement.SetAttribute(string.Format("{0}", dentry.Key), string.Format("{0}", dentry.Value));
                }
            }
        }