Пример #1
0
        public ArrayDescriptor AddArray(string name, CFlatType type, CFlatType baseType, int lower, int upper)
        {
            var descriptor = new ArrayDescriptor(type, baseType, name, lower, upper);

            CurrentScope.Descriptors.Add(name, descriptor);
            return(descriptor);
        }
Пример #2
0
 public override void VisitArray(Array array, ArrayDescriptor descriptor)
 {
     if (!IsArrayOfPrimitiveType(descriptor))
     {
         base.VisitArray(array, descriptor);
     }
 }
Пример #3
0
        private TypeFullDescriptor ReadFullTypeDescriptor()
        {
            TypeFullDescriptor type;
            var typeIdOrPosition = reader.ReadInt32();

            if (typeIdOrPosition == Consts.NullObjectId)
            {
                return(null);
            }

            var isGenericParameter = reader.ReadBoolean();

            if (isGenericParameter)
            {
                var genericType = ReadFullTypeDescriptor().UnderlyingType;
                type = (TypeFullDescriptor)genericType.GetGenericArguments()[typeIdOrPosition];
            }
            else
            {
                if (types.Count > typeIdOrPosition)
                {
                    type = (TypeFullDescriptor)types[typeIdOrPosition];
                }
                else
                {
                    type = new TypeFullDescriptor();
                    types.Add(type);

                    type.Read(this);
                }
            }

            if (type.UnderlyingType.IsGenericType)
            {
                var containsAnyFixedGenericArguments = reader.ReadBoolean();
                if (containsAnyFixedGenericArguments)
                {
                    var args = new Type[type.UnderlyingType.GetGenericArguments().Count()];
                    for (int i = 0; i < args.Length; i++)
                    {
                        args[i] = ReadFullTypeDescriptor().UnderlyingType;
                    }

                    type = (TypeFullDescriptor)type.UnderlyingType.MakeGenericType(args);
                }
            }

            if (Helpers.ContainsGenericArguments(type.UnderlyingType))
            {
                var ranks = reader.ReadArray();
                if (ranks.Length > 0)
                {
                    var arrayDescriptor = new ArrayDescriptor(type.UnderlyingType, ranks);
                    type = (TypeFullDescriptor)arrayDescriptor.BuildArrayType();
                }
            }

            return(type);
        }
Пример #4
0
            public override void VisitArrayItem(Array array, ArrayDescriptor descriptor, int index, object item, ITypeDescriptor itemDescriptor)
            {
                base.VisitArrayItem(array, descriptor, index, item, itemDescriptor);
                var assetReference    = item as AssetReference;
                var assetBase         = item as AssetBase;
                var attachedReference = item != null?AttachedReferenceManager.GetAttachedReference(item) : null;

                if (assetReference != null)
                {
                    AddLink(item,
                            (guid, location) =>
                    {
                        var newValue = AssetReference.New(descriptor.ElementType, guid.HasValue ? guid.Value : assetReference.Id, location);
                        array.SetValue(newValue, index);
                        return(newValue);
                    });
                }
                else if (assetBase != null)
                {
                    AddLink(item,
                            (guid, location) =>
                    {
                        var newValue = new AssetBase(location, assetBase.Asset);
                        array.SetValue(newValue, index);
                        return(newValue);
                    });
                }
                else if (attachedReference != null)
                {
                    AddLink(new AttachedContentReference(attachedReference),
                            (guid, location) =>
                    {
                        object newValue = guid.HasValue && guid.Value != Guid.Empty ? AttachedReferenceManager.CreateSerializableVersion(descriptor.ElementType, guid.Value, location) : null;
                        array.SetValue(newValue, index);
                        return(newValue);
                    });
                }
                else if (item is UFile)
                {
                    AddLink(item,
                            (guid, location) =>
                    {
                        var newValue = new UFile(location);
                        array.SetValue(newValue, index);
                        return(newValue);
                    });
                }
                else if (item is UDirectory)
                {
                    AddLink(item,
                            (guid, location) =>
                    {
                        var newValue = new UFile(location);
                        array.SetValue(newValue, index);
                        return(newValue);
                    });
                }
            }
            public override void VisitArrayItem(Array array, ArrayDescriptor descriptor, int index, object item, ITypeDescriptor itemDescriptor)
            {
                if (ProcessObject(item, descriptor.ElementType))
                {
                    return;
                }

                base.VisitArrayItem(array, descriptor, index, item, itemDescriptor);
            }
Пример #6
0
        private int TouchAndWriteTypeIdWithFullStamp(Type type)
        {
            var typeDescriptor = (TypeFullDescriptor)type;
            // stamping `Type` is different than `Module`, `Assembly`, etc. so we need a special method for that
            ArrayDescriptor arrayDescriptor = null;

            if (Helpers.ContainsGenericArguments(typeDescriptor.UnderlyingType))
            {
                if (typeDescriptor.UnderlyingType.IsArray)
                {
                    arrayDescriptor = new ArrayDescriptor(typeDescriptor.UnderlyingType);
                    typeDescriptor  = (TypeFullDescriptor)arrayDescriptor.ElementType;
                }
                else
                {
                    arrayDescriptor = ArrayDescriptor.EmptyRanks;
                }
            }

            if (typeDescriptor.UnderlyingType.IsGenericType)
            {
                var genericTypeDefinition           = typeDescriptor.UnderlyingType.GetGenericTypeDefinition();
                var genericTypeDefinitionDescriptor = (TypeFullDescriptor)genericTypeDefinition;

                TouchAndWriteTypeIdWithFullStampInner(genericTypeDefinitionDescriptor);

                var typeOfUnderlyingType = Helpers.GetTypeOfGenericType(typeDescriptor.UnderlyingType);
                if (typeOfUnderlyingType == Helpers.TypeOfGenericType.OpenGenericType)
                {
                    writer.Write(false);
                }
                else if (typeOfUnderlyingType == Helpers.TypeOfGenericType.ClosedGenericType || typeOfUnderlyingType == Helpers.TypeOfGenericType.FixedNestedGenericType)
                {
                    writer.Write(true);
                    foreach (var genericArgumentType in typeDescriptor.UnderlyingType.GetGenericArguments())
                    {
                        TouchAndWriteTypeIdWithFullStamp(genericArgumentType);
                    }
                }
                else
                {
                    throw new ArgumentException(string.Format("Unexpected generic type: {0}", typeDescriptor.UnderlyingType));
                }
            }
            else
            {
                TouchAndWriteTypeIdWithFullStampInner(typeDescriptor);
            }

            if (arrayDescriptor != null)
            {
                writer.WriteArray(arrayDescriptor.Ranks);
            }

            return(0);
        }
Пример #7
0
        public void TestArrayDescriptor()
        {
            var attributeRegistry = new AttributeRegistry();
            var descriptor        = new ArrayDescriptor(attributeRegistry, typeof(int[]), new DefaultNamingConvention());

            descriptor.Initialize();

            Assert.AreEqual(0, descriptor.Count);
            Assert.AreEqual(typeof(int), descriptor.ElementType);
        }
Пример #8
0
 /// <inheritdoc/>
 public override void VisitArrayItem(Array array, ArrayDescriptor descriptor, int index, object item, ITypeDescriptor itemDescriptor)
 {
     if (CurrentPath.Match(MemberPath))
     {
         VisitAssetMember(item, itemDescriptor);
     }
     else
     {
         base.VisitArrayItem(array, descriptor, index, item, itemDescriptor);
     }
 }
Пример #9
0
        public override void VisitArrayItem(Array array, ArrayDescriptor descriptor, int index, object item, ITypeDescriptor itemDescriptor)
        {
            var node    = stackItems.Peek();
            var newNode = new DataVisitArrayItem(index, item, itemDescriptor);

            AddItem(node, newNode);

            stackItems.Push(newNode);
            base.VisitArrayItem(array, descriptor, index, item, itemDescriptor);
            stackItems.Pop();
        }
Пример #10
0
        public void TestArrayDescriptor()
        {
            var attributeRegistry = new AttributeRegistry();
            var factory           = new TypeDescriptorFactory(attributeRegistry);
            var descriptor        = new ArrayDescriptor(factory, typeof(int[]), false, new DefaultNamingConvention());

            descriptor.Initialize(new DefaultKeyComparer());

            Assert.Equal(0, descriptor.Count);
            Assert.Equal(typeof(int), descriptor.ElementType);
        }
Пример #11
0
 public override void VisitArray(Array array, ArrayDescriptor descriptor)
 {
     if (ShouldGenerateItemIdCollection(array))
     {
         var itemIds = CollectionItemIdHelper.GetCollectionItemIds(array);
         for (var i = 0; i < array.Length; ++i)
         {
             itemIds.Add(i, ItemId.New());
         }
     }
     base.VisitArray(array, descriptor);
 }
        public override void VisitArray(Array array, ArrayDescriptor descriptor)
        {
            CollectionItemIdentifiers itemIds;

            if (inNonIdentifiableType == 0 && !CollectionItemIdHelper.TryGetCollectionItemIds(array, out itemIds))
            {
                itemIds = CollectionItemIdHelper.GetCollectionItemIds(array);
                for (var i = 0; i < array.Length; ++i)
                {
                    itemIds.Add(i, ItemId.New());
                }
            }
            base.VisitArray(array, descriptor);
        }
Пример #13
0
            public override void VisitArrayItem(Array array, ArrayDescriptor descriptor, int index, object item, ITypeDescriptor itemDescriptor)
            {
                base.VisitArrayItem(array, descriptor, index, item, itemDescriptor);
                var assetReference = item as AssetReference;

                if (assetReference != null)
                {
                    AddLink(item,
                            (guid, location) =>
                    {
                        var newValue = AssetReference.New(descriptor.ElementType, guid.HasValue ? guid.Value : assetReference.Id, location);
                        array.SetValue(newValue, index);
                        return(newValue);
                    });
                }
                else
                {
                    var assetBase = item as AssetBase;
                    if (assetBase != null)
                    {
                        AddLink(item,
                                (guid, location) =>
                        {
                            var newValue = new AssetBase(location, assetBase.Asset);
                            array.SetValue(newValue, index);
                            return(newValue);
                        });
                    }
                    else if (item is UFile)
                    {
                        AddLink(item,
                                (guid, location) =>
                        {
                            var newValue = new UFile(location);
                            array.SetValue(newValue, index);
                            return(newValue);
                        });
                    }
                    else if (item is UDirectory)
                    {
                        AddLink(item,
                                (guid, location) =>
                        {
                            var newValue = new UFile(location);
                            array.SetValue(newValue, index);
                            return(newValue);
                        });
                    }
                }
            }
Пример #14
0
        private int TouchAndWriteTypeIdWithFullStamp(Type type)
        {
            var typeDescriptor = (TypeFullDescriptor)type;
            // stamping `Type` is different than `Module`, `Assembly`, etc. so we need a special method for that
            ArrayDescriptor arrayDescriptor = null;

            if (Helpers.ContainsGenericArguments(typeDescriptor.UnderlyingType))
            {
                if (typeDescriptor.UnderlyingType.IsArray)
                {
                    arrayDescriptor = new ArrayDescriptor(typeDescriptor.UnderlyingType);
                    typeDescriptor  = (TypeFullDescriptor)arrayDescriptor.ElementType;
                }
                else
                {
                    arrayDescriptor = ArrayDescriptor.EmptyRanks;
                }
            }

            if (typeDescriptor.UnderlyingType.IsGenericType)
            {
                var genericTypeDefinition           = typeDescriptor.UnderlyingType.GetGenericTypeDefinition();
                var genericTypeDefinitionDescriptor = (TypeFullDescriptor)genericTypeDefinition;

                TouchAndWriteTypeIdWithFullStampInner(genericTypeDefinitionDescriptor);

                var isOpen = Helpers.IsOpenGenericType(typeDescriptor.UnderlyingType);
                writer.Write(isOpen);
                if (!isOpen)
                {
                    foreach (var genericArgumentType in typeDescriptor.UnderlyingType.GetGenericArguments())
                    {
                        TouchAndWriteTypeIdWithFullStamp(genericArgumentType);
                    }
                }
            }
            else
            {
                TouchAndWriteTypeIdWithFullStampInner(typeDescriptor);
            }

            if (arrayDescriptor != null)
            {
                writer.WriteArray(arrayDescriptor.Ranks);
            }

            return(0);
        }
Пример #15
0
            public override void VisitArrayItem(Array array, ArrayDescriptor descriptor, int index, object item, ITypeDescriptor itemDescriptor)
            {
                base.VisitArrayItem(array, descriptor, index, item, itemDescriptor);
                var assetReference    = item as AssetReference;
                var attachedReference = AttachedReferenceManager.GetAttachedReference(item);

                if (assetReference != null)
                {
                    AddLink(item,
                            (guid, location) =>
                    {
                        var newValue = AssetReference.New(guid ?? assetReference.Id, location);
                        array.SetValue(newValue, index);
                        return(newValue);
                    });
                }
                else if (attachedReference != null)
                {
                    AddLink(attachedReference,
                            (guid, location) =>
                    {
                        object newValue = guid.HasValue && guid.Value != AssetId.Empty ? AttachedReferenceManager.CreateProxyObject(descriptor.ElementType, guid.Value, location) : null;
                        array.SetValue(newValue, index);
                        return(newValue);
                    });
                }
                else if (item is UFile)
                {
                    AddLink(item,
                            (guid, location) =>
                    {
                        var newValue = new UFile(location);
                        array.SetValue(newValue, index);
                        return(newValue);
                    });
                }
                else if (item is UDirectory)
                {
                    AddLink(item,
                            (guid, location) =>
                    {
                        var newValue = new UFile(location);
                        array.SetValue(newValue, index);
                        return(newValue);
                    });
                }
            }
Пример #16
0
 public override void VisitArray(Array array, ArrayDescriptor descriptor)
 {
     Fixup(array);
     base.VisitArray(array, descriptor);
 }