コード例 #1
0
        private static PropertyInfo SetParams(cfg.classref config, object instance)
        {
            PropertyInfo customScriptProperty = null;

            if (null != config.property)
            {
                foreach (var v in config.property)
                {
                    PropertyInfo pi = instance.GetType().GetProperty(v.name);
                    if (pi.GetCustomAttributes(typeof(BooDecoratorAttribute), true).Length > 0)
                    {
                        if (customScriptProperty != null)
                        {
                            throw new Exception("Too many property specify a boo derivative of class:" + instance.GetType().Name);
                        }
                        customScriptProperty = pi;
                    }
                    if (pi == null || !pi.CanWrite)
                    {
                        throw new Exception(string.Format("Can't configure type {0}: property {1} does not exists or is read-only", instance.GetType().Name, v.name));
                    }
                    pi.SetValue(instance, Convert.ChangeType(v.Value, pi.PropertyType), null);
                }
            }
            return(customScriptProperty);
        }
コード例 #2
0
        public static T Create <T>(cfg.classref config) where T : class
        {
            T            instance             = Create <T>(config.@class);
            PropertyInfo customScriptProperty = null;

            customScriptProperty = SetParams(config, instance);

            /*
             * if (null != customScriptProperty)
             * {
             *  string script = customScriptProperty.GetValue(instance, null) as string;
             *  if (!string.IsNullOrEmpty(script))
             *  {
             *      instance = BooActivator.CreateInstance<T>(script);
             *      Inject(instance);
             *      SetParams(config, instance);
             *  }
             * }*/
            return(instance);
        }