Ejemplo n.º 1
0
        public override bool hasMatch(ISerializableContainer container)
        {
            if (sortedFieldInfo.Value.ContainsKey(container.SerializedName))
            {
                if (SerializedTypeManipulator.isInterfaceCollectionType(sortedFieldInfo.Value[container.SerializedName].Type()))
                {
                    if (sortedFieldInfo.Value[container.SerializedName].Type().IsGenericType)                     //if true then it's something like IEnumerable<ISomething>
                    {
                        if (container.SerializedType == sortedFieldInfo.Value[container.SerializedName].Type().GetGenericArguments().First())
                        {
                            return(true);
                        }
                    }
                    else
                    {
                        //It could still be an array. Those aren't considered generic
                        if (sortedFieldInfo.Value[container.SerializedName].Type().IsArray)
                        {
                            if (container.SerializedType == sortedFieldInfo.Value[container.SerializedName].Type().GetElementType())
                            {
                                return(true);
                            }
                        }
                    }
                }
            }

            return(false);
        }
Ejemplo n.º 2
0
        private Dictionary <string, FieldInfo> CreateDictionary()
        {
            Dictionary <string, FieldInfo> dict = new Dictionary <string, FieldInfo>();

            //prepare the dictionary
            //It'll help speed things up with O(1) lookup
            foreach (FieldInfo fi in SerializedTypeManipulator.GetCollectionFields(parseTarget))
            {
                dict.Add(fi.Name, fi);
            }

            return(dict);
        }
		private IEnumerable<FieldInfo> GetSerializedInterfaceFields(IEnumerable<FieldInfo> fields)
		{
			IEnumerable<FieldInfo> parsedFields = fields //find the interface fields
				.Where(fi => SerializedTypeManipulator.isInterfaceCollectionType(fi.Type())) //where it's an interface collection type
				.Where(fi => (fi.IsPrivate && fi.GetCustomAttribute<SerializeField>(true) != null) || fi.IsPublic && fi.GetCustomAttribute<HideInInspector>(true) == null);

			IEnumerable<FieldInfo> backingFieldsToProps = parseTarget.Properties(Flags.InstanceAnyVisibility)
				.Where(pi => SerializedTypeManipulator.isInterfaceCollectionType(pi.Type())) //where it's an interface collection type
				.Where(pi => pi.GetCustomAttribute<SerializeField>(true) != null)
				.Select(pi => parseTarget.Field($"<{pi.Name}>k__BackingField")); //add the backing fields for the properties

			return parsedFields.Concat(backingFieldsToProps);
		}
Ejemplo n.º 4
0
        public override IEnumerable <FieldInfo> FindUnContainedFields <TSerializableContainerType>(IEnumerable <TSerializableContainerType> containers)
        {
            //This may not actually be quicker but the idea is to create an O(1) lookup table that'll allow us
            //to find members that we don't know yet
            Dictionary <string, TSerializableContainerType> tempDictionary = new Dictionary <string, TSerializableContainerType>(containers.Count());

            foreach (TSerializableContainerType con in containers)
            {
                tempDictionary.Add(con.SerializedName, con);
            }

            return(sortedFieldInfo.Value.Values
                   .Where(x => !tempDictionary.ContainsKey(x.Name))                             //where we don't already have a mapped name
                   .Where(x => SerializedTypeManipulator.isInterfaceCollectionType(x.Type()))); //where it's an interface collection type
        }
        public override bool hasMatch(ISerializableContainer container)
        {
            if (sortedFieldInfo.Value.ContainsKey(container.SerializedName))
            {
                if (!SerializedTypeManipulator.isInterfaceCollectionType(sortedFieldInfo.Value[container.SerializedName].Type())) //make sure it's NOT
                {
                    if (sortedFieldInfo.Value[container.SerializedName].Type() == container.SerializedType)                       //if true then it's something like IEnumerable<ISomething>
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
        public override bool hasMatch(ISerializableContainer container)
        {
            if (sortedFieldInfo.Value.ContainsKey(container.SerializedName))
            {
                if (!SerializedTypeManipulator.isInterfaceCollectionType(sortedFieldInfo.Value[container.SerializedName].Type()))               //make sure it's NOT something like IEnumerable<ISomething>
                {
                    if (container.SerializedTypeName.Contains(sortedFieldInfo.Value[container.SerializedName].Type().Name))                     //makes sure the Type is still approximately the same
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
        private Dictionary <string, FieldInfo> CreateDictionary()
        {
            Dictionary <string, FieldInfo> dict = new Dictionary <string, FieldInfo>();

            //prepare the dictionary
            //It'll help speed things up with O(1) lookup
            IEnumerable <FieldInfo> fields = parseTarget.Fields(Flags.InstanceAnyVisibility)
                                             .Where(fi => fi.Type().IsInterface)                                            //find the interface fields
                                             .Where(fi => !SerializedTypeManipulator.isInterfaceCollectionType(fi.Type())); //exclude the collection ones

            foreach (FieldInfo fi in fields)
            {
                dict.Add(fi.Name, fi);
            }

            return(dict);
        }
        private IEnumerable <FieldInfo> GetSerializedInterfaceFields(IEnumerable <FieldInfo> fields)
        {
            IEnumerable <FieldInfo> parsedFields = fields.Where(fi => fi.Type().IsInterface)                                     //find the interface fields
                                                   .Where(x => !SerializedTypeManipulator.isInterfaceCollectionType(x.Type()))   //where it's NOT an interface collection type
                                                   .Where(fi => !SerializedTypeManipulator.isInterfaceCollectionType(fi.Type())) //exclude the collection ones
                                                   .Where(fi => ((fi.IsPrivate || fi.IsFamily) && fi.GetCustomAttribute <SerializeField>(true) != null) || fi.IsPublic && fi.GetCustomAttribute <HideInInspector>(true) == null)
                                                   .Where(fi => !fi.Type().IsValueType);                                         //ignore value types.

            IEnumerable <FieldInfo> backingFieldsToProps = parseTarget.Properties(Flags.InstanceAnyVisibility)
                                                           .Where(pi => pi.Type().IsInterface)                                           //find the interface properties
                                                           .Where(pi => !SerializedTypeManipulator.isInterfaceCollectionType(pi.Type())) //exclude the collection ones
                                                           .Where(pi => pi.GetCustomAttribute <SerializeField>(true) != null)
                                                           .Where(pi => !pi.Type().IsValueType)                                          //ignore value types.
                                                           .Select(pi => parseTarget.Field($"<{pi.Name}>k__BackingField"));              //add the backing fields for the properties

            return(parsedFields.Concat(backingFieldsToProps));
        }
Ejemplo n.º 9
0
        private void InitializeSerializedCollectionContainers()
        {
            ContainerParser <CollectionComponentDataStore> collectionContainerParser =
                new ContainerParser <CollectionComponentDataStore>(collectionDataStoreCollection, new CollectionContainerFieldMatcher(this.GetType()));

            ContainerParser <SingleComponentDataStore> singleContainerParser =
                new ContainerParser <SingleComponentDataStore>(singleDataStoreCollection, new SingleContainerFieldMatcher(this.GetType()));

            //Find the removed interfaces and remove them from the collection
            RemoveSerializedContainers(singleContainerParser.ComputeStaleContainers(), singleDataStoreCollection);
            //Find the new members and create serialized containers for them
            singleDataStoreCollection.AddRange(singleContainerParser.FindNewCollectionMembers().Select(x => new SingleComponentDataStore(x.Type(), x.Name)));

            //At this point all non-collection interfaces have containers in the serializable collection
            //We must now do the same for Collection types
            RemoveSerializedContainers(collectionContainerParser.ComputeStaleContainers(), collectionDataStoreCollection);
            collectionDataStoreCollection.AddRange(collectionContainerParser.FindNewCollectionMembers().Select(x => new CollectionComponentDataStore(SerializedTypeManipulator.CollectionInferaceType(x.Type()), x.Type(), x.Name)));
        }