コード例 #1
0
        public static void LoadReferences <T>(this IDbCommand dbCmd, T instance, IEnumerable <string> include = null)
        {
            var loadRef   = new LoadReferencesSync <T>(dbCmd, instance);
            var fieldDefs = loadRef.FieldDefs;

            var includeSet = include != null
                ? new HashSet <string>(include, StringComparer.OrdinalIgnoreCase)
                : null;

            foreach (var fieldDef in fieldDefs)
            {
                if (includeSet != null && !includeSet.Contains(fieldDef.Name))
                {
                    continue;
                }

                dbCmd.Parameters.Clear();
                var listInterface = fieldDef.FieldType.GetTypeWithGenericInterfaceOf(typeof(IList <>));
                if (listInterface != null)
                {
                    loadRef.SetRefFieldList(fieldDef, listInterface.GenericTypeArguments()[0]);
                }
                else
                {
                    loadRef.SetRefField(fieldDef, fieldDef.FieldType);
                }
            }
        }
コード例 #2
0
        public static void LoadReferences <T>(this IDbCommand dbCmd, T instance, string[] include = null)
        {
            var loadRef   = new LoadReferencesSync <T>(dbCmd, instance);
            var fieldDefs = loadRef.FieldDefs;

            if (!include.IsEmpty())
            {
                // Check that any include values aren't reference fields of the specified type
                var fields  = fieldDefs.Select(q => q.FieldName);
                var invalid = include.Except <string>(fields).ToList();
                if (invalid.Count > 0)
                {
                    throw new ArgumentException("Fields '{0}' are not Reference Properties of Type '{1}'".Fmt(invalid.Join("', '"), typeof(T).Name));
                }

                fieldDefs = fieldDefs.Where(fd => include.Contains(fd.FieldName)).ToList();
            }

            foreach (var fieldDef in fieldDefs)
            {
                dbCmd.Parameters.Clear();
                var listInterface = fieldDef.FieldType.GetTypeWithGenericInterfaceOf(typeof(IList <>));
                if (listInterface != null)
                {
                    loadRef.SetRefFieldList(fieldDef, listInterface.GenericTypeArguments()[0]);
                }
                else
                {
                    loadRef.SetRefField(fieldDef, fieldDef.FieldType);
                }
            }
        }
コード例 #3
0
        public static void LoadReferences <T>(this IDbCommand dbCmd, T instance)
        {
            var loadRef = new LoadReferencesSync <T>(dbCmd, instance);

            foreach (var fieldDef in loadRef.FieldDefs)
            {
                dbCmd.Parameters.Clear();
                var listInterface = fieldDef.FieldType.GetTypeWithGenericInterfaceOf(typeof(IList <>));
                if (listInterface != null)
                {
                    loadRef.SetRefFieldList(fieldDef, listInterface.GenericTypeArguments()[0]);
                }
                else
                {
                    loadRef.SetRefField(fieldDef, fieldDef.FieldType);
                }
            }
        }