コード例 #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);
        }
コード例 #2
0
		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);
		}
コード例 #3
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
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
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
            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);
        }
コード例 #7
0
        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));
        }