Пример #1
0
        private ControlConverter()
        {
            ConvertersFromTo = new Dictionary <Type, Dictionary <Type, IControlConverter> >();
            ConvertersToFrom = new Dictionary <Type, Dictionary <Type, IControlConverter> >();
            foreach (Type controlType in typeof(IControl).GetTypeInfo().Assembly.GetTypes()) // find all Control classes via the fact they implement IControl
            {
                // This code might work better by scanning implicit or explicit cast implementation
                if (controlType.IsClass && controlType.GetInterfaces().Contains(typeof(IControl)))                       // ensure the target is a class and has the IControl interface
                {
                    foreach (Type controlInterface in controlType.GetInterfaces())                                       // scan the interfaces on the class
                    {
                        if (controlInterface.IsInterface && controlInterface.GetInterfaces().Contains(typeof(IControl))) // if the found interface also implements IControl
                        {
                            Console.WriteLine($"{controlType} can convert to {controlInterface} via interface tree");    // save this as an implicit conversion via saved interface
                            if (!ConvertersFromTo.ContainsKey(controlType))
                            {
                                ConvertersFromTo[controlType] = new Dictionary <Type, IControlConverter>();
                            }
                            if (!ConvertersToFrom.ContainsKey(controlInterface))
                            {
                                ConvertersToFrom[controlInterface] = new Dictionary <Type, IControlConverter>();
                            }

                            Type converterType       = typeof(BasicControlConverter <,>).MakeGenericType(controlType, controlInterface);
                            IControlConverter plugin = (IControlConverter)Activator.CreateInstance(converterType);
                            ConvertersFromTo[controlType][controlInterface] = plugin;
                            ConvertersToFrom[controlInterface][controlType] = plugin;
                        }
                    }
                }
                // scan for adapaters that register to convert an IControl implementer to an interface it's not normally compatiable with
                // the only reason for this is so that plugins in the future can add converters without needing to implement implicit or explicit casts into the control classes
            }
        }
Пример #2
0
 public void AddSizeBinding(IControlConverter container, string suffix)
 {
     string js = container.ControlType.Name + "_" + suffix + "(" + container.ID + ");";
     _resizebuilder.WriteLine(js);
 }
Пример #3
0
 public void AddMouseBinding(IControlConverter target, MouseBinding mb)
 {
     new BindingConverter(CodeBuilder).AddMouseBinding(target.ID, mb);
 }
Пример #4
0
 void IConverterContext.AddKeyBinding(IControlConverter target, KeyBinding kb)
 {
     new BindingConverter(CodeBuilder).AddKeyBinding(target.ID, kb);
 }
Пример #5
0
 void IConverterContext.AddBinding(IControlConverter target, string prop, Binding b)
 {
     new BindingConverter(CodeBuilder).AddBinding(target.ID, prop, b);
 }
Пример #6
0
 /// <summary>
 /// Allocates a unique identifier for a control converter instance.
 /// </summary>
 /// <param name="converter">The object representing the control.</param>
 /// <returns>The newly allocated identifier.</returns>
 string IConverterContext.AllocateIdentifier(IControlConverter converter)
 {
     var prefix = converter.GetType().Name;
     var id = AllocateIdentifier(prefix);
     _controls[id] = converter;
     return id;
 }