Пример #1
0
 public void SetValue(AssignableValue assignableValue, object destination)
 {
     var key = new CacheKey(destination.GetType(), assignableValue.PropertyName);
     PropertyInfo prop;
     if (setters.TryGetValue(key, out prop) == false)
     {
         setters[key] = prop = destination.GetType().GetProperty(assignableValue.PropertyName);
     }
     prop.SetValue(destination, assignableValue.DestinationValue, null);
 }
Пример #2
0
 public object GetValue(string propertyName, object source)
 {
     var key = new CacheKey(source.GetType(), propertyName);
     PropertyInfo prop;
     if (getters.TryGetValue(key, out prop) == false)
     {
         getters[key] = prop = source.GetType().GetProperty(propertyName);
     }
     return prop.GetValue(source, null);
 }
Пример #3
0
 public bool Equals(CacheKey other)
 {
     if (ReferenceEquals(null, other)) return false;
     if (ReferenceEquals(this, other)) return true;
     return Equals(other.type, type) && Equals(other.name, name);
 }
Пример #4
0
        private MemberGetter TryCacheGet(Type targetType, string propertyName)
        {
            var key = new CacheKey(targetType, propertyName);
            MemberGetter getter;
            if(IsCacheable(targetType))
            {
                //there should only be few writers to this bit at execution time
                // note that this could be locked inside the MemberGetter delegate (below)
                // todo: cache all these during initialization
                locker.EnterWriteLock();
                if (getters.TryGetValue(key, out getter) == false)
                {
                    getters[key] = getter = targetType.DelegateForGetPropertyValue(propertyName, Flags.InstanceAnyVisibility);
                }
                locker.ExitWriteLock();
                return getter;
            }

            if(getters.TryGetValue(key,out getter)==false)
            {
                getters[key] = getter = new MemberGetter(impl =>
                {
                    var implementationGetter = TryCacheGet(impl.GetType(), propertyName);
                    return implementationGetter(impl);
                });
            }
            return getter;
        }
Пример #5
0
 public bool HasCachedGetterFor(Type type, string name)
 {
     var key = new CacheKey(type, name);
     return getters.ContainsKey(key);
 }
Пример #6
0
        private MemberSetter TryCacheSet(Type targetType, string propertyName)
        {
            var key = new CacheKey(targetType, propertyName);

            MemberSetter setter;
            if (setters.TryGetValue(key, out setter) == false)
            {
                setters[key] =
                    setter = targetType.DelegateForSetPropertyValue(propertyName, Flags.InstanceAnyVisibility);
            }
            return setter;
        }