コード例 #1
0
        private IPropertySerializationInfo CreateReferenceSerializationInfo(IReference arg)
        {
            var actualType = arg.ReferenceType ?? ModelElement.ClassInstance;
            var mapping    = actualType.GetExtension <MappedType>();
            ITypeSerializationInfo type;

            if (mapping != null)
            {
                type = GetSerializationInfo(mapping.SystemType, true);
            }
            else
            {
                type = _serializationInfos[actualType];
            }
            if (arg.UpperBound != 1)
            {
                type = new CollectionTypeSerializationInfo(type);
            }
            var referenceInfo = new DynamicReferenceSerializationInfo(arg, type);

            if (arg.Opposite != null)
            {
                if (_serializationInfos.TryGetValue(arg.Opposite.DeclaringType, out var oppositeType) && oppositeType.DeclaredElementProperties != null)
                {
                    var oppositeSerializationInfo = oppositeType.DeclaredElementProperties
                                                    .Concat(oppositeType.DeclaredAttributeProperties)
                                                    .OfType <DynamicReferenceSerializationInfo>()
                                                    .Single(r => r.Reference == arg.Opposite);

                    oppositeSerializationInfo.Opposite = referenceInfo;
                    referenceInfo.Opposite             = oppositeSerializationInfo;
                }
            }
            return(referenceInfo);
        }
コード例 #2
0
        private IPropertySerializationInfo CreateAttributeSerializationInfo(IAttribute arg)
        {
            ITypeSerializationInfo type = GetAttributeType(arg);

            if (arg.UpperBound != 1)
            {
                type = new CollectionTypeSerializationInfo(type);
            }
            return(new DynamicAttributeSerializationInfo(arg, type));
        }