Example #1
0
        private static void CreatePolicy(PolicyConfig config,ICachedManager cm)
        {
            IPolicy result = null;
            Type objectType = Type.GetType(config.ObjectType);
            Type policyType = Type.GetType(config.Type);
            if(objectType ==null)
                throw new CacheDBException("{0} object type notfound!", config.Type);
            if(policyType==null)
                throw new CacheDBException("{0} Policy type notfound!", config.Type);
            result = (IPolicy)Activator.CreateInstance(policyType);

            foreach (PropertyConfig p in config.Properties)
            {
                PropertyInfo pi = policyType.GetProperty(p.Name, BindingFlags.Public | BindingFlags.Instance);
                if (pi != null && pi.CanWrite)
                {
                    try
                    {
                        pi.SetValue(result, Convert.ChangeType(p.Value, pi.PropertyType), null);
                    }
                    catch
                    {
                    }
                }
            }
            cm.AddPolicy(objectType, result);
          
        }
Example #2
0
        private static void CreatePolicy(PolicyConfig config, ICachedManager cm)
        {
            IPolicy result     = null;
            Type    objectType = Type.GetType(config.ObjectType);
            Type    policyType = Type.GetType(config.Type);

            if (objectType == null)
            {
                throw new CacheDBException("{0} object type notfound!", config.Type);
            }
            if (policyType == null)
            {
                throw new CacheDBException("{0} Policy type notfound!", config.Type);
            }
            result = (IPolicy)Activator.CreateInstance(policyType);

            foreach (PropertyConfig p in config.Properties)
            {
                PropertyInfo pi = policyType.GetProperty(p.Name, BindingFlags.Public | BindingFlags.Instance);
                if (pi != null && pi.CanWrite)
                {
                    try
                    {
                        pi.SetValue(result, Convert.ChangeType(p.Value, pi.PropertyType), null);
                    }
                    catch
                    {
                    }
                }
            }
            cm.AddPolicy(objectType, result);
        }