Пример #1
0
 private static void AddTypeValue(ITypeValue obj)
 {
     foreach (Type supportedType in obj.SupportedTypes)
     {
         propertyInterpreters.Add(supportedType, obj);
     }
 }
Пример #2
0
        /// <summary>
        /// Return text respresentation of the object.
        /// </summary>
        /// <param name="rawValue">Object to get value from.</param>
        /// <returns>
        /// Text representation of the object and object's properties.
        /// </returns>
        public static string GetPropertyValue(object rawValue)
        {
            string value = string.Empty;

            try
            {
                // See if we have any special type interpreters for this
                // type.
                ITypeValue interpreter = TypeValueFinder.GetTypeInterpreter(rawValue.GetType());
                if (interpreter != null)
                {
                    value = interpreter.GetValue(rawValue);
                }
                else
                {
                    // If no interpreters are found, simply return the
                    // ToString() value of the object.
                    value = rawValue.ToString();
                }
            }
            catch (TargetInvocationException tie)
            {
                // Special handling for this exception because
                // the inner exception text is nice
                value = tie.InnerException.Message;
                DebugLog.WriteVerbose("Handled TargetInvocationException", tie);
            }
            catch (Exception ex)
            {
                value = ex.Message;
                DebugLog.WriteVerbose("Handled exception", ex);
            }

            return(value);
        }
Пример #3
0
        public string GetPropertyValue(GetUserSettingsResponse owner, UserSettingName userSettingName, out string typeName, out bool hasErrors)
        {
            object value = null;

            typeName  = string.Empty;
            hasErrors = false;
            if (owner.Settings.TryGetValue(userSettingName, out value))
            {
                if (value == null)
                {
                    return(string.Empty);
                }
                typeName = value.GetType().FullName;
                ITypeValue interpreter = TypeValueFinder.GetTypeInterpreter(value.GetType());
                return(interpreter != null?interpreter.GetValue(value) : value.ToString());
            }
            foreach (UserSettingError err in owner.UserSettingErrors)
            {
                if (err.SettingName != userSettingName.ToString())
                {
                    continue;
                }
                typeName  = typeof(UserSettingError).FullName;
                hasErrors = true;
                return($"{err.ErrorCode}: {err.ErrorMessage}");
            }
            return(string.Empty);
        }
Пример #4
0
        /// <summary>
        /// Return text representation of a property value.  Some property types have
        /// specialized logic, if so then dispatch to the appropriate method for
        /// translation.  Also return the type name of the property.
        /// </summary>
        /// <param name="ownerInstance">Property owner instance to pull the value from.</param>
        /// <param name="propInfo">Property to pull from the owner</param>
        /// <param name="typeName">Text representing the type of the property.</param>
        /// <returns>
        /// Text representation of a property value.
        /// </returns>
        public static string GetPropertyValue(object ownerInstance, PropertyInfo propInfo, out string typeName, out bool hasErrors)
        {
            string value = string.Empty;

            hasErrors = false;

            try
            {
                typeName = propInfo.PropertyType.FullName;

                // See if we have any special type interpreters for this
                // type.
                ITypeValue interpreter = TypeValueFinder.GetTypeInterpreter(propInfo.PropertyType);
                if (interpreter != null)
                {
                    value = interpreter.GetValue(ownerInstance, propInfo);
                }
                else
                {
                    // If no interpreters are found, simply return the
                    // ToString() value of the object.
                    if (propInfo.GetValue(ownerInstance, null) != null)
                    {
                        value = propInfo.GetValue(ownerInstance, null).ToString();
                    }
                }
            }
            catch (TargetInvocationException tie)
            {
                // Special handling for this exception because
                // the inner exception text is nice
                typeName  = tie.InnerException.GetType().Name;
                value     = tie.InnerException.Message;
                hasErrors = true;

                DebugLog.WriteVerbose("Handled TargetInvocationException", tie);
            }
            catch (Exception ex)
            {
                typeName  = ex.GetType().Name;
                value     = ex.Message;
                hasErrors = true;

                DebugLog.WriteVerbose("Handled exception", ex);
            }

            return(value);
        }
Пример #5
0
        /// <summary>
        /// Get text representation of a property value and the property value's type. Some
        /// property types have specialized logic, if so then dispatch to the appropriate method
        /// for translation.
        /// </summary>
        /// <param name="owner">ServiceObject which is the owner of the property</param>
        /// <param name="propDef">Definition of the property</param>
        /// <param name="typeName">Output: The type name of the property value.</param>
        /// <returns>
        /// Text representation of a property value and the property value's type.  If
        /// TryGetProperty() fails for this property, no values is returned.
        /// </returns>
        public static string GetPropertyValue(ServiceObject owner, PropertyDefinitionBase propDef, out string typeName)
        {
            object value = null;

            typeName = string.Empty;

            if (owner.TryGetProperty(propDef, out value))
            {
                ExtendedPropertyDefinition extProp = propDef as ExtendedPropertyDefinition;
                if (extProp != null)
                {
                    typeName = string.Format(System.Globalization.CultureInfo.CurrentCulture, "{0}.{1}",
                                             extProp.MapiType.GetType().FullName,
                                             extProp.MapiType.ToString());
                }
                else
                {
                    typeName = value.GetType().FullName;
                }

                // See if we have any special type interpreters for this type.
                if (value != null)
                {
                    ITypeValue interpreter = TypeValueFinder.GetTypeInterpreter(value.GetType());
                    if (interpreter != null)
                    {
                        return(interpreter.GetValue(value));
                    }
                    else
                    {
                        // If no interpreters are found, simply return the
                        // ToString() value of the object.
                        return(value.ToString());
                    }
                }
            }

            return(string.Empty);
        }