public void SimpleValues_AreComparedByTypeAndValue()
        {
            SimpleValue value1 = (byte)100;
            SimpleValue value2 = (byte)100;
            SimpleValue value3 = (long)100;

            Assert.True(value1 == value2);
            Assert.False(value1 != value2);
            Assert.True(value1.Equals(value2));
            Assert.True(value1.Equals((object)value2));

            Assert.False(value1 == value3);
            Assert.True(value1 != value3);
            Assert.False(value1.Equals(value3));
            Assert.False(value1.Equals((object)value3));
        }
Beispiel #2
0
        private string GetPresentationInner(ISolution solution, IDeclaredElement declaredElement, bool prefabImport, bool makeTextShorter)
        {
            solution.GetComponent <IShellLocks>().AssertReadAccessAllowed();
            var type = declaredElement.Type();

            if (type == null)
            {
                return("...");
            }
            if (type.IsBool())
            {
                if (SimpleValue.Equals("0"))
                {
                    return("\"false\"");
                }
                return("\"true\"");
            }

            if (type.IsEnumType())
            {
                if (!int.TryParse(SimpleValue, out var result))
                {
                    return("...");
                }
                var @enum          = type.GetTypeElement() as IEnum;
                var enumMemberType = @enum?.EnumMembers.FirstOrDefault()?.ConstantValue.Type;
                if (enumMemberType == null)
                {
                    return("...");
                }
                var enumMembers = CSharpEnumUtil.CalculateEnumMembers(new ConstantValue(result, enumMemberType), @enum);

                return(string.Join(" | ", enumMembers.Select(t => t.ShortName)));
            }

            var textPresentation = SimpleValue;

            if (makeTextShorter && textPresentation != null)
            {
                textPresentation = StringUtil.DropMiddleIfLong(textPresentation, 30);
            }
            return($"\"{textPresentation ?? "..." }\"");
        }