public static string CombinePathParts(IList <ClrPathPart> parts, int startIndex, int count) { StringBuilder stringBuilder = new StringBuilder(); ClrPathPart clrPathPart1 = (ClrPathPart)null; for (int index = 0; index < count && index + startIndex < parts.Count; ++index) { ClrPathPart clrPathPart2 = parts[index + startIndex]; if (clrPathPart1 == null) { stringBuilder.Append(clrPathPart2.NewPath); } else if (clrPathPart2.Category == ClrPathPartCategory.CurrentItem || clrPathPart1.Category == ClrPathPartCategory.CurrentItem) { stringBuilder.Append(clrPathPart2.NewPath); } else if (clrPathPart2.Category == ClrPathPartCategory.IndexStep) { stringBuilder.Append(clrPathPart2.NewPath); } else { stringBuilder.Append("."); stringBuilder.Append(clrPathPart2.NewPath); } clrPathPart1 = clrPathPart2; } return(stringBuilder.ToString()); }
private static DataSourceMatchCriteria CompareClrPaths(string thisPath, string otherPath) { if (string.IsNullOrEmpty(thisPath)) { return(string.IsNullOrEmpty(otherPath) ? DataSourceMatchCriteria.Exact : DataSourceMatchCriteria.Compatible); } if (string.IsNullOrEmpty(otherPath)) { return(DataSourceMatchCriteria.Ignore); } IList <ClrPathPart> list1 = ClrPropertyPathHelper.SplitPath(thisPath); IList <ClrPathPart> list2 = ClrPropertyPathHelper.SplitPath(otherPath); if (list1 == null || list2 == null || list1.Count > list2.Count) { return(DataSourceMatchCriteria.Ignore); } for (int index = 0; index < list1.Count; ++index) { ClrPathPart clrPathPart1 = list1[index]; ClrPathPart clrPathPart2 = list2[index]; if (clrPathPart1.Category == ClrPathPartCategory.PropertyName != (clrPathPart2.Category == ClrPathPartCategory.PropertyName) || clrPathPart1.Category == ClrPathPartCategory.PropertyName && clrPathPart1.Path != clrPathPart2.Path) { return(DataSourceMatchCriteria.Ignore); } } return(list1.Count < list2.Count ? DataSourceMatchCriteria.Compatible : DataSourceMatchCriteria.Exact); }
public DataSchemaNodePath GetNodePathFromPath(string path) { if (string.IsNullOrEmpty(path)) { return(this.CreateNodePath()); } DataSchemaNode endNode = this.root; IList <ClrPathPart> list = ClrPropertyPathHelper.SplitPath(path); if (list == null) { return((DataSchemaNodePath)null); } for (int index = 0; index < list.Count && endNode != null; ++index) { ClrPathPart clrPathPart = list[index]; string pathName = clrPathPart.Category == ClrPathPartCategory.PropertyName ? clrPathPart.Path : DataSchemaNode.IndexNodePath; endNode = endNode.FindChildByPathName(pathName); } if (endNode != null) { return(new DataSchemaNodePath((ISchema)this, endNode)); } return((DataSchemaNodePath)null); }
private RawDataSourceInfoBase GetRelativeSourceTargetBindingDataSource(DataBindingProcessingContext context) { if (context.OuterContext == null || !context.IsStyleOrControlTemplateScope) { return((RawDataSourceInfoBase)null); } string bindingRelativeSource = this.GetBindingRelativeSource(context); if (string.IsNullOrEmpty(bindingRelativeSource)) { return((RawDataSourceInfoBase)null); } DataBindingProcessingContext context1 = (DataBindingProcessingContext)null; if (context.Scope == ProcessingContextScope.Style && bindingRelativeSource == "Self") { if (context.OuterContext != null) { context1 = context.OuterContext.ParentContext; } } else if (context.Scope == ProcessingContextScope.ControlTemplate && bindingRelativeSource == "TemplatedParent") { context1 = this.GetTemplatedParentContext(context); } if (context1 == null || PlatformTypes.DictionaryEntry.IsAssignableFrom((ITypeId)context1.DocumentNode.Type)) { return((RawDataSourceInfoBase)null); } string bindingPath = DataContextHelper.GetBindingPath(context.DocumentCompositeNode); if (string.IsNullOrEmpty(bindingPath)) { return((RawDataSourceInfoBase)null); } IList <ClrPathPart> parts = ClrPropertyPathHelper.SplitPath(bindingPath); if (parts == null || parts.Count == 0) { return((RawDataSourceInfoBase)null); } ClrPathPart clrPathPart = parts[0]; if (clrPathPart.Category != ClrPathPartCategory.PropertyName) { return((RawDataSourceInfoBase)null); } RawDataSourceInfoBase sourceFromProperty = this.GetDataSourceFromProperty(context1, clrPathPart.Path); if (sourceFromProperty == null || !sourceFromProperty.IsValid) { return((RawDataSourceInfoBase)null); } string path = ClrPropertyPathHelper.CombinePathParts(parts, 1); sourceFromProperty.AppendClrPath(path); return(sourceFromProperty); }
public static string[] SplitAtFirstProperty(string path) { if (string.IsNullOrEmpty(path)) { return new string[2] { string.Empty, string.Empty } } ; string pathPart1 = path; string str = string.Empty; int index = path.IndexOfAny(ClrPropertyPathHelper.pathPartSeparators, 1); if (index > 0) { pathPart1 = path.Substring(0, index); if ((int)path[index] == 46) { if (index == path.Length - 1) { return((string[])null); } ++index; } str = path.Substring(index); } ClrPathPart pathPart2 = ClrPropertyPathHelper.GetPathPart(pathPart1); if (pathPart2 == null || pathPart2.Category != ClrPathPartCategory.PropertyName) { return((string[])null); } return(new string[2] { pathPart1, str }); }
public static IList <ClrPathPart> SplitPath(string path) { if (string.IsNullOrEmpty(path)) { return((IList <ClrPathPart>) new List <ClrPathPart>()); } if ((int)path[0] == 46 || (int)path[path.Length - 1] == 46) { return((IList <ClrPathPart>)null); } List <ClrPathPart> list = new List <ClrPathPart>(); int startIndex = 0; for (int index = path.IndexOfAny(ClrPropertyPathHelper.pathPartSeparators, 1); index > 0; index = path.IndexOfAny(ClrPropertyPathHelper.pathPartSeparators, index + 1)) { ClrPathPart pathPart = ClrPropertyPathHelper.GetPathPart(path.Substring(startIndex, index - startIndex)); if (pathPart == null) { return((IList <ClrPathPart>)null); } list.Add(pathPart); if ((int)path[index] == 47) { list.Add(ClrPathPart.CurrentItem); startIndex = index + 1; } else { startIndex = (int)path[index] != 46 ? index : index + 1; } } ClrPathPart pathPart1 = ClrPropertyPathHelper.GetPathPart(path.Substring(startIndex)); if (pathPart1 == null) { return((IList <ClrPathPart>)null); } list.Add(pathPart1); return((IList <ClrPathPart>)list); }
private static object CreateClrDataContext(DataSourceInfo dataSource, SceneViewModel viewModel) { DocumentNode sourceNode = dataSource.SourceNode; if (PlatformTypes.DataTemplate.IsAssignableFrom((ITypeId)sourceNode.Type)) { return((object)null); } object obj1 = (object)null; using (StandaloneInstanceBuilderContext instanceBuilderContext = new StandaloneInstanceBuilderContext(viewModel.Document.DocumentContext, viewModel.DesignerContext)) { try { IInstanceBuilder builder = instanceBuilderContext.InstanceBuilderFactory.GetBuilder(sourceNode.TargetType); ViewNode viewNode = builder.GetViewNode((IInstanceBuilderContext)instanceBuilderContext, sourceNode); if (builder.Instantiate((IInstanceBuilderContext)instanceBuilderContext, viewNode)) { obj1 = DataContextEvaluator.GetEvaluatedValue(viewNode.Instance); } } catch { } } if (obj1 == null || string.IsNullOrEmpty(dataSource.Path)) { return(obj1); } object instance = obj1; try { IList <ClrPathPart> list1 = ClrPropertyPathHelper.SplitPath(dataSource.Path); if (list1 == null) { return((object)null); } for (int index = 0; index < list1.Count; ++index) { if (instance != null) { Type type = instance.GetType(); object obj2 = (object)null; ClrPathPart clrPathPart = list1[index]; if (clrPathPart.Category == ClrPathPartCategory.PropertyName) { PropertyInfo property = type.GetProperty(clrPathPart.Path); if (property != (PropertyInfo)null) { obj2 = property.GetValue(instance, (object[])null); } } else { CollectionAdapterDescription adapterDescription = CollectionAdapterDescription.GetAdapterDescription(type); if (adapterDescription != null) { IList list2 = adapterDescription.GetCollectionAdapter(instance) as IList; if (list2 != null) { int result = 0; if (clrPathPart.Category == ClrPathPartCategory.IndexStep) { if (!int.TryParse(clrPathPart.Path.Trim('[', ']'), out result)) { goto label_23; } } obj2 = list2[result]; } } } label_23: instance = obj2; } else { break; } } } catch { instance = (object)null; } return(instance); }