Пример #1
0
        /// <summary>
        /// 初始化成员包装器集合
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        protected virtual MemberInvokerCollection InitializeInvokers(Type type)
        {
            // fix issue#多线程下导致 FieldCount 不正确
            // 单个实例只初始化一次

            //Fixed issue#匿名类的属性不可写
            //匿名类:new{ClientId=a.ClientId}

            if (!_isInitialize)
            {
                lock (_lock)
                {
                    if (!_isInitialize)
                    {
                        var invokers   = new MemberInvokerCollection();
                        var collection = this.GetMembers(type, _private).Select(x => MemberInvokerBase.Create(x));

                        foreach (MemberInvokerBase invoker in collection)
                        {
                            if (invoker.GetCustomAttribute <System.Runtime.CompilerServices.CompilerGeneratedAttribute>() != null)
                            {
                                continue;
                            }

                            // 判断当前成员是否重复
                            if (invokers.Contains(invoker.Name))
                            {
                                // 属性和字段不允许重复
                                if (invoker.Member.MemberType != MemberTypes.Method)
                                {
                                    continue;
                                }
                                else
                                {
                                    // 方法成员考虑到有重载的情况,允许重复
                                    int dup = invokers.Count(x => x.Member.Name == invoker.Name);
                                    invoker.Name = string.Format("{0}{1}", invoker.Name, dup);
                                }
                            }
                            // 添加成员
                            invokers.Add(invoker);

                            // 累计数据字段,即与数据库一一对应的字段
                            bool isDataField = !(invoker.Column != null && invoker.Column.NoMapped || invoker.ForeignKey != null || invoker.Member.MemberType == MemberTypes.Method);
                            if (isDataField)
                            {
                                _dataFieldCount += 1;
                            }
                        }


                        _invokers     = invokers;
                        _isInitialize = true;
                    }
                }
            }


            return(_invokers);
        }
Пример #2
0
        /// <summary>
        /// 初始化成员包装器集合
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        protected virtual Dictionary <string, MemberInvokerBase> InitializeInvoker(Type type)
        {
            // fix issue#多线程下导致 FieldCount 不正确
            // 单个实例只初始化一次

            //Fixed issue#匿名类的属性不可写
            //匿名类:new{ClientId=a.ClientId}

            if (!_isInitialize)
            {
                lock (_lock)
                {
                    if (!_isInitialize)
                    {
                        Dictionary <string, MemberInvokerBase> invokers = new Dictionary <string, MemberInvokerBase>();
                        var collection = this.GetMembers(type).Select(x => MemberInvokerBase.Create(x));

                        foreach (MemberInvokerBase invoker in collection)
                        {
                            if (invoker.GetCustomAttribute <System.Runtime.CompilerServices.CompilerGeneratedAttribute>() != null)
                            {
                                continue;
                            }
                            if (!invokers.ContainsKey(invoker.Member.Name))
                            {
                                invokers.Add(invoker.Member.Name, invoker);
                            }
                            if (!(invoker.Column != null && invoker.Column.NoMapped || invoker.ForeignKey != null || invoker.Member.MemberType == MemberTypes.Method))
                            {
                                _dataFieldCount += 1;
                            }
                        }


                        _invokers     = invokers;
                        _isInitialize = true;
                    }
                }
            }


            return(_invokers);
        }