Exemplo n.º 1
0
        protected static AttributeList ConvertToAttributeList(object curvalue)
        {
            AttributeList multi;

            if (curvalue == null)
            {
                multi = new AttributeList(); // make list to hold multiple values
                multi.Add(curvalue);         // Add previous single-valued attribute
            }
            else if (curvalue.GetType() == typeof(AttributeList))
            {
                // already a list made by Template
                multi = (AttributeList)curvalue;
            }
            else if (curvalue is IList)
            {
                // existing attribute is non-Template List
                // must copy to an Template-managed list before adding new attribute
                // (can't alter incoming attributes)
                IList listAttr = (IList)curvalue;
                multi = new AttributeList(listAttr.Count);
                multi.AddRange(listAttr.Cast <object>());
            }
            else
            {
                // curvalue nonlist and we want to Add an attribute
                // must convert curvalue existing to list
                multi = new AttributeList(); // make list to hold multiple values
                multi.Add(curvalue);         // Add previous single-valued attribute
            }
            return(multi);
        }
Exemplo n.º 2
0
    /// <summary>
    /// Gets a list of custom attributes
    /// </summary>
    /// <param name="propertyInfo"></param>
    /// <returns></returns>
    public static AttributeList GetCustomAttributeList(ICustomAttributeProvider propertyInfo)
    {
        var result = new AttributeList();

        result.AddRange(propertyInfo.GetCustomAttributes(false).Cast <Attribute>());
        return(result);
    }
Exemplo n.º 3
0
 internal void Override(OverrideEditConfig ovEdit)
 {
     if (ovEdit.ReadOnly.HasValue)
     {
         ReadOnly = ovEdit.ReadOnly.Value;
     }
     if (ovEdit.Class != null)
     {
         Class = ovEdit.Class;
     }
     if (ovEdit.DefaultValue != null)
     {
         DefaultValue = ovEdit.DefaultValue;
     }
     if (ovEdit.Updating != null)
     {
         Updating = ovEdit.Updating;
     }
     if (ovEdit.AttributeList != null)
     {
         if (AttributeList == null)
         {
             AttributeList = ovEdit.AttributeList;
         }
         else
         {
             AttributeList.AddRange(ovEdit.AttributeList);
         }
     }
     if (ovEdit.Display != null)
     {
         Display = ovEdit.Display;
     }
 }
Exemplo n.º 4
0
        public virtual Template Add(string name, object value)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (name.IndexOf('.') >= 0)
            {
                throw new ArgumentException("cannot have '.' in attribute names");
            }

            if (Group.TrackCreationEvents)
            {
                if (_debugState == null)
                {
                    _debugState = new TemplateDebugState();
                }
                _debugState.AddAttributeEvents.Add(name, new AddAttributeEvent(name, value));
            }

            FormalArgument arg = null;

            if (impl.HasFormalArgs)
            {
                arg = impl.TryGetFormalArgument(name);
                if (arg == null)
                {
                    throw new ArgumentException("no such attribute: " + name);
                }
            }
            else
            {
                // define and make room in locals (a hack to make new Template("simple template") work.)
                arg = impl.TryGetFormalArgument(name);
                if (arg == null)
                {
                    // not defined
                    arg = new FormalArgument(name);
                    impl.AddArgument(arg);
                    if (locals == null)
                    {
                        locals = new object[1];
                    }
                    else
                    {
                        Array.Resize(ref locals, impl.FormalArguments.Count);
                    }

                    locals[arg.Index] = EmptyAttribute;
                }
            }

            object curvalue = locals[arg.Index];

            if (curvalue == EmptyAttribute)
            {
                // new attribute
                locals[arg.Index] = value;
                return(this);
            }

            // attribute will be multi-valued for sure now
            // convert current attribute to list if not already
            // copy-on-Write semantics; copy a list injected by user to Add new value
            AttributeList multi = ConvertToAttributeList(curvalue);

            locals[arg.Index] = multi; // replace with list

            // now, Add incoming value to multi-valued attribute
            IList list = value as IList;

            if (list != null)
            {
                // flatten incoming list into existing list
                multi.AddRange(list.Cast <object>());
            }
            else
            {
                multi.Add(value);
            }

            return(this);
        }
 //
 // Helper to add a enum of attributes ot an existing list
 //
 private static void AddAttributes(AttributeList list, IEnumerable <object> attributes)
 {
     // Attributes are ordered so those at the end of the
     // list take prececence over those at the front.
     list.AddRange(attributes);
 }
Exemplo n.º 6
0
 protected static AttributeList ConvertToAttributeList(object curvalue)
 {
     AttributeList multi;
     if (curvalue == null)
     {
         multi = new AttributeList(); // make list to hold multiple values
         multi.Add(curvalue);         // add previous single-valued attribute
     }
     else if (curvalue.GetType() == typeof(AttributeList))
     { // already a list made by ST
         multi = (AttributeList)curvalue;
     }
     else if (curvalue is IList)
     { // existing attribute is non-ST List
         // must copy to an ST-managed list before adding new attribute
         // (can't alter incoming attributes)
         IList listAttr = (IList)curvalue;
         multi = new AttributeList(listAttr.Count);
         multi.AddRange(listAttr);
     }
     else if (curvalue.GetType().IsArray)
     { // copy array to list
         object[] a = (object[])curvalue;
         multi = new AttributeList(a.Length);
         multi.AddRange(a); // asList doesn't copy as far as I can tell
     }
     else
     {
         // curvalue nonlist and we want to add an attribute
         // must convert curvalue existing to list
         multi = new AttributeList(); // make list to hold multiple values
         multi.Add(curvalue);         // add previous single-valued attribute
     }
     return multi;
 }