Пример #1
0
 private void AddSubtype(ClassDataType subtype)
 {
     if (subtypes == null)
     {
         subtypes = new List <ClassDataType> ();
     }
     subtypes.Add(subtype);
 }
        public void RegisterProperty(Type targetType, ItemProperty property)
        {
            if (!typeof(IExtendedDataItem).IsAssignableFrom(targetType))
            {
                throw new InvalidOperationException("The type '" + targetType + "' does not implement the IExtendedDataItem interface and cannot be extended with new properties");
            }

            ClassDataType ctype = (ClassDataType)GetConfigurationDataType(targetType);

            ctype.AddProperty(property);
        }
        public void RegisterProperty(Type targetType, string name, Type propertyType, bool isExternal, bool skipEmpty)
        {
            if (!typeof(IExtendedDataItem).IsAssignableFrom(targetType))
            {
                throw new InvalidOperationException("The type '" + targetType + "' does not implement the IExtendedDataItem interface and cannot be extended with new properties");
            }

            ClassDataType ctype = (ClassDataType)GetConfigurationDataType(targetType);
            ItemProperty  prop  = new ItemProperty(name, propertyType);

            prop.Unsorted   = true;
            prop.IsExternal = isExternal;
            prop.SkipEmpty  = skipEmpty;
            ctype.AddProperty(prop);
        }
Пример #4
0
 internal ClassTypeHandler(SerializationContext ctx, ClassDataType cdt)
 {
     this.ctx = ctx;
     this.cdt = cdt;
 }
Пример #5
0
        protected override void Initialize()
        {
            IDataItemAttribute atd = (IDataItemAttribute)Context.AttributeProvider.GetCustomAttribute(ValueType, typeof(IDataItemAttribute), false);

            if (atd != null)
            {
                if (!string.IsNullOrEmpty(atd.Name))
                {
                    Name = atd.Name;
                }
                if (atd.FallbackType != null)
                {
                    fallbackType = atd.FallbackType;
                    if (!typeof(IExtendedDataItem).IsAssignableFrom(fallbackType))
                    {
                        throw new InvalidOperationException("Fallback type '" + fallbackType + "' must implement IExtendedDataItem");
                    }
                    if (!ValueType.IsAssignableFrom(fallbackType))
                    {
                        throw new InvalidOperationException("Fallback type '" + fallbackType + "' must be a subclass of '" + ValueType + "'");
                    }
                }
            }

            object[] incs = Attribute.GetCustomAttributes(ValueType, typeof(DataIncludeAttribute), true);
            foreach (DataIncludeAttribute incat in incs)
            {
                Context.IncludeType(incat.Type);
            }

            if (ValueType.BaseType != null)
            {
                ClassDataType baseType = (ClassDataType)Context.GetConfigurationDataType(ValueType.BaseType);
                baseType.AddSubtype(this);
                int n = 0;
                foreach (ItemProperty prop in baseType.Properties)
                {
                    properties.Add(prop.Name, prop);
                    sortedPoperties.Insert(n++, prop);
                }

                // Inherit the fallback type
                if (fallbackType == null && baseType.fallbackType != null)
                {
                    fallbackType = baseType.fallbackType;
                }
            }

            foreach (Type interf in ValueType.GetInterfaces())
            {
                ClassDataType baseType = (ClassDataType)Context.GetConfigurationDataType(interf);
                baseType.AddSubtype(this);
            }

            MemberInfo[] members = ValueType.GetMembers(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
            foreach (MemberInfo member in members)
            {
                if ((member is FieldInfo || member is PropertyInfo) && member.DeclaringType == ValueType)
                {
                    Type memberType = member is FieldInfo ? ((FieldInfo)member).FieldType : ((PropertyInfo)member).PropertyType;
                    AddProperty(member, member.Name, memberType);
                }
            }

            foreach (ItemMember member in Context.AttributeProvider.GetItemMembers(ValueType))
            {
                AddProperty(member, member.Name, member.Type);
            }

            if (fallbackType != null)
            {
                Context.IncludeType(fallbackType);
            }
        }
        public IEnumerable <ItemProperty> GetProperties(SerializationContext serCtx, object instance)
        {
            ClassDataType ctype = (ClassDataType)GetConfigurationDataType(instance.GetType());

            return(ctype.GetProperties(serCtx, instance));
        }
        public void UnregisterProperty(Type targetType, string name)
        {
            ClassDataType ctype = (ClassDataType)GetConfigurationDataType(targetType);

            ctype.RemoveProperty(name);
        }
        public void SetConfigurationItemData(SerializationContext serCtx, object obj, DataItem data)
        {
            ClassDataType dataType = (ClassDataType)GetConfigurationDataType(obj.GetType());

            dataType.Deserialize(serCtx, null, data, obj);
        }
		internal ClassTypeHandler (SerializationContext ctx, ClassDataType cdt)
		{
			this.ctx = ctx;
			this.cdt = cdt;
		}
		private void AddSubtype (ClassDataType subtype)
		{
			if (subtypes == null)
				subtypes = new List<ClassDataType> ();
			subtypes.Add (subtype); 
		}