Beispiel #1
0
        /// <summary>
        /// Sets a custom property.
        /// </summary>
        /// <param name="property">The property name.</param>
        /// <param name="value">The value for the property.</param>
        /// <returns><c>true</c> if the property was successfully set, [otherwise] <c>false</c></returns>
        public bool SetCustomProperty(String property, Object value)
        {
            if (!String.IsNullOrWhiteSpace(property) && xDocumentProperties != null)
            {
                XPropertyContainer customProperties = xDocumentProperties.getUserDefinedProperties();
                if (customProperties != null && customProperties is XPropertySet)
                {
                    try
                    {
                        XPropertySetInfo info = ((XPropertySet)customProperties).getPropertySetInfo();
                        if (info != null && !info.hasPropertyByName(property))
                        {
                            customProperties.addProperty(property, 0, Any.Get(""));
                        }

                        if (info != null && info.hasPropertyByName(property))
                        {
                            ((XPropertySet)customProperties).setPropertyValue(property, Any.Get(value));
                            return(true);
                        }
                    }
                    catch (Exception) { }
                }
            }
            return(false);
        }
Beispiel #2
0
        /// <summary>
        /// Gets all custom properties.
        /// </summary>
        /// <returns>a dictionary of names and string-values of properties</returns>
        public Dictionary <String, String> GetAllCustomProperties()
        {
            Dictionary <String, String> properties = new Dictionary <String, String>();

            if (xDocumentProperties != null)
            {
                XPropertyContainer customProperties = xDocumentProperties.getUserDefinedProperties();
                if (customProperties != null && customProperties is XPropertySet)
                {
                    if (customProperties != null && customProperties is XPropertySet)
                    {
                        XPropertySetInfo info = ((XPropertySet)customProperties).getPropertySetInfo();
                        if (info != null)
                        {
                            foreach (Property p in info.getProperties())
                            {
                                if (p != null)
                                {
                                    var val = ((XPropertySet)customProperties).getPropertyValue(p.Name);
                                    if (val.hasValue())
                                    {
                                        properties.Add(p.Name, val.Value.ToString());
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(properties);
        }
Beispiel #3
0
        internal static Dictionary <String, uno.Any> GetAllProperties(Object obj)
        {
            // Debug.GetAllInterfacesOfObject(obj);
            Dictionary <String, uno.Any> props = new Dictionary <string, uno.Any>();

            if (obj != null && obj is XPropertySet)
            {
                XPropertySetInfo bla = ((XPropertySet)obj).getPropertySetInfo();
                if (bla != null)
                {
                    Property[]    properties = bla.getProperties();
                    List <String> storable   = new List <string>();

                    foreach (Property item in properties)
                    {
                        if (item != null)
                        {
                            OO.PropertyAttribute att = ((OO.PropertyAttribute)item.Attributes);
                            //if (item.Attributes == 0) { storable.Add(item.Name); }
                            if (!att.HasFlag(OO.PropertyAttribute.READONLY))
                            {
                                //if (att.HasFlag(OO.PropertyAttribute.MAYBEDEFAULT))
                                //{
                                //}
                                storable.Add(item.Name);
                            }
                        }
                    }

                    try
                    {
                        if (obj is XMultiPropertySet)
                        {
                            var values = ((XMultiPropertySet)obj).getPropertyValues(storable.ToArray());

                            if (values.Length == storable.Count)
                            {
                                for (int i = 0; i < values.Length; i++)
                                {
                                    props.Add(storable[i], values[i]);
                                }
                            }
                            else
                            {
                                // does not get all values
                            }

                            return(props);
                        }
                    }
                    catch (Exception ex) { }
                }
            }
            return(null);
        }
Beispiel #4
0
 /// <summary>
 /// Gets a property value.
 /// </summary>
 /// <param name="obj">The obj.</param>
 /// <param name="propName">Name of the property.</param>
 /// <returns>
 /// the property form the property set or null
 /// </returns>
 internal static Object GetProperty(XPropertySet obj, String propName)
 {
     try
     {
         if (obj != null)
         {
             XPropertySetInfo propInfo = obj.getPropertySetInfo();
             if (propInfo != null && propInfo.hasPropertyByName(propName))
             {
                 return(obj.getPropertyValue(propName).Value);
             }
         }
     }
     catch { }
     return(null);
 }
Beispiel #5
0
        /// <summary>
        /// Gets a custom property.
        /// </summary>
        /// <param name="property">The property name.</param>
        /// <returns>The property's value or <c>null</c>.</returns>
        public Object GetCustomProperty(String property)
        {
            if (!String.IsNullOrWhiteSpace(property) && xDocumentProperties != null)
            {
                XPropertyContainer customProperties = xDocumentProperties.getUserDefinedProperties();
                if (customProperties != null && customProperties is XPropertySet)
                {
                    XPropertySetInfo info = ((XPropertySet)customProperties).getPropertySetInfo();
                    if (info != null && info.hasPropertyByName(property))
                    {
                        var val = ((XPropertySet)customProperties).getPropertyValue(property);

                        if (val.hasValue())
                        {
                            // TODO: type the property
                            return(val.Value);
                        }
                    }
                }
            }
            return(null);
        }