Esempio n. 1
0
        /// <summary>
        /// Loads assemblt
        /// </summary>
        /// <param name="editor">Assembly editor</param>
        public static void LoadAssembly(this ISeparatedAssemblyEditedObject editor)
        {
            ISeparatedPropertyEditor ed = editor.Editor;

            if (ed != null)
            {
                return;
            }
            Type type           = editor.GetType();
            Func <Type, bool> f = (Type t) =>
            {
                bool b = false;
                if (t.GetInterface(typeof(ISeparatedPropertyEditor).FullName) == null)
                {
                    return(false);
                }
                b = type.CompareLinkedType(t);
                if (b)
                {
                    ConstructorInfo          ci = t.GetConstructor(new Type[0]);
                    ISeparatedPropertyEditor pe = ci.Invoke(new object[0]) as ISeparatedPropertyEditor;
                    editor.Editor = pe;
                }
                return(b);
            };

            f.GetFirstAssemblyBytes(AppDomain.CurrentDomain.BaseDirectory);
        }
Esempio n. 2
0
        private void buttonAccept_Click(object sender, EventArgs e)
        {
            obj.Name = comboBoxName.SelectedItem + "";
            ISeparatedAssemblyEditedObject s = obj.GetObject <ISeparatedAssemblyEditedObject>();

            if (s != null)
            {
                s.FirstLoad();
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Gets editor
 /// </summary>
 /// <param name="editor">Edited object</param>
 /// <returns>Editor</returns>
 public static object GetEditor(this ISeparatedAssemblyEditedObject editor)
 {
     try
     {
         ISeparatedPropertyEditor ed = editor.Editor;
         Type type = editor.GetType();
         if (ed == null)
         {
             byte[] b = editor.AssemblyBytes;
             if (b != null)
             {
                 Assembly ass   = Assembly.Load(b);
                 Type[]   types = ass.GetTypes();
                 foreach (Type t in types)
                 {
                     if (t.GetInterface(typeof(ISeparatedPropertyEditor).FullName) != null)
                     {
                         if (type.CompareLinkedType(t))
                         {
                             ConstructorInfo          ci = t.GetConstructor(new Type[0]);
                             ISeparatedPropertyEditor se = ci.Invoke(new object[0]) as ISeparatedPropertyEditor;
                             ed = se;
                             break;
                         }
                     }
                 }
             }
         }
         if (ed == null)
         {
             Func <Type, bool> f = (Type t) =>
             {
                 if (t.GetInterface(typeof(ISeparatedPropertyEditor).FullName)
                     == null)
                 {
                     return(false);
                 }
                 if (t.CompareLinkedType(type))
                 {
                     ConstructorInfo          ci = t.GetConstructor(new Type[0]);
                     ISeparatedPropertyEditor pe = ci.Invoke(new object[0]) as ISeparatedPropertyEditor;
                     ed = pe;
                     return(true);
                 }
                 return(false);
             };
             f.GetFirstAssemblyBytes(AppDomain.CurrentDomain.BaseDirectory);
         }
         editor.Editor = ed;
         if (ed == null)
         {
             return(false);
         }
         return(ed.GetEditor(editor));
     }
     catch (Exception ex)
     {
         ex.ShowError(10);
     }
     return(null);
 }
Esempio n. 4
0
 /// <summary>
 /// Creates object the corresponds to button
 /// </summary>
 /// <param name="button">The button</param>
 /// <returns>Created object</returns>
 public virtual ICategoryObject CreateObject(IPaletteButton button)
 {
     foreach (IUIFactory f in factories)
     {
         ICategoryObject o = f.CreateObject(button);
         if (o != null)
         {
             return(o);
         }
     }
     if (defaultValue)
     {
         Type   t    = button.ReflectionType;
         string kind = button.Kind;
         if (t != null)
         {
             if (kind.Length > 0) // Kind or additional parameter
             {
                 // Searches constructor from string
                 ConstructorInfo ci = t.GetConstructor(new System.Type[] { typeof(string) });
                 if (ci != null)
                 {
                     // Creates an object
                     ICategoryObject ob = ci.Invoke(new object[] { kind }) as ICategoryObject;
                     if (ob is ISeparatedAssemblyEditedObject)
                     {
                         ISeparatedAssemblyEditedObject sa = ob as ISeparatedAssemblyEditedObject;
                         if (sa.AssemblyBytes == null)
                         {
                             sa.FirstLoad();
                         }
                     }
                     return(ob); // returns the object
                 }
             }
             if (t.Equals(typeof(ObjectsCollection)))
             {
                 string s  = button.Kind;
                 Type   to = Type.GetType(s, true, false);
                 return(new ObjectsCollection(to));
             }
             if (t.GetInterface(typeof(IObjectFactory).ToString()) != null)
             {
                 IObjectFactory of = null;
                 FieldInfo      fi = t.GetField("Object");
                 if (fi != null)
                 {
                     of = fi.GetValue("Object") as IObjectFactory;
                 }
                 else
                 {
                     of = t.GetConstructor(new Type[] { }).Invoke(new object[] { }) as IObjectFactory;
                 }
                 return(of[kind]);
             }
             ConstructorInfo cons = t.GetConstructor(new System.Type[0]);
             if (cons != null)
             {
                 ICategoryObject ob = cons.Invoke(null) as ICategoryObject;
                 if (ob is ISeparatedAssemblyEditedObject)
                 {
                     ISeparatedAssemblyEditedObject sa = ob as ISeparatedAssemblyEditedObject;
                     if (sa.AssemblyBytes == null)
                     {
                         sa.FirstLoad();
                     }
                 }
                 return(ob);
             }
         }
     }
     return(null);
 }