Exemplo n.º 1
0
 public override bool Equals(object obj)
 {
     if (!base.Equals(obj))
     {
         return(false);
     }
     else if (obj is JMappingObject jmapping)
     {
         if (BaseTypes.Numbers.Contains(jmapping.InstanceType))
         {
             return(JMappingObject.ToDouble(jmapping.InstanceType, jmapping.Instance) == Value);
         }
         else
         {
             return(false);
         }
     }
     else if (obj is JNumber)
     {
         return(((JNumber)obj).Value == Value);
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 2
0
 public JMappingFunction(JMappingObject parent, object instance, Func <object, object[], object> invoker, Type[] parameterTypes, string name) : base()
 {
     Parent         = parent;
     Instance       = instance;
     Invoker        = invoker;
     Name           = name;
     ParameterTypes = parameterTypes;
 }
Exemplo n.º 3
0
 public JMappingObject(object instance,
                       JMappingObject parent,
                       string name,
                       Func <object, object> getter,
                       Action <object, object> setter)
 {
     Instance = instance;
     Parent   = parent;
     Name     = name;
     Getter   = getter;
     Setter   = setter;
 }
Exemplo n.º 4
0
        public JMappingObject GetProperty(string name)
        {
            /*
             *  search in the properties cache
             */
            if (_properties.ContainsKey(name))
            {
                if (_properties[name].Getter != null)
                {
                    /*
                     * mutiple thread run
                     * must reget value ,avoid instance has changed in c# code,but we still cache the old value
                     */
                    _properties[name].Instance = _properties[name].Getter(Instance);
                }

                return(_properties[name]);
            }


            var property = _cache.GetItem(InstanceType).Properties.GetItemByName(name);

            if (property != null)
            {
                var newItem = new JMappingObject(property.GetValue(Instance), this, name, property.Getter, property.Setter);
                _properties.Add(name, newItem);

                return(_properties[name]);
            }


            var field = _cache.GetItem(InstanceType).Fileds.GetItemByName(name);

            if (field != null)
            {
                var newItem = new JMappingObject(field.GetValue(Instance), this, name, field.Getter, field.Setter);

                _properties.Add(name, newItem);

                return(_properties[name]);
            }

            var methods = _cache.GetItem(InstanceType).Methods.GetMethodsByName(name);

            if (methods != null)
            {
                if (methods.Length == 1)
                {
                    _properties.Add(name, new JMappingFunction(this, Instance, methods[0].Invoker, methods[0].ParamerTypies, name));
                }
                else
                {
                    var functions = new List <JMappingFunction>();

                    foreach (var item in methods)
                    {
                        functions.Add(new JMappingFunction(this, Instance, item.Invoker, item.ParamerTypies, name));
                    }

                    _properties.Add(name, new JMappingFunctions(functions));
                }

                return(_properties[name]);
            }


            throw new PropertyNotFoundException();
        }