コード例 #1
0
        private static void checkCache()
        {
            if (tableNameByRowType == null)
            {
                tableNameByRowType    = new Dictionary <Type, string>();
                moduleNameByTableName = new Dictionary <string, string>();

                foreach (AppModuleAttribute attr in AppModuleAttribute.Collection)
                {
                    var nestedTypes = attr.ModuleType.GetNestedTypes();
                    foreach (var type in nestedTypes)
                    {
                        if (typeof(ITable).IsAssignableFrom(type))
                        {
                            string tableName = null;
                            Type   rowType   = null;

                            var attribute = TableNameAttribute.GetAttribute(type);
                            if (attribute != null)
                            {
                                tableName = attribute.TableName;
                                rowType   = attribute.RowType;
                            }
                            else
                            {
                                var tableType = getTableBaseType(type);
                                if (tableType != null)
                                {
                                    rowType   = tableType.GetGenericArguments().First();
                                    attribute = TableNameAttribute.GetAttribute(rowType);
                                    if (attribute != null)
                                    {
                                        tableName = attribute.TableName;
                                    }
                                    else
                                    {
                                        var attributes = rowType.GetCustomAttributes(typeof(System.ComponentModel.DataAnnotations.Schema.TableAttribute), true);
                                        if (attributes.Length > 0)
                                        {
                                            tableName = ((System.ComponentModel.DataAnnotations.Schema.TableAttribute)attributes[0]).Name;
                                        }
                                    }
                                }
                            }

                            if (string.IsNullOrEmpty(tableName))
                            {
                                tableName = type.Name;
                            }

                            moduleNameByTableName.Add(tableName, attr.ModuleName);
                            if (rowType != null)
                            {
                                tableNameByRowType.Add(rowType, tableName);
                            }
                        }
                    }
                }
            }
        }
コード例 #2
0
ファイル: TableNameAttribute.cs プロジェクト: Ogiss/AbakTools
        public static string GetTableName(Type classType)
        {
            TableNameAttribute a = GetAttribute(classType);

            if (a != null)
            {
                return(a.tableName);
            }
            return(null);
        }