예제 #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)
         );
 }
예제 #2
0
        public void ClearProperty(string property)
        {
            PropertyProvider.CheckProperty(property);
            PropertyInfo pd = _GetProperty(property);

            if (pd != null)
            {
                _ResetProperty(pd);
            }
        }
예제 #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)));
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
 }
예제 #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)));
        }
예제 #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));
        }
예제 #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);
            }
        }
예제 #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));
        }
예제 #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);
        }
예제 #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);
        }
예제 #16
0
 public Type GetPropertyType(string property)
 {
     PropertyProvider.CheckProperty(property);
     return(_indexer.PropertyType);
 }
 public Type GetPropertyType(string property)
 {
     return(PropertyProvider.InferPropertyType(this, property));
 }
예제 #18
0
 public string Format(IEnumerable <KeyValuePair <string, object> > propertyProvider)
 {
     return(Format(PropertyProvider.Compose(propertyProvider)));
 }
예제 #19
0
 public LateBoundPropertyProvider(TypeReference type)
 {
     _item = new Lazy <IPropertyProvider>(
         () => PropertyProvider.FromValue(Activation.CreateInstance(type.Resolve()))
         );
 }
예제 #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)))));
        }
예제 #21
0
 void IProperties.ClearProperty(string property)
 {
     PropertyProvider.CheckProperty(property);
 }
예제 #22
0
 void IProperties.SetProperty(string property, object value)
 {
     PropertyProvider.CheckProperty(property);
 }
예제 #23
0
 public bool TrySetProperty(string property, object value)
 {
     PropertyProvider.CheckProperty(property);
     return(false);
 }
예제 #24
0
 Type IPropertyProvider.GetPropertyType(string property)
 {
     PropertyProvider.CheckProperty(property);
     return(null);
 }