本文整理汇总了C#中System.Type.GetEvents方法的典型用法代码示例。如果您正苦于以下问题:C# Type.GetEvents方法的具体用法?C# Type.GetEvents怎么用?C# Type.GetEvents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Type
的用法示例。
在下文中一共展示了Type.GetEvents方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Build
/*----------------------------------------------------------------------------------------*/
/// <summary>
/// Executed to build the activation plan.
/// </summary>
/// <param name="binding">The binding that points at the type whose activation plan is being released.</param>
/// <param name="type">The type whose activation plan is being manipulated.</param>
/// <param name="plan">The activation plan that is being manipulated.</param>
/// <returns>
/// A value indicating whether to proceed or interrupt the strategy chain.
/// </returns>
public override StrategyResult Build(IBinding binding, Type type, IActivationPlan plan)
{
EventInfo[] events = type.GetEvents(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
foreach (EventInfo evt in events)
{
#if !MONO
PublishAttribute[] attributes = evt.GetAllAttributes<PublishAttribute>();
#else
PublishAttribute[] attributes = ExtensionsForICustomAttributeProvider.GetAllAttributes<PublishAttribute>(evt);
#endif
foreach (PublishAttribute attribute in attributes)
plan.Directives.Add(new PublicationDirective(attribute.Channel, evt));
}
MethodInfo[] methods = type.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
var injectorFactory = binding.Components.Get<IInjectorFactory>();
foreach (MethodInfo method in methods)
{
#if !MONO
SubscribeAttribute[] attributes = method.GetAllAttributes<SubscribeAttribute>();
#else
SubscribeAttribute[] attributes = ExtensionsForICustomAttributeProvider.GetAllAttributes<SubscribeAttribute>(method);
#endif
foreach (SubscribeAttribute attribute in attributes)
{
IMethodInjector injector = injectorFactory.GetInjector(method);
plan.Directives.Add(new SubscriptionDirective(attribute.Channel, injector, attribute.Thread));
}
}
return StrategyResult.Proceed;
}
示例2: ClassInstance
public ClassInstance(Type wrappedType, Type objectInstanceType)
{
_wrappedType = wrappedType;
// Create a wrapper for each non-collection property.
_classProperties = _wrappedType
.GetProperties()
.Select(p => ClassMemberIndependent.Intercept(new ClassMemberProperty(p, objectInstanceType)))
.Concat<ClassMember>(_wrappedType
.GetFields()
.Select(f => ClassMemberIndependent.Intercept(new ClassMemberField(f, objectInstanceType))))
.ToList();
_classProperties.AddRange(
(from method in _wrappedType.GetMethods()
where method.ReturnType == typeof(void) && method.GetParameters().Length == 0
let can = (from p in _classProperties
where p.Name == "Can" + method.Name && p.PropertyType == typeof(bool)
select p).FirstOrDefault()
select new ClassMemberCommand(method, can, objectInstanceType)).ToList());
_propertyDescriptors = new PropertyDescriptorCollection(_classProperties.ToArray());
// Create a pass-through for each event.
_classEvents = _wrappedType
.GetEvents()
.Select(e => new ClassEvent(e))
.ToList();
_eventDescriptors = new EventDescriptorCollection(_classEvents.ToArray());
}
示例3: TypeNodeViewModel
/// <summary>
/// Initializes a new instance of the <see cref="TypeNodeViewModel"/> class.
/// </summary>
/// <param name="pType">Type of the port.</param>
public TypeNodeViewModel(Type pType)
{
this.DisplayString = pType.Name;
this.Description = "A class sample node.";
foreach (PropertyInfo lPropertyInfo in pType.GetProperties())
{
if (lPropertyInfo.CanWrite)
{
PortViewModel lPort = null;
lPort = new PortViewModel {Direction = PortDirection.Input, DisplayString = lPropertyInfo.Name, PortType = "Property"};
this.Ports.Add(lPort);
}
if (lPropertyInfo.CanRead)
{
PortViewModel lPort = null;
lPort = new PortViewModel { Direction = PortDirection.Output, DisplayString = lPropertyInfo.Name, PortType = "Property" };
this.Ports.Add(lPort);
}
}
foreach (EventInfo lEventInfo in pType.GetEvents())
{
PortViewModel lPort = new PortViewModel {Direction = PortDirection.Output, PortType = "Event", DisplayString = lEventInfo.Name};
this.Ports.Add(lPort);
}
}
示例4: DefineInterface
public static void DefineInterface(TypeBuilder typeBuilder, Type interfaceType, Type implementType,
Action<ILGenerator, MethodInfo, MethodInfo> ilGenerator)
{
var proxyMethodBuilder = new ProxyMethodBuilder(typeBuilder);
InterfaceMapping mapping = implementType.GetInterfaceMap(interfaceType);
for (int i = 0; i < mapping.InterfaceMethods.Length; i++)
mapping.TargetMethods[i] = proxyMethodBuilder.DefineMethod(mapping.InterfaceMethods[i],
il => ilGenerator(il, mapping.InterfaceMethods[i], mapping.TargetMethods[i]));
foreach (PropertyInfo propertyInfo in interfaceType.GetProperties())
{
MethodBuilder getMethodBuilder = null;
MethodInfo getMethodInfo = propertyInfo.GetGetMethod();
if (getMethodInfo != null)
getMethodBuilder = (MethodBuilder)GetTargetMethodInfo(ref mapping, getMethodInfo);
MethodBuilder setMethodBuilder = null;
MethodInfo setMethodInfo = propertyInfo.GetSetMethod();
if (setMethodInfo != null)
setMethodBuilder = (MethodBuilder)GetTargetMethodInfo(ref mapping, setMethodInfo);
ProxyBuilderHelper.DefineProperty(typeBuilder, propertyInfo, getMethodBuilder, setMethodBuilder);
}
foreach (EventInfo eventInfo in interfaceType.GetEvents())
{
var addMethodBuilder = (MethodBuilder)GetTargetMethodInfo(ref mapping, eventInfo.GetAddMethod());
var removeMethodBuilder = (MethodBuilder)GetTargetMethodInfo(ref mapping, eventInfo.GetRemoveMethod());
ProxyBuilderHelper.DefineEvent(typeBuilder, eventInfo, addMethodBuilder, removeMethodBuilder);
}
}
示例5: SetupEventSubscriptions
public void SetupEventSubscriptions(DynamicHubProxyInterceptor interceptor, IDynamicHubProxy proxy, Type proxyType)
{
var events = proxyType.GetEvents(BindingFlags.Public | BindingFlags.Instance);
foreach (var @event in events)
_proxy.Subscribe(@event.Name).Data += (tokens) =>
{
if( _events.ContainsKey(@event.Name)) {
var eventMethods = _events[@event.Name];
foreach (var eventMethod in eventMethods)
{
var actualParameters = new List<object>();
var parameters = eventMethod.Method.GetParameters();
for( var parameterIndex=0; parameterIndex<parameters.Length; parameterIndex++ )
{
var actualMethod = _toObjectMethod.MakeGenericMethod(parameters[parameterIndex].ParameterType);
var actualParameter = actualMethod.Invoke(tokens[parameterIndex], null);
actualParameters.Add(actualParameter);
}
eventMethod.DynamicInvoke(actualParameters.ToArray());
}
}
};
}
示例6: EmitEventBridgeType
/// <summary>
/// EmitEventBridgeType 发射实现了IEventBridge接口的事件桥类型
/// </summary>
/// <param name="typeOfEventPublisher">发布事件的类型</param>
/// <param name="typeOfEventHandler">包含了事件处理器方法的类型</param>
/// <param name="eventHandlerNamePrefix">处理器方法的名称的前缀(即该前缀加上事件名称就得到处理器方法的名称)</param>
/// <returns>实现了IEventBridge接口的事件桥类型,其构造参数为:typeOfEventPublisher,typeOfEventHandler</returns>
public Type EmitEventBridgeType(Type typeOfEventPublisher, Type typeOfEventHandler ,string eventHandlerNamePrefix)
{
Dictionary<string, string> eventAndHanlerMapping = new Dictionary<string, string>();
foreach (EventInfo eventInfo in typeOfEventPublisher.GetEvents())
{
string handlerName = eventHandlerNamePrefix + eventInfo.Name ;
MethodInfo method = typeOfEventHandler.GetMethod(handlerName) ;
if (method == null)
{
throw new Exception(string.Format("Can't find proper handler for {0}.{1} event in {2}!", typeOfEventPublisher, eventInfo.Name, typeOfEventHandler));
}
Type[] argTypes = EmitHelper.GetParametersType(method);
Type[] eventArgTypes = EmitHelper.GetParametersType(eventInfo.EventHandlerType.GetMethod("Invoke"));
if (argTypes.Length != eventArgTypes.Length)
{
throw new Exception(string.Format("Can't find proper handler for {0}.{1} event in {2}!", typeOfEventPublisher, eventInfo.Name, typeOfEventHandler));
}
for (int i = 0; i < argTypes.Length; i++)
{
if (argTypes[i] != eventArgTypes[i])
{
throw new Exception(string.Format("Can't find proper handler for {0}.{1} event in {2}!", typeOfEventPublisher, eventInfo.Name, typeOfEventHandler));
}
}
eventAndHanlerMapping.Add(eventInfo.Name, handlerName);
}
return this.EmitEventBridgeType(typeOfEventPublisher, typeOfEventHandler ,eventAndHanlerMapping);
}
示例7: WriteExtensionClass
private static void WriteExtensionClass(Type type, TextWriter output)
{
var usingNamespaces = new SortedSet<string>
{
type.Namespace,
"System.Reactive",
"System.Reactive.Linq"
};
var builder = new StringBuilder();
builder.AppendLine("namespace EventToObservableReflection");
builder.AppendLine("{");
builder.AppendLine(string.Format("\tpublic static class {0}EventToObservableExtensions", type.Name));
builder.AppendLine("\t{");
foreach (var e in type.GetEvents())
{
WriteExtensionMethod(type, e, builder, usingNamespaces);
}
builder.AppendLine("\t}");
builder.AppendLine("}");
foreach (var ns in usingNamespaces)
{
output.WriteLine("using {0};", ns);
}
output.WriteLine();
output.WriteLine(builder.ToString());
output.Flush();
}
示例8: GetEventsToProxy
private IEnumerable<EventInfo> GetEventsToProxy(Type contractType)
{
var declaredEvents = contractType.GetEvents();
var inheritedEvents = contractType.GetInterfaces().SelectMany(i => i.GetEvents());
var eventsToProxy = declaredEvents.Union(inheritedEvents);
return eventsToProxy;
}
示例9: ProxyTypeDescriptor
public ProxyTypeDescriptor(Type type)
{
Meta = TypeMeta.Get(type);
ProxyType = typeof(PlatformProxy<>).MakeGenericType(type);
_properties = Meta.Members.Select(m => new ProxyPropertyDescriptor(this, m)).ToArray();
_propertyCollection = new PropertyDescriptorCollection(_properties);
_events = new EventDescriptorCollection(type.GetEvents().Select(e => new ProxyEventDescriptor(e)).ToArray());
}
示例10: JSClassWrapper
public JSClassWrapper(ExecutionContext GLOBAL, Type t)
{
object thisOb = null;
mThisType = t;
BindingFlags flags = BindingFlags.DeclaredOnly | BindingFlags.Static | BindingFlags.Public;
string applyMethod = null;
object []attributes = t.GetCustomAttributes(false);
List<MethodInfo> applying = new List<MethodInfo>();
foreach (object attribute in attributes)
{
if (attribute is ApplyAttribute)
applyMethod = ((ApplyAttribute)attribute).MethodName;
}
if (t == typeof(Type))
{
thisOb = t;
flags |= BindingFlags.Instance;
}
Dictionary<string, List<MethodInfo>> namedMethods = new Dictionary<string, List<MethodInfo>>();
foreach (FieldInfo fieldInfo in mThisType.GetFields(flags))
{
this.SetItem(GLOBAL, fieldInfo.Name, new JSNativeField(thisOb, fieldInfo));
}
foreach (PropertyInfo propInfo in mThisType.GetProperties(flags))
{
this.SetItem(GLOBAL, propInfo.Name, new JSNativeProperty(thisOb, propInfo));
}
foreach (MethodInfo methodInfo in mThisType.GetMethods(flags))
{
List<MethodInfo> ml;
if (applyMethod != null && methodInfo.Name == applyMethod && methodInfo.IsStatic)
applying.Add(methodInfo);
if (!namedMethods.TryGetValue(methodInfo.Name, out ml))
{
ml = new List<MethodInfo>(new MethodInfo[] { methodInfo });
namedMethods[methodInfo.Name] = ml;
}
else
ml.Add(methodInfo);
}
foreach (EventInfo eventInfo in mThisType.GetEvents(flags))
{
this.SetItem(GLOBAL, eventInfo.Name, new JSNativeEvent(GLOBAL, thisOb, eventInfo));
}
foreach (KeyValuePair<string, List<MethodInfo>> method in namedMethods)
{
this.SetItem(GLOBAL, method.Key, new JSNativeMethod(method.Value.ToArray()));
}
if (applying.Count > 0)
{
mApplyMethod = new JSNativeMethod(applying.ToArray());
}
}
示例11: GetEventNames
///<summary>
/// Retrives a list of names of events that the given type publishes.
///</summary>
///<param name="type"></param>
///<returns></returns>
public static ICollection<string> GetEventNames(Type type)
{
List<string> list = new List<string>();
foreach (EventInfo info in type.GetEvents())
{
list.Add(info.Name);
}
return list;
}
示例12: BuildEventFields
private static void BuildEventFields(Type t, List<FieldInfo> lst)
{
lst.AddRange(
from ei in t.GetEvents(AllBindings)
let dt = ei.DeclaringType
select dt.GetField(ei.Name, AllBindings)
into fi
where fi != null
select fi);
}
示例13: InitializeFollowers
private static void InitializeFollowers(IServiceProvider context, Type interfaceType, string followermethodName)
{
if (!CorrelationResolver.IsInitializingMember(interfaceType, followermethodName, null))
{
foreach (EventInfo info in interfaceType.GetEvents())
{
CreateFollowerEntry(context, interfaceType, followermethodName, info.Name);
}
}
}
示例14: BuildEventFields
static void BuildEventFields(Type t, List<FieldInfo> lst)
{
// Type.GetEvent(s) gets all Events for the type AND it's ancestors
// Type.GetField(s) gets only Fields for the exact type.
// (BindingFlags.FlattenHierarchy only works on PROTECTED & PUBLIC
// doesn't work because Fields are PRIVATE)
// NEW version of this routine uses .GetEvents and then uses .DeclaringType
// to get the correct ancestor type so that we can get the FieldInfo.
lst.AddRange(from ei in t.GetEvents(AllBindings) let dt = ei.DeclaringType select dt.GetField(ei.Name, AllBindings) into fi where fi != null select fi);
}
示例15: GetEventsFor
private IList<IEventInfo> GetEventsFor(Type netType)
{
IList<IEventInfo> events = new List<IEventInfo>();
System.Reflection.EventInfo[] netEvents = netType.GetEvents(BindingFlags.Public | BindingFlags.NonPublic);
foreach (System.Reflection.EventInfo netEvent in netEvents)
{
IEventInfo eventInfo = new EventInfo();
eventInfo.Name = netEvent.Name;
events.Add(eventInfo);
}
return events;
}