Base class of all value descriptor classes.
Ejemplo n.º 1
0
        /// <summary>
        /// Sets the member of dom specified by name to val.
        /// If a member with the specified name does not exist an ArgumentException will be thrown.
        /// </summary>
        public void SetValue(DocumentObject dom, string name, object val)
        {
            int dot = name.IndexOf('.');

            if (dot == 0)
            {
                throw new ArgumentException(DomSR.InvalidValueName(name));
            }
            string trail = null;

            if (dot > 0)
            {
                trail = name.Substring(dot + 1);
                name  = name.Substring(0, dot);
            }
            ValueDescriptor vd = this.vds[name];

            if (vd == null)
            {
                throw new ArgumentException(DomSR.InvalidValueName(name));
            }

            if (trail != null)
            {
                //REVIEW DaSt: dom.GetValue(name) und rekursiv SetValue aufrufen,
                //             oder dom.GetValue(name.BisVorletzteElement) und erst SetValue aufrufen.
                DocumentObject doc = dom.GetValue(name) as DocumentObject;
                doc.SetValue(trail, val);
            }
            else
            {
                vd.SetValue(dom, val);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sets the member of dom specified by name to val.
        /// If a member with the specified name does not exist an ArgumentException will be thrown.
        /// </summary>
        public void SetValue(DocumentObject dom, string name, object val)
        {
            int dot = name.IndexOf('.');

            if (dot == 0)
            {
                throw new ArgumentException(DomSR.InvalidValueName(name));
            }
            string trail = null;

            if (dot > 0)
            {
                trail = name.Substring(dot + 1);
                name  = name.Substring(0, dot);
            }
            ValueDescriptor vd = _vds[name];

            if (vd == null)
            {
                throw new ArgumentException(DomSR.InvalidValueName(name));
            }

            if (trail != null)
            {
                //REVIEW DaSt: dom.GetValue(name) and call SetValue recursively,
                //             or dom.GetValue(name.BisVorletzteElement) and then call SetValue?
                DocumentObject doc = (DocumentObject)dom.GetValue(name);
                doc.SetValue(trail, val);
            }
            else
            {
                vd.SetValue(dom, val);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Sets the member of dom specified by name to null.
        /// If a member with the specified name does not exist an ArgumentException will be thrown.
        /// </summary>
        public void SetNull(DocumentObject dom, string name)
        {
            ValueDescriptor vd = _vds[name];

            if (vd == null)
            {
                throw new ArgumentException(DomSR.InvalidValueName(name));
            }

            vd.SetNull(dom);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Determines whether the member of dom specified by name is null.
        /// If a member with the specified name does not exist an ArgumentException will be thrown.
        /// </summary>
        public virtual bool IsNull(DocumentObject dom, string name)
        {
            //bool isNull = false;
            int dot = name.IndexOf('.');

            if (dot == 0)
            {
                throw new ArgumentException(DomSR.InvalidValueName(name));
            }
            string trail = null;

            if (dot > 0)
            {
                trail = name.Substring(dot + 1);
                name  = name.Substring(0, dot);
            }
            ValueDescriptor vd = this.vds[name];

            if (vd == null)
            {
                throw new ArgumentException(DomSR.InvalidValueName(name));
            }

            if (vd is NullableDescriptor || vd is ValueTypeDescriptor)
            {
                if (trail != null)
                {
                    throw new ArgumentException(DomSR.InvalidValueName(name));
                }
                return(vd.IsNull(dom));
            }
            DocumentObject docObj = (DocumentObject)vd.GetValue(dom, GV.ReadOnly);

            if (docObj == null)
            {
                return(true);
            }
            if (trail != null)
            {
                return(docObj.IsNull(trail));
            }
            else
            {
                return(docObj.IsNull());
            }

            //      DomValueDescriptor vd = vds[name];
            //      if (vd == null)
            //        throw new ArgumentException(DomSR.InvalidValueName(name));
            //
            //      return vd.IsNull(dom);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Adds a value descriptor for each field and property found in type to meta.
        /// </summary>
        static void AddValueDescriptors(Meta meta, Type type)
        {
#if !NETFX_CORE
            FieldInfo[] fieldInfos = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
#else
            var fieldInfos = type.GetTypeInfo().DeclaredFields;
#endif
            foreach (FieldInfo fieldInfo in fieldInfos)
            {
#if DEBUG_
                string name = fieldInfo.Name;
                if (name == "parent")
                {
                    name.GetType();
                }
#endif
                DVAttribute[] dvs = (DVAttribute[])fieldInfo.GetCustomAttributes(typeof(DVAttribute), false);
                if (dvs.Length == 1)
                {
                    ValueDescriptor vd = ValueDescriptor.CreateValueDescriptor(fieldInfo, dvs[0]);
                    meta.ValueDescriptors.Add(vd);
                }
            }

#if !NETFX_CORE
            PropertyInfo[] propInfos = type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
#else
            var propInfos = type.GetTypeInfo().DeclaredProperties;
#endif
            foreach (PropertyInfo propInfo in propInfos)
            {
#if DEBUG_
                string name = propInfo.Name;
                if (name == "Font")
                {
                    name.GetType();
                }
#endif
                DVAttribute[] dvs = (DVAttribute[])propInfo.GetCustomAttributes(typeof(DVAttribute), false);
                if (dvs.Length == 1)
                {
                    ValueDescriptor vd = ValueDescriptor.CreateValueDescriptor(propInfo, dvs[0]);
                    meta.ValueDescriptors.Add(vd);
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Gets the object specified by name from dom.
        /// </summary>
        public object GetValue(DocumentObject dom, string name, GV flags)
        {
            int dot = name.IndexOf('.');

            if (dot == 0)
            {
                throw new ArgumentException(DomSR.InvalidValueName(name));
            }
            string trail = null;

            if (dot > 0)
            {
                trail = name.Substring(dot + 1);
                name  = name.Substring(0, dot);
            }
            ValueDescriptor vd = _vds[name];

            if (vd == null)
            {
                throw new ArgumentException(DomSR.InvalidValueName(name));
            }

            object value = vd.GetValue(dom, flags);

            if (value == null && flags == GV.GetNull)  //??? also for GV.ReadOnly?
            {
                return(null);
            }

            //REVIEW DaSt: Create object in case of GV.ReadWrite?
            if (trail != null)
            {
                if (value == null || trail == "")
                {
                    throw new ArgumentException(DomSR.InvalidValueName(name));
                }
                DocumentObject doc = value as DocumentObject;
                if (doc == null)
                {
                    throw new ArgumentException(DomSR.InvalidValueName(name));
                }
                value = doc.GetValue(trail, flags);
            }
            return(value);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Gets the object specified by name from dom.
        /// </summary>
        public object GetValue(DocumentObject dom, string name, GV flags)
        {
            int dot = name.IndexOf('.');

            if (dot == 0)
            {
                throw new ArgumentException(DomSR.InvalidValueName(name));
            }
            string trail = null;

            if (dot > 0)
            {
                trail = name.Substring(dot + 1);
                name  = name.Substring(0, dot);
            }
            ValueDescriptor vd = this.vds[name];

            if (vd == null)
            {
                throw new ArgumentException(DomSR.InvalidValueName(name));
            }

            object value = vd.GetValue(dom, flags);

            if (value == null && flags == GV.GetNull) //??? oder auch GV.ReadOnly?
            {
                return(null);
            }

            //REVIEW DaSt: Sollte beim GV.ReadWrite das Objekt angelegt werden?
            if (trail != null)
            {
                if (value == null || trail == "")
                {
                    throw new ArgumentException(DomSR.InvalidValueName(name));
                }
                DocumentObject doc = value as DocumentObject;
                if (doc == null)
                {
                    throw new ArgumentException(DomSR.InvalidValueName(name));
                }
                value = doc.GetValue(trail, flags);
            }
            return(value);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Determines whether all members of the specified dom are null. If dom contains no members IsNull
        /// returns true.
        /// </summary>
        public bool IsNull(DocumentObject dom)
        {
            int count = _vds.Count;

            for (int index = 0; index < count; index++)
            {
                ValueDescriptor vd = _vds[index];
                if (vd.IsRefOnly)
                {
                    continue;
                }
                if (!vd.IsNull(dom))
                {
                    return(false);
                }
            }
            return(true);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Parses the assignment to a Value l-value.
        /// </summary>
        private void ParseValueAssignment(DocumentObject dom, ValueDescriptor vd)
        {
            try
            {
                // What ever it is, send it to SetValue.
                dom.SetValue(vd.ValueName, Token);
            }
            catch (Exception ex)
            {
                ThrowParserException(ex, DomMsgID.InvalidEnum, _scanner.Token, vd.ValueName);
            }

            ReadCode();  // read next token
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Determines whether this meta contains a value with the specified name.
        /// </summary>
        public bool HasValue(string name)
        {
            ValueDescriptor vd = _vds[name];

            return(vd != null);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Parses the assignment to a boolean l-value.
        /// </summary>
        private void ParseBoolAssignment(DocumentObject dom, ValueDescriptor vd)
        {
            AssertCondition(Symbol == Symbol.True || Symbol == Symbol.False, DomMsgID.BoolExpected,
              _scanner.Token);

            dom.SetValue(vd.ValueName, Symbol == Symbol.True);
            ReadCode();
        }
 /// <summary>
 /// Adds the specified ValueDescriptor.
 /// </summary>
 public void Add(ValueDescriptor vd)
 {
     _dictionary.Add(vd.ValueName, vd);
     _list.Add(vd);
 }
Ejemplo n.º 13
0
        /// <summary>
        /// Parses the assignment to an integer l-value.
        /// </summary>
        private void ParseIntegerAssignment(DocumentObject dom, ValueDescriptor vd)
        {
            AssertCondition(Symbol == Symbol.IntegerLiteral || Symbol == Symbol.HexIntegerLiteral || Symbol == Symbol.StringLiteral,
              DomMsgID.IntegerExpected, Token);

            int n = Int32.Parse(_scanner.Token, CultureInfo.InvariantCulture);
            dom.SetValue(vd.ValueName, n);

            ReadCode();
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Parses the assignment to a floating point l-value.
        /// </summary>
        private void ParseRealAssignment(DocumentObject dom, ValueDescriptor vd)
        {
            AssertCondition(Symbol == Symbol.RealLiteral || Symbol == Symbol.IntegerLiteral || Symbol == Symbol.StringLiteral,
              DomMsgID.RealExpected, _scanner.Token);

            double r = double.Parse(_scanner.Token, CultureInfo.InvariantCulture);
            dom.SetValue(vd.ValueName, r);

            ReadCode();
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Parses an assign statement in an attribute declaration block.
        /// </summary>
        private void ParseAssign(DocumentObject dom, ValueDescriptor vd)
        {
            if (dom == null)
                throw new ArgumentNullException("dom");
            if (vd == null)
                throw new ArgumentNullException("vd");

            if (Symbol == Symbol.Assign)
                ReadCode();

            Type valType = vd.ValueType;
            try
            {
                if (valType == typeof(string))
                    ParseStringAssignment(dom, vd);
                else if (valType == typeof(int))
                    ParseIntegerAssignment(dom, vd);
                else if (valType == typeof(Unit))
                    ParseUnitAssignment(dom, vd);
                else if (valType == typeof(double) || valType == typeof(float))
                    ParseRealAssignment(dom, vd);
                else if (valType == typeof(bool))
                    ParseBoolAssignment(dom, vd);
#if !NETFX_CORE
                else if (typeof(Enum).IsAssignableFrom(valType))
#else
                else if (typeof(Enum).GetTypeInfo().IsAssignableFrom(valType.GetTypeInfo()))
#endif
                    ParseEnumAssignment(dom, vd);
                else if (valType == typeof(Color))
                    ParseColorAssignment(dom, vd);
#if !NETFX_CORE
                else if (typeof(ValueType).IsAssignableFrom(valType))
#else
                else if (typeof(ValueType).GetTypeInfo().IsAssignableFrom(valType.GetTypeInfo()))
#endif
                {
                    ParseValueTypeAssignment(dom, vd);
                }
#if !NETFX_CORE
                else if (typeof(DocumentObject).IsAssignableFrom(valType))
#else
                else if (typeof(DocumentObject).GetTypeInfo().IsAssignableFrom(valType.GetTypeInfo()))
#endif
                {
                    ParseDocumentObjectAssignment(dom, vd);
                }
                else
                {
                    AdjustToNextStatement();
                    ThrowParserException(DomMsgID.InvalidType, vd.ValueType.Name, vd.ValueName);
                }
            }
            catch (Exception ex)
            {
                ReportParserException(ex, DomMsgID.InvalidAssignment, vd.ValueName);
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Parses the assignment to a DocumentObject l-value.
        /// </summary>
        private void ParseDocumentObjectAssignment(DocumentObject dom, ValueDescriptor vd)
        {
            // Create value if it does not exist
            object val = vd.GetValue(dom, GV.ReadWrite);
            //DocumentObject docObj = (DocumentObject)val;

            try
            {
                if (Symbol == Symbol.Null)
                {
                    //string name = vd.ValueName;
                    Type type = vd.ValueType;
                    if (typeof(Border) == type)
                        ((Border)val).Clear();
                    else if (typeof(Borders) == type)
                        ((Borders)val).ClearAll();
                    else if (typeof(Shading) == type)
                        ((Shading)val).Clear();
                    else if (typeof(TabStops) == type)
                    {
                        TabStops tabStops = (TabStops)vd.GetValue(dom, GV.ReadWrite);
                        tabStops.ClearAll();
                    }
                    else
                        ThrowParserException(DomMsgID.NullAssignmentNotSupported, vd.ValueName);

                    ReadCode();
                }
                else
                {
                    throw new Exception("Case: TopPosition");
                    //dom.SetValue(vd.ValueName, docObj);
                }
            }
            catch (Exception ex)
            {
                ReportParserException(ex, DomMsgID.InvalidAssignment, vd.ValueName);
            }
        }
Ejemplo n.º 17
0
 /// <summary>
 /// Parses the assignment to a struct (i.e. LeftPosition) l-value.
 /// </summary>
 private void ParseValueTypeAssignment(DocumentObject dom, ValueDescriptor vd)
 {
     object val = vd.GetValue(dom, GV.ReadWrite);
     try
     {
         INullableValue ival = (INullableValue)val;
         ival.SetValue(Token);
         dom.SetValue(vd.ValueName, val);
         ReadCode();
     }
     catch (Exception ex)
     {
         ReportParserException(ex, DomMsgID.InvalidAssignment, vd.ValueName);
     }
 }
Ejemplo n.º 18
0
        /// <summary>
        /// Parses the assignment to an enum l-value.
        /// </summary>
        private void ParseEnumAssignment(DocumentObject dom, ValueDescriptor vd)
        {
            AssertSymbol(Symbol.Identifier, DomMsgID.IdentifierExpected, _scanner.Token);

            try
            {
                object val = Enum.Parse(vd.ValueType, Token, true);
                dom.SetValue(vd.ValueName, val);
            }
            catch (Exception ex)
            {
                ThrowParserException(ex, DomMsgID.InvalidEnum, _scanner.Token, vd.ValueName);
            }

            ReadCode();  // read next token
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Parses the assignment to a string l-value.
        /// </summary>
        private void ParseStringAssignment(DocumentObject dom, ValueDescriptor vd)
        {
            AssertCondition(Symbol == Symbol.StringLiteral, DomMsgID.StringExpected, _scanner.Token);

            vd.SetValue(dom, Token);  //dom.SetValue(vd.ValueName, scanner.Token);

            ReadCode();  // read next token
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Parses the assignment to a Unit l-value.
        /// </summary>
        private void ParseUnitAssignment(DocumentObject dom, ValueDescriptor vd)
        {
            AssertCondition(Symbol == Symbol.RealLiteral || Symbol == Symbol.IntegerLiteral || Symbol == Symbol.StringLiteral,
              DomMsgID.RealExpected, _scanner.Token);

            Unit unit = Token;
            dom.SetValue(vd.ValueName, unit);
            ReadCode();
        }
Ejemplo n.º 21
0
 /// <summary>
 /// Parses the assignment to a Color l-value.
 /// </summary>
 private void ParseColorAssignment(DocumentObject dom, ValueDescriptor vd)
 {
     object val = vd.GetValue(dom, GV.ReadWrite);
     Color color = ParseColor();
     dom.SetValue(vd.ValueName, color);
 }
 /// <summary>
 /// Adds the specified ValueDescriptor.
 /// </summary>
 public int Add(ValueDescriptor vd)
 {
     this.hashTable.Add(vd.ValueName, vd);
       return this.arrayList.Add(vd);
 }
Ejemplo n.º 23
0
 /// <summary>
 /// Adds the specified ValueDescriptor.
 /// </summary>
 public int Add(ValueDescriptor vd)
 {
     this.hashTable.Add(vd.ValueName, vd);
     return(this.arrayList.Add(vd));
 }
Ejemplo n.º 24
0
 /// <summary>
 /// Adds the specified ValueDescriptor.
 /// </summary>
 public void Add(ValueDescriptor vd)
 {
     _dictionary.Add(vd.ValueName, vd);
     _list.Add(vd);
 }