コード例 #1
0
        public static void Test_ActionTypeMapper_Maps_To_Expected_UnityEvent_Type(Type t, Type expectedType)
        {
            //arrange
            ActionTypeRelationalMapper mapper = new ActionTypeRelationalMapper();

            //act
            Type resultType = mapper.ResolveMappedType(t);

            Assert.NotNull(resultType, "Failed to get non null type mapped for {0}", t);
            Assert.AreEqual(expectedType, resultType, "Failed to map {0} to {1}. Got {2} instead.", t, expectedType, resultType);
        }
コード例 #2
0
        public static void Test_ActionTypeMapper_Maps_To_Expected_UnityEvent_Type(Type t, Type expectedType)
        {
            //arrange
            ActionTypeRelationalMapper mapper = new ActionTypeRelationalMapper();

            //act
            Type resultType = mapper.ResolveMappedType(t);

            Assert.NotNull(resultType, "Failed to get non null type mapped for {0}", t);
            Assert.AreEqual(expectedType, resultType, "Failed to map {0} to {1}. Got {2} instead.", t, expectedType, resultType);
        }
コード例 #3
0
        public void Process(IClassBuilder builder, Type typeToParse)
        {
            //This is so inefficient. We do this so often, thankfully it's technically cached.
            //Anyway, we need the member types again.

            IEnumerable <MemberInfo> parsedInfos = typeParser.Parse(System.Reflection.MemberTypes.Property | System.Reflection.MemberTypes.Field, typeToParse);

            //Should now be a collection of only Action fields
            IEnumerable <MemberInfo> actionInfoTypes = parsedInfos.Where(x => actionMapper.isActionType(x.Type()));

            foreach (MemberInfo mi in actionInfoTypes)
            {
                //this class can't handle generic events
                if (actionMapper.isGenericActionType(mi.Type()))
                {
                    //get a new class name that is shared across all events of the same sig
                    string newClassName = actionMapper.GetSharedGenericEventTypeName(mi.Type().GetGenericArguments());
                    eventTracker.Register(newClassName, mi.Type().GetGenericArguments());                     //register info about the generic event to be tracked

                    //we can add the field to the class now
                    builder.AddClassField(new UnitySerializedFieldImplementationProvider(mi.Name, newClassName, new Common.Unity3D.WiredToAttribute(mi.MemberType, mi.Name, mi.Type())));
                }
                else
                {
                    //action mapper can resolve Action/TestityEvent types
                    //Non-generic events require no messing with
                    builder.AddClassField(new UnitySerializedFieldImplementationProvider(mi.Name, actionMapper.ResolveMappedType(mi.Type()), new Common.Unity3D.WiredToAttribute(mi.MemberType, mi.Name, mi.Type())));
                }
            }
        }