Ejemplo n.º 1
0
        private void Start()
        {
            //we can add our own type to the StringToType system
            StringToType.SetConverterDelegateForType(
                typeof(ConsoleStaticCommandsTest.SomethingSupported),
                (s) => { return(new ConsoleStaticCommandsTest.SomethingSupported()
                {
                    val = int.Parse(s)
                }); });

            //we temp bind the error log to nothing, so we aren't spammed during adding items we know will
            //  have lots of failures.
            var prevLog = ConsoleBindingHelper.OnErrorLogDelegate;

            ConsoleBindingHelper.OnErrorLogDelegate = delegate { };

            //binding a class intended to have all static items added
            ConsoleBindingHelper.AddAllToConsole(null, null, typeof(ConsoleStaticCommandsTest));

            //binding a specific instance to the console
            ConsoleBindingHelper.AddAllToConsole(instTest, "instTest");

            //binding a class that is a monostate/c# wrapper around a singleton from Unity
            ConsoleBindingHelper.AddAllToConsole(null, null, typeof(Physics));

            Console.Log("Try entering Console.AddStaticTypeByString Physics2D");

            //restore the logger
            ConsoleBindingHelper.OnErrorLogDelegate = prevLog;
        }
Ejemplo n.º 2
0
        private T PopulateObject(Dictionary <PropertyInfo, string> values)
        {
            var obj = (T)Activator.CreateInstance(typeof(T));

            values.Keys.ToList().ForEach(k =>
            {
                var val = values[k];
                if (!string.IsNullOrEmpty(val))
                {
                    var parsedVal = StringToType.ToType(val, k.PropertyType);
                    k.SetValue(obj, parsedVal);
                }
            });
            return(obj);
        }
Ejemplo n.º 3
0
        static bool paramMatches(ActionParameter actionParam, MessageToken messageParam)
        {
            // If a name has been explicitly specified for this param, check it.
            if (messageParam.TokenType == MessageTokenType.Double)
            {
                if (!isMatch(messageParam.ItemOne, actionParam.Name))
                {
                    return(false);
                }
            }

            var messageParamValue = messageParam.TokenType == MessageTokenType.Single
                ? messageParam.ItemOne
                : messageParam.ItemTwo;

            return(StringToType.ConvertsToType(actionParam.Type, messageParamValue));
        }