Inheritance: System.ComponentModel.TypeConverter
        private void UpdateIncludedAndExcluded(EventResponseSave instance)
        {
            ////////////////////Early Out/////////////////////////
            if (instance == null)
            {
                return;
            }
            ///////////////////End Early Out///////////////////////
            ResetToDefault();

            ExcludeMember("ToStringDelegate");
            ExcludeMember("Contents");

            AvailableCustomVariables typeConverter = new AvailableCustomVariables(CurrentElement);
            typeConverter.IncludeNone = false;

            typeConverter.InclusionPredicate = DoesCustomVariableCreateEvent;
            IncludeMember(typeof(EventResponseSave).GetProperty("SourceVariable").Name,
                typeof(EventResponseSave), typeConverter);


            if (string.IsNullOrEmpty(instance.SourceVariable))
            {
                ExcludeMember( typeof(EventResponseSave).GetProperty("BeforeOrAfter").Name);
            }



            AvailableNamedObjectsAndFiles availableNamedObjects = new AvailableNamedObjectsAndFiles(
                CurrentElement);
            availableNamedObjects.IncludeReferencedFiles = false;
            IncludeMember(typeof(EventResponseSave).GetProperty("SourceObject").Name,
                typeof(EventResponseSave),
                availableNamedObjects);

            AvailableEvents availableEvents = new AvailableEvents();
            availableEvents.Element = CurrentElement;
            availableEvents.NamedObjectSave = CurrentElement.GetNamedObjectRecursively(instance.SourceObject);
            IncludeMember(typeof(EventResponseSave).GetProperty("SourceObjectEvent").Name,
                typeof(EventResponseSave),
                availableEvents);

        }
Esempio n. 2
0
        private TypeConverter HandleGetTypeConverter(IElement container, NamedObjectSave instance, TypedMemberBase typedMember)
        {
            Type memberType = typedMember.MemberType;
            string memberName = typedMember.MemberName;

            TypeConverter typeConverter = null;

            // If the NOS references a FRB type, we need to adjust the type appropriately

            bool wasTypeModified = false;
            Type oldType = memberType;

            bool handled = false;






            if (instance.SourceType == SourceType.FlatRedBallType)
            {
                Type type = TypeManager.GetTypeFromString(instance.SourceClassType);

                if (type == typeof(Sprite) && memberName == "CurrentChainName")
                {
                    // special case handling for CurrentChainName
                    typeConverter = new AvailableAnimationChainsStringConverter(container, instance);

                    handled = true;
                }

                // Victor Chelaru
                // October 26, 2015:
                // I don't think we need this anymore - we should just let the CSVs do their job
                // defining variables and not rely on reflection. That way plugins will be able to
                // handle everything without relying on reflection
                //if (!handled && type != null)
                //{
                //    FieldInfo fieldInfo = type.GetField(memberName);
                //    if (fieldInfo != null)
                //    {
                //        memberType = fieldInfo.FieldType;
                //        wasTypeModified = true;
                //    }

                //    if (wasTypeModified == false)
                //    {
                //        PropertyInfo propertyInfo = type.GetProperty(memberName);
                //        if (propertyInfo != null)
                //        {
                //            memberType = propertyInfo.PropertyType;
                //            wasTypeModified = true;
                //        }

                //    }
                //}
            }
            else if (instance.SourceType == SourceType.File)
            {
                if (instance.ClassType == "Sprite" && memberName == "CurrentChainName")
                {
                    // special case handling for CurrentChainName
                    typeConverter = new AvailableAnimationChainsStringConverter(container, instance);

                    handled = true;
                }

            }

            if (!handled)
            {
                if (instance.DoesMemberNeedToBeSetByContainer(memberName))
                {
                    typeConverter = new AvailableNamedObjectsAndFiles(container);
                }
                else if (memberType.IsEnum)
                {
                    typeConverter = new EnumConverter(memberType);
                }
                else if (memberType == typeof(Microsoft.Xna.Framework.Color))
                {
                    typeConverter = new AvailableColorTypeConverter();
                    memberType = typeof(string);
                }
                else if (IsTypeFile(typedMember))
                {
                    AvailableFileStringConverter availableFileStringConverter = new AvailableFileStringConverter(container);
                    availableFileStringConverter.QualifiedRuntimeTypeName = memberType.FullName;
                    if(!string.IsNullOrEmpty( typedMember.CustomTypeName ))
                    {
                        availableFileStringConverter.QualifiedRuntimeTypeName = typedMember.CustomTypeName;
                    }
                    availableFileStringConverter.RemovePathAndExtension = true;
                    typeConverter = availableFileStringConverter;

                    memberType = typeof(string);
                }
                else if (instance.SourceType == SourceType.Entity && !string.IsNullOrEmpty(instance.SourceClassType))
                {

                    EntitySave entity = ObjectFinder.Self.GetEntitySave(instance.SourceClassType);

                    if (entity != null)
                    {
                        CustomVariable customVariable = entity.GetCustomVariable(memberName);

                        if (customVariable != null)
                        {
                            typeConverter = customVariable.GetTypeConverter(entity);
                        }
                    }
                }
            }
            //else if (this.SourceType == SaveClasses.SourceType.FlatRedBallType &&
            //    typedMember != null && typedMember.MemberType != null)
            //{

            //}

            if (wasTypeModified)
            {
                memberType = oldType;
            }

            return typeConverter;

        }