コード例 #1
0
        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));
            }
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        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);
        }
コード例 #4
0
ファイル: AdapterFactory.cs プロジェクト: Carbonfrost/f-core
        internal static object NewInstance(object adaptee, Type type)
        {
            var props = Properties.FromArray(adaptee);

            return(Activation.CreateInstance(type, props, ServiceProvider.Current));
        }
コード例 #5
0
ファイル: Template.Static.cs プロジェクト: Carbonfrost/f-core
 public void Apply(object value)
 {
     Activation.Initialize(value, _properties);
 }
コード例 #6
0
 public LateBoundPropertyProvider(TypeReference type)
 {
     _item = new Lazy <IPropertyProvider>(
         () => PropertyProvider.FromValue(Activation.CreateInstance(type.Resolve()))
         );
 }
コード例 #7
0
 public override object Activate(IEnumerable <KeyValuePair <string, object> > arguments,
                                 IServiceProvider services)
 {
     return(Activation.CreateInstance(type, arguments, services));
 }
コード例 #8
0
 public override object GetValue()
 {
     return(Activation.CreateInstance(type));
 }
コード例 #9
0
 public object ReadValue(Type componentType)
 {
     return(Activation.FromStreamContext(componentType, this));
 }