GetFieldsOrdered() public static method

public static GetFieldsOrdered ( Type type ) : IList
type System.Type
return IList
Exemplo n.º 1
0
        public static FieldInfo GetFieldByName(Type type, string name)
        {
            IList <FieldInfo> fields = SEntity.GetFieldsOrdered(type);

            foreach (FieldInfo field in fields)
            {
                if (field.Name.Equals(name))
                {
                    return(field);
                }
            }

            return(null);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Marks object as in-use (setting Exists to True) such that any unmarked objects may then be garbage collected.
        /// </summary>
        public void Mark()
        {
            if (this.Existing)
            {
                return;
            }

            this.Existing = true;

            Type t = this.GetType();
            IList <FieldInfo> listFields = SEntity.GetFieldsOrdered(t);

            foreach (FieldInfo field in listFields)
            {
                if (typeof(SEntity).IsAssignableFrom(field.FieldType))
                {
                    SEntity obj = field.GetValue(this) as SEntity;
                    if (obj != null)
                    {
                        obj.Mark();
                    }
                }
                else if (field.FieldType.IsGenericType && field.FieldType.GetGenericTypeDefinition() == typeof(List <>) &&
                         typeof(SEntity).IsAssignableFrom(field.FieldType.GetGenericArguments()[0]))

                {
                    System.Collections.IList list = (System.Collections.IList)field.GetValue(this) as System.Collections.IList;
                    if (list != null)
                    {
                        foreach (object obj in list)
                        {
                            if (obj is SEntity)
                            {
                                SEntity ent = (SEntity)obj;
                                ent.Mark();
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        public virtual object Clone()
        {
            Type t = this.GetType();

            // make a copy, attached to broker
            SEntity clone = (SEntity)Activator.CreateInstance(t);

            // reference all registered fields
            IList <FieldInfo> fields = SEntity.GetFieldsOrdered(t);

            foreach (FieldInfo field in fields)
            {
                if (field.FieldType.IsValueType || field.FieldType == typeof(string))
                {
                    // copy over value types
                    object val = field.GetValue(this);
                    field.SetValue(clone, val);
                }
                else if (field.FieldType.IsInterface || typeof(SEntity).IsAssignableFrom(field.FieldType))
                {
                    // make unique copy of referenced type except for owner history!!!
                    object val = field.GetValue(this);
                    if (val is SEntity)
                    {
                        SEntity sentity = (SEntity)val;

                        SEntity valclone = (SEntity)sentity.Clone();
                        field.SetValue(clone, valclone);
                    }
                    else
                    {
                        field.SetValue(clone, val);
                    }
                }
                else if (typeof(IList).IsAssignableFrom(field.FieldType))
                {
                    IList listSource = (IList)field.GetValue(this);
                    if (listSource != null)
                    {
                        // don't copy collections, but initialize new collection
                        System.Collections.IList listClone = (System.Collections.IList)Activator.CreateInstance(field.FieldType);
                        field.SetValue(clone, listClone);

                        Type[] genericargs = field.FieldType.GetGenericArguments();
                        if (genericargs.Length == 1)
                        {
                            foreach (object element in listSource)
                            {
                                object elemClone = null;

                                // clone resources -- don't carry over rooted objects
                                if (element is ICloneable)
                                {
                                    // clone resources, list of list, e.g. IfcBSplineSurface
                                    elemClone = ((ICloneable)element).Clone();
                                }
                                else
                                {
                                    // i.e. length coordinate
                                    elemClone = element;
                                }

                                // now add to list, INCLUDING IF NULL such as blank entries of table
                                listClone.Add(elemClone);
                            }
                        }
                    }
                }
            }

            return(clone);
        }