示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
        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);
        }
示例#4
0
 public override void AppendClrPath(string path)
 {
     if (string.IsNullOrEmpty(path))
     {
         return;
     }
     if (this.TargetProperty == null)
     {
         this.InitializePath(path);
     }
     else
     {
         this.PathSuffix = ClrPropertyPathHelper.CombinePaths(this.PathSuffix, path);
         this.clrPath    = ClrPropertyPathHelper.CombinePaths(this.clrPath, path);
     }
 }
示例#5
0
 private void InitializePath(string path)
 {
     this.clrPath = path;
     string[] strArray = ClrPropertyPathHelper.SplitAtFirstProperty(this.clrPath);
     if (strArray == null)
     {
         this.SetInvalid();
     }
     else
     {
         this.TargetPropertyName = strArray[0];
         this.PathSuffix         = strArray[1];
         this.TargetProperty     = this.TargetElement.Type.GetMember(MemberType.LocalProperty, this.TargetPropertyName, MemberAccessTypes.Public) as IProperty;
         if (this.TargetProperty != null || string.IsNullOrEmpty(this.TargetPropertyName))
         {
             return;
         }
         this.SetInvalid();
     }
 }
        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);
        }
 public static string CombinePathParts(IList <ClrPathPart> parts, int startIndex)
 {
     return(ClrPropertyPathHelper.CombinePathParts(parts, startIndex, parts.Count - startIndex));
 }
 public static string CombinePathParts(IList <ClrPathPart> parts)
 {
     return(ClrPropertyPathHelper.CombinePathParts(parts, 0, parts.Count));
 }
示例#10
0
        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);
        }
示例#11
0
        public override RawDataSourceInfoBase CombineWith(RawDataSourceInfoBase localSource)
        {
            if (localSource == null)
            {
                return((RawDataSourceInfoBase)this);
            }
            if (!localSource.IsValid || localSource.SourceNode != null)
            {
                return(localSource);
            }
            if (!this.IsValid)
            {
                return((RawDataSourceInfoBase)this);
            }
            RawDataSourceInfo rawDataSourceInfo1 = localSource as RawDataSourceInfo;
            RawDataSourceInfo rawDataSourceInfo2 = new RawDataSourceInfo(this.SourceNode, ClrPropertyPathHelper.CombinePaths(this.ClrPath, rawDataSourceInfo1.ClrPath));

            rawDataSourceInfo2.XmlPath = XmlSchema.CombineXPaths(this.XmlPath, rawDataSourceInfo1.XmlPath);
            for (int index = 0; index < rawDataSourceInfo1.pendingIndexSteps; ++index)
            {
                rawDataSourceInfo2.AppendIndexStep();
            }
            return((RawDataSourceInfoBase)rawDataSourceInfo2);
        }
示例#12
0
 public override void AppendClrPath(string path)
 {
     this.clrPath = ClrPropertyPathHelper.CombinePaths(this.clrPath, path);
 }
示例#13
0
 public static string CombinePaths(string inheritedPath, string localPath)
 {
     return(ClrPropertyPathHelper.CombinePaths(inheritedPath, localPath));
 }