internal static bool ExtractValue(IUxmlAttributes bag, CreationContext cc, out Type resEnumType, out Enum resEnumValue, out bool resIncludeObsoleteValues) { resIncludeObsoleteValues = false; resEnumValue = null; resEnumType = type.GetValueFromBag(bag, cc); if (resEnumType == null) { return(false); } string specifiedValue = null; object resEnumValueObject = null; if (value.TryGetValueFromBag(bag, cc, ref specifiedValue) && !Enum.TryParse(resEnumType, specifiedValue, false, out resEnumValueObject)) { Debug.LogErrorFormat("EnumField: Could not parse value of '{0}', because it isn't defined in the {1} enum.", specifiedValue, resEnumType.FullName); return(false); } resEnumValue = specifiedValue != null && resEnumValueObject != null ? (Enum)resEnumValueObject : (Enum)Enum.ToObject(resEnumType, 0); resIncludeObsoleteValues = includeObsoleteValues.GetValueFromBag(bag, cc); return(true); }
/// <summary> /// Initialize <see cref="TextField"/> properties using values from the attribute bag. /// </summary> /// <param name="ve">The object to initialize.</param> /// <param name="bag">The attribute bag.</param> /// <param name="cc">The creation context; unused.</param> public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc) { TextField field = ((TextField)ve); field.multiline = m_Multiline.GetValueFromBag(bag, cc); base.Init(ve, bag, cc); // Re-defining the value to account for the "obsolete" text property. // We are doing it here because TextField binds the value to the text and this // is not the case in the base class. var value = string.Empty; if (k_Value.TryGetValueFromBag(bag, cc, ref value)) { field.SetValueWithoutNotify(value); } }