ProxyGenerationOptions
using System;
using System.Collections.Generic;
using System.Reflection.Emit;
namespace Castle.DynamicProxy
{
public class ProxyGenerationOptions
{
public static readonly ProxyGenerationOptions Default = new ProxyGenerationOptions();
private List<object> mixins;
internal readonly IList<Attribute> attributesToAddToGeneratedTypes = new List<Attribute>();
private readonly IList<CustomAttributeBuilder> additionalAttributes = new List<CustomAttributeBuilder>();
private MixinData mixinData;
public IProxyGenerationHook Hook { get; set; }
public IInterceptorSelector Selector { get; set; }
public Type BaseTypeForInterfaceProxy { get; set; }
[Obsolete("This property is obsolete and will be removed in future versions. Use AdditionalAttributes property instead. You can use AttributeUtil class to simplify creating CustomAttributeBuilder instances for common cases.")]
public IList<Attribute> AttributesToAddToGeneratedTypes {
get {
return attributesToAddToGeneratedTypes;
}
}
public IList<CustomAttributeBuilder> AdditionalAttributes => additionalAttributes;
public MixinData MixinData {
get {
if (mixinData == null)
throw new InvalidOperationException("Call Initialize before accessing the MixinData property.");
return mixinData;
}
}
public bool HasMixins {
get {
if (mixins != null)
return mixins.Count != 0;
return false;
}
}
public ProxyGenerationOptions(IProxyGenerationHook hook)
{
BaseTypeForInterfaceProxy = typeof(object);
Hook = hook;
}
public ProxyGenerationOptions()
: this(new AllMethodsHook())
{
}
public void Initialize()
{
if (mixinData == null)
try {
mixinData = new MixinData(mixins);
} catch (ArgumentException ex) {
throw new InvalidMixinConfigurationException("There is a problem with the mixins added to this ProxyGenerationOptions: " + ex.Message, ex);
}
}
public void AddMixinInstance(object instance)
{
if (instance == null)
throw new ArgumentNullException("instance");
if (mixins == null)
mixins = new List<object>();
mixins.Add(instance);
mixinData = null;
}
public object[] MixinsAsArray()
{
if (mixins == null)
return new object[0];
return mixins.ToArray();
}
public override bool Equals(object obj)
{
if (object.ReferenceEquals(this, obj))
return true;
ProxyGenerationOptions proxyGenerationOptions = obj as ProxyGenerationOptions;
if (object.ReferenceEquals(proxyGenerationOptions, null))
return false;
Initialize();
proxyGenerationOptions.Initialize();
if (!object.Equals(Hook, proxyGenerationOptions.Hook))
return false;
if (!object.Equals(Selector == null, proxyGenerationOptions.Selector == null))
return false;
if (!object.Equals(MixinData, proxyGenerationOptions.MixinData))
return false;
if (!object.Equals(BaseTypeForInterfaceProxy, proxyGenerationOptions.BaseTypeForInterfaceProxy))
return false;
return true;
}
public override int GetHashCode()
{
Initialize();
int num = (Hook != null) ? Hook.GetType().GetHashCode() : 0;
num = 29 * num + ((Selector != null) ? 1 : 0);
num = 29 * num + MixinData.GetHashCode();
return 29 * num + (((object)BaseTypeForInterfaceProxy != null) ? BaseTypeForInterfaceProxy.GetHashCode() : 0);
}
}
}