public override MethodInfo GetAddMethod(bool nonPublic)
        {
            if (this.addMethod == null)
            {
                Type handlerType = declaringType.ResolveType(DesignTimeType.GetTypeNameFromCodeTypeReference(this.codeDomEvent.Type, declaringType));
                if (handlerType != null)
                {
                    CodeMemberMethod codeAddMethod = new CodeMemberMethod();

                    codeAddMethod.Name       = "add_" + this.name;
                    codeAddMethod.ReturnType = new CodeTypeReference(typeof(void));
                    codeAddMethod.Parameters.Add(new CodeParameterDeclarationExpression(this.codeDomEvent.Type, "Handler"));
                    codeAddMethod.Attributes = this.memberAttributes;
                    this.addMethod           = new DesignTimeMethodInfo(this.declaringType, codeAddMethod, true);
                }
            }
            return(this.addMethod);
        }
Ejemplo n.º 2
0
        internal static Attribute[] LoadCustomAttributes(CodeAttributeDeclarationCollection codeAttributeCollection, DesignTimeType declaringType)
        {
            if (declaringType == null)
            {
                throw new ArgumentNullException("declaringType");
            }

            if (codeAttributeCollection == null)
            {
                return(new Attribute[0]);
            }

            List <Attribute> attributes = new List <Attribute>();

            // walk through the attributes
            foreach (CodeAttributeDeclaration codeAttribute in codeAttributeCollection)
            {
                String[] argumentNames  = new String[codeAttribute.Arguments.Count];
                object[] argumentValues = new object[codeAttribute.Arguments.Count];

                Type attributeType = declaringType.ResolveType(codeAttribute.Name);

                if (attributeType != null)
                {
                    int index = 0;

                    // walk through tha arguments
                    foreach (CodeAttributeArgument codeArgument in codeAttribute.Arguments)
                    {
                        argumentNames[index] = codeArgument.Name;

                        if (codeArgument.Value is CodePrimitiveExpression)
                        {
                            argumentValues[index] = (codeArgument.Value as CodePrimitiveExpression).Value;
                        }
                        else if (codeArgument.Value is CodeTypeOfExpression)
                        {
                            argumentValues[index] = codeArgument.Value;
                        }
                        else if (codeArgument.Value is CodeSnippetExpression)
                        {
                            argumentValues[index] = (codeArgument.Value as CodeSnippetExpression).Value;
                        }
                        else
                        {
                            argumentValues[index] = new ArgumentException(SR.GetString(SR.Error_TypeSystemAttributeArgument));
                        }

                        index++;
                    }
                    bool alreadyExists = false;
                    foreach (AttributeInfoAttribute attribInfo in attributes)
                    {
                        if (attribInfo.AttributeInfo.AttributeType.FullName.Equals(attributeType.FullName))
                        {
                            alreadyExists = true;
                            break;
                        }
                    }
                    //

                    bool allowMultiple = false;
                    if (alreadyExists && attributeType.Assembly != null)
                    {
                        object[] usageAttribs = attributeType.GetCustomAttributes(typeof(System.AttributeUsageAttribute), true);
                        if (usageAttribs != null && usageAttribs.Length > 0)
                        {
                            AttributeUsageAttribute usage = usageAttribs[0] as AttributeUsageAttribute;
                            allowMultiple = usage.AllowMultiple;
                        }
                    }
                    // now create and add the placeholder attribute
                    if (!alreadyExists || allowMultiple)
                    {
                        attributes.Add(AttributeInfoAttribute.CreateAttributeInfoAttribute(attributeType, argumentNames, argumentValues));
                    }
                }
            }
            return(attributes.ToArray());
        }
 internal static Attribute[] LoadCustomAttributes(CodeAttributeDeclarationCollection codeAttributeCollection, DesignTimeType declaringType)
 {
     if (declaringType == null)
     {
         throw new ArgumentNullException("declaringType");
     }
     if (codeAttributeCollection == null)
     {
         return new Attribute[0];
     }
     List<Attribute> list = new List<Attribute>();
     foreach (CodeAttributeDeclaration declaration in codeAttributeCollection)
     {
         string[] argumentNames = new string[declaration.Arguments.Count];
         object[] argumentValues = new object[declaration.Arguments.Count];
         Type attributeType = declaringType.ResolveType(declaration.Name);
         if (attributeType != null)
         {
             int index = 0;
             foreach (CodeAttributeArgument argument in declaration.Arguments)
             {
                 argumentNames[index] = argument.Name;
                 if (argument.Value is CodePrimitiveExpression)
                 {
                     argumentValues[index] = (argument.Value as CodePrimitiveExpression).Value;
                 }
                 else if (argument.Value is CodeTypeOfExpression)
                 {
                     argumentValues[index] = argument.Value;
                 }
                 else if (argument.Value is CodeSnippetExpression)
                 {
                     argumentValues[index] = (argument.Value as CodeSnippetExpression).Value;
                 }
                 else
                 {
                     argumentValues[index] = new ArgumentException(SR.GetString("Error_TypeSystemAttributeArgument"));
                 }
                 index++;
             }
             bool flag = false;
             foreach (AttributeInfoAttribute attribute in list)
             {
                 if (attribute.AttributeInfo.AttributeType.FullName.Equals(attributeType.FullName))
                 {
                     flag = true;
                     break;
                 }
             }
             bool allowMultiple = false;
             if (flag && (attributeType.Assembly != null))
             {
                 object[] customAttributes = attributeType.GetCustomAttributes(typeof(AttributeUsageAttribute), true);
                 if ((customAttributes != null) && (customAttributes.Length > 0))
                 {
                     AttributeUsageAttribute attribute2 = customAttributes[0] as AttributeUsageAttribute;
                     allowMultiple = attribute2.AllowMultiple;
                 }
             }
             if (!flag || allowMultiple)
             {
                 list.Add(AttributeInfoAttribute.CreateAttributeInfoAttribute(attributeType, argumentNames, argumentValues));
             }
         }
     }
     return list.ToArray();
 }
Ejemplo n.º 4
0
        internal static Attribute[] LoadCustomAttributes(CodeAttributeDeclarationCollection codeAttributeCollection, DesignTimeType declaringType)
        {
            if (declaringType == null)
                throw new ArgumentNullException("declaringType");

            if (codeAttributeCollection == null)
                return new Attribute[0];

            List<Attribute> attributes = new List<Attribute>();

            // walk through the attributes 
            foreach (CodeAttributeDeclaration codeAttribute in codeAttributeCollection)
            {
                String[] argumentNames = new String[codeAttribute.Arguments.Count];
                object[] argumentValues = new object[codeAttribute.Arguments.Count];

                Type attributeType = declaringType.ResolveType(codeAttribute.Name);

                if (attributeType != null)
                {
                    int index = 0;

                    // walk through tha arguments
                    foreach (CodeAttributeArgument codeArgument in codeAttribute.Arguments)
                    {
                        argumentNames[index] = codeArgument.Name;

                        if (codeArgument.Value is CodePrimitiveExpression)
                            argumentValues[index] = (codeArgument.Value as CodePrimitiveExpression).Value;
                        else if (codeArgument.Value is CodeTypeOfExpression)
                            argumentValues[index] = codeArgument.Value;
                        else if (codeArgument.Value is CodeSnippetExpression)
                            argumentValues[index] = (codeArgument.Value as CodeSnippetExpression).Value;
                        else
                            argumentValues[index] = new ArgumentException(SR.GetString(SR.Error_TypeSystemAttributeArgument));

                        index++;
                    }
                    bool alreadyExists = false;
                    foreach (AttributeInfoAttribute attribInfo in attributes)
                    {
                        if (attribInfo.AttributeInfo.AttributeType.FullName.Equals(attributeType.FullName))
                        {
                            alreadyExists = true;
                            break;
                        }
                    }
                    // 

                    bool allowMultiple = false;
                    if (alreadyExists && attributeType.Assembly != null)
                    {
                        object[] usageAttribs = attributeType.GetCustomAttributes(typeof(System.AttributeUsageAttribute), true);
                        if (usageAttribs != null && usageAttribs.Length > 0)
                        {
                            AttributeUsageAttribute usage = usageAttribs[0] as AttributeUsageAttribute;
                            allowMultiple = usage.AllowMultiple;
                        }
                    }
                    // now create and add the placeholder attribute
                    if (!alreadyExists || allowMultiple)
                        attributes.Add(AttributeInfoAttribute.CreateAttributeInfoAttribute(attributeType, argumentNames, argumentValues));
                }
            }
            return attributes.ToArray();
        }
Ejemplo n.º 5
0
        internal static Attribute[] LoadCustomAttributes(CodeAttributeDeclarationCollection codeAttributeCollection, DesignTimeType declaringType)
        {
            if (declaringType == null)
            {
                throw new ArgumentNullException("declaringType");
            }
            if (codeAttributeCollection == null)
            {
                return(new Attribute[0]);
            }
            List <Attribute> list = new List <Attribute>();

            foreach (CodeAttributeDeclaration declaration in codeAttributeCollection)
            {
                string[] argumentNames  = new string[declaration.Arguments.Count];
                object[] argumentValues = new object[declaration.Arguments.Count];
                Type     attributeType  = declaringType.ResolveType(declaration.Name);
                if (attributeType != null)
                {
                    int index = 0;
                    foreach (CodeAttributeArgument argument in declaration.Arguments)
                    {
                        argumentNames[index] = argument.Name;
                        if (argument.Value is CodePrimitiveExpression)
                        {
                            argumentValues[index] = (argument.Value as CodePrimitiveExpression).Value;
                        }
                        else if (argument.Value is CodeTypeOfExpression)
                        {
                            argumentValues[index] = argument.Value;
                        }
                        else if (argument.Value is CodeSnippetExpression)
                        {
                            argumentValues[index] = (argument.Value as CodeSnippetExpression).Value;
                        }
                        else
                        {
                            argumentValues[index] = new ArgumentException(SR.GetString("Error_TypeSystemAttributeArgument"));
                        }
                        index++;
                    }
                    bool flag = false;
                    foreach (AttributeInfoAttribute attribute in list)
                    {
                        if (attribute.AttributeInfo.AttributeType.FullName.Equals(attributeType.FullName))
                        {
                            flag = true;
                            break;
                        }
                    }
                    bool allowMultiple = false;
                    if (flag && (attributeType.Assembly != null))
                    {
                        object[] customAttributes = attributeType.GetCustomAttributes(typeof(AttributeUsageAttribute), true);
                        if ((customAttributes != null) && (customAttributes.Length > 0))
                        {
                            AttributeUsageAttribute attribute2 = customAttributes[0] as AttributeUsageAttribute;
                            allowMultiple = attribute2.AllowMultiple;
                        }
                    }
                    if (!flag || allowMultiple)
                    {
                        list.Add(AttributeInfoAttribute.CreateAttributeInfoAttribute(attributeType, argumentNames, argumentValues));
                    }
                }
            }
            return(list.ToArray());
        }