public static bool GetYesOrNoAsBool(this ObjVerEx targetEx, MFIdentifier prop, out bool value) { value = false; // if the object doesn't have the property, return null if (!targetEx.HasProperty(prop)) { return(false); } // get the text version of the property var propText = targetEx.GetPropertyText(prop); // if the text version of the property is "Yes", return true if (propText.Equals("Yes")) { value = true; return(true); } // if the text version of the property is "No", return false if (propText.Equals("No")) { value = false; return(true); } // couldn't parse the text value, return null return(false); }
public static bool GetDouble(this ObjVerEx targetEx, MFIdentifier prop, out double value) { // set default value value = 0.0; // check if the property exists on the target if (!targetEx.HasProperty(prop)) { return(false); } // attempt to get the text value of the property var text = targetEx.GetPropertyText(prop); // attempt to parse it return(double.TryParse(text, out value)); }
/// <summary> /// Enhanced method for <see cref="ObjVerEx.GetPropertyText(MFIdentifier)"/> /// to return a <see langword="null"/> value even if the property was not set or could not be resolved, /// otherwise the value which was set or <see cref="string.Empty"/>. /// </summary> /// /// <param name="objVerEx"> /// The <see cref="ObjVerEx"/> object to be used as base for calling <see cref="ObjVerEx.GetPropertyText(MFIdentifier)"/>. /// </param> /// <param name="prop"> /// The <see cref="MFIdentifier"/> object for the property which can be <see langword="null"/> or not resolved. /// </param> /// <param name="result"> /// The <see cref="string"/> value to be returned as output parameter. /// </param> /// /// <returns> /// <list type="table"> /// <item> /// <term><see cref="true"/></term> /// <description>if <paramref name="prop"/> is not <see langword="null"/> and can be resolved</description> /// </item> /// <item> /// <term><see cref="false"/></term> /// <description>if <paramref name="prop"/> is <see langword="null"/> or cannot be resolved</description> /// </item> /// </list> /// </returns> public static bool TryGetPropertyText( this ObjVerEx objVerEx, MFIdentifier prop, out string result) { // Sanity if (null == objVerEx) { throw new ArgumentNullException(nameof(objVerEx)); } // return the nullValue specified if not set or not resolved as result and false as return value if (null == prop || !prop.IsResolved) { result = null; return(false); } // return value and return that all is ok result = objVerEx.GetPropertyText(prop); return(true); }