Esempio 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));
        }