Example #1
0
        public IndentTheme()
        {
            ContentType       = null;
            LineFormats       = new Dictionary <int, LineFormat>();
            PageWidthMarkers  = new PageWidthMarkerGetter(this);
            DefaultLineFormat = new LineFormat(this);
            Behavior          = new LineBehavior();
            CaretHandler      = DefaultCaretHandler;

            // Ensure format for indent 0 is hidden by default
            LineFormat format = new LineFormat(this);

            format.FormatIndex = 0;
            format.Reset();
            LineFormats[0] = format;
        }
Example #2
0
        public static LineFormat FromInvariantStrings(IndentTheme theme, Dictionary <string, string> values)
        {
            Type   subclass = typeof(LineFormat);
            string subclassName;

            if (values.TryGetValue("TypeName", out subclassName))
            {
                subclass = Type.GetType(subclassName, false) ?? typeof(LineFormat);
            }

            LineFormat inst = subclass.InvokeMember(null, BindingFlags.CreateInstance, null, null,
                                                    new[] { theme }) as LineFormat;

            if (inst == null)
            {
                throw new InvalidOperationException("Unable to create instance of " + subclass.FullName);
            }

            foreach (KeyValuePair <string, string> kv in values)
            {
                if (kv.Key == "TypeName")
                {
                    continue;
                }

                PropertyInfo prop = subclass.GetProperty(kv.Key);
                if (prop != null)
                {
                    try
                    {
                        prop.SetValue(inst,
                                      TypeDescriptor.GetConverter(prop.PropertyType).ConvertFromInvariantString(kv.Value));
                    }
                    catch (Exception ex)
                    {
                        Trace.TraceError("Error setting {0} to {1}:\n", kv.Key, kv.Value, ex);
                    }
                }
                else
                {
                    Trace.TraceWarning("Unable to find property {0} on type {1}", kv.Key, subclass.FullName);
                }
            }

            return(inst);
        }