Пример #1
0
 internal static IObserver CreateBindingSource(IDataContext context, string path, object src,
                                               bool ignoreSrc = false)
 {
     if (src == null && (ignoreSrc || !context.TryGetData(BindingBuilderConstants.Source, out src)))
     {
         src = BindingServiceProvider
               .ContextManager
               .GetBindingContext(context.GetData(BindingBuilderConstants.Target, true),
                                  context.GetData(BindingBuilderConstants.TargetPath, true).Path);
     }
     return(BindingServiceProvider
            .ObserverProvider
            .Observe(src, BindingServiceProvider.BindingPathFactory(path), false, context));
 }
        internal static object[] GetIndexerValues(IList <ParameterInfo> parameters, string path, Type castType = null)
        {
            string replace = path.Replace("[", string.Empty).Replace("]", string.Empty);
            var    strings = replace.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);
            var    result  = new object[strings.Length];

            for (int i = 0; i < strings.Length; i++)
            {
                var s = strings[i];
                if (parameters != null)
                {
                    castType = parameters[i].ParameterType;
                }
                result[i] = s == "null" ? null : BindingServiceProvider.ValueConverter(castType, s);
            }
            return(result);
        }
Пример #3
0
        public static object GetValueFromPath(object src, string strPath, int firstMemberIndex = 0)
        {
            IBindingPath path = BindingServiceProvider.BindingPathFactory(strPath);

            for (int index = firstMemberIndex; index < path.Parts.Count; index++)
            {
                string item = path.Parts[index];
                if (src.IsNullOrUnsetValue())
                {
                    return(null);
                }
                IBindingMemberInfo member = BindingServiceProvider
                                            .MemberProvider
                                            .GetBindingMember(src.GetType(), item, false, true);
                src = member.GetValue(src, null);
            }
            return(src);
        }
        internal static object[] GetIndexerValues(string path, IList <ParameterInfo> parameters = null, Type castType = null)
        {
            var args = path
                       .RemoveBounds()
                       .Split(CommaSeparator, StringSplitOptions.RemoveEmptyEntries);
            var result = new object[args.Length];

            for (int i = 0; i < args.Length; i++)
            {
                var s = args[i];
                if (parameters != null)
                {
                    castType = parameters[i].ParameterType;
                }
                if (!string.IsNullOrEmpty(s) && s[0] == '\"' && s.EndsWith("\""))
                {
                    s = s.RemoveBounds();
                }
                result[i] = s == "null" ? null : BindingServiceProvider.ValueConverter(BindingMemberInfo.Empty, castType, s);
            }
            return(result);
        }