Exemplo n.º 1
0
        public GenericClassSerializationInfo Create(TypeDefinition definition)
        {
            var messagePackAttribute = definition.CustomAttributes.SingleOrDefault(CustomAttributeHelper.IsMessagePackObjectAttribute);

            if (messagePackAttribute is null)
            {
                throw new MessagePackGeneratorResolveFailedException("invalid generic class type. type : " + definition.FullName);
            }

            var variations      = finder.Find(definition).ToArray();
            var customFormatter = definition.CustomAttributes.SingleOrDefault(CustomAttributeHelper.IsMessagePackFormatterAttribute);

            if (!(customFormatter is null))
            {
                return(new GenericClassSerializationInfo(definition, CustomFormatterDetector.Detect(definition, customFormatter), variations));
            }

            CustomAttributeHelper.IsMessagePackObjectAttribute(messagePackAttribute, out var isKeyAsPropertyName);
            var fieldInfos    = MessagePackObjectHelper.CollectFieldInfos(definition, false);
            var propertyInfos = MessagePackObjectHelper.CollectPropertyInfos(definition, isKeyAsPropertyName);

            var(minIntKey, maxIntKey) = MessagePackObjectHelper.FindMinMaxIntKey(fieldInfos, propertyInfos);

            return(new GenericClassSerializationInfo(definition, fieldInfos, propertyInfos, minIntKey, maxIntKey, variations));
        }
Exemplo n.º 2
0
        public GenericStructSerializationInfo Create(TypeDefinition definition)
        {
            var messagePackAttribute = definition.CustomAttributes.SingleOrDefault(CustomAttributeHelper.IsMessagePackObjectAttribute);

            if (messagePackAttribute is null)
            {
                throw new MessagePackGeneratorResolveFailedException("invalid generic struct type. type : " + definition.FullName);
            }

            var serializationConstructor = SerializationConstructorUtility.Find(definition);
            var variations      = finder.Find(definition).ToArray();
            var customFormatter = definition.CustomAttributes.SingleOrDefault(CustomAttributeHelper.IsMessagePackFormatterAttribute);

            if (!(customFormatter is null))
            {
                var customFormatterTypeInfo = CustomFormatterDetector.Detect(definition, customFormatter);
                return(new GenericStructSerializationInfo(definition, customFormatterTypeInfo, serializationConstructor, variations));
            }

            var fieldInfos    = MessagePackObjectHelper.CollectFieldInfos(definition, true);
            var propertyInfos = MessagePackObjectHelper.CollectPropertyInfos(definition, true);

            var(minIntKey, maxIntKey) = MessagePackObjectHelper.FindMinMaxIntKey(fieldInfos, propertyInfos);

            return(new GenericStructSerializationInfo(definition, fieldInfos, propertyInfos, minIntKey, maxIntKey, serializationConstructor, variations));
        }