Пример #1
0
 internal static System.Type GetDelegateFromEvent(EventInfo eventInfo)
 {
     if (eventInfo.EventHandlerType != null)
     {
         return(eventInfo.EventHandlerType);
     }
     return(TypeProvider.GetEventHandlerType(eventInfo));
 }
Пример #2
0
        internal void GetParameterPropertyDescriptors(IDictionary properties)
        {
            if (((IComponent)this).Site == null)
            {
                return;
            }

            ITypeProvider typeProvider = (ITypeProvider)((IComponent)this).Site.GetService(typeof(ITypeProvider));

            if (typeProvider == null)
            {
                throw new InvalidOperationException(SR.GetString(SR.General_MissingService, typeof(ITypeProvider).FullName));
            }

            Type type = this.InterfaceType;

            if (type == null)
            {
                return;
            }

            if (this.GetType() != typeof(HandleExternalEventActivity))
            {
                return; // if custom activity do not add parameter binding
            }
            EventInfo eventInfo = type.GetEvent(this.EventName);

            if (eventInfo != null)
            {
                Type delegateType = TypeProvider.GetEventHandlerType(eventInfo);
                if (delegateType != null)
                {
                    MethodInfo method    = delegateType.GetMethod("Invoke");
                    ArrayList  paramInfo = new ArrayList();
                    if (method != null)
                    {
                        paramInfo.AddRange(method.GetParameters());
                        if (!(method.ReturnType == typeof(void)))
                        {
                            paramInfo.Add(method.ReturnParameter);
                        }
                    }

                    foreach (ParameterInfo param in paramInfo)
                    {
                        PropertyDescriptor prop = new ParameterInfoBasedPropertyDescriptor(typeof(HandleExternalEventActivity), param, true, DesignOnlyAttribute.Yes);
                        properties[prop.Name] = prop;
                    }
                }
            }
        }
Пример #3
0
        internal static ValidationErrorCollection Validate(ValidationManager manager, object obj)
        {
            ValidationErrorCollection validationErrors = new ValidationErrorCollection();
            Activity activity = obj as Activity;

            if (!(activity is CallExternalMethodActivity) && !(activity is HandleExternalEventActivity))
            {
                throw new ArgumentException(SR.GetString("Error_UnexpectedArgumentType", new object[] { typeof(Activity).FullName }), "obj");
            }
            Type type = (activity is CallExternalMethodActivity) ? ((CallExternalMethodActivity)activity).InterfaceType : ((HandleExternalEventActivity)activity).InterfaceType;

            if (type != null)
            {
                string str = (activity is CallExternalMethodActivity) ? ((CallExternalMethodActivity)activity).MethodName : ((HandleExternalEventActivity)activity).EventName;
                if (string.IsNullOrEmpty(str))
                {
                    return(validationErrors);
                }
                WorkflowParameterBindingCollection parameterBindings = (activity is CallExternalMethodActivity) ? ((CallExternalMethodActivity)activity).ParameterBindings : ((HandleExternalEventActivity)activity).ParameterBindings;
                MethodInfo method = type.GetMethod(str);
                if ((method == null) && (activity is CallExternalMethodActivity))
                {
                    return(validationErrors);
                }
                bool isEvent = false;
                if (method == null)
                {
                    EventInfo eventInfo = type.GetEvent(str);
                    if ((eventInfo == null) || (eventInfo.GetAddMethod(true) == null))
                    {
                        return(validationErrors);
                    }
                    Type eventHandlerType = eventInfo.EventHandlerType;
                    if (eventHandlerType == null)
                    {
                        eventHandlerType = TypeProvider.GetEventHandlerType(eventInfo);
                    }
                    method  = eventHandlerType.GetMethod("Invoke");
                    isEvent = true;
                }
                ValidateParameterBinding(manager, activity, isEvent, str, method, parameterBindings, validationErrors);
            }
            return(validationErrors);
        }
 internal void GetParameterPropertyDescriptors(IDictionary properties)
 {
     if (this.Site != null)
     {
         if (((ITypeProvider)this.Site.GetService(typeof(ITypeProvider))) == null)
         {
             throw new InvalidOperationException(SR.GetString("General_MissingService", new object[] { typeof(ITypeProvider).FullName }));
         }
         Type interfaceType = this.InterfaceType;
         if ((interfaceType != null) && (base.GetType() == typeof(HandleExternalEventActivity)))
         {
             EventInfo eventInfo = interfaceType.GetEvent(this.EventName);
             if (eventInfo != null)
             {
                 Type eventHandlerType = TypeProvider.GetEventHandlerType(eventInfo);
                 if (eventHandlerType != null)
                 {
                     MethodInfo method = eventHandlerType.GetMethod("Invoke");
                     ArrayList  list   = new ArrayList();
                     if (method != null)
                     {
                         list.AddRange(method.GetParameters());
                         if (!(method.ReturnType == typeof(void)))
                         {
                             list.Add(method.ReturnParameter);
                         }
                     }
                     foreach (ParameterInfo info3 in list)
                     {
                         PropertyDescriptor descriptor = new System.Workflow.Activities.Common.ParameterInfoBasedPropertyDescriptor(typeof(HandleExternalEventActivity), info3, true, new Attribute[] { DesignOnlyAttribute.Yes });
                         properties[descriptor.Name] = descriptor;
                     }
                 }
             }
         }
     }
 }
        private static ValidationErrorCollection ValidateHostInterfaceMembers(Type interfaceType, Activity activity)
        {
            ValidationErrorCollection errors = new ValidationErrorCollection();

            foreach (MemberInfo info in interfaceType.GetMembers())
            {
                if (((info is MethodInfo) || (info is EventInfo)) && (!(info is MethodInfo) || !((MethodInfo)info).IsSpecialName))
                {
                    MethodInfo method           = null;
                    Type       eventHandlerType = null;
                    if (info is EventInfo)
                    {
                        EventInfo eventInfo = (EventInfo)info;
                        eventHandlerType = eventInfo.EventHandlerType;
                        if (eventHandlerType == null)
                        {
                            eventHandlerType = TypeProvider.GetEventHandlerType(eventInfo);
                        }
                        if (eventHandlerType == null)
                        {
                            throw new InvalidOperationException();
                        }
                        method = eventHandlerType.GetMethod("Invoke");
                    }
                    else
                    {
                        method = (MethodInfo)info;
                    }
                    if (method.IsGenericMethod)
                    {
                        ValidationError item = new ValidationError(string.Format(CultureInfo.CurrentCulture, SR.GetString("Error_GenericMethodsNotSupported"), new object[] { (info is EventInfo) ? eventHandlerType.Name : method.Name }), 0x155);
                        if (info is EventInfo)
                        {
                            item.UserData.Add(typeof(EventInfo), ((EventInfo)info).Name);
                        }
                        else
                        {
                            item.UserData.Add(typeof(MethodInfo), method.Name);
                        }
                        errors.Add(item);
                    }
                    if ((method.ReturnType != typeof(void)) && (info is EventInfo))
                    {
                        ValidationError error2 = new ValidationError(string.Format(CultureInfo.CurrentCulture, SR.GetString("Error_ReturnTypeNotVoid"), new object[] { (info is EventInfo) ? eventHandlerType.Name : method.Name }), 0x156);
                        if (info is EventInfo)
                        {
                            error2.UserData.Add(typeof(EventInfo), ((EventInfo)info).Name);
                        }
                        else
                        {
                            error2.UserData.Add(typeof(MethodInfo), method.Name);
                        }
                        errors.Add(error2);
                    }
                    foreach (ParameterInfo info4 in method.GetParameters())
                    {
                        if (info4.IsOut || info4.IsRetval)
                        {
                            ValidationError error3 = new ValidationError(string.Format(CultureInfo.CurrentCulture, SR.GetString("Error_OutRefParameterNotSupported"), new object[] { (info is EventInfo) ? eventHandlerType.Name : method.Name, info4.Name }), 0x157);
                            if (info is EventInfo)
                            {
                                error3.UserData.Add(typeof(EventInfo), ((EventInfo)info).Name);
                            }
                            else
                            {
                                error3.UserData.Add(typeof(MethodInfo), method.Name);
                            }
                            error3.UserData.Add(typeof(ParameterInfo), info4.Name);
                            errors.Add(error3);
                        }
                    }
                }
            }
            return(errors);
        }