public void ChangeLocalName_should_change_nominal() { QualifiedName n = QualifiedName.Create(NamespaceUri.Default, "default"); n = n.ChangeLocalName("name"); Assert.Same("name", n.LocalName); }
private Type ConvertToType(PropertyTreeNavigator nav, Type rootType) { QualifiedName fixedName = nav.QualifiedName; string name = fixedName.LocalName; if (char.IsLower(name[0])) { name = char.ToUpperInvariant(name[0]) + name.Substring(1); fixedName = fixedName.ChangeLocalName(name); } if (string.IsNullOrEmpty(nav.Namespace)) { // Try looking for the name in the same assembly var choices = rootType.GetTypeInfo().Assembly.GetTypesHelper() .Where(t => t.IsPublic && t.Name == name); if (choices.Any()) { return(choices.SingleOrThrow(() => PropertyTreesFailure.UnableToMatchTypeNameAmbiguous(nav.Name, choices)).AsType()); } else { throw PropertyTreesFailure.UnableToMatchTypeNameZero(name); } } else { return(App.GetTypeByQualifiedName(fixedName, true)); } }
public PropertyDefinition FindProperty(PropertyTreeDefinition definition, Type componentType, QualifiedName qn, IEnumerable <PropertyTreeDefinition> ancestors) { // Allow any namespace contained in the definition base classes var result = definition .EnumerateProperties() .FirstOrDefault(t => Compare(t, qn, definition)); if (result != null) { return(result); } int dot = qn.LocalName.IndexOf('.'); if (dot > 0) { // TODO Index whether the PTD has extenders so we can skip some ancestors (perf) string prefix = qn.LocalName.Substring(0, dot); foreach (var currentDef in ancestors) { if (currentDef.Name == prefix) { // TODO Local name could be different var prop = currentDef.GetProperty(qn); if (prop != null) { return(prop); } } } } else { foreach (var curDefinition in ancestors) { var prop = curDefinition.GetProperty(qn); if (IsValidExtender(prop, componentType)) { return(prop); } var qn2 = qn.ChangeLocalName(curDefinition.Name + "." + qn.LocalName); prop = curDefinition.GetProperty(qn2); if (IsValidExtender(prop, componentType)) { return(prop); } } } return(null); }
public PropertyDefinition FindProperty(PropertyTreeDefinition definition, Type componentType, QualifiedName qn, IEnumerable<PropertyTreeDefinition> ancestors) { // Allow any namespace contained in the definition base classes var result = definition .EnumerateProperties() .FirstOrDefault(t => Compare(t, qn, definition)); if (result != null) return result; int dot = qn.LocalName.IndexOf('.'); if (dot > 0) { // TODO Index whether the PTD has extenders so we can skip some ancestors (perf) string prefix = qn.LocalName.Substring(0, dot); foreach (var currentDef in ancestors) { if (currentDef.Name == prefix) { // TODO Local name could be different var prop = currentDef.GetProperty(qn); if (prop != null) { return prop; } } } } else { foreach (var curDefinition in ancestors) { var prop = curDefinition.GetProperty(qn); if (IsValidExtender(prop, componentType)) return prop; var qn2 = qn.ChangeLocalName(curDefinition.Name + "." + qn.LocalName); prop = curDefinition.GetProperty(qn2); if (IsValidExtender(prop, componentType)) return prop; } } return null; }
IEnumerable<QualifiedName> SelectNames(QualifiedName qn) { IEnumerable<string> names = this.Name.Split( new [] { ' ', ',', '\t', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); return names.Select(t => qn.ChangeLocalName(t)); }