Esempio n. 1
0
        public static string GenerateByOperate <T>(this T t, GenerateOperate generateOperate)
        {
            var conditions = new StringBuilder();
            var properties = t.GetType().GetProperties(BindingFlags.Public | BindingFlags.DeclaredOnly | BindingFlags.Instance);

            (from property in properties
             where property.GetValue(t, null) != null
             //let des = property.GetCustomAttribute<IgnoreFieldAttribute>()
             let des = property.IsDefined(typeof(IgnoreFieldAttribute)) //optimizate GetCustomAttribute by IsDefined
                                                                        //where des == null
                       where des == false
                       select property).Each <PropertyInfo>(property =>
            {
                if (generateOperate == GenerateOperate.Condition)
                {
                    conditions.Append(" AND ").Append(property.Name).Append("=@").Append(property.Name);
                }
                if (generateOperate == GenerateOperate.UpdateField)
                {
                    conditions.Append(" SET ").Append(property.Name).Append("=@").Append(property.Name).Append(",");
                }
            });
            #region foreach
            //foreach (var property in from property in properties
            //                         where property.GetValue(t, null) != null
            //                         let des = property.GetCustomAttribute<IgnoreFieldAttribute>()
            //                         where des == null
            //                         select property)
            //{
            //    conditions.Append(" AND ").Append(property.Name).Append("=@").Append(property.Name);
            //}
            #endregion
            #region Parallel.ForEach
            //var propertys = from property in properties
            //                where property.GetValue(t, null) != null
            //                let des = property.GetCustomAttribute<IgnoreFieldAttribute>()
            //                where des == null
            //                select property;
            //Parallel.ForEach(propertys, (property) =>
            //{
            //    conditions.Append(" AND " + property.Name + "=@" + property.Name + " ");
            //});
            #endregion
            #region foreach

            //foreach (var property in properties)
            //{
            //    if (property.GetValue(t, null) == null) continue;
            //    var des = property.GetCustomAttribute<IgnoreFieldAttribute>();
            //    if (des == null)
            //    {
            //        conditions.Append(" AND " + property.Name + "=@" + property.Name + " ");
            //    }
            //}
            #endregion
            return(conditions.ToString());
        }
Esempio n. 2
0
        private void GenerateCode(TreeModel treeModel)
        {
            var window = new ArgumentWindow
            {
                Owner = this
            };

            var result = window.ShowDialog();

            if (!result.HasValue || !result.Value)
            {
                return;
            }

            var tables = new GenerateOperate(treeModel, XmlNodeOperate.Context.TableInfos).GetGenerateTables();

            var progressWindow = new ProgressWindow(tables, window.GenerateArgument)
            {
                Owner = this
            };

            progressWindow.ShowDialog();
        }