Пример #1
0
        private void AddProperties(Type t, HashSet <string> existingProperties, ISerializeContext ctx)
        {
            foreach (var prop in t.GetProperties(BindingFlags.Instance | BindingFlags.GetProperty | BindingFlags.SetProperty | BindingFlags.Public))
            {
                if (existingProperties.Contains(prop.Name))
                {
                    continue;
                }
                if (prop.GetIndexParameters().Length > 0)
                {
                    // ignore index properties
                    continue;
                }
                if (!prop.CanRead || !prop.CanWrite)
                {
                    continue;
                }
                if (prop.PropertyType.Equals(type))
                {
                    // ignore same nested types because of recursive endless loop
                    continue;
                }

                IValueItem item = ValueItem.CreateValueItem(prop, ctx);
                items.Add(item);

                existingProperties.Add(prop.Name);
            }
        }
Пример #2
0
        public IValueItem GetByType(Type type, ISerializeContext ctx)
        {
            IValueItem result;

            if (globalStructureMapping.TryGetValue(type, out result))
            {
                return(result);
            }

            var newItemStructure = ValueItem.CreateValueItem(null, type, null, null, null, ctx);

            RegisterTypeMapping(type, newItemStructure);

            return(newItemStructure);
        }
Пример #3
0
        internal bool AddTolerantLayoutProperty(ISerializeContext ctx, string propertyName) //, ItemType itemType, uint propertyTypeId, bool isNullable)
        {
            PropertyInfo prop = type.GetProperty(propertyName);

            if (!prop.CanRead || !prop.CanWrite)
            {
                return(false);
            }
            if (prop.PropertyType.Equals(type))
            {
                // ignore same nested types because of recursive endless loop
                return(false);
            }

            IValueItem item = ValueItem.CreateValueItem(prop, ctx);

            items.Add(item);

            return(true);
        }