Example #1
0
 private void AddAttribute(object target, IExpression attrExpr)
 {
     try
     {
         ICompilerAttribute value = evaluator.Evaluate(attrExpr) as ICompilerAttribute;
         if (value == null)
         {
             throw new InvalidExpressionException("Expression must evaluate to an ICompilerAttribute");
         }
         // TODO: Fix this temporary hack to allow quoting of this expression later
         if (value is MarginalPrototype)
         {
             ((MarginalPrototype)value).prototypeExpression = ((IObjectCreateExpression)attrExpr).Arguments[0];
         }
         object[] auas = value.GetType().GetCustomAttributes(typeof(AttributeUsageAttribute), true);
         if (auas.Length > 0)
         {
             AttributeUsageAttribute aua = (AttributeUsageAttribute)auas[0];
             if (!aua.AllowMultiple)
             {
                 Context.InputAttributes.RemoveOfType(target, value.GetType());
             }
         }
         Context.InputAttributes.Set(target, value);
     }
     catch (Exception ex)
     {
         Error("Could not evaluate attribute " + attrExpr, ex);
     }
 }