/// <summary> /// Finds the SchemaObject within the currently loaded schema based on the type /// </summary> /// <param name="type">The type to look for within the current schema. Expects it to be a complex type</param> public SchemaObject FindFromType(string type) { if (string.IsNullOrEmpty(type)) { return(null); } SchemaObject complexType = this.complexTypes.SingleOrDefault(y => y.Name != null && y.Name.ToLower() == type.ToLower()); if (complexType != null) { SchemaObject newComplexType = complexType.Clone(this); newComplexType.IsInitialized = false; return(newComplexType); } return(null); }
/// <summary> /// Finds a SchemaObject element within the currently loaded schema based on the path specified. /// </summary> public SchemaObject FindFromPath(string path) { if (string.IsNullOrEmpty(path)) { return(null); } string[] pathParts = path.Split('/'); SchemaObject current = null; foreach (string cPathPart in pathParts) { string cActualContext = cPathPart; string cActualDataType = string.Empty; if (this.uniqueStringContextRegex.IsMatch(cPathPart)) { Match uniqueStringMatch = this.uniqueStringContextRegex.Match(cPathPart); cActualContext = uniqueStringMatch.Groups[1].Value; cActualDataType = uniqueStringMatch.Groups[2].Value; } bool isAttribute = cActualContext != null?cActualContext.StartsWith("@") : false; if (isAttribute) { cActualContext = cActualContext.Substring(1); } if (current == null) { current = this.Children.SingleOrDefault(y => y.Name == cActualContext && y.IsAttribute == isAttribute); } else { current = current.Children.SingleOrDefault(y => y.Name == cActualContext && y.IsAttribute == isAttribute); } if (current == null) { SchemaObject complexType = null; if (!string.IsNullOrEmpty(cActualDataType)) { complexType = this.ComplexTypes.SingleOrDefault(y => y.Name == cActualDataType); } else if (!string.IsNullOrEmpty(cActualContext)) { complexType = this.ComplexTypes.SingleOrDefault(y => y.Name == cActualContext); } if (complexType != null) { complexType = complexType.Clone(this); complexType.Name = cActualContext; complexType.Parent = current; current = complexType; } } if (current == null) { return(null); } } return(current); }