コード例 #1
0
        /// <summary> Property  getter
        /// </summary>
        public VelPropertyGet getPropertyGet(Object obj, String identifier, Info i)
        {
            AbstractExecutor executor;

            Type claz = obj.GetType();

            /*
             *  first try for a getFoo() type of property
             *  (also getfoo() )
             */

            executor = new PropertyExecutor(rlog, introspector, claz, identifier);

            /*
             *  if that didn't work, look for get("foo")
             */

            if (!executor.isAlive())
            {
                executor = new GetExecutor(rlog, introspector, claz, identifier);
            }

            /*
             *  finally, look for boolean isFoo()
             */

            if (!executor.isAlive())
            {
                executor = new BooleanPropertyExecutor(rlog, introspector, claz, identifier);
            }

            return((executor != null) ? new VelGetterImpl(this, executor) : null);
        }
コード例 #2
0
        /// <summary>
        /// Property getter.
        /// </summary>
        public IVelPropertyGet GetPropertyGet(Object obj, String identifier, Info i)
        {
            AbstractExecutor executor;

            Type type = obj.GetType();

            // First try for a getFoo() type of property (also getfoo())
            executor = new PropertyExecutor(runtimeLogger, introspector, type, identifier);

            // If that didn't work, look for get("foo")
            if (!executor.IsAlive)
            {
                executor = new GetExecutor(runtimeLogger, introspector, type, identifier);
            }

            // If that didn't work, look for boolean isFoo()
            if (!executor.IsAlive)
            {
                executor = new BooleanPropertyExecutor(runtimeLogger, introspector, type, identifier);
            }

            // If that didn't work, look for an enumeration
            if (!executor.IsAlive && (obj is Type) && (obj as Type).IsEnum)
            {
                executor = new EnumValueExecutor(runtimeLogger, introspector, obj as Type, identifier);
            }

            return(new VelGetterImpl(executor));
        }
コード例 #3
0
 public void ThrowsForNonExistentObjectWhenSet()
 {
     Assert.Throws <InvalidOperationException>(() =>
     {
         var propertyExecutor = new PropertyExecutor <object>(
             new ReadOnlyDictionary <long, ObjectDescriptor>(new Dictionary <long, ObjectDescriptor>()),
             context => { });
         propertyExecutor.Execute(new PropertySetExecution <object>()
         {
             ObjectId = 1
         });
     });
 }
コード例 #4
0
ファイル: UberspectImpl.cs プロジェクト: SkelletonX/DDTServer
        public IVelPropertyGet GetPropertyGet(object obj, string identifier, Info i)
        {
            Type             type             = obj.GetType();
            AbstractExecutor abstractExecutor = new PropertyExecutor(this.rlog, UberspectImpl.introspector, type, identifier);

            if (!abstractExecutor.IsAlive)
            {
                abstractExecutor = new GetExecutor(this.rlog, UberspectImpl.introspector, type, identifier);
            }
            if (!abstractExecutor.IsAlive)
            {
                abstractExecutor = new BooleanPropertyExecutor(this.rlog, UberspectImpl.introspector, type, identifier);
            }
            return((abstractExecutor != null) ? new UberspectImpl.VelGetterImpl(abstractExecutor) : null);
        }
コード例 #5
0
        private static void ParseSegment(string inlineConstraint, ModelMetadata metadata, IDictionary <IConstraint, object> constraints)
        {
            var model = metadata.Model;

            string[] split        = inlineConstraint.Split(':');
            string   propertyName = split[0];
            object   value        = model;

            if (!string.IsNullOrEmpty(propertyName) && metadata.PropertyName != propertyName)
            {
                ModelMetadata propertyMetadata = null;
                if (metadata.Container == null)
                {
                    propertyMetadata = metadata.Properties.FirstOrDefault(p => p.PropertyName == propertyName);
                    if (propertyMetadata == null)
                    {
                        return;
                    }
                    value = propertyMetadata.Model;
                }
                else
                {
                    //防止循环中频繁反射损伤性能,使用表达式树做了编译缓存
                    PropertyExecutor executor = new PropertyExecutor(metadata.ContainerType.FullName, propertyName);
                    value = executor.GetValue(metadata.Container);
                    //var propertyInfo= metadata.ContainerType.GetProperty(propertyName);
                    //if (propertyInfo==null)
                    //{
                    //    return;
                    //}
                    //value = propertyInfo.GetValue(metadata.Container);
                }
            }

            DefaultInlineConstraintResolver defaultInlineConstraint = new DefaultInlineConstraintResolver();
            IList <IConstraint>             constraintList          = new List <IConstraint>();

            for (int i = 1; i < split.Length; i++)
            {
                var constraint = defaultInlineConstraint.ResolveConstraint(split[i]);
                if (constraint != null)
                {
                    constraintList.Add(constraint);
                }
            }

            constraints.Add(new CompositeConstraint(constraintList), value);
        }
コード例 #6
0
 public void ThrowsForNonExistentPropertyWhenSet()
 {
     Assert.Throws <InvalidOperationException>(() =>
     {
         var propertyExecutor = new PropertyExecutor <object>(
             new ReadOnlyDictionary <long, ObjectDescriptor>(
                 new Dictionary <long, ObjectDescriptor>()
         {
             { 1, ObjectDescriptor.Create().WithProperties(new List <PropertyDescriptor>()).WithId(1).Get() }
         }), context => { });
         propertyExecutor.Execute(new PropertySetExecution <object>()
         {
             ObjectId   = 1,
             PropertyId = 2
         });
     });
 }
コード例 #7
0
        /// <summary> Property  getter</summary>
        /// <param name="obj">
        /// </param>
        /// <param name="identifier">
        /// </param>
        /// <param name="i">
        /// </param>
        /// <returns> A Velocity Getter Method.
        /// </returns>
        /// <throws>  Exception </throws>
        public virtual IVelPropertyGet GetPropertyGet(object obj, string identifier, Info i)
        {
            if (obj == null)
            {
                return(null);
            }

            System.Type claz = obj.GetType();

            /*
             *  first try for a getFoo() type of property
             *  (also getfoo() )
             */
            AbstractExecutor executor = new PropertyExecutor(log, introspector, claz, identifier);

            /*
             * Let's see if we are a map...
             */
            if (!executor.Alive)
            {
                executor = new MapGetExecutor(log, claz, identifier);
            }

            /*
             *  if that didn't work, look for Get("foo")
             */

            if (!executor.Alive)
            {
                executor = new GetExecutor(log, introspector, claz, identifier);
            }

            /*
             *  finally, look for boolean isFoo()
             */

            if (!executor.Alive)
            {
                executor = new BooleanPropertyExecutor(log, introspector, claz, identifier);
            }

            return((executor.Alive) ? new VelGetterImpl(executor) : null);
        }