Example #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 = _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);
            }
        }
Example #2
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);
        }
Example #3
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 /* not 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 = _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));
            }
            return(docObj.IsNull());

            //      DomValueDescriptor vd = vds[name];
            //      if (vd == null)
            //        throw new ArgumentException(DomSR.InvalidValueName(name));
            //
            //      return vd.IsNull(dom);
        }
Example #4
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);
                }
            }
        }
Example #5
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);
        }
Example #6
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);
        }
 /// <summary>
 /// Adds the specified ValueDescriptor.
 /// </summary>
 public void Add(ValueDescriptor vd)
 {
     _dictionary.Add(vd.ValueName, vd);
     _list.Add(vd);
 }
Example #8
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);
        }