private ProxyGenerationOptions(SerializationInfo info, StreamingContext context) { hook = (IProxyGenerationHook)info.GetValue("hook", typeof(IProxyGenerationHook)); selector = (IInterceptorSelector)info.GetValue("selector", typeof(IInterceptorSelector)); mixins = (List<object>)info.GetValue("mixins", typeof(List<object>)); baseTypeForInterfaceProxy = Type.GetType(info.GetString("baseTypeForInterfaceProxy.AssemblyQualifiedName")); }
protected override IEnumerable<MembersCollector> CollectElementsToProxyInternal(IProxyGenerationHook hook) { Debug.Assert(hook != null, "hook != null"); var targetItem = new DelegateMembersCollector(targetType) { Logger = Logger }; targetItem.CollectMembersToProxy(hook); yield return targetItem; }
private void CollectProperties(IProxyGenerationHook hook) { PropertyInfo[] propertiesFound = type.GetProperties(Flags); foreach (PropertyInfo property in propertiesFound) { AddProperty(property, hook); } }
private void CollectEvents(IProxyGenerationHook hook) { EventInfo[] eventsFound = type.GetEvents(Flags); foreach (EventInfo @event in eventsFound) { AddEvent(@event, hook); } }
private void CollectMethods(IProxyGenerationHook hook) { var methodsFound = MethodFinder.GetAllInstanceMethods(type, Flags); foreach (var method in methodsFound) { AddMethod(method, hook, true); } }
private void CollectProperties(IProxyGenerationHook hook) { var propertiesFound = type.GetProperties(Flags); foreach (var property in propertiesFound) { AddProperty(property, hook); } }
public override void CollectMembersToProxy( IProxyGenerationHook hook, IMembersCollectorSink sink ) { base.CollectMembersToProxy(hook, sink); CollectFields(hook); // TODO: perhaps we should also look for nested classes... }
private ProxyGenerationOptions(SerializationInfo info, StreamingContext context) { hook = (IProxyGenerationHook) info.GetValue ("hook", typeof (IProxyGenerationHook)); selector = (IInterceptorSelector) info.GetValue ("selector", typeof (IInterceptorSelector)); mixins = (ArrayList) info.GetValue ("mixins", typeof (ArrayList)); baseTypeForInterfaceProxy = Type.GetType (info.GetString ("baseTypeForInterfaceProxy.AssemblyQualifiedName")); useSingleInterfaceProxy = info.GetBoolean ("useSingleInterfaceProxy"); useSelector = info.GetBoolean ("useSelector"); }
private void CollectProperties(IProxyGenerationHook hook) { var propertiesFound = new List <PropertyInfo>(type.GetProperties(Flags)).AsIPropertyInfos(); foreach (var property in propertiesFound) { AddProperty(property, hook); } }
protected override IEnumerable<MembersCollector> CollectElementsToProxyInternal(IProxyGenerationHook hook) { foreach (var @interface in interfaces) { var item = new InterfaceMembersCollector(@interface); item.CollectMembersToProxy(hook); yield return item; } }
private void CollectEvents(IProxyGenerationHook hook) { var eventsFound = type.GetEvents(Flags); foreach (var @event in eventsFound) { AddEvent(@event, hook); } }
/// <summary> /// Performs some basic screening and invokes the <see cref="IProxyGenerationHook"/> /// to select methods. /// </summary> /// <param name="method"></param> /// <param name="onlyVirtuals"></param> /// <param name="hook"></param> /// <returns></returns> protected bool AcceptMethod(MethodInfo method, bool onlyVirtuals, IProxyGenerationHook hook) { // we can never intercept a sealed (final) method if (method.IsFinal) { Logger.Debug("Excluded sealed method {0} on {1} because it cannot be intercepted.", method.Name, method.DeclaringType.FullName); return(false); } bool isInternalsAndNotVisibleToDynamicProxy = InternalsHelper.IsInternal(method); if (isInternalsAndNotVisibleToDynamicProxy) { isInternalsAndNotVisibleToDynamicProxy = InternalsHelper.IsInternalToDynamicProxy(method.DeclaringType.Assembly) == false; } if (isInternalsAndNotVisibleToDynamicProxy) { return(false); } if (onlyVirtuals && !method.IsVirtual) { #if SILVERLIGHT if (method.DeclaringType != typeof(object)) #else if (method.DeclaringType != typeof(object) && method.DeclaringType != typeof(MarshalByRefObject)) #endif { Logger.Debug("Excluded non-virtual method {0} on {1} because it cannot be intercepted.", method.Name, method.DeclaringType.FullName); hook.NonVirtualMemberNotification(type, method); } return(false); } //can only proxy methods that are public or protected (or internals that have already been checked above) if ((method.IsPublic || method.IsFamily || method.IsAssembly || method.IsFamilyOrAssembly) == false) { return(false); } if (method.DeclaringType == typeof(object)) { return(false); } #if !SILVERLIGHT if (method.DeclaringType == typeof(MarshalByRefObject)) { return(false); } #endif return(hook.ShouldInterceptMethod(type, method)); }
protected override MetaMethod GetMethodToGenerate(IMethodInfo method, IProxyGenerationHook hook, bool isStandalone) { if (method.IsAccessible() == false) { return null; } var proxyable = AcceptMethod(method, false, hook); return new MetaMethod(method, method, isStandalone, proxyable, false); }
protected override MetaMethod GetMethodToGenerate(IMethodInfo method, IProxyGenerationHook hook, bool isStandalone) { var accepted = AcceptMethod(method, true, hook); if (accepted == false) { //we don't need to do anything... return null; } return new MetaMethod(method, method, isStandalone, true, !method.IsAbstract); }
protected override MetaMethod GetMethodToGenerate(MethodInfo method, IProxyGenerationHook hook, bool isStandalone) { if (method.Name == "Invoke" && method.DeclaringType.IsDelegateType()) { return(new MetaMethod(method, method, isStandalone, true, false)); } else { return(null); } }
protected override MetaMethod GetMethodToGenerate(MethodInfo method, IProxyGenerationHook hook, bool isStandalone) { if (method.IsAccessible() == false) { return(null); } var proxyable = AcceptMethod(method, false, hook); return(new MetaMethod(method, method, isStandalone, proxyable, false)); }
protected override IEnumerable<MembersCollector> CollectElementsToProxyInternal(IProxyGenerationHook hook) { Debug.Assert(hook != null, "hook != null"); foreach (var @interface in interfaces) { var item = GetCollectorForInterface(@interface); item.Logger = Logger; item.CollectMembersToProxy(hook); yield return item; } }
protected override MetaMethod GetMethodToGenerate(MethodInfo method, IProxyGenerationHook hook, bool isStandalone) { var accepted = AcceptMethod(method, true, hook); if (accepted == false) { //we don't need to do anything... return(null); } return(new MetaMethod(method, scope, method, isStandalone, true, !method.IsAbstract)); }
public void CollectElementsToProxy(IProxyGenerationHook hook, MetaType model) { Debug.Assert(hook != null); Debug.Assert(model != null); var sink = new MembersCollectorSink(model, this); foreach (var collector in GetCollectors()) { collector.CollectMembersToProxy(hook, sink); } }
/// <summary> /// Performs some basic screening and invokes the <see cref = "IProxyGenerationHook" /> /// to select methods. /// </summary> /// <param name = "method"></param> /// <param name = "onlyVirtuals"></param> /// <param name = "hook"></param> /// <returns></returns> protected bool AcceptMethod(MethodInfo method, bool onlyVirtuals, IProxyGenerationHook hook) { if (IsInternalAndNotVisibleToDynamicProxy(method)) { return(false); } var isOverridable = method.IsVirtual && !method.IsFinal; if (onlyVirtuals && !isOverridable) { if ( #if !SILVERLIGHT method.DeclaringType != typeof(MarshalByRefObject) && #endif method.IsGetType() == false && method.IsMemberwiseClone() == false) { Logger.DebugFormat("Excluded non-overridable method {0} on {1} because it cannot be intercepted.", method.Name, method.DeclaringType.FullName); hook.NonProxyableMemberNotification(type, method); } return(false); } // we can never intercept a sealed (final) method if (method.IsFinal) { Logger.DebugFormat("Excluded sealed method {0} on {1} because it cannot be intercepted.", method.Name, method.DeclaringType.FullName); return(false); } //can only proxy methods that are public or protected (or internals that have already been checked above) if ((method.IsPublic || method.IsFamily || method.IsAssembly || method.IsFamilyOrAssembly) == false) { return(false); } #if !SILVERLIGHT if (method.DeclaringType == typeof(MarshalByRefObject)) { return(false); } #endif if (method.IsFinalizer()) { return(false); } return(hook.ShouldInterceptMethod(type, method)); }
private void CollectFields(IProxyGenerationHook hook) { var fields = Type.GetAllFields(); foreach (var field in fields) { if (IsOKToBeOnProxy(field)) { continue; } hook.NonProxyableMemberNotification(Type, field); } }
private void CollectFields(IProxyGenerationHook hook) { var fields = type.GetAllFields(); foreach (var field in fields) { if (IsOKToBeOnProxy(field)) { continue; } hook.NonProxyableMemberNotification(type, field); } }
public void CollectMembersToProxy(IProxyGenerationHook hook) { if (checkedMethods == null) // this method was already called! { throw new InvalidOperationException("Can't call CollectMembersToProxy twice"); } CollectProperties(hook); CollectEvents(hook); // Methods go last, because properties and events have methods too (getters/setters add/remove) // and we don't want to get duplicates, so we collect property and event methods first // then we collect methods, and add only these that aren't there yet CollectMethods(hook); checkedMethods = null; // this is ugly, should have a boolean flag for this or something }
public void CollectMembersToProxy(IProxyGenerationHook hook) { if (checkedMethods == null)// this method was already called! { throw new InvalidOperationException("Can't call CollectMembersToProxy twice"); } CollectProperties(hook); CollectEvents(hook); // Methods go last, because properties and events have methods too (getters/setters add/remove) // and we don't want to get duplicates, so we collect property and event methods first // then we collect methods, and add only these that aren't there yet CollectMethods(hook); checkedMethods = null; // this is ugly, should have a boolean flag for this or something }
protected override IEnumerable<MembersCollector> CollectElementsToProxyInternal(IProxyGenerationHook hook) { Debug.Assert(hook != null, "hook != null"); var targetItem = new ClassMembersCollector(targetType) { Logger = Logger }; targetItem.CollectMembersToProxy(hook); yield return targetItem; foreach (var @interface in interfaces) { var item = new InterfaceMembersOnClassCollector(@interface, true, targetType.GetTypeInfo().GetRuntimeInterfaceMap(@interface)) { Logger = Logger }; item.CollectMembersToProxy(hook); yield return item; } }
protected override MetaMethod GetMethodToGenerate(MethodInfo method, IProxyGenerationHook hook, bool isStandalone) { if (method.IsAccessible() == false) { return null; } var accepted = AcceptMethod(method, true, hook); if (!accepted && !method.IsAbstract) { //we don't need to do anything... return null; } return new MetaMethod(method, method, isStandalone, accepted, hasTarget: true); }
public virtual void CollectMembersToProxy(IProxyGenerationHook hook) { if (checkedMethods == null) // this method was already called! { throw new InvalidOperationException( string.Format("Can't call 'CollectMembersToProxy' method twice. This usually signifies a bug in custom {0}.", typeof(ITypeContributor))); } CollectProperties(hook); CollectEvents(hook); // Methods go last, because properties and events have methods too (getters/setters add/remove) // and we don't want to get duplicates, so we collect property and event methods first // then we collect methods, and add only these that aren't there yet CollectMethods(hook); checkedMethods = null; // this is ugly, should have a boolean flag for this or something }
public virtual void CollectMembersToProxy(IProxyGenerationHook hook) { if (checkedMethods == null) // this method was already called! { throw new InvalidOperationException( string.Format("Can't call 'CollectMembersToProxy' method twice. This usually signifies a bug in custom {0}.", typeof(ITypeContributor))); } CollectProperties(hook); CollectEvents(hook); // Methods go last, because properties and events have methods too (getters/setters add/remove) // and we don't want to get duplicates, so we collect property and event methods first // then we collect methods, and add only these that aren't there yet CollectMethods(hook); checkedMethods = null; // this is ugly, should have a boolean flag for this or something }
protected override MetaMethod GetMethodToGenerate(MethodInfo method, IProxyGenerationHook hook, bool isStandalone) { if (scope.Internals.IsAccessible(method) == false) { return null; } if (onlyProxyVirtual && IsVirtuallyImplementedInterfaceMethod(method)) { return null; } var methodOnTarget = GetMethodOnTarget(method); var proxyable = AcceptMethod(method, onlyProxyVirtual, hook); return new MetaMethod(method, scope, methodOnTarget, isStandalone, proxyable, methodOnTarget.IsPrivate == false); }
protected override MetaMethod GetMethodToGenerate(MethodInfo method, IProxyGenerationHook hook, bool isStandalone) { if (ProxyUtil.IsAccessibleMethod(method) == false) { return(null); } var accepted = AcceptMethod(method, true, hook); if (!accepted && !method.IsAbstract) { //we don't need to do anything... return(null); } return(new MetaMethod(method, method, isStandalone, accepted, hasTarget: true)); }
protected override MetaMethod GetMethodToGenerate(MethodInfo method, IProxyGenerationHook hook, bool isStandalone) { if (method.IsAccessible() == false) { return(null); } if (onlyProxyVirtual && IsVirtuallyImplementedInterfaceMethod(method)) { return(null); } var methodOnTarget = GetMethodOnTarget(method); var proxyable = AcceptMethod(method, onlyProxyVirtual, hook); return(new MetaMethod(method, methodOnTarget, isStandalone, proxyable, methodOnTarget.IsPrivate == false)); }
protected override MetaMethod GetMethodToGenerate(MethodInfo method, IProxyGenerationHook hook, bool isStandalone) { if (ProxyUtil.IsAccessibleMethod(method) == false) { return(null); } var interceptable = AcceptMethodPreScreen(method, true, hook); if (!interceptable) { //we don't need to do anything... return(null); } var accepted = hook.ShouldInterceptMethod(type, method); return(new MetaMethod(method, method, isStandalone, accepted, hasTarget: true)); }
public void CollectElementsToProxy(IProxyGenerationHook hook, MetaType model) { foreach (var collector in CollectElementsToProxyInternal(hook)) { foreach (var method in collector.Methods) { if (!IsInterceptable(collector, method.Method)) { continue; } model.AddMethod(method); methods.Add(method); } foreach (var @event in collector.Events) { if (!IsInterceptable(collector, @event.Event)) { continue; } model.AddEvent(@event); events.Add(@event); } foreach (var property in collector.Properties) { if (!IsInterceptable(collector, property.Property)) { continue; } model.AddProperty(property); properties.Add(property); foreach (var method in collector.Methods .Where(m => (property.CanRead && m.Method == property.GetMethod) || (property.CanWrite && m.Method == property.SetMethod))) { model.AddMethod(method); methods.Add(method); } } } }
private MetaMethod AddMethod(MethodInfo method, IProxyGenerationHook hook, bool isStandalone) { if (checkedMethods.Contains(method)) { return(null); } checkedMethods.Add(method); if (methods.ContainsKey(method)) { return(null); } var methodToGenerate = GetMethodToGenerate(method, hook, isStandalone); if (methodToGenerate != null) { methods[method] = methodToGenerate; } return(methodToGenerate); }
public void CollectElementsToProxy(IProxyGenerationHook hook, MetaType model) { foreach (var collector in CollectElementsToProxyInternal(hook)) { foreach (var method in collector.Methods) { model.AddMethod(method); methods.Add(method); } foreach (var @event in collector.Events) { model.AddEvent(@event); events.Add(@event); } foreach (var property in collector.Properties) { model.AddProperty(property); properties.Add(property); } } }
public void CollectElementsToProxy(IProxyGenerationHook hook, MetaType model) { foreach (var collector in CollectElementsToProxyInternal(hook)) { foreach (var method in collector.Methods) { model.AddMethod(method); methods.Add(method); } foreach (var @event in collector.Events) { model.AddEvent(@event); events.Add(@event); } foreach (var property in collector.Properties) { model.AddProperty(property); properties.Add(property); } } }
private static IReference <IProxyGenerationHook> ObtainProxyHook(IKernel kernel, IConfiguration config) { IProxyGenerationHook hook = null; if (config != null) { var hookAttrib = config.Attributes[Constants.ControlProxyHookAttrib]; if (hookAttrib != null) { var hookComponent = ReferenceExpressionUtil.ExtractComponentKey(hookAttrib); if (hookComponent != null) { return(new ComponentReference <IProxyGenerationHook>("synchronize-proxy-generation-hook", hookComponent)); } var converter = kernel.GetConversionManager(); var hookType = converter.PerformConversion <Type>(hookAttrib); if (hookType.Is <IProxyGenerationHook>() == false) { var message = String.Format("The specified controlProxyHook does " + "not implement the interface {1}. Type {0}", hookType.FullName, typeof(IProxyGenerationHook).Name); throw new ConfigurationErrorsException(message); } hook = hookType.CreateInstance <IProxyGenerationHook>(); } } if (hook == null) { hook = SynchronizeProxyHook.Instance; } return(new InstanceReference <IProxyGenerationHook>(hook)); }
public override void CollectElementsToProxy(IProxyGenerationHook hook, MetaType model) { delegateToBaseGetObjectData = VerifyIfBaseImplementsGetObjectData( targetType, model, out var getObjectData ); // This contributor is going to add a `GetObjectData` method to the proxy type. // If a method with the same name and signature exists in the proxied class type, // and another contributor has decided to proxy it, we need to tell it not to. // Otherwise, we'll end up with two implementations! if (getObjectData == null) { // `VerifyIfBaseImplementsGetObjectData` only searches for `GetObjectData` // in the implementation map for `ISerializable`. In the best case, it was // already found there. If not, we need to look again, since *any* method // with the same signature is a problem. var getObjectDataMethod = targetType.GetMethod( "GetObjectData", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, null, new[] { typeof(SerializationInfo), typeof(StreamingContext) }, null ); if (getObjectDataMethod != null) { getObjectData = model.FindMethod(getObjectDataMethod); } } if (getObjectData != null && getObjectData.Proxyable) { getObjectData.Ignore = true; } }
protected override MetaMethod GetMethodToGenerate(IMethodInfo method, IProxyGenerationHook hook, bool isStandalone) { if (method.IsFamily) { // we can't proxy protected methods like this on Silverlight return(null); } if (method.IsAccessible() == false) { return(null); } var accepted = AcceptMethod(method, true, hook); if (!accepted && !method.IsAbstract) { //we don't need to do anything... return(null); } return(new MetaMethod(method, method, isStandalone, accepted, hasTarget: true)); }
protected override MetaMethod GetMethodToGenerate(MethodInfo method, IProxyGenerationHook hook, bool isStandalone) { #if SILVERLIGHT if(method.IsFamily) { // we can't proxy protected methods like this on Silverlight return null; } #endif if (method.IsAccessible() == false) { return null; } var accepted = AcceptMethod(method, true, hook); if (!accepted && !method.IsAbstract) { //we don't need to do anything... return null; } return new MetaMethod(method, method, isStandalone, accepted, hasTarget: true); }
public void CollectElementsToProxy(IProxyGenerationHook hook, MetaType model) { foreach (var collector in CollectElementsToProxyInternal(hook)) { foreach (var method in collector.Methods) { if (!IsInterceptable(collector, method.Method)) continue; model.AddMethod(method); methods.Add(method); } foreach (var @event in collector.Events) { if (!IsInterceptable(collector, @event.Event)) continue; model.AddEvent(@event); events.Add(@event); } foreach (var property in collector.Properties) { if (!IsInterceptable(collector, property.Property)) continue; model.AddProperty(property); properties.Add(property); foreach (var method in collector.Methods .Where(m => (property.CanRead && m.Method == property.GetMethod) || (property.CanWrite && m.Method == property.SetMethod))) { model.AddMethod(method); methods.Add(method); } } } }
private void AddEvent(EventInfo @event, IProxyGenerationHook hook) { var addMethod = @event.GetAddMethod(true); var removeMethod = @event.GetRemoveMethod(true); MetaMethod adder = null; MetaMethod remover = null; if (addMethod != null) { adder = AddMethod(addMethod, hook, false); } if (removeMethod != null) { remover = AddMethod(removeMethod, hook, false); } if (adder == null && remover == null) { return; } events[@event] = new MetaEvent(@event, adder, remover, EventAttributes.None); }
private MixinData mixinData; // this is calculated dynamically on proxy type creation /// <summary> /// Initializes a new instance of the <see cref="ProxyGenerationOptions"/> class. /// </summary> /// <param name="hook">The hook.</param> public ProxyGenerationOptions(IProxyGenerationHook hook) { this.hook = hook; useSelector = false; }
private void AddProperty(PropertyInfo property, IProxyGenerationHook hook) { MetaMethod getter = null; MetaMethod setter = null; if (property.CanRead) { MethodInfo getMethod = property.GetGetMethod(true); getter = AddMethod(getMethod, hook, false); } if (property.CanWrite) { MethodInfo setMethod = property.GetSetMethod(true); setter = AddMethod(setMethod, hook, false); } if (setter==null && getter == null) { return; } var nonInheritableAttributes = AttributeUtil.GetNonInheritableAttributes(property); properties[property] = new MetaProperty(property.Name, property.PropertyType, property.DeclaringType, getter, setter, PropertyAttributes.None, nonInheritableAttributes); }
/// <summary> /// Performs some basic screening and invokes the <see cref="IProxyGenerationHook"/> /// to select methods. /// </summary> /// <param name="method"></param> /// <param name="onlyVirtuals"></param> /// <param name="hook"></param> /// <returns></returns> protected bool AcceptMethod(MethodInfo method, bool onlyVirtuals, IProxyGenerationHook hook) { // we can never intercept a sealed (final) method if (method.IsFinal) { Logger.Debug("Excluded sealed method {0} on {1} because it cannot be intercepted.", method.Name, method.DeclaringType.FullName); return false; } bool isInternalsAndNotVisibleToDynamicProxy = InternalsHelper.IsInternal(method); if (isInternalsAndNotVisibleToDynamicProxy) { isInternalsAndNotVisibleToDynamicProxy = InternalsHelper.IsInternalToDynamicProxy(method.DeclaringType.Assembly) == false; } if (isInternalsAndNotVisibleToDynamicProxy) return false; if (onlyVirtuals && !method.IsVirtual) { #if SILVERLIGHT if (method.DeclaringType != typeof(object)) #else if (method.DeclaringType != typeof(object) && method.DeclaringType != typeof(MarshalByRefObject)) #endif { Logger.Debug("Excluded non-virtual method {0} on {1} because it cannot be intercepted.", method.Name, method.DeclaringType.FullName); hook.NonVirtualMemberNotification(type, method); } return false; } //can only proxy methods that are public or protected (or internals that have already been checked above) if ((method.IsPublic || method.IsFamily || method.IsAssembly || method.IsFamilyOrAssembly) == false) return false; if (method.DeclaringType == typeof (object)) { return false; } #if !SILVERLIGHT if (method.DeclaringType == typeof (MarshalByRefObject)) { return false; } #endif return hook.ShouldInterceptMethod(type, method); }
protected override IEnumerable <MembersCollector> CollectElementsToProxyInternal(IProxyGenerationHook hook) { Debug.Assert(hook != null, "hook != null"); var targetItem = new WrappedClassMembersCollector(targetType) { Logger = Logger }; targetItem.CollectMembersToProxy(hook); yield return(targetItem); foreach (var @interface in interfaces) { var item = new InterfaceMembersOnClassCollector(@interface, true, targetType.GetInterfaceMap(@interface)) { Logger = Logger }; item.CollectMembersToProxy(hook); yield return(item); } }
protected override IEnumerable <MembersCollector> CollectElementsToProxyInternal(IProxyGenerationHook hook) { Debug.Assert(hook != null, "hook != null"); foreach (var @interface in interfaces) { var item = GetCollectorForInterface(@interface); item.Logger = Logger; item.CollectMembersToProxy(hook); yield return(item); } }
private MixinData mixinData; // this is calculated dynamically on proxy type creation /// <summary> /// Initializes a new instance of the <see cref = "ProxyGenerationOptions" /> class. /// </summary> /// <param name = "hook">The hook.</param> public ProxyGenerationOptions(IProxyGenerationHook hook) { BaseTypeForInterfaceProxy = typeof(object); Hook = hook; }
private MixinData mixinData; // this is calculated dynamically on proxy type creation /// <summary> /// Initializes a new instance of the <see cref="ProxyGenerationOptions"/> class. /// </summary> /// <param name="hook">The hook.</param> public ProxyGenerationOptions(IProxyGenerationHook hook) { BaseTypeForInterfaceProxy = typeof(object); Hook = hook; }
private void AddEvent(EventInfo @event, IProxyGenerationHook hook) { var addMethod = @event.GetAddMethod(true); var removeMethod = @event.GetRemoveMethod(true); MetaMethod adder = null; MetaMethod remover = null; if (addMethod != null) { adder = AddMethod(addMethod, hook, false); } if (removeMethod != null) { remover = AddMethod(removeMethod, hook, false); } if (adder == null && remover == null) { return; } events[@event] = new MetaEvent(@event.Name, @event.DeclaringType, @event.EventHandlerType, adder, remover, EventAttributes.None); }
private MetaMethod AddMethod(MethodInfo method, IProxyGenerationHook hook, bool isStandalone) { if (checkedMethods.Contains(method)) { return null; } checkedMethods.Add(method); if (methods.ContainsKey(method)) { return null; } var methodToGenerate = GetMethodToGenerate(method, hook, isStandalone); if (methodToGenerate != null) { methods[method] = methodToGenerate; } return methodToGenerate; }
protected abstract MetaMethod GetMethodToGenerate(MethodInfo method, IProxyGenerationHook hook, bool isStandalone);
private void AddProperty(PropertyInfo property, IProxyGenerationHook hook) { MetaMethod getter = null; MetaMethod setter = null; if (property.CanRead) { var getMethod = property.GetGetMethod(true); getter = AddMethod(getMethod, hook, false); } if (property.CanWrite) { var setMethod = property.GetSetMethod(true); setter = AddMethod(setMethod, hook, false); } if (setter == null && getter == null) { return; } var nonInheritableAttributes = property.GetNonInheritableAttributes(); var arguments = property.GetIndexParameters(); properties[property] = new MetaProperty(property.Name, property.PropertyType, property.DeclaringType, getter, setter, nonInheritableAttributes, arguments.Select(a => a.ParameterType).ToArray()); }
protected abstract MetaMethod GetMethodToGenerate(MethodInfo method, IProxyGenerationHook hook, bool isStandalone);
protected override IEnumerable <MembersCollector> CollectElementsToProxyInternal(IProxyGenerationHook hook) { Debug.Assert(hook != null, "hook != null"); var targetItem = new DelegateMembersCollector(targetType) { Logger = Logger }; targetItem.CollectMembersToProxy(hook); yield return(targetItem); }
protected abstract IEnumerable<MembersCollector> CollectElementsToProxyInternal(IProxyGenerationHook hook);
public override void CollectMembersToProxy(IProxyGenerationHook hook) { base.CollectMembersToProxy(hook); CollectFields(hook); // TODO: perhaps we should also look for nested classes... }
public virtual void CollectElementsToProxy(IProxyGenerationHook hook, MetaType model) { }
/// <summary> /// Performs some basic screening and invokes the <see cref = "IProxyGenerationHook" /> /// to select methods. /// </summary> /// <param name = "method"></param> /// <param name = "onlyVirtuals"></param> /// <param name = "hook"></param> /// <returns></returns> protected bool AcceptMethod(MethodInfo method, bool onlyVirtuals, IProxyGenerationHook hook) { // we can never intercept a sealed (final) method if (method.IsFinal) { Logger.DebugFormat("Excluded sealed method {0} on {1} because it cannot be intercepted.", method.Name, method.DeclaringType.FullName); return false; } if (IsInternalAndNotVisibleToDynamicProxy(method)) { return false; } if (onlyVirtuals && !method.IsVirtual) { if ( #if !SILVERLIGHT method.DeclaringType != typeof(MarshalByRefObject) && #endif method.IsGetType() == false && method.IsMemberwiseClone() == false) { Logger.DebugFormat("Excluded non-virtual method {0} on {1} because it cannot be intercepted.", method.Name, method.DeclaringType.FullName); hook.NonProxyableMemberNotification(type, method); } return false; } //can only proxy methods that are public or protected (or internals that have already been checked above) if ((method.IsPublic || method.IsFamily || method.IsAssembly || method.IsFamilyOrAssembly) == false) { return false; } #if !SILVERLIGHT if (method.DeclaringType == typeof(MarshalByRefObject)) { return false; } #endif if (method.IsFinalizer()) { return false; } return hook.ShouldInterceptMethod(type, method); }
private void CollectMethods(IProxyGenerationHook hook) { var methodsFound = MethodFinder.GetAllInstanceMethods(type, Flags); foreach (var method in methodsFound) { AddMethod(method, hook, true); } }