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); } } } }
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); } } }
// You may have noticed that most contributors do not query `MetaType` at all, // but only their own collections. So perhaps you are wondering why collected // type elements are added to `model` at all, and not just to `contributor`? // // TL;DR: This prevents member name collisions in the generated proxy type. // // `MetaType` uses `MetaTypeElementCollection`s internally, which switches members // to explicit implementation whenever a name collision with a previously added // member occurs. // // It would be pointless to do this at the level of the individual contributor, // because name collisions could still occur across several contributors. This // is why they all share the same `MetaType` instance. public void Add(MetaEvent @event) { model.AddEvent(@event); contributor.events.Add(@event); }