Exemplo n.º 1
0
        XAttributeLiteral AssignToValues(XAttributeList list, XAttribute definedAttribute, string value)
        {
            if (value != null)
            {
                XAttributeLiteral attr = (XAttributeLiteral)definedAttribute.Clone();

                attr.Value = value;
                list.AddToCollection(attr);

                return(attr);
            }
            return(null);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Derives a prototype for the given attribute. This prototype attribute
        /// will be equal in all respects, expect for the value of the attribute.
        /// This value will be set to a default value, depending on the specific type
        /// of the given attribute.
        /// </summary>
        /// <returns>The derived prototype attribute.</returns>
        /// <param name="instance">Attribute to derive prototype from.</param>
        public static XAttribute DerivePrototype(XAttribute instance)
        {
            XAttribute prototype = (XAttribute)instance.Clone();

            if (!(prototype is XAttributeList))
            {
                if (!(prototype is XAttributeContainer))
                {
                    if (prototype is XAttributeLiteral)
                    {
                        ((XAttributeLiteral)prototype).Value = "DEFAULT";
                    }
                    else if (prototype is XAttributeBoolean)
                    {
                        ((XAttributeBoolean)prototype).Value = true;
                    }
                    else if (prototype is XAttributeContinuous)
                    {
                        ((XAttributeContinuous)prototype).Value = 0.0D;
                    }
                    else if (prototype is XAttributeDiscrete)
                    {
                        ((XAttributeDiscrete)prototype).Value = 0L;
                    }
                    else if (prototype is IXAttributeTimestamp)
                    {
                        ((XAttributeTimestamp)prototype).ValueMillis = 0L;
                    }
                    else if (prototype is XAttributeID)
                    {
                        ((XAttributeID)prototype).Value = XIDFactory.Instance.CreateId();
                    }
                    else
                    {
                        throw new InvalidOperationException("Unexpected attribute type!");
                    }
                }
            }
            return(prototype);
        }