Ejemplo n.º 1
0
        override public void OnAttribute(Boo.Lang.Compiler.Ast.Attribute node)
        {
            Type attrType = AttributeType(node);

            if (attrType == null)
            {
                return;
            }

            // check allowed attribute usage(s)
            System.Attribute[] usages = System.Attribute.GetCustomAttributes(attrType, typeof(AttributeUsageAttribute));
            if (usages.Length == 0)
            {
                return;
            }

            //only one AttributeUsage is allowed anyway
            AttributeUsageAttribute usage = (AttributeUsageAttribute)usages[0];

            if (AttributeTargets.All != usage.ValidOn)
            {
                AttributeTargets?target = TargetFor(node);
                if (target.HasValue && !IsValid(usage, target.Value))
                {
                    Errors.Add(
                        CompilerErrorFactory.InvalidAttributeTarget(node, attrType, usage.ValidOn));
                }
            }
            if (!usage.AllowMultiple)
            {
                INodeWithAttributes m = node.ParentNode as INodeWithAttributes;
                foreach (Boo.Lang.Compiler.Ast.Attribute mAttr in m.Attributes)
                {
                    if (mAttr == node)
                    {
                        continue;
                    }
                    IExternalEntity mAttrEnt = mAttr.Entity as IExternalEntity;
                    if (null != mAttrEnt && mAttrEnt.MemberInfo.DeclaringType == attrType)
                    {
                        Errors.Add(
                            CompilerErrorFactory.MultipleAttributeUsage(node, attrType));
                    }
                }
            }

            // handle special compiler-supported attributes
            //TODO: ObsoleteAttribute
        }
Ejemplo n.º 2
0
 void EmitAttributes(INodeWithAttributes node, CustomAttributeSetter setCustomAttribute)
 {
     foreach (Attribute attribute in node.Attributes)
     {
         setCustomAttribute(GetCustomAttributeBuilder(attribute));
     }
 }
Ejemplo n.º 3
0
		void EmitAttributes(INodeWithAttributes node, CustomAttributeSetter setCustomAttribute, TypeCreator knownTypes)
		{
			foreach (Attribute attribute in node.Attributes)
				knownTypes.CreateAttributeTypes(attribute);
			foreach (Attribute attribute in node.Attributes)
				setCustomAttribute(GetCustomAttributeBuilder(attribute));
		}
Ejemplo n.º 4
0
 public void FlushAttributes(INodeWithAttributes node)
 {
     node.get_Attributes().AddRange(this._attributes);
     this._attributes.Clear();
 }