예제 #1
0
        public static IValueContainerFactory GetFactory(IEnumerable <KeyValuePair <string, Type> > properties)
        {
#warning Pre-cache
            var containerType = ValueContainerTypeBuilder.Build(properties);
            var factoryType   = typeof(ValueContainerFactory <>).MakeGenericType(containerType);
            return((IValueContainerFactory)Activator.CreateInstance(factoryType));
        }
예제 #2
0
        public ValueContainerBase()
        {
            var delegatedMembers = new List <MemberInfo>();

            foreach (var mi in GetType().GetMembers(BindingFlags.Instance | BindingFlags.Public))
            {
                if (mi is FieldInfo fieldInfo)
                {
                    if (!fieldInfo.IsInitOnly && !fieldInfo.IsStatic)
                    {
                        delegatedMembers.Add(fieldInfo);
                    }
                    continue;
                }

                if (mi is PropertyInfo propertyInfo)
                {
                    if (propertyInfo.CanRead && propertyInfo.CanWrite && !propertyInfo.GetMethod.IsStatic)
                    {
                        delegatedMembers.Add(propertyInfo);
                    }
                    continue;
                }
            }

            var containerType = ValueContainerTypeBuilder.Build(GetType(), delegatedMembers);

            _impl = (IValueContainer)Activator.CreateInstance(containerType, new object[] { this });
        }
예제 #3
0
        public static IValueContainerProxyFactory GetProxyFactory(Type delegatedType, IEnumerable <KeyValuePair <string, MemberInfo> > properties)
        {
#warning Pre-cache
            var containerType = ValueContainerTypeBuilder.Build(delegatedType, properties);
            var factoryType   = typeof(ValueContainerProxyFactory <,>).MakeGenericType(delegatedType, containerType);
            return((IValueContainerProxyFactory)Activator.CreateInstance(factoryType));
        }
예제 #4
0
        public static IValueContainerProxyFactory GetProxyFactory(Type delegatedType)
        {
            var properties = GetDelegatedMembers(delegatedType);

#warning Pre-cache
            var containerType = ValueContainerTypeBuilder.Build(delegatedType, properties);
            var factoryType   = typeof(ValueContainerProxyFactory <,>).MakeGenericType(delegatedType, containerType);
            return((IValueContainerProxyFactory)Activator.CreateInstance(factoryType));
        }
예제 #5
0
        public static IValueContainer CreateProxy(object target)
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }
            var containerType = ValueContainerTypeBuilder.Build(target.GetType(), GetDelegatedMembers(target.GetType()));

            return((IValueContainer)Activator.CreateInstance(containerType, new object[] { target }));
        }
예제 #6
0
        public static IValueContainer Create(IEnumerable <KeyValuePair <string, Type> > properties)
        {
            if (properties == null)
            {
                throw new ArgumentNullException(nameof(properties));
            }

            var containerType = ValueContainerTypeBuilder.Build(properties);

            return((IValueContainer)Activator.CreateInstance(containerType));
        }
예제 #7
0
        public static IValueContainer CreateProxy(object target, IEnumerable <KeyValuePair <string, MemberInfo> > properties)
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }
            if (properties == null)
            {
                throw new ArgumentNullException(nameof(properties));
            }

#warning Disable readonly members

            var containerType = ValueContainerTypeBuilder.Build(target.GetType(), properties);
            return((IValueContainer)Activator.CreateInstance(containerType, new object[] { target }));
        }