Ejemplo n.º 1
0
 public NamespacePropertyProvider(IEnumerable <KeyValuePair <string, IPropertyProvider> > elements)
 {
     _items = elements.GroupBy(l => l.Key, l => l.Value).ToDictionary(
         grouping => grouping.Key,
         grouping => PropertyProvider.Compose(grouping)
         );
 }
Ejemplo n.º 2
0
        public void ClearProperty(string property)
        {
            PropertyProvider.CheckProperty(property);
            PropertyInfo pd = _GetProperty(property);

            if (pd != null)
            {
                _ResetProperty(pd);
            }
        }
Ejemplo n.º 3
0
        public static string Format(string format,
                                    IEnumerable <KeyValuePair <string, object> > propertyProviders)
        {
            if (string.IsNullOrEmpty(format))
            {
                return(string.Empty);
            }

            return(Format(format, PropertyProvider.Compose(propertyProviders)));
        }
Ejemplo n.º 4
0
        public bool TrySetProperty(string property, object value)
        {
            PropertyProvider.CheckProperty(property);
            PropertyInfo pd = _GetProperty(property);

            if (pd != null && pd.GetValue(ObjectContext) != value)
            {
                pd.SetValue(ObjectContext, value);
                return(true);
            }
            return(false);
        }
Ejemplo n.º 5
0
        public Type GetPropertyType(string property)
        {
            PropertyProvider.CheckProperty(property);
            object result;

            if (TryGetProperty(property, typeof(object), out result))
            {
                return((result == null) ? _items.GetType().GetElementType() : result.GetType());
            }

            return(null);
        }
Ejemplo n.º 6
0
 public bool TryGetProperty(string property, Type propertyType, out object value)
 {
     PropertyProvider.CheckProperty(property);
     value = null;
     foreach (var pp in _items)
     {
         if (pp.TryGetProperty(property, propertyType, out value))
         {
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 7
0
        public void SetProperty(string property, object value)
        {
            PropertyProvider.CheckProperty(property);
            PropertyInfo pd = _GetProperty(property);

            if (pd == null)
            {
                throw RuntimeFailure.PropertyNotFound(nameof(property), property);
            }
            if (pd.GetValue(ObjectContext) != value)
            {
                pd.SetValue(ObjectContext, value);
            }
        }
        public IPropertyProvider AddNew(string name, object value = null, TypeReference type = null)
        {
            if (value == null && type == null)
            {
                throw RuntimeFailure.DataProviderTypeOrValueNotBoth();
            }

            if (value != null)
            {
                return(AddOne(name, PropertyProvider.FromValue(value)));
            }

            return(AddOne(name, PropertyProvider.LateBound(type)));
        }
Ejemplo n.º 9
0
        public bool TryGetProperty(string property, Type propertyType, out object value)
        {
            PropertyProvider.CheckProperty(property);
            value = null;
            int index;

            if (!int.TryParse(property, out index) || index < 0 || index >= _items.Length)
            {
                return(false);
            }

            value = _items[index];
            return(value == null || propertyType.GetTypeInfo().IsInstanceOfType(value));
        }
Ejemplo n.º 10
0
        protected override int MatchCriteriaCore(object criteria)
        {
            if (criteria == null)
            {
                return(0);
            }

            int result = 0;
            var pp     = PropertyProvider.FromValue(criteria);

            result += EnumerateExtensions().Contains(pp.GetString("Extension")) ? 1 : 0;
            result += EnumerateContentTypes().Contains(pp.GetString("ContentType")) ? 1 : 0;
            result += MatchType(pp.GetProperty("OutputType"));

            return(result);
        }
        public Type GetPropertyType(string property)
        {
            PropertyProvider.CheckProperty(property);

            PropertyInfo descriptor = _GetProperty(property);

            if (descriptor == null)
            {
                return(null);
            }

            else
            {
                return(descriptor.PropertyType);
            }
        }
Ejemplo n.º 12
0
        public bool TryGetProperty(string property, Type propertyType, out object value)
        {
            PropertyProvider.CheckProperty(property);

            value = null;
            if (!property.Contains(':'))
            {
                return(false);
            }

            string[] items  = property.Split(new [] { ':' }, 2);
            string   prefix = items[0];
            string   myProp = items[1];
            var      pp     = _items.GetValueOrDefault(prefix) ?? PropertyProvider.Null;

            return(pp.TryGetProperty(myProp, propertyType, out value));
        }
Ejemplo n.º 13
0
        public bool TryGetProperty(string property, Type propertyType, out object value)
        {
            PropertyProvider.CheckProperty(property);
            value = null;

            try {
                value = _indexer.GetValue(_objectContext, new object[] { property });
            } catch (TargetInvocationException ex) {
                if (ex.InnerException is KeyNotFoundException ||
                    ex.InnerException is ArgumentException)
                {
                    return(false);
                }

                throw;
            }

            return(true);
        }
        public bool TryGetProperty(string property, Type requiredType, out object value)
        {
            PropertyProvider.CheckProperty(property);

            PropertyInfo pd = _GetProperty(property);

            requiredType = requiredType ?? typeof(object);
            value        = null;

            if (pd != null && TryGetValue(pd, out object tempValue))
            {
                if (tempValue == null)
                {
                    return(true);
                }
                return(TryCoerceValue(pd, tempValue, requiredType, out value) &&
                       requiredType.IsInstanceOfType(value));
            }
            return(false);
        }
Ejemplo n.º 15
0
        internal static int MemberwiseEquals(object criteria, object other)
        {
            var pp    = (other == null ? PropertyProvider.Null : PropertyProvider.FromValue(other));
            int score = 0;

            foreach (var m in Properties.FromValue(criteria))
            {
                var comparand = pp.GetProperty(m.Key);
                if (comparand is Type && m.Value is Type)
                {
                    if (((Type)m.Value).GetTypeInfo().IsAssignableFrom((Type)comparand))
                    {
                        score++;
                    }
                }

                if (object.Equals(comparand, m.Value))
                {
                    score++;
                }
            }
            return(score);
        }
Ejemplo n.º 16
0
 public Type GetPropertyType(string property)
 {
     PropertyProvider.CheckProperty(property);
     return(_indexer.PropertyType);
 }
Ejemplo n.º 17
0
 public Type GetPropertyType(string property)
 {
     return(PropertyProvider.InferPropertyType(this, property));
 }
Ejemplo n.º 18
0
 public string Format(IEnumerable <KeyValuePair <string, object> > propertyProvider)
 {
     return(Format(PropertyProvider.Compose(propertyProvider)));
 }
Ejemplo n.º 19
0
 public LateBoundPropertyProvider(TypeReference type)
 {
     _item = new Lazy <IPropertyProvider>(
         () => PropertyProvider.FromValue(Activation.CreateInstance(type.Resolve()))
         );
 }
Ejemplo n.º 20
0
        public static IPropertyProvider Compose(
            IEnumerable <KeyValuePair <string, object> > propertyProviders)
        {
            if (propertyProviders == null)
            {
                throw new ArgumentNullException(nameof(propertyProviders));
            }

            return(Compose(propertyProviders.Select(
                               s => new KeyValuePair <string, IPropertyProvider>(s.Key, PropertyProvider.FromValue(s.Value)))));
        }
Ejemplo n.º 21
0
 void IProperties.ClearProperty(string property)
 {
     PropertyProvider.CheckProperty(property);
 }
Ejemplo n.º 22
0
 void IProperties.SetProperty(string property, object value)
 {
     PropertyProvider.CheckProperty(property);
 }
Ejemplo n.º 23
0
 public bool TrySetProperty(string property, object value)
 {
     PropertyProvider.CheckProperty(property);
     return(false);
 }
Ejemplo n.º 24
0
 Type IPropertyProvider.GetPropertyType(string property)
 {
     PropertyProvider.CheckProperty(property);
     return(null);
 }