/// <summary> /// /// </summary> /// <param name="ownerTreeNode">This is only used to add validation errors</param> public void Initialize(TreeNode ownerTreeNode) { foreach (Match match in TemplateRegex.Matches(this.Template)) { if (match.Value.StartsWith(PreFix) == false) { continue; } string value = match.Groups["string"].Value; string[] values = value.Split(':'); if (values.Length != 4) { ownerTreeNode.AddValidationError("TreeValidationError.DataFieldValueHelper.WrongFormat", match.Value, string.Format(@"{0}[InterfaceType]:[FieldName]}}", PreFix)); return; } string typeName = values[2]; Type interfaceType = TypeManager.TryGetType(typeName); if (interfaceType == null) { ownerTreeNode.AddValidationError("TreeValidationError.Common.UnknownInterfaceType", typeName); return; } if (typeof(IData).IsAssignableFrom(interfaceType) == false) { ownerTreeNode.AddValidationError("TreeValidationError.Common.NotImplementingIData", interfaceType, typeof(IData)); return; } string fieldName = values[3]; PropertyInfo propertyInfo = interfaceType.GetPropertiesRecursively(f => f.Name == fieldName).SingleOrDefault(); if (propertyInfo == null) { ownerTreeNode.AddValidationError("TreeValidationError.Common.MissingProperty", interfaceType, fieldName); return; } bool possibleAttachmentPointsExist = ownerTreeNode.Tree.PossibleAttachmentPoints.OfType <IDataItemAttachmentPoint>().Any(f => f.InterfaceType == interfaceType); bool attachmentPointsExist = ownerTreeNode.Tree.AttachmentPoints.OfType <IDataItemAttachmentPoint>().Any(f => f.InterfaceType == interfaceType); if (!possibleAttachmentPointsExist && !attachmentPointsExist && !ownerTreeNode.SelfAndParentsHasInterface(interfaceType)) { ownerTreeNode.AddValidationError("TreeValidationError.DataFieldValueHelper.InterfaceNotInParentTree", interfaceType); return; } bool isReferencingProperty = DataReferenceFacade.GetForeignKeyProperties(interfaceType).Any(f => f.SourcePropertyInfo.Equals(propertyInfo)); DataFieldValueHelperEntry entry = new DataFieldValueHelperEntry( match.Value, interfaceType, propertyInfo, isReferencingProperty ); if (_entries.Contains(entry) == false) { _entries.Add(entry); } } }
/// <summary> /// /// </summary> /// <param name="ownerTreeNode">This is only used to add validation errors</param> public void Initialize(TreeNode ownerTreeNode) { foreach (Match match in TemplateRegex.Matches(this.Template)) { if (match.Value.StartsWith(PreFix) == false) continue; string value = match.Groups["string"].Value; string[] values = value.Split(':'); if (values.Length != 4) { ownerTreeNode.AddValidationError("TreeValidationError.DataFieldValueHelper.WrongFormat", match.Value, string.Format(@"{0}[InterfaceType]:[FieldName]}}", PreFix)); return; } string typeName = values[2]; Type interfaceType = TypeManager.TryGetType(typeName); if (interfaceType == null) { ownerTreeNode.AddValidationError("TreeValidationError.Common.UnknownInterfaceType", typeName); return; } if (typeof(IData).IsAssignableFrom(interfaceType) == false) { ownerTreeNode.AddValidationError("TreeValidationError.Common.NotImplementingIData", interfaceType, typeof(IData)); return; } string fieldName = values[3]; PropertyInfo propertyInfo = interfaceType.GetPropertiesRecursively(f => f.Name == fieldName).SingleOrDefault(); if (propertyInfo == null) { ownerTreeNode.AddValidationError("TreeValidationError.Common.MissingProperty", interfaceType, fieldName); return; } bool possibleAttachmentPointsExist = ownerTreeNode.Tree.PossibleAttachmentPoints.OfType<IDataItemAttachmentPoint>().Any(f => f.InterfaceType == interfaceType); bool attachmentPointsExist = ownerTreeNode.Tree.AttachmentPoints.OfType<IDataItemAttachmentPoint>().Any(f => f.InterfaceType == interfaceType); if (!possibleAttachmentPointsExist && !attachmentPointsExist && !ownerTreeNode.SelfAndParentsHasInterface(interfaceType)) { ownerTreeNode.AddValidationError("TreeValidationError.DataFieldValueHelper.InterfaceNotInParentTree", interfaceType); return; } bool isReferencingProperty = DataReferenceFacade.GetForeignKeyProperties(interfaceType).Any(f => f.SourcePropertyInfo.Equals(propertyInfo)); DataFieldValueHelperEntry entry = new DataFieldValueHelperEntry( match.Value, interfaceType, propertyInfo, isReferencingProperty ); if (_entries.Contains(entry) == false) { _entries.Add(entry); } } }
public bool Equals(DataFieldValueHelperEntry entry) { return(entry != null && object.Equals(this.Match, entry.Match)); }
public bool Equals(DataFieldValueHelperEntry entry) { return entry != null && object.Equals(this.Match, entry.Match); }