예제 #1
0
        private static void AddObjectMetadata(Type type)
        {
            if (ObjectData.ContainsKey(type))
            {
                return;
            }

            ObjectMetadata data = new ObjectMetadata();

            if (type.GetInterface("System.Collections.IDictionary") != null)
            {
                data.IsDictionary = true;
            }

            data.Properties = new Dictionary <string, PropertyInfo>();

            foreach (PropertyInfo propertyInfo in type.GetProperties())
            {
                string propertyName = GetPropertyName(propertyInfo);

                if (propertyName == "Item")
                {
                    ParameterInfo[] parameters = propertyInfo.GetIndexParameters();

                    if (parameters.Length != 1)
                    {
                        continue;
                    }

                    if (parameters[0].ParameterType == typeof(string))
                    {
                        data.ElementType = propertyInfo.PropertyType;
                    }

                    continue;
                }

                data.Properties.Add(propertyName, propertyInfo);
            }

            lock (objectMetadataLock)
            {
                try
                {
                    ObjectData.Add(type, data);
                }
                catch (ArgumentException)
                {
                    return;
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Returns property value from either base class or this instance
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public object GetProperty(string name)
        {
            object value = null;

            if (ObjectData?.ContainsKey(name) == true)
            {
                value = ((JValue)ObjectData[name]).Value;
            }

            if (value == null && ClassData?.ContainsKey(name) == true)
            {
                value = ((JValue)ClassData[name]).Value;
            }

            return(value);
        }
예제 #3
0
        public EntityObject(JObject objectData, EntityClassManager classManager)
        {
            ObjectData = (JObject)objectData.DeepClone();
            JObject classData;

            if (Class != null && classManager.EntityClassDictionary.TryGetValue(Class, out classData))
            {
                ClassData = classData;
            }
            if (Guid == null)
            {
                Guid = System.Guid.NewGuid().ToString("N");
            }

            if (ObjectData.ContainsKey("Children"))
            {
                Children = new List <EntityObject>();
                foreach (JObject child in (JArray)ObjectData["Children"])
                {
                    Children.Add(new EntityObject(child, classManager));
                }
                ObjectData["Children"] = null;
            }
        }