private void FindInherited(Type type, SqlTable table)
		{
			if (type.IsDefined(typeof(MapAttribute), false))
			{
				object[] attrs = type.GetCustomAttributes(typeof(MapAttribute), false);
				foreach (MapAttribute attr in attrs)
				{
					IDataBridge data = null;
					BindingFlags flags = BindingFlags.Instance|BindingFlags.Public|BindingFlags.NonPublic;
					MemberInfo member = type.GetProperty(attr.Field, flags);
					if (member != null)
					{
						data = new PropertyBridge((PropertyInfo)member);
					}
					else
					{
						member = type.GetField(attr.Field, flags);
						if (member != null)
							data = new FieldBridge((FieldInfo)member);
						else
							throw new LightException("member " + attr.Field + " not found in class " + type.Name);
					}
					if (attr.Name == null || attr.Name.Length == 0)
						attr.Name = member.Name;
					SqlColumn column = new SqlColumn(table, attr.Name, data);
					if (attr.Alias == null || attr.Alias.Length == 0)
						column.Alias = attr.Field;
					else
						column.Alias = attr.Alias;
					column.IsID = attr.ID;
					column.IsPK = attr.PK;
					table.Add(column);
				}
			}
		}
Пример #2
0
 private void FindInherited(Type type, SqlTable table)
 {
     if (type.IsDefined(typeof(MapAttribute), false))
     {
         object[] attrs = type.GetCustomAttributes(typeof(MapAttribute), false);
         foreach (MapAttribute attr in attrs)
         {
             IDataBridge  data   = null;
             BindingFlags flags  = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
             MemberInfo   member = type.GetProperty(attr.Field, flags);
             if (member != null)
             {
                 data = new PropertyBridge((PropertyInfo)member);
             }
             else
             {
                 member = type.GetField(attr.Field, flags);
                 if (member != null)
                 {
                     data = new FieldBridge((FieldInfo)member);
                 }
                 else
                 {
                     throw new LightException("member " + attr.Field + " not found in class " + type.Name);
                 }
             }
             if (attr.Name == null || attr.Name.Length == 0)
             {
                 attr.Name = member.Name;
             }
             SqlColumn column = new SqlColumn(table, attr.Name, data);
             if (attr.Alias == null || attr.Alias.Length == 0)
             {
                 column.Alias = attr.Field;
             }
             else
             {
                 column.Alias = attr.Alias;
             }
             column.IsID = attr.ID;
             column.IsPK = attr.PK;
             table.Add(column);
         }
     }
 }
Пример #3
0
 private void ProcessFields(Type type, SqlTable table)
 {
     FieldInfo[] fields = type.GetFields(
         BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
     foreach (FieldInfo field in fields)
     {
         if (!field.IsDefined(typeof(ColumnAttribute), false))
         {
             continue;
         }
         ColumnAttribute colAttr = (ColumnAttribute)
                                   field.GetCustomAttributes(typeof(ColumnAttribute), false)[0];
         FieldBridge data = new FieldBridge(field);
         if (colAttr.Name == null || colAttr.Name.Length == 0)
         {
             colAttr.Name = field.Name;
         }
         SqlColumn column = new SqlColumn(table, colAttr.Name, data);
         if (colAttr.Alias == null || colAttr.Alias.Length == 0)
         {
             column.Alias = field.Name;
         }
         else
         {
             column.Alias = colAttr.Alias;
         }
         if (field.IsDefined(typeof(IDAttribute), false))
         {
             column.IsID = true;
         }
         if (field.IsDefined(typeof(PKAttribute), false))
         {
             column.IsPK = true;
         }
         table.Add(column);
     }
 }
		private void ProcessProperties(Type type, SqlTable table)
		{
			PropertyInfo[] fields = type.GetProperties(
				BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
			foreach (PropertyInfo field in fields)
			{
				if (!field.IsDefined(typeof(ColumnAttribute), false))
					continue;
				ColumnAttribute colAttr = (ColumnAttribute)
					field.GetCustomAttributes(typeof(ColumnAttribute), false)[0];
				PropertyBridge data = new PropertyBridge(field);
				if (colAttr.Name == null || colAttr.Name.Length == 0)
					colAttr.Name = field.Name;
				SqlColumn column = new SqlColumn(table, colAttr.Name, data);
				if (colAttr.Alias == null || colAttr.Alias.Length == 0)
					column.Alias = field.Name;
				else
					column.Alias = colAttr.Alias;
				if (field.IsDefined(typeof(IDAttribute), false))
					column.IsID = true;
				if (field.IsDefined(typeof(PKAttribute), false))
					column.IsPK = true;
				table.Add(column);
			}
		}