private CorrelationAliasAttribute GetMatchingCorrelationAlias(CorrelationParameterAttribute paramAttribute, Dictionary <string, CorrelationAliasAttribute> correlationAliases, bool defaultParameter)
        {
            CorrelationAliasAttribute attribute = null;

            if (correlationAliases == null)
            {
                return(null);
            }
            if (!defaultParameter || !correlationAliases.TryGetValue("", out attribute))
            {
                correlationAliases.TryGetValue(paramAttribute.Name, out attribute);
            }
            return(attribute);
        }
Exemplo n.º 2
0
        private CorrelationAliasAttribute GetMatchingCorrelationAlias(CorrelationParameterAttribute paramAttribute, Dictionary <String, CorrelationAliasAttribute> correlationAliases, bool defaultParameter)
        {
            CorrelationAliasAttribute corrAlias = null;

            if (correlationAliases == null)
            {
                return(null);
            }

            if (defaultParameter)
            {
                if (correlationAliases.TryGetValue("", out corrAlias))
                {
                    return(corrAlias);
                }
            }

            correlationAliases.TryGetValue(paramAttribute.Name, out corrAlias);
            return(corrAlias);
        }
        private CorrelationAliasAttribute GetMatchingCorrelationAlias(CorrelationParameterAttribute paramAttribute, Dictionary<String, CorrelationAliasAttribute> correlationAliases, bool defaultParameter)
        {
            CorrelationAliasAttribute corrAlias = null;

            if (correlationAliases == null) return null;

            if (defaultParameter)
            {
                if (correlationAliases.TryGetValue("", out corrAlias))
                {
                    return corrAlias;
                }
            }

            correlationAliases.TryGetValue(paramAttribute.Name, out corrAlias);
            return corrAlias;
        }
        private static ValidationErrorCollection ValidateHostInterfaceAttributes(Type interfaceType)
        {
            if (interfaceType == null)
            {
                throw new ArgumentNullException("interfaceType");
            }
            ValidationErrorCollection validationErrors = new ValidationErrorCollection();
            ArrayList list = new ArrayList();

            foreach (object obj2 in interfaceType.GetCustomAttributes(typeof(CorrelationParameterAttribute), false))
            {
                CorrelationParameterAttribute attributeFromObject = Helpers.GetAttributeFromObject <CorrelationParameterAttribute>(obj2);
                if (string.IsNullOrEmpty(attributeFromObject.Name) || (attributeFromObject.Name.Trim().Length == 0))
                {
                    ValidationError item = new ValidationError(SR.GetString(CultureInfo.CurrentCulture, "Error_CorrelationAttributeInvalid", new object[] { typeof(CorrelationParameterAttribute).Name, "Name", interfaceType.Name }), 0x150);
                    item.UserData.Add(typeof(CorrelationParameterAttribute), interfaceType.Name);
                    validationErrors.Add(item);
                }
                else if (list.Contains(attributeFromObject.Name))
                {
                    ValidationError error2 = new ValidationError(SR.GetString(CultureInfo.CurrentCulture, "Error_DuplicateCorrelationAttribute", new object[] { typeof(CorrelationParameterAttribute).Name, attributeFromObject.Name, interfaceType.Name }), 0x151);
                    error2.UserData.Add(typeof(CorrelationParameterAttribute), interfaceType.Name);
                    validationErrors.Add(error2);
                }
                else
                {
                    list.Add(attributeFromObject.Name);
                }
            }
            Hashtable hashtable  = new Hashtable();
            Hashtable hashtable2 = new Hashtable();
            Hashtable hashtable3 = new Hashtable();
            int       num        = 0;

            foreach (MemberInfo info in interfaceType.GetMembers())
            {
                if ((info is MethodInfo) && !((MethodInfo)info).IsSpecialName)
                {
                    Hashtable hashtable4 = new Hashtable();
                    hashtable2.Add(info, hashtable4);
                    FillCorrelationAliasAttrs(info, hashtable4, validationErrors);
                    int length = info.GetCustomAttributes(typeof(CorrelationInitializerAttribute), false).Length;
                    num += length;
                    if (length > 0)
                    {
                        foreach (string str in list)
                        {
                            string paramPath = str;
                            if (hashtable4.Contains(str))
                            {
                                paramPath = ((CorrelationAliasAttribute)hashtable4[str]).Path;
                            }
                            Type type = FetchParameterType(info, paramPath);
                            if ((type != null) && !hashtable.ContainsKey(str))
                            {
                                hashtable[str] = type;
                            }
                        }
                    }
                }
                else if (info is EventInfo)
                {
                    int num3 = info.GetCustomAttributes(typeof(CorrelationInitializerAttribute), false).Length;
                    num += num3;
                    Hashtable hashtable5 = new Hashtable();
                    hashtable2.Add(info, hashtable5);
                    FillCorrelationAliasAttrs(info, hashtable5, validationErrors);
                    Type delegateFromEvent = Helpers.GetDelegateFromEvent((EventInfo)info);
                    delegateFromEvent.GetMethod("Invoke");
                    FillCorrelationAliasAttrs(delegateFromEvent, hashtable5, validationErrors);
                    Hashtable correlationAliasAttrs = new Hashtable();
                    FillCorrelationAliasAttrs(delegateFromEvent, correlationAliasAttrs, validationErrors);
                    if (hashtable3[delegateFromEvent] == null)
                    {
                        hashtable3.Add(delegateFromEvent, correlationAliasAttrs);
                    }
                    if (num3 > 0)
                    {
                        foreach (string str3 in list)
                        {
                            string path = str3;
                            if (hashtable5.Contains(str3))
                            {
                                path = ((CorrelationAliasAttribute)hashtable5[str3]).Path;
                            }
                            Type type3 = FetchParameterType(info, path);
                            if ((type3 != null) && !hashtable.ContainsKey(str3))
                            {
                                hashtable[str3] = type3;
                            }
                        }
                    }
                }
            }
            foreach (DictionaryEntry entry in hashtable2)
            {
                MemberInfo key        = entry.Key as MemberInfo;
                Hashtable  hashtable7 = (Hashtable)entry.Value;
                foreach (string str5 in hashtable7.Keys)
                {
                    if (!list.Contains(str5) && (!(key is EventInfo) || (((Hashtable)hashtable3[Helpers.GetDelegateFromEvent((EventInfo)key)])[str5] == null)))
                    {
                        ValidationError error3 = new ValidationError(SR.GetString(CultureInfo.CurrentCulture, "Error_CorrelationParameterNotFound", new object[] { typeof(CorrelationAliasAttribute).Name, str5, key.Name, typeof(CorrelationParameterAttribute).Name, interfaceType.Name }), 0x153);
                        error3.UserData.Add(typeof(CorrelationAliasAttribute), key.Name);
                        validationErrors.Add(error3);
                    }
                }
            }
            foreach (string str6 in list)
            {
                foreach (DictionaryEntry entry2 in hashtable2)
                {
                    string     str7       = str6;
                    MemberInfo info3      = (MemberInfo)entry2.Key;
                    Hashtable  hashtable8 = (Hashtable)entry2.Value;
                    if (hashtable8.Contains(str6))
                    {
                        str7 = ((CorrelationAliasAttribute)hashtable8[str6]).Path;
                    }
                    Type type4 = FetchParameterType((MemberInfo)entry2.Key, str7);
                    if (type4 == null)
                    {
                        if (!(info3 is EventInfo) || (((Hashtable)hashtable3[Helpers.GetDelegateFromEvent((EventInfo)info3)])[str6] == null))
                        {
                            ValidationError error4 = new ValidationError(SR.GetString(CultureInfo.CurrentCulture, "Error_CorrelationInvalid", new object[] { (info3.DeclaringType == interfaceType) ? info3.Name : info3.DeclaringType.Name, str6 }), 0x158);
                            error4.UserData.Add(typeof(CorrelationParameterAttribute), (info3.DeclaringType == interfaceType) ? info3.Name : info3.DeclaringType.Name);
                            validationErrors.Add(error4);
                        }
                    }
                    else if (hashtable.ContainsKey(str6) && (((Type)hashtable[str6]) != type4))
                    {
                        ValidationError error5 = new ValidationError(SR.GetString(CultureInfo.CurrentCulture, "Error_CorrelationTypeNotConsistent", new object[] { str7, typeof(CorrelationAliasAttribute).Name, (info3.DeclaringType == interfaceType) ? info3.Name : info3.DeclaringType.Name, type4.Name, ((Type)hashtable[str6]).Name, str6, interfaceType.Name }), 340);
                        error5.UserData.Add(typeof(CorrelationAliasAttribute), (info3.DeclaringType == interfaceType) ? info3.Name : info3.DeclaringType.Name);
                        validationErrors.Add(error5);
                    }
                }
            }
            if (num == 0)
            {
                ValidationError error6 = new ValidationError(SR.GetString(CultureInfo.CurrentCulture, "Error_CorrelationInitializerNotDefinied", new object[] { interfaceType.Name }), 0x159);
                error6.UserData.Add(typeof(CorrelationInitializerAttribute), interfaceType.Name);
                validationErrors.Add(error6);
            }
            return(validationErrors);
        }