Beispiel #1
0
        public static SQLPropertyInfo FromPropertyInfo(PropertyInfo pi, SQLTypeInfo TypeInfo)
        {
            //If it's SQL ignored, just return null
            if (pi.GetFirstAttribute <SQLIgnoredFieldAttribute>() != null)
            {
                return(null);
            }

            SQLPropertyInfo myResult = new SQLPropertyInfo(pi, TypeInfo);

            //Mark as read only now, if applicable
            myResult.ReadOnly = (pi.GetFirstAttribute <SQLReadOnlyFieldAttribute>() != null);

            myResult.KeyField = pi.GetFirstAttribute <SQLKeyFieldAttribute>();

            //Set the default mappings for standard properties
            SQLFieldAttribute FieldAttribute = pi.GetFirstAttribute <SQLFieldAttribute>();

            //Set the primary field name based on the field attribute if specified, or the property name itself if not
            myResult.DatabaseFieldName = (FieldAttribute == null ? myResult.PropertyInfo.Name : FieldAttribute.FieldName);

            //If the database field is a function of any kind it has to be read-only
            if (myResult.DatabaseFieldName.Contains('('))
            {
                myResult.ReadOnly = true;
            }
            else
            {
                //It should be an updatable property (unless flagged as read only by the user);
                //The update from property is always this property's name
                myResult.UpdateFromProperty = pi.Name;
            }

            return(myResult);
        }
Beispiel #2
0
        private static SQLTypeInfo GetSQLInfo(Type T, string Prefix = "")
        {
            SQLTypeInfo myResult = new SQLTypeInfo();

            //Add this item to the cached type info now that the object exists and we know the type
            CachedSQLTypeInfos.Add(T, myResult);

            //Get the table name to pull the class data from
            SQLTableAttribute TableAttribute = T.GetFirstAttribute <SQLTableAttribute>();

            //If no table attribute is specified, default to the class name...
            if (TableAttribute == null)
            {
                myResult.TableName = T.Name;
            }
            else
            {
                myResult.TableName = TableAttribute.TableName;
            }

            //Load the sql information for each property of the class type that's a key field
            foreach (PropertyInfo pi in T.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).Where(x => x.GetFirstAttribute <SQLKeyFieldAttribute>() != null))
            {
                SQLPropertyInfo sqlPI = SQLPropertyInfo.FromPropertyInfo(pi, myResult);

                if (sqlPI != null)
                {
                    myResult.Properties.Add(sqlPI);
                }
            }

            myResult.KeyFields = (from x in myResult.Properties where x.KeyField != null select x).ToList();

            if (myResult.KeyFields.Count == 0)
            {
                myResult.KeyType = SQLKeyType.None;
            }
            else if (myResult.KeyFields.Count == 1)
            {
                if (myResult.KeyFields[0].KeyField.AutoNumber)
                {
                    myResult.KeyType = SQLKeyType.AutoNumber;
                }
                else
                {
                    myResult.KeyType = SQLKeyType.Single;
                }
            }
            else
            {
                myResult.KeyType = SQLKeyType.Multiple;
            }

            //Load the sql information for each property of the class type that's not a key field
            foreach (PropertyInfo pi in T.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).Where(x => x.GetFirstAttribute <SQLKeyFieldAttribute>() == null))
            {
                SQLPropertyInfo sqlPI = SQLPropertyInfo.FromPropertyInfo(pi, myResult);

                //Skip SQLIgnored Properties
                if (sqlPI != null)
                {
                    myResult.Properties.Add(sqlPI);
                }
            }

            BuildSelectSQL(myResult);

            return(myResult);
        }
Beispiel #3
-1
        public static SQLPropertyInfo FromPropertyInfo(PropertyInfo pi, SQLTypeInfo TypeInfo)
        {
            //If it's SQL ignored, just return null
            if (pi.GetFirstAttribute<SQLIgnoredFieldAttribute>() != null)
            {
                return null;
            }

            SQLPropertyInfo myResult = new SQLPropertyInfo(pi, TypeInfo);

            //Mark as read only now, if applicable
            myResult.ReadOnly = (pi.GetFirstAttribute<SQLReadOnlyFieldAttribute>() != null);

            myResult.KeyField = pi.GetFirstAttribute<SQLKeyFieldAttribute>();

            //Set the default mappings for standard properties
            SQLFieldAttribute FieldAttribute = pi.GetFirstAttribute<SQLFieldAttribute>();

            //Set the primary field name based on the field attribute if specified, or the property name itself if not
            myResult.DatabaseFieldName = (FieldAttribute == null ? myResult.PropertyInfo.Name : FieldAttribute.FieldName);

            //If the database field is a function of any kind it has to be read-only
            if (myResult.DatabaseFieldName.Contains('('))
            {
                myResult.ReadOnly = true;
            }
            else
            {
                //It should be an updatable property (unless flagged as read only by the user);
                //The update from property is always this property's name
                myResult.UpdateFromProperty = pi.Name;
            }

            return myResult;
        }