private static void _GetProperties(ReflectionInfo info, PropertySelectionStrategy propertyTypes, List <SerializationInfo> properties) { if (propertyTypes.HasFlag(PropertySelectionStrategy.ReadWriteOnly)) { properties.AddRange(info.ReadWriteProperties); } if (propertyTypes.HasFlag(PropertySelectionStrategy.ReadOnly)) { properties.AddRange(info.ReadOnlyProperties); } }
public static IEnumerable <SerializationInfo> GetTypeMembers(Type type, PropertySelectionStrategy propertyTypes, bool includeFields) { var info = _InitializeStaticCache(type); var members = new List <SerializationInfo>(); _GetProperties(info, propertyTypes, members); if (includeFields) { _GetFields(info, members); } return(members); }
/// <summary>Builds up the given object and injects the dependencies.</summary> /// <param name="instance">The instance. </param> /// <param name="strategy">The strategy that selects the properties that are injected. </param> /// <exception cref="ArgumentNullException"><paramref name="instance"/> is <see langword="null"/>.</exception> /// <exception cref="TargetException">The object does not match the target type.-or-The property is an instance property, but obj is null. </exception> /// <exception cref="TargetParameterCountException">The number of parameters in index does not match the number of parameters the indexed property takes. </exception> /// <exception cref="MethodAccessException">There was an illegal attempt to access a private or protected method inside a class. </exception> /// <exception cref="TargetInvocationException">An error occurred while setting the property value. For example, an index value specified for an indexed property is out of range. The /// <see cref="P:System.Exception.InnerException"/> property indicates the reason for the error.</exception> public void BuildUp([NotNull] object instance, PropertySelectionStrategy strategy) { if (instance == null) { throw new ArgumentNullException(nameof(instance), "Container can not build up a null object"); } IEnumerable <PropertyInfo> injectables = strategy.SelectProperties(instance.GetType()); foreach (var propertyInfo in injectables.ToList()) { var injectionInstance = ResolveNamed(propertyInfo.PropertyType, ComputeName(propertyInfo)); if (injectionInstance != null) { propertyInfo.SetValue(instance, injectionInstance, null); } } }