Exemple #1
0
 public bool TryGetPropertyTransaction(string name, out PropertyTransaction propertyTransaction)
 {
     if (PropertyDataPairList == null)
     {
         propertyTransaction = null;
         return(false);
     }
     propertyTransaction = PropertyDataPairList.Find(property => property.Property.Name.Equals(name));
     return(propertyTransaction != null);
 }
Exemple #2
0
        private void BuildTransactionPropertys(object owner)
        {
            //this.ownerObject = owner;
            //有實作IDataTransaction但非繼承自ObjectTransaction的不需處理
            IDataTransactionBasic dt;

            if (TryGet(out dt))
            {
                return;
            }

            Type type = owner.GetType();
            List <PropertyInfo> propertyInfoList;

            lock (this)
            {
                if (!propertyDataPairMap.TryGetValue(type, out propertyInfoList))
                {
                    propertyInfoList = new List <PropertyInfo>();
                    List <PropertyInfo> allPropertyInfoList = new List <PropertyInfo>();
                    foreach (PropertyInfo propertyInfo in type.GetProperties(BindingFlags.Instance | BindingFlags.Public))
                    {
                        if (!propertyInfo.IsDefined(typeof(NotDataTransactionAttribute), false))
                        {
                            allPropertyInfoList.Add(propertyInfo);
                        }
                        if (propertyInfo.IsDefined(typeof(DataTransactionAttribute), false))
                        {
                            propertyInfoList.Add(propertyInfo);
                        }
                    }
                    //若整個Owner的property都沒定DataTransactionAttribute則視同全部Pproperty受Transaction控制
                    if (propertyInfoList.Count == 0)
                    {
                        propertyInfoList = allPropertyInfoList;
                    }
                    propertyDataPairMap[type] = propertyInfoList;
                }
            }
            propertyDataPairList = new List <PropertyTransaction>();
            foreach (PropertyInfo propertyInfo in propertyInfoList)
            {
                PropertyTransaction propertyTransaction = new PropertyTransaction(this.ownerObject);
                propertyTransaction.Property = propertyInfo;
                propertyDataPairList.Add(propertyTransaction);
            }
        }