Пример #1
0
        public ReactEventInfo(FieldInfo fieldInfo, ReactEventAttribute eventAttribute)
        {
            EventName = eventAttribute.EventName ?? fieldInfo.Name;
            var eventArgType = GetEventArgType(fieldInfo.FieldType,
                                               formatError: message => $"{message} Module: {fieldInfo.DeclaringType.Name}, Field: {fieldInfo.Name}");

            EventImpl = new Lazy <ReactEventImpl>(() => MakeEvent(fieldInfo, eventArgType), LazyThreadSafetyMode.PublicationOnly);
        }
        public ReactEventInfo(PropertyInfo propertyInfo, ReactEventAttribute eventAttribute, string eventEmitterName)
        {
            var eventName = eventAttribute.EventName ?? propertyInfo.Name;

            eventEmitterName = eventAttribute.EventEmitterName ?? eventEmitterName;
            var eventArgTypes = GetEventArgTypes(propertyInfo.PropertyType,
                                                 formatError: message => $"{message} Module: {propertyInfo.DeclaringType.Name}, Property: {propertyInfo.Name}");

            EventImpl = new Lazy <ReactEventImpl>(() =>
                                                  MakeEvent(propertyInfo, eventEmitterName, eventName, eventArgTypes), LazyThreadSafetyMode.PublicationOnly);
        }
        public ReactEventInfo(PropertyInfo propertyInfo, ReactEventAttribute eventAttribute)
        {
            EventName = eventAttribute.EventName ?? propertyInfo.Name;

            Type propertyType = propertyInfo.PropertyType;

            if (!typeof(Delegate).IsAssignableFrom(propertyType))
            {
                throw new ArgumentException("React event must be a delegate", propertyInfo.Name);
            }
            ReflectionMethodInfo eventDelegateMethod = propertyType.GetMethod("Invoke");

            ParameterInfo[] parameters = eventDelegateMethod.GetParameters();
            if (parameters.Length != 1)
            {
                throw new ArgumentException($"React event delegate must have one parameter. Module: {propertyInfo.DeclaringType.FullName}, Event: {propertyInfo.Name}");
            }
            EventImpl = new Lazy <ReactEventImpl>(() => MakeEvent(propertyInfo, parameters[0]), LazyThreadSafetyMode.PublicationOnly);
        }