Example #1
0
        private object CreateRef(bool isProto, Type resType, string refToResource, string rootRef)
        {
            //stupid normalization, but honestly I don't know how to do it here, because we're not just working with filesystem but with our dictionary
            //TODO: change to proper normalization
            //bug: only supports ./something/something, not ./../../and/so/on

            var path = rootRef.Substring(0, rootRef.LastIndexOf('/'));

            refToResource = path + refToResource.Substring(1);

            OnDefReferenceFound?.Invoke(refToResource);

            var         type   = typeof(DefRef <>).MakeGenericType(resType);
            Func <IDef> lambda = () => deserializer.LoadResource(refToResource, resType, isProto);
            // ReSharper disable once PossibleNullReferenceException
            var retVal = type.GetConstructor(new[] { typeof(Func <IDef>) }).Invoke(new object[] { lambda });

            if (!_onDemand)
            {
                var methodName = nameof(DefRef <BaseDef> .Load);
                var loadMethod = type.GetMethod(methodName, BindingFlags.NonPublic | BindingFlags.Instance);
                // ReSharper disable once PossibleNullReferenceException
                loadMethod.Invoke(retVal, Array.Empty <object>());
            }
            return(retVal);
        }
Example #2
0
        private object CreateRef(bool isProto, Type resType, string refToResource)
        {
            var         type   = typeof(DefRef <>).MakeGenericType(resType);
            Func <IDef> lambda = () => deserializer.LoadResource(refToResource, resType, isProto);

            OnDefReferenceFound?.Invoke(refToResource);

            // ReSharper disable once PossibleNullReferenceException
            var retVal = type.GetConstructor(new[] { typeof(Func <IDef>) }).Invoke(new object[] { lambda });

            if (!_onDemand)
            {
                var methodName = nameof(DefRef <BaseDef> .Load);
                var loadMethod = type.GetMethod(methodName, BindingFlags.NonPublic | BindingFlags.Instance);
                // ReSharper disable once PossibleNullReferenceException
                loadMethod.Invoke(retVal, Array.Empty <object>());
            }
            return(retVal);
        }