Exemple #1
0
 protected abstract Task VerifyTable(DataSet.Define define);
Exemple #2
0
        public static DataSet.Define GetDefine <TKey, TColumn>(string name)
            where TKey : Key <TKey>
            where TColumn : Column <TColumn>
        {
            DefineIndex index = new DefineIndex
            {
                Name   = name,
                Key    = typeof(TKey),
                Column = typeof(TColumn)
            };

            DataSet.Define define;
            if (defines.TryGetValue(index, out define))
            {
                return(define);
            }
            return(defines.GetOrAdd(index, idx =>
            {
                DataSet.Define def = new DataSet.Define(idx.Name);
                Dictionary <uint, DataSet.Type> keytypes = new Dictionary <uint, DataSet.Type>();
                foreach (MemberInfo member in Key <TKey> .Members)
                {
                    foreach (Attribute attribute in member.GetCustomAttributes(false))
                    {
                        KeyAttribute keyattr = attribute as KeyAttribute;
                        if (keyattr != null)
                        {
                            if (keyattr.Type.HasValue)
                            {
                                keytypes.Add(keyattr.Index, keyattr.Type.Value);
                            }
                            else
                            {
                                Type type = member.MemberType == MemberTypes.Field
                                                                        ? (member as FieldInfo).FieldType
                                                                        : (member as PropertyInfo).PropertyType;
                                keytypes.Add(keyattr.Index, SelectType(type));
                            }
                            break;
                        }
                    }
                }
                Dictionary <string, DataSet.Type> columntypes = new Dictionary <string, DataSet.Type>();
                foreach (MemberInfo member in Column <TColumn> .Members.Values)
                {
                    foreach (Attribute attribute in member.GetCustomAttributes(false))
                    {
                        ColumnAttribute columnattr = attribute as ColumnAttribute;
                        if (columnattr != null)
                        {
                            string columnname = columnattr.Auto ? member.Name : columnattr.Name;
                            if (columnattr.Type.HasValue)
                            {
                                columntypes.Add(columnname, columnattr.Type.Value);
                            }
                            else
                            {
                                Type type = member.MemberType == MemberTypes.Field
                                                                        ? (member as FieldInfo).FieldType
                                                                        : (member as PropertyInfo).PropertyType;
                                columntypes.Add(columnname, SelectType(type));
                            }
                            break;
                        }
                    }
                }
                for (uint i = 0; i < keytypes.Count; ++i)
                {
                    def.AddKey(keytypes[i]);
                }
                foreach (var kv in columntypes)
                {
                    def.AddColumn(kv.Key, kv.Value);
                }
                return def;
            }));
        }