using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace W
{
    class Program
    {
        static void Main(string[] args)
        {
            Type t = typeof(Contact);
            PropertyInfo[] properties = t.GetProperties();
            foreach(PropertyInfo property in properties)
            {
                Console.Write("[" + property.Name + "] ");
                object[] attributes1 = property.GetCustomAttributes(typeof(FeldtypAttribute), false);
                foreach (FeldtypAttribute feldtyp in attributes1)
                {
                    Console.Write("[" + feldtyp.Typ + "] ");
                    if (feldtyp.Max != -1)
                    {
                        Console.Write("(");
                        if (feldtyp.Min != -1)
                            Console.Write(feldtyp.Min + ",");
                        Console.Write(feldtyp.Max + ")");
                    }
                }
                object[] attributes2 = property.GetCustomAttributes(typeof(IdentityAttribute), false);
                foreach (IdentityAttribute notnull in attributes2)
                    Console.Write(" IDENTITY");
                object[] attributes3 = property.GetCustomAttributes(typeof(NotNullAttribute), false);
                foreach (NotNullAttribute f in attributes3)
                    Console.Write(" NOT NULL");
                Console.WriteLine();
            }
            Console.Read();
        }
    }

    [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
    public class FeldtypAttribute : Attribute
    {
        private string typ;
        public string Typ
        {
            get { return typ; }
        }
        private int min;
        public int Min
        {
            get { return min; }
        }
        private int max;
        public int Max
        {
            get { return max; }
        }

        public FeldtypAttribute(string typ, int min, int max)
        {
            this.typ = typ;
            this.min = min;
            this.max = max;
        }

        public FeldtypAttribute(string typ, int max) : this(typ, -1, max) { }

        public FeldtypAttribute(string typ) : this(typ, -1, -1) { }
    }

    [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
    public class NotNullAttribute : Attribute {}

    [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
    public class IdentityAttribute : Attribute {}

    public class Contact
    {
        private int id;
        [Feldtyp("int", 1, 1)]
        [Identity]
        [NotNull]
        public int Id
        {
            get { return id; }
            set { id = value; }
        }

        private string email;
        [Feldtyp("varchar", 80)]
        [NotNull]
        public string Email
        {
            get { return email; }
            set { email = value; }
        }

        private string address;
        [Feldtyp("varchar", 80)]
        [NotNull]
        public string Address
        {
            get { return address; }
            set { address = value; }
        }

        private string city;
        [Feldtyp("varchar", 50)]
        [NotNull]
        public string City
        {
            get { return city; }
            set { city = value; }
        }

        private string name;
        [Feldtyp("varchar", 50)]
        [NotNull]
        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        private int age;
        [Feldtyp("int")]
        [NotNull]
        public int Age
        {
            get { return age; }
            set { age = value; }
        }
    }
}
