예제 #1
0
        internal PropertyInfo[] GetPropertiesFromCache(Type type)
        {
            if (type == null)
            {
                return(new PropertyInfo[0]);
            }

            var entityName = type.AssemblyQualifiedName;

            if (PropertyCache.ContainsKey(entityName))
            {
                PropertyCache.TryGetValue(entityName, out var properties);
                return(properties);
            }

            var props = type.GetTypeInfo().GetProperties();

            if (IsAnonymousType(type))
            {
                return(props);
            }

            PropertyCache.TryAdd(entityName, props);
            return(props);
        }
        public ChangeTracker(T target)
        {
            Target = target;

            var type = Target.GetType();

            lock (PropertyCache) {
                if (!PropertyCache.ContainsKey(type))
                {
                    PropertyCache.Add(type, type.GetProperties().Select(each => each).ToList());
                }
            }

            Properties = PropertyCache[type].Select(each => new ChangeTrackerProperty(each)).ToList();
            GetChanges();
        }