void updatePropertyFromName() { if (string.IsNullOrEmpty(propertyName)) { return; } else { string[] parts = propertyName.Split('|'); if (parts.Length == 1) { if (Step != null) { ITypeData stepType = TypeData.GetTypeData(Step); Property = stepType.GetMember(parts[0]); } else { Property = null; } } else { var typename = parts[0]; ITypeData stepType = TypeData.GetTypeData(typename); Property = stepType.GetMember(parts[1]); } } if (Property != null) { propertyName = null; } }
public IMemberData GetMember(string name) { if (name == BreakConditions.Name) { return(BreakConditions); } return(innerType.GetMember(name)); }
/// <summary> Returns true if a member is enabled. </summary> public static bool IsEnabled(IMemberData property, object instance, out IMemberData dependentProp, out IComparable dependentValue, out bool hidden) { if (property == null) { throw new ArgumentNullException(nameof(property)); } if (instance == null) { throw new ArgumentNullException(nameof(instance)); } ITypeData instanceType = TypeData.GetTypeData(instance); var dependencyAttrs = property.GetAttributes <EnabledIfAttribute>(); dependentProp = null; dependentValue = 0; hidden = false; bool enabled = true; foreach (var at in dependencyAttrs) { bool newEnabled = true; dependentProp = instanceType.GetMember(at.PropertyName); if (dependentProp == null) { // We cannot be sure that the step developer has used this attribute correctly // (could just be a typo in the (weakly typed) property name), thus we need to // provide a good error message that leads the developer to where the error is. log.Warning("Could not find property '{0}' on '{1}'. EnabledIfAttribute can only refer to properties of the same class as the property it is decorating.", at.PropertyName, instanceType.Name); enabled = false; return(false); } var depValue = dependentProp.GetValue(instance); try { newEnabled = calcEnabled(at, depValue); } catch (ArgumentException) { // CompareTo throws ArgumentException when obj is not the same type as this instance. newEnabled = false; } if (!newEnabled && at.HideIfDisabled) { hidden = true; } enabled &= newEnabled; } return(enabled); }
/// <summary> Creates a Key and a Value node in the XML.</summary> public override bool Serialize(XElement node, object obj, ITypeData _expectedType) { if (obj == null || false == obj.GetType().DescendsTo(typeof(KeyValuePair <,>))) { return(false); } if (_expectedType is TypeData expectedType2 && expectedType2.Type is Type expectedType) { var key = new XElement("Key"); var value = new XElement("Value"); bool keyok = Serializer.Serialize(key, _expectedType.GetMember("Key").GetValue(obj), TypeData.FromType(expectedType.GetGenericArguments()[0])); bool valueok = Serializer.Serialize(value, _expectedType.GetMember("Value").GetValue(obj), TypeData.FromType(expectedType.GetGenericArguments()[1])); if (!keyok || !valueok) { return(false); } node.Add(key); node.Add(value); return(true); } return(false); }