コード例 #1
0
ファイル: JObject.cs プロジェクト: anlei-fu/Jasmine
        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();
        }