<PackageReference Include="Castle.Windsor" Version="2.5.4" />

ProxyOptions

public class ProxyOptions
Represents options to configure proxies.
using Castle.Core; using Castle.DynamicProxy; using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; namespace Castle.MicroKernel.Proxy { public class ProxyOptions { private readonly DependencyModelCollection dependencies; private IReference<IProxyGenerationHook> hook; private List<Type> interfaceList; private List<IReference<object>> mixInList; private IReference<IInterceptorSelector> selector; public Type[] AdditionalInterfaces { get { if (interfaceList != null) return interfaceList.ToArray(); return Type.EmptyTypes; } } public bool AllowChangeTarget { get; set; } public bool UseMarshalByRefAsBaseClass { get; set; } public IReference<IProxyGenerationHook> Hook { get { return hook; } set { SetReferenceValue(ref hook, value); } } public IEnumerable<IReference<object>> MixIns { get { if (mixInList != null) { foreach (IReference<object> mixIn in mixInList) { yield return mixIn; } } } } public bool OmitTarget { get; set; } public IReference<IInterceptorSelector> Selector { get { return selector; } set { SetReferenceValue(ref selector, value); } } [Obsolete("Prefer using a IProxyGenerationHook.")] [EditorBrowsable(EditorBrowsableState.Advanced)] public bool UseSingleInterfaceProxy { get; set; } public ProxyOptions(DependencyModelCollection dependencies) { this.dependencies = dependencies; UseSingleInterfaceProxy = false; OmitTarget = false; } public void AddAdditionalInterfaces(params Type[] interfaces) { if (interfaces == null) throw new ArgumentNullException("interfaces"); if (interfaceList == null) interfaceList = new List<Type>(); interfaceList.AddRange(interfaces); } public void AddMixIns(params object[] mixIns) { if (mixIns == null) throw new ArgumentNullException("mixIns"); if (mixInList == null) mixInList = new List<IReference<object>>(); foreach (object instance in mixIns) { InstanceReference<object> instanceReference = new InstanceReference<object>(instance); mixInList.Add(instanceReference); instanceReference.Attach(dependencies); } } public void AddMixinReference(IReference<object> mixIn) { if (mixIn == null) throw new ArgumentNullException("mixIn"); if (mixInList == null) mixInList = new List<IReference<object>>(); mixInList.Add(mixIn); mixIn.Attach(dependencies); } public override bool Equals(object obj) { if (this == obj) return true; ProxyOptions proxyOptions = obj as ProxyOptions; if (proxyOptions == null) return false; if (!object.Equals(Hook, proxyOptions.Hook)) return false; if (!object.Equals(Selector, proxyOptions.Selector)) return false; if (!object.Equals(UseSingleInterfaceProxy, proxyOptions.UseSingleInterfaceProxy)) return false; if (!object.Equals(OmitTarget, proxyOptions.OmitTarget)) return false; if (!AdditionalInterfacesAreEquals(proxyOptions)) return false; return MixInsAreEquals(proxyOptions); } public override int GetHashCode() { return 29 * base.GetHashCode() + GetCollectionHashCode(interfaceList) + GetCollectionHashCode(mixInList); } private bool AdditionalInterfacesAreEquals(ProxyOptions proxyOptions) { if (!object.Equals(interfaceList == null, proxyOptions.interfaceList == null)) return false; if (interfaceList == null) return true; if (interfaceList.Count != proxyOptions.interfaceList.Count) return false; for (int i = 0; i < interfaceList.Count; i++) { if (!proxyOptions.interfaceList.Contains(interfaceList[0])) return false; } return true; } private int GetCollectionHashCode(IEnumerable items) { int num = 0; if (items == null) return num; foreach (object item in items) { num = 29 * num + item.GetHashCode(); } return num; } private bool MixInsAreEquals(ProxyOptions proxyOptions) { if (!object.Equals(mixInList == null, proxyOptions.mixInList == null)) return false; if (mixInList == null) return true; if (mixInList.Count != proxyOptions.mixInList.Count) return false; for (int i = 0; i < mixInList.Count; i++) { if (!proxyOptions.mixInList.Contains(mixInList[0])) return false; } return true; } private void SetReferenceValue<T>(ref IReference<T> reference, IReference<T> value) { if (reference != null) reference.Detach(dependencies); value?.Attach(dependencies); reference = value; } } }