Ich habe folgende mixin definiert:Wie kann ich Attribute mit Dynamic Proxy mischen, die auf Mixin-Instanzen definiert sind?
public interface IMixin
{
string SomeProperty { get; set; }
}
public class Mixin : IMixin
{
[SomeAttribute]
public string SomeProperty { get; set; }
}
Das mit dem folgenden "Proxy-Erzeugungs" -Aufruf injiziert wird:
using Castle.DynamicProxy;
var proxyGenerationOptions = new ProxyGenerationOptions();
var mixin = new Mixin();
proxyGenerationsOptions.AddMixinInstance(mixin);
var additionalInterfacesToProxy = new []
{
typeof (IMixin)
};
var proxyGenerator = new ProxyGenerator();
var proxy = proxyGenerator.CreateClassProxy(/* base type */,
additionalInterfacesToProxy,
proxyGenerationOptions,
/* interceptor instance */);
Das Problem, das ich bin vor:
var instance = /* proxy instance */;
var propertyInfo = instance.GetType()
.GetProperty(nameof(IMixin.SomeProperty));
var attribute = Attribute.GetCustomAttribute(propertyInfo,
typeof(SomeAttribute),
true);
attribute
ist Null.
Wie kann ich eine konkrete Instanz mischen, einschließlich der Attribute, die im Typ definiert sind (über properties/class/methods/fields/...)?
Was sagt 'instance.GetType(). FullName'? –
@ LasseV.Karlsen 'Castle.Proxies. ** BaseType ** Proxy',' propertyInfo' ist nicht null, daher wird das Mixin entsprechend den 'proxyGenerationOptions' angewendet. –
Ich vermute, Sie wollen nicht das Attribut auf "IMixin" -Schnittstelle? –