Beispiel #1
0
        public void Construct_GridLength_two_parameter_ctors_one_isenum()
        {
            var tf = new TypeFinder();

            var ctor = new UIConstructor
            {
                TypeName   = typeof(GridLength).AssemblyQualifiedName,
                Parameters = new[]
                {
                    new UIParameter
                    {
                        TypeName      = "System.Double",
                        ParameterName = "value",
                        Position      = 0,
                        Value         = 7
                    },
                    new UIParameter
                    {
                        TypeName      = typeof(GridUnitType).FullName,
                        ParameterName = "type",
                        Position      = 1,
                        Value         = GridUnitType.Star
                    }
                }
            };

            var obj    = UIConstructorMethods.Construct(tf, ctor);
            var casted = (GridLength)obj;

            Assert.AreEqual(7, casted.Value);
            Assert.AreEqual(GridUnitType.Star, casted.GridUnitType);
        }
Beispiel #2
0
        public void Construct_GridLength_single_numeric_parameter_ctor()
        {
            var tf = new TypeFinder();

            var ctor = new UIConstructor
            {
                TypeName   = typeof(GridLength).AssemblyQualifiedName,
                Parameters = new[]
                {
                    new UIParameter
                    {
                        TypeName      = "System.Double",
                        ParameterName = "value",
                        Position      = 0,
                        Value         = 5
                    }
                }
            };

            var obj    = UIConstructorMethods.Construct(tf, ctor);
            var casted = (GridLength)obj;

            Assert.AreEqual(5, casted.Value);
            Assert.AreEqual(GridUnitType.Absolute, casted.GridUnitType);
        }
Beispiel #3
0
        public void Empty_params_should_return_default_ctor()
        {
            var ctor = new UIConstructor
            {
                TypeName = typeof(Rectangle).FullName
            };

            Assert.AreEqual("Rectangle()", ctor.DisplayName);
        }
Beispiel #4
0
        public static object Construct(ITypeFinder finder, UIConstructor ctor)
        {
            var cType = finder.Find(ctor.TypeName);

            if (cType == null)
            {
                return(null);
            }
            object[] ps = null;

            if (ctor.Parameters.Any())
            {
                ps = ctor
                     .Parameters
                     .OrderBy(c => c.Position)
                     .Select(p =>
                {
                    if (p == null)
                    {
                        return(null);
                    }

                    var pType = finder.Find(p.TypeName);
                    if (pType == null)
                    {
                        return(null);
                    }
                    object val;

                    try
                    {
                        if (pType.GetTypeInfo().IsEnum)
                        {
                            val = ReflectionMethods.CreateEnum(pType, p.Value);
                        }
                        else
                        {
                            val = Convert.ChangeType(p.Value, pType);
                        }
                    }
                    catch (Exception)
                    {
                        val = p.Value;
                    }

                    return(val);
                }).ToArray();
            }

            return(Activator.CreateInstance(cType, ps));
        }
Beispiel #5
0
        public static UIConstructor[] GetConstructors(Type type)
        {
            if (type == null)
            {
                return new UIConstructor[] {}
            }
            ;

            var xctors = new List <UIConstructor>();
            var tctors = type.GetConstructors();

            foreach (var tctor in tctors)
            {
                if (tctor.IsAbstract)
                {
                    continue;
                }

                var xctor = new UIConstructor();

                var xparams = new List <UIParameter>();

                xctor.TypeName = type.AssemblyQualifiedName;

                foreach (var pi in tctor.GetParameters())
                {
                    var xparam = new UIParameter
                    {
                        ParameterName = pi.Name,
                        Position      = pi.Position,
                        TypeName      = pi.ParameterType.FullName,
                        IsTypeEnum    = pi.ParameterType.GetTypeInfo().IsEnum
                    };

                    xparams.Add(xparam);
                }

                xctor.Parameters = xparams.ToArray();
                xctors.Add(xctor);
            }

            return(xctors.ToArray());
        }
    }
Beispiel #6
0
    void Awake()
    {
        System.Globalization.CultureInfo.CurrentCulture = System.Globalization.CultureInfo.GetCultures(System.Globalization.CultureTypes.NeutralCultures)[0];

        appPath = Application.streamingAssetsPath;

        dialogueLine = new List <int>(1)
        {
            0
        };

        parser        = new TextParser(this);
        choiceManager = new ChoiceManager();
        charManager   = new CharacterManager(startingCast);

        themeConstructor = new ThemeConstructor(this);

        uiConstructor = new UIConstructor();
        uiManager     = new UIManager(this, uiConstructor.ConstructText(Color.black), uiConstructor.ConstructGroup(1, false, Color.gray), uiConstructor.ConstructCanvas(), uiConstructor.ConstructButton(Color.black, Color.black), uiConstructor.ConstructGroup(0, false, Color.gray), uiConstructor.ConstructLayoutGroup());

        varManager      = new VariableManager();
        functionManager = new FunctionManager(this);

        //Base starting values
        if (startWithExposition)
        {
            varManager.SetVar(new string[] { "charVisible=0" });
        }
        else
        {
            varManager.SetVar(new string[] { "charVisible=1" });
        }
        varManager.SetVar(new string[] { "typeRate=" + startingTextSpeed });
        varManager.SetVar(new string[] { "buildV=" + version });
        varManager.SetVar(new string[] { "pitch=1" });

        thes      = new Thesaurus("Default");
        uiManager = themeConstructor.ConstructTheme("Default");
    }
Beispiel #7
0
        public void No_typename_should_return_null_displayname()
        {
            var ctor = new UIConstructor();

            Assert.IsNull(ctor.DisplayName);
        }