Esempio n. 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);
        }
Esempio n. 2
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);
 }
Esempio n. 3
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);
        }