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)); }
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 }); }
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)); }
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)); }
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 })); }
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)); }
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 })); }