コード例 #1
0
ファイル: nTinyPass.cs プロジェクト: jiatsang/nTinyPass
            public T Query(nTinyPassMode TinyPassMode = nTinyPassMode.NoCheck)
            {
                T NewObject = CreateNew();

                QueryFill(NewObject, TinyPassMode);
                return(NewObject);
            }
コード例 #2
0
 public static bool QueryFill(this IDataReader reader, object obj, nTinyPassMode TinyPassMode = nTinyPassMode.CheckAndException)
 {
     if (obj != null)
     {
         Type       TinyPassGeneric     = typeof(nTinyPass <>);
         Type       TinyPassConstructed = TinyPassGeneric.MakeGenericType(obj.GetType());
         MethodInfo GetMethodInfo       = TinyPassConstructed.GetMethod("QueryFill");
         try
         {
             GetMethodInfo.Invoke(null, new object[] { obj, reader, TinyPassMode });
         }
         catch (TargetInvocationException ex)
         {
             throw ex.InnerException;
         }
         return(true);
     }
     return(false);
 }
コード例 #3
0
ファイル: nTinyPass.cs プロジェクト: jiatsang/nTinyPass
 public static int QueryFill(T NewObject, IDataReader reader, nTinyPassMode TinyPassMode)
 {
     return(new PassForDataReader(reader).QueryFill(NewObject, TinyPassMode));
 }
コード例 #4
0
ファイル: nTinyPass.cs プロジェクト: jiatsang/nTinyPass
            /// <summary>
            ///
            /// </summary>
            /// <param name="NewObject"></param>
            /// <returns></returns>
            public int QueryFill(T NewObject, nTinyPassMode TinyPassMode)
            {
                List <string> InvalidColumns = new List <string>();

                //TODO: check IsFillALlNewObject Or Not

                int          field_count = 0;
                PropertyInfo p_count     = null;
                string       FiledName   = null;

                foreach (PropertyInfo prop in PropertyInfos)
                {
                    FiledName = null;
                    if (ColumnNameCheck(prop, ref FiledName))
                    {
                        if (Update(prop, NewObject))
                        {
                            field_count++;
                        }
                        else
                        {
                            if (FiledName == null || prop.Name == FiledName)
                            {
                                InvalidColumns.Add(prop.Name);
                            }
                            else
                            {
                                InvalidColumns.Add(prop.Name + "->" + FiledName);
                            }
                        }
                    }
                }

                foreach (FieldInfo field in FieldInfos)
                {
                    FiledName = null;
                    if (ColumnNameCheck(field, ref FiledName))
                    {
                        if (Update(field, NewObject))
                        {
                            field_count++;
                        }
                        else
                        {
                            if (FiledName == null || field.Name == FiledName)
                            {
                                InvalidColumns.Add(field.Name);
                            }
                            else
                            {
                                InvalidColumns.Add(field.Name + "->" + FiledName);
                            }
                        }
                    }
                }

                if (p_count != null)
                {
                    Update(p_count, NewObject, field_count);
                }

                if (InvalidColumns.Count > 0 && TinyPassMode == nTinyPassMode.CheckAndException)
                {
                    StringBuilder sb = new StringBuilder();
                    foreach (var InvalidColumn in InvalidColumns)
                    {
                        sb.AppendFormat("{0},", InvalidColumn);
                    }
                    throw new InvalidColumnNameException(sb.ToString());
                }

                return(field_count);
            }