예제 #1
0
        static bool InitializeDefaultValue(PocoPropertyInfo p, IActivityMonitor monitor)
        {
            bool success = true;
            var  aDefs   = p.DeclaredProperties.Select(x => (Prop: x, x.GetCustomAttribute <DefaultValueAttribute>()))
                           .Where(a => a.Item2 != null)
                           .Select(a => (a.Prop, a.Item2 !.Value));

            var first = aDefs.FirstOrDefault();

            if (first.Prop != null)
            {
                p.HasDefaultValue = true;
                p.DefaultValue    = first.Value;
                var    w             = new StringCodeWriter();
                string defaultSource = p.DefaultValueSource = w.Append(first.Value).ToString();
                foreach (var other in aDefs.Skip(1))
                {
                    w.StringBuilder.Clear();
                    var o = w.Append(other.Value).ToString();
                    if (defaultSource != o)
                    {
                        monitor.Error($"Default values difference between {first.Prop.DeclaringType}.{first.Prop.Name} = {defaultSource} and {other.Prop.DeclaringType}.{other.Prop.Name} = {o}.");
                        success = false;
                    }
                }
            }
            return(success);
        }
예제 #2
0
        public void And_combiner_works()
        {
            var w1 = new StringCodeWriter(new StringBuilder());
            var w2 = new StringCodeWriter(new StringBuilder());

            w1.And(w2).AppendSourceString("Hello!");

            w1.ToString().Should().Be("@\"Hello!\"");
            w2.ToString().Should().Be("@\"Hello!\"");
        }
예제 #3
0
        public void AppendVariable_use_At_sign_for_reserved_keywords()
        {
            var writer = new StringCodeWriter(new StringBuilder());

            foreach (var n in ReservedKeyword.ReservedKeywords)
            {
                writer.AppendVariable(n).Append("|");
            }
            var c = writer.ToString();

            foreach (var n in ReservedKeyword.ReservedKeywords)
            {
                c.Should().Contain("@" + n + "|");
            }
        }
예제 #4
0
        public void appending_an_unknown_typed_object_is_an_error()
        {
            var w = new StringCodeWriter();

            w.Invoking(x => x.Append(this)).Should().Throw <ArgumentException>();
        }