public override object Load(TextReader reader, Type instanceType) { if (reader == null) { throw new ArgumentNullException("reader"); } using (PropertiesReader pr = new PropertiesReader(reader)) { var items = pr.ReadToEnd().Select(t => new KeyValuePair <string, object>(t.Key, t.Value)); if (typeof(IProperties).Equals(instanceType) || typeof(Properties).Equals(instanceType) || typeof(IPropertyProvider).Equals(instanceType)) { return(new Properties(items)); } return(Activation.CreateInstance(instanceType, items, ServiceProvider.Null)); } }
protected override bool TryGetPropertyCore(string property, Type requiredType, out object value) { // Review the local storage to determine if it is contained requiredType = requiredType ?? typeof(object); if (InnerMap.TryGetValue(property, out value)) { if (requiredType.GetTypeInfo().IsInstanceOfType(value) || value == null) { return(true); } // Type coercion var str = value as string; if (str != null) { value = Activation.FromText(requiredType, str, null, null); return(true); } } value = null; return(base.TryGetPropertyCore(property, requiredType, out value)); }
public static object GetDefaultValue(this PropertyInfo property) { if (property == null) { throw new ArgumentNullException(nameof(property)); } var data = property.CustomAttributes.FirstOrDefault(t => t.AttributeType == typeof(DefaultValueAttribute)); if (data != null && data.ConstructorArguments.Count == 2) { // Do a parse to extract the value return(Activation.FromText((Type)data.ConstructorArguments[0].Value, (string)data.ConstructorArguments[1].Value)); } var attr = property.GetCustomAttribute <DefaultValueAttribute>(); if (attr == null) { return(property.PropertyType.GetDefaultValue()); } return(attr.Value); }
internal static object NewInstance(object adaptee, Type type) { var props = Properties.FromArray(adaptee); return(Activation.CreateInstance(type, props, ServiceProvider.Current)); }
public void Apply(object value) { Activation.Initialize(value, _properties); }
public LateBoundPropertyProvider(TypeReference type) { _item = new Lazy <IPropertyProvider>( () => PropertyProvider.FromValue(Activation.CreateInstance(type.Resolve())) ); }
public override object Activate(IEnumerable <KeyValuePair <string, object> > arguments, IServiceProvider services) { return(Activation.CreateInstance(type, arguments, services)); }
public override object GetValue() { return(Activation.CreateInstance(type)); }
public object ReadValue(Type componentType) { return(Activation.FromStreamContext(componentType, this)); }