/// <summary> /// Creates the storage description. /// </summary> /// <param name="type">The type.</param> /// <param name="includeReverseLookup">if set to <c>true</c> include reverse lookup].</param> /// <returns></returns> internal static StorageItemsList CreateStorageDescription(Type type, bool includeReverseLookup) { StorageItemsList storage = new StorageItemsList(); SortedList <string, MemberInfo> _removed = new SortedList <string, MemberInfo>(); CreateStorageDescription(type, storage, _removed, includeReverseLookup); return(storage); }
/// <summary> /// Creates the storage description without reverse lookup columns for all types derived from <paramref name="type"/>. /// </summary> /// <param name="type">The type.</param> /// <returns></returns> internal static Dictionary <string, StorageItemsList> CreateStorageDescription(Type type) { Dictionary <string, Type> _types = type.GetDerivedTypes(); Dictionary <string, StorageItemsList> _ret = new Dictionary <string, StorageItemsList>(); foreach (KeyValuePair <string, Type> _typex in _types) { StorageItemsList _storage = new StorageItemsList(); SortedList <string, MemberInfo> _removed = new SortedList <string, MemberInfo>(); CreateStorageDescription(_typex.Value, _storage, _removed, false); _ret.Add(_typex.Key, _storage); } return(_ret); }
//methods private static void CreateStorageDescription(Type type, StorageItemsList storage, SortedList <string, MemberInfo> removed, bool includeReverseLookup) { Dictionary <string, MemberInfo> _mmbrs = type.GetDictionaryOfMembers(); foreach (MemberInfo _ax in from _pidx in _mmbrs where _pidx.Value.MemberType == MemberTypes.Property select _pidx.Value) { if (removed.ContainsKey(_ax.Name)) { continue; } foreach (Attribute _AttributeX in _ax.GetCustomAttributes(false)) { if (_AttributeX is RemovedColumnAttribute) { if (!removed.ContainsKey(_ax.Name)) { removed.Add(_ax.Name, _ax); } break; } if (!(_AttributeX is DataAttribute)) { continue; } DataAttribute _dataAttribute = _AttributeX as DataAttribute; AssociationAttribute _att = _dataAttribute as AssociationAttribute; if (_att != null && !includeReverseLookup && _att.MultivalueType == AssociationType.Backward) { break; } ColumnAttribute _columnAttribute = _dataAttribute as ColumnAttribute; if (_columnAttribute != null) { if (_columnAttribute.FieldType.Equals(FieldType.Lookup.ToString()) || _columnAttribute.FieldType.Equals(FieldType.WorkflowStatus.ToString()) || (_columnAttribute.FieldType.Equals(FieldType.User.ToString()) && _columnAttribute.IsLookupId) ) { break; } } //The property could be overridden in the derived class and the storage is in the base class. StorageItem _newStorageItem = null; if (!storage.TryGetValue(_ax.Name, out _newStorageItem)) { _newStorageItem = new StorageItem(_ax.Name, _dataAttribute); storage.Add(_ax.Name, _newStorageItem); } if (!_mmbrs.Keys.Contains <string>(_dataAttribute.Storage)) { break; } _newStorageItem.m_Storage = _mmbrs[_dataAttribute.Storage] as FieldInfo; if (_columnAttribute != null && _columnAttribute.FieldType.Contains(FieldType.Counter.ToString())) { storage.IdStorage = _newStorageItem; } break; } } if (type.BaseType != typeof(Object)) { CreateStorageDescription(type.BaseType, storage, removed, includeReverseLookup); } else { Debug.Assert(storage.IdStorage != null); } }