thank you for messages, Daniil's that post was my starting point in the first place,
let me explain my case
MyTextField.cs
public partial class MyTextField:Ext.Net.TextField
{
public MyTextField():base()
{
this.SetFieldClass();
}
//.....
// override InstanceOf, XType, Resources properties
//.... any other individual functions
}
MyComboBox.cs
public partial class MyComboBox:Ext.Net.ComboBox
{
public MyComboBox():base()
{
this.SetFieldClass();
}
//.....
// override InstanceOf, XType, Resources properties
//.... any other individual functions
}
MyGridPanel.cs
public partial class MyGridPanel:Ext.Net.GridPanel
{
public MyGridPanel():base()
{
}
//.....
// override InstanceOf, XType, Resources properties
//.... any other individual functions
}
FieldExtensions.cs
public static class FieldExtensions
{
public static void SetFieldClass(this Field field)
{
field.FieldCls = "form-control";
if (field is TextFieldBase)
(field as TextFieldBase).TriggerWrapCls = "my-form-trigger-wrap";
field.InvalidCls = "my-form-invalid";
}
}
TextFieldBaseExtensions.cs
public static class TextFieldBaseExtensions
{
public static void AddTrigger(this TextFieldBase owner, FieldTrigger.Config config)
{
owner.Triggers.Add(new FieldTrigger(config));
}
public static void AddTrigger(this TextFieldBase owner, TriggerIcon icon, string handler, string qTip = "", string tag = "")
{
owner.Triggers.Add(
new FieldTrigger(
new FieldTrigger.Config()
{
Icon = icon,
Handler = handler,
QTip = qTip,
Tag = tag
}
)
);
owner.TriggerWrapCls = "";
}
}
StoreExtensions.cs
public static class StoreExtensions
{
public static void BuildStore(this IStore<Store> storeOwner, string url, IEnumerable<StoreParameter> paramList)
{
var store = (storeOwner.Store.Count == 1) ? (storeOwner.Store[0]) : (new Store());
var proxy = new AjaxProxy();
proxy.Reader.Add(new JsonReader() { RootProperty = "data" });
proxy.Url = url;
store.Proxy.Add(proxy);
if (paramList != null)
{
foreach (var item in paramList)
{
store.Parameters.Add(item);
}
}
if (storeOwner.Store.Count == 1)
{
// storeOwner.Store[0] = store;
}
else
{
storeOwner.Store.Add(store);
}
}
public static void BuildStore(this IStore<Store> storeOwner, string url, StoreParameter param)
{
List<StoreParameter> pl = null;
if (param != null)
{
pl = new List<StoreParameter>() { param };
}
BuildStore(storeOwner, url, pl);
}
public static void BuildStore(this IStore<Store> storeOwner, string url)
{
BuildStore(storeOwner, url, (StoreParameter)null);
}
public static void SetStoreID(this IStore<Store> storeOwner, string storeID)
{
if ((storeOwner.Store != null) && (storeOwner.Store.Count == 1))
{
storeOwner.Store[0].ID = storeID;
}
}
public static void AddStoreParam(this IStore<Store> storeOwner, StoreParameter p)
{
if ((storeOwner.Store != null) && (storeOwner.Store.Count == 1))
{
storeOwner.Store[0].Parameters.Add(p);
storeOwner.Store[0].AutoLoad = false;
}
}
public static void SetStoreModel(this IStore<Store> storeOwner, Type modelType)
{
var store = (storeOwner.Store.Count == 1) ? (storeOwner.Store[0]) : (new Store());
var m = new Model();
foreach (var p in modelType.GetProperties())
{
ModelFieldType mft = ModelFieldType.Auto;
if (p.PropertyType == typeof(int))
mft = ModelFieldType.Int;
m.Fields.Add(new ModelField(p.Name, mft));
}
store.Model.Add(m);
if (storeOwner.Store.Count == 1)
{
// storeOwner.Store[0] = store;
}
else
{
storeOwner.Store.Add(store);
}
}
public static void SetStoreModel<TModelType>(this IStore<Store> storeOwner)
{
SetStoreModel(storeOwner, typeof(TModelType));
}
public static void SetStoreModel(this IStore<Store> storeOwner, Model model)
{
var store = (storeOwner.Store.Count == 1) ? (storeOwner.Store[0]) : (new Store());
store.Model.Add(model);
if (storeOwner.Store.Count == 1)
storeOwner.Store[0] = store;
else
storeOwner.Store.Add(store);
}
public static void ItemsFromAction(this IStore<Store> storeOwner, string url, StoreParameter param)
{
storeOwner.BuildStore(url, param);
string id = (storeOwner is BaseControl) ? ((storeOwner as BaseControl).ID) : null;
if (id != null)
storeOwner.GetStore().ID = id + "Store";
}
public static void ItemsFromAction(this IStore<Store> storeOwner, string url)
{
storeOwner.BuildStore(url);
string id = (storeOwner is BaseControl) ? ((storeOwner as BaseControl).ID) : null;
if (id != null)
storeOwner.GetStore().ID = id + "Store";
}
public static void ItemsFromAction(this IStore<Store> storeOwner, string url, IEnumerable<StoreParameter> paramList)
{
storeOwner.BuildStore(url, paramList);
string id = (storeOwner is BaseControl) ? ((storeOwner as BaseControl).ID) : null;
if (id != null)
storeOwner.GetStore().ID = id + "Store";
}
public static void StoreUrl(this IStore<Store> storeOwner, string url)
{
if ((storeOwner.Store != null) && (storeOwner.Store.Count == 1))
{
var proxy = new AjaxProxy();
proxy.Reader.Add(new JsonReader() { RootProperty = "data" });
proxy.Url = url;
storeOwner.Store[0].Proxy.Add(proxy);
}
}
}
i want MyTextBox.Builder and MyComboBox.Builder has methods for implemented in TextFieldBaseExtensions
and also MyGridPanel.Builder and MyComboBox.Builder has methods for implemented in StoreExtensions.
i can add methods for builder classes one by one, but i want to learn can i extend base builder classes (TextFieldBase.Builder, IStore.Builder) and get rid of copy/paste