コード例 #1
0
ファイル: PropertyInfoEx.cs プロジェクト: nsarris/Dynamix
        private void InitializeGet(bool enableDelegateCaching)
        {
            var getMethod = this.PropertyInfo.GetGetMethod(true);

            if (getMethod == null)
            {
                return;
            }

            this.CanGet    = true;
            this.IsStatic  = getMethod.IsStatic;
            this.PublicGet = getMethod.IsPublic;

            if (enableDelegateCaching)
            {
                this.Getter = MemberAccessorDelegateBuilder.CachedPropertyBuilder.BuildGenericGetter(this.PropertyInfo);
            }
            else
            {
                var builder = new PropertyAccessorLambdaBuilder(false);
                this.Getter = builder.BuildGenericGetter(this.PropertyInfo).Compile();
            }
        }
コード例 #2
0
        public GenericPropertyGetter BuildGenericGetter(PropertyInfo propertyInfo)
        {
            if (propertyInfo == null)
            {
                throw new ArgumentNullException(nameof(propertyInfo));
            }

            if (EnableCaching)
            {
                if (genericGetterCache.TryGetValue(propertyInfo, out var cachedDelegate))
                {
                    return((GenericPropertyGetter)cachedDelegate);
                }
            }

            var delegate_ = builder.BuildGenericGetter(propertyInfo).Compile();

            if (EnableCaching)
            {
                genericGetterCache.TryAdd(propertyInfo, delegate_);
            }

            return(delegate_);
        }