Exemplo n.º 1
0
        /// <summary>
        /// Process the given type and construct the corresponding ObjectMap instance.
        /// </summary>
        /// <param name="broker">The PersistenceBroker to use for obtaining metadata on the type. If
        /// null is passed the DefaultProvider will be used.</param>
        /// <param name="type">The type to process.</param>
        /// <returns>An ObjectMap instance describing the type</returns>
        protected static ObjectMap ConstructMap(PersistenceBroker broker, Type type)
        {
            Check.Verify(IsTypeSupported(type), Error.UnsupportedType, type);
            ObjectMap map = new ObjectMap(broker, type);
            // get persistence attributes
            IList memberAttributeInfos = Reflector.FindMembers(Reflector.InstanceCriteria,
                                                               type, false, typeof(TableColumnAttribute),
                                                               typeof(PrimaryKeyAttribute), typeof(ForeignKeyAttribute),
                                                               typeof(ConcurrencyAttribute), typeof(SoftDeleteAttribute),
                                                               typeof(SequenceNameAttribute), typeof(InheritanceAttribute));

            foreach (MemberAttributeInfo mai in memberAttributeInfos)
            {
                map.Fields.Add(new FieldMap(map, mai));
            }
            // get custom view(s)
            memberAttributeInfos = Reflector.FindMembers(Reflector.InstanceCriteria, type, true, typeof(CustomViewAttribute));
            foreach (MemberAttributeInfo mai in memberAttributeInfos)
            {
                if (mai.MemberInfo is PropertyInfo)
                {
                    foreach (CustomViewAttribute cv in mai.Attributes)
                    {
                        PropertyInfo pi = mai.MemberInfo as PropertyInfo;
                        // create a viewmap for this attribute
                        ViewMap vm = new ViewMap(map, pi.Name, pi.PropertyType, cv);
                        // add it to the specified view
                        map.AddViewColumn(cv.ViewName, vm);
                    }
                }
            }
            // get validation(s)
            memberAttributeInfos = Reflector.FindMembers(Reflector.InstanceCriteria, type, false,
                                                         typeof(ValidatorBaseAttribute));
            foreach (MemberAttributeInfo mai in memberAttributeInfos)
            {
                foreach (ValidatorBaseAttribute vb in mai.Attributes)
                {
                    PropertyInfo pi = mai.MemberInfo as PropertyInfo;
                    // create a validation map for this attribute
                    ValidationMap va = new ValidationMap(map, pi.Name, pi.PropertyType, vb);
                    // add it to the specified view
                    map.Validations.Add(va);
                }
            }

            // analyze the actual database schema and update our internal maps accordingly
            if (GentleSettings.AnalyzerLevel != AnalyzerLevel.None)
            {
                if (broker == null)
                {
                    broker = new PersistenceBroker(type);
                }
                IDatabaseAnalyzer da = broker.Provider.GetAnalyzer();
                if (da != null)                  // not all persistence engines may support this
                {
                    da.UpdateObjectMap(map);
                }
            }
            // return the generated object <-> database map
            return(map);
        }
Exemplo n.º 2
0
		/// <summary>
		/// Adds a column to this view. 
		/// </summary>
		/// <param name="viewMap">The view map instance to use for this column</param>
		public void AddColumn( ViewMap viewMap )
		{
			viewMaps.Add( viewMap );
		}
Exemplo n.º 3
0
		/// <summary>
		/// Adds a column to the specified named DataView. The ViewMap is a small helper class
		/// used to connect DataView columns with object properties.
		/// </summary>
		/// <param name="viewName">The name of the DataView</param>
		/// <param name="viewMap">The ViewMap instance to add to this view</param>
		public void AddViewColumn( string viewName, ViewMap viewMap )
		{
			ObjectView view;
			if( ! views.ContainsKey( viewName ) )
			{
				view = new ObjectView( this, viewName );
				views[ viewName ] = view;
			}
			else
			{
				view = (ObjectView) views[ viewName ];
			}
			view.AddColumn( viewMap );
		}