internal static clsTypeInfo CreateTypeInfo(Type t, Type map = null)
        {
            var myType = new clsTypeInfo() { TypeName = t.FullName, Type = t, MapType = map };

            var tiT = t.GetTypeInfo();
            var tiMap = map == null ? tiT : map.GetTypeInfo();

            // 1. get type attribs
            var attribTable = tiMap.GetCustomAttribute<TSMTableAttribute>();
            if (attribTable != null && !string.IsNullOrWhiteSpace(attribTable.TableName))
                myType.TableName = attribTable.TableName;
            else
                myType.TableName = tiMap.Name; // tiT.Name;

            var attribQuery = tiMap.GetCustomAttribute<TSMQueryAttribute>();
            if (attribQuery != null && !string.IsNullOrWhiteSpace(attribQuery.TSMSqlQuery))
                myType.TSMSqlQuery = attribQuery.TSMSqlQuery;

            // TSM version attrib?
            var attribTableVersion = tiMap.GetCustomAttribute<TSMVersionAttribute>();
            if (attribTableVersion != null)
                myType.RequiredVersion = attribTableVersion.ServerVersion;

            myType.CreateObject = CreateConstructorMethod(t, tiT);

            // 2. foreach(prop) get attrib.
            // create source hash.
            SortedDictionary<string, PropertyInfo> tiPropHash = null;
            if (map != null)
            {
                tiPropHash = new SortedDictionary<string, PropertyInfo>();
                foreach (var p in tiT.DeclaredProperties)
                    tiPropHash.Add(p.Name, p);
            }

            foreach (var p in tiMap.DeclaredProperties)
            {
                if (map != null)
                    if (!tiPropHash.ContainsKey(p.Name))
                        continue; // if not matching key name, skip it.

                var ignoreAttrib = p.GetCustomAttribute<TSMIgnore>();
                if (ignoreAttrib != null)
                    continue; //TODO: Should we instead mark prop as ignore but keep it?

                var cT = new clsColumnInfo() { MemberName = p.Name };

                var attribColumn = p.GetCustomAttribute<TSMColumnAttribute>();
                if (attribColumn != null && !string.IsNullOrWhiteSpace(attribColumn.ColumnName))
                    cT.ColumnName = attribColumn.ColumnName;
                else
                    cT.ColumnName = cT.MemberName;

                // TSM version attrib?
                var attribVersion = p.GetCustomAttribute<TSMVersionAttribute>();
                if (attribVersion != null)
                    cT.RequiredVersion = attribVersion.ServerVersion;

                // CSV Convert info
                cT.MemberType = p.PropertyType;
                cT.SetValue = CreateSetProperty(p);
                cT.DataType = GetTSMDataType(p.PropertyType);

                //is nullable
                if (cT.MemberType.IsGenericType &&
                    cT.MemberType.GetGenericTypeDefinition() == typeof(Nullable))
                        cT.IsNullable = true;                

                myType.Add(cT);
            }


            return myType;
        }
Example #2
0
 public void Add(clsColumnInfo ci)
 {
     Columns.Add(ci);
     ColumnHash.Add(ci.ColumnName, ci);
     MemberHash.Add(ci.MemberName, ci);
 }