Example #1
0
        protected MessagePropertyAttribute GetDefaultMessageSerializedPropertyAttribute(bool defaultExcludeProperty)
        {
            MessagePropertyAttribute messagePropertyAttribute = new MessagePropertyAttribute();

            messagePropertyAttribute.Exclude = defaultExcludeProperty;
            return(messagePropertyAttribute);
        }
Example #2
0
        public MessageSerializedPropertyInfo(int index, PropertyInfo propertyInfo, MessagePropertyAttribute messagePropertyAttribute, SerializationDefaults serializationDefaults, MessageClassAttribute classAttribute)
        {
            Index        = index;
            PropertyInfo = propertyInfo;
            SetElementType(propertyInfo.PropertyType);
            ElementIsMessageSerializableObject = TypeIsMessageSerializableObject(ElementType);
            MessagePropertyAttribute           = messagePropertyAttribute;
            CalculatedFieldAttributes          = GetCalculatedFieldAttributes(propertyInfo);

            //TODO: throw new Exception("Probably need to change this to be called after all the MessageSerializedPropertyInfos are created and then pass the list in to CheckRules.  Also, since it's a member, a bunch of the parameters don't need to be passed in anyways");
            CheckRules(messagePropertyAttribute, propertyInfo, ElementType, ElementIsMessageSerializableObject, serializationDefaults, classAttribute);
        }
Example #3
0
        protected void CheckRules(MessagePropertyAttribute messagePropertyAttribute, PropertyInfo propertyInfo, Type elementType, bool isMessageSerializable, SerializationDefaults serializationDefaults, MessageClassAttribute classAttribute)
        {
            if (serializationDefaults is null)
            {
                return;
            }

            messagePropertyAttribute.ApplyingRules = true;
            foreach (IPropertyRule propertyRule in serializationDefaults.PropertyRules)
            {
                propertyRule.Check(this, serializationDefaults, classAttribute);
            }

            messagePropertyAttribute.ApplyingRules = false;
        }
Example #4
0
        protected List <MessageSerializedPropertyInfo> GetPropertiesForType(Type type, ConfigClassInfo configClassInfo, ref int totalLengthWithoutVariableData, ref int nonVaryingLengthPartOfMessageLength)
        {
            PropertyInfo[] objectProperties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
            List <MessageSerializedPropertyInfo> messageSerializedProperties = new List <MessageSerializedPropertyInfo>();
            int indexInMessage = 0;

            foreach (PropertyInfo propertyInfo in objectProperties)
            {
                MessagePropertyAttribute messagePropertyAttribute =
                    GetMessageSerializedPropertyAttributeFromClassInfo(propertyInfo, configClassInfo, MessageClassAttribute.DefaultExcludeProperty)
                    ?? GetMessageSerializedPropertyAttribute(propertyInfo, MessageClassAttribute.DefaultExcludeProperty);

                if (messagePropertyAttribute.Exclude)
                {
                    continue;
                }

                // Note: If you want to check something with the attribute you should use it after creating the MessageSerializablePropertyInfo
                // as that is what initializes any of the unset values
                MessageSerializedPropertyInfo messageSerializedPropertyInfo = new MessageSerializedPropertyInfo(indexInMessage++, propertyInfo, messagePropertyAttribute, SerializationDefaults, MessageClassAttribute);

                if (messagePropertyAttribute.MaxLength != -1 && messagePropertyAttribute.MaxLength < messagePropertyAttribute.MinLength)
                {
                    throw new Exception(string.Format("For {0} the MinLength ({1}) > MaxLength ({2}) which is not allowed",
                                                      messageSerializedPropertyInfo.PropertyInfo.Name, messageSerializedPropertyInfo.MessagePropertyAttribute.MinLength, messageSerializedPropertyInfo.MessagePropertyAttribute.MaxLength));
                }

                if (messageSerializedPropertyInfo.IsVariableLength)
                {
                    IsVariableLength = true;
                }

                int propertyLength = messageSerializedPropertyInfo.MessagePropertyAttribute.Length;
                if (messageSerializedPropertyInfo.MessagePropertyAttribute.BlobType == BlobTypes.Data)
                {
                    ContainsBlobData = true;
                }
                else if (!messageSerializedPropertyInfo.IsVariableLength)
                {
                    totalLengthWithoutVariableData += propertyLength;
                }

                messageSerializedProperties.Add(messageSerializedPropertyInfo);
            }

            return(messageSerializedProperties);
        }
Example #5
0
        public string ToString(int indentLevel)
        {
            var sb = new StringBuilder();

            // List<int> Blah
            //    ElementType: int
            //    Attributes:
            //    MessagePropertyAttribute: Not Specified
            //    Calculated Fields (1):
            //        CalculatedLength: Exclude = true
            sb.AppendLine(indentLevel++.GetIndent() + $"{PropertyInfo.PropertyType.PrintableType()} {PropertyInfo.Name}:");
            sb.AppendLine(indentLevel.GetIndent() + $"IsList: {IsList}, ElementType: {ElementType.PrintableType()}");
            if (ElementIsMessageSerializableObject)
            {
                sb.AppendLine(indentLevel.GetIndent() + $"Element Is Message Serializable");
                sb.Append(Serializer.Instance.GetClassInfoString(ElementType, indentLevel + 1));
            }
            else
            {
                string messagePropertyAttributeString = MessagePropertyAttribute.ToString();
                if (!string.IsNullOrWhiteSpace(messagePropertyAttributeString) || CalculatedFieldAttributes.Count > 0)
                {
                    sb.AppendLine(indentLevel.GetIndent() + "Attributes:");
                    ++indentLevel;

                    if (!string.IsNullOrWhiteSpace(messagePropertyAttributeString))
                    {
                        sb.AppendLine(indentLevel.GetIndent() + messagePropertyAttributeString);
                    }

                    if (CalculatedFieldAttributes.Count > 0)
                    {
                        sb.AppendLine(indentLevel.GetIndent() + $"CalculatedFieldAttributes: {CalculatedFieldAttributes.Count}");
                        foreach (CalculatedFieldAttribute calculatedFieldAttribute in CalculatedFieldAttributes)
                        {
                            sb.AppendLine((indentLevel + 1).GetIndent() + $"{calculatedFieldAttribute}");
                        }
                    }
                }
            }

            return(sb.ToString());
        }