//-/////////////////////////////////////////////////////////////////////// //-/////////////////////////////////////////////////////////////////////// public SavedAttrValue GetSavedValue() { SavedAttrValue sav = new SavedAttrValue(_name, GetValue()); return(sav); }
//-/////////////////////////////////////////////////////////////////////// //-/////////////////////////////////////////////////////////////////////// /// <summary> /// returns Attr for the given attribute on the given object. /// </summary> /// <param name="pyobj"></param> /// <param name="name"></param> /// <returns></returns> private Attr attr(object pyobj, string name) { Attr newAttr = new Attr(this, pyobj, name); foreach (Attr attr in _attrPool) { if (attr.IsEquivalent(newAttr)) { return(attr); } } _attrPool.Add(newAttr); // Got an equivalent in the saved attributes list? if (_savedAttrValues != null) { Type valueType = null; object value = newAttr.GetValue(); if (value != null) { valueType = value.GetType(); } int index = -1; for (int i = 0; i < _savedAttrValues.Count; ++i) { SavedAttrValue sav = _savedAttrValues[i]; if (sav.Name == name) { Type savedType = null; if (sav.Value != null) { savedType = sav.Value.GetType(); } bool match = false; if (valueType == savedType) { match = true; } else if ((valueType == typeof(float) || valueType == typeof(double)) && (savedType == typeof(float) || savedType == typeof(double))) { // float, double, float, double... *shrug* match = true; } if (match) { index = i; break; } } } if (index >= 0) { newAttr.SetValue(_savedAttrValues[index].Value); _savedAttrValues.RemoveAt(index); } } return(newAttr); }