This question is locked. New answers and comments are not allowed.
Im trying to get the field length from an entity field with a user control that will be bound inside a FormView.
Thus far i have the following, however im having trouble reflecting
Thus far i have the following, however im having trouble reflecting
OpenAccessEnhancedStateManager
Any ideas or better approach..( maybe grab from config??)
private static volatile IDictionary<Type, IDictionary<string, int>> oaMaxLenCache = new Dictionary<Type, IDictionary<string, int>>(); |
public static int GetOpenAccessMaxLength(Control cf,string fieldName) |
{ |
int maxLen = -1; |
IDataItemContainer nc = cf.NamingContainer as IDataItemContainer; |
if (nc != null) |
{ |
object di = nc.DataItem; |
if (di != null) |
{ |
Type t = di.GetType(); |
if (!oaMaxLenCache.ContainsKey(t)) { oaMaxLenCache.Add(t, new Dictionary<string, int>()); }//Add dict for type |
if (oaMaxLenCache[t].ContainsKey(fieldName)) |
{ |
//Load from cache |
maxLen = oaMaxLenCache[t][fieldName]; |
} |
else |
{ |
PropertyInfo fi = t.GetProperty("OpenAccessEnhancedStateManager",BindingFlags.Public); //Doesnt get the property...?? not sure why |
if (fi != null) |
{ |
OpenAccessRuntime.DataObjects.PCStateMan sm = (OpenAccessRuntime.DataObjects.PCStateMan)fi.GetValue(di,null); |
if (sm != null) |
{ |
OpenAccessRuntime.metadata.FieldMetaData stateField = sm.owner.stateFields.Where(m => m.name == fieldName).SingleOrDefault(); |
if (stateField != null) |
{ |
OpenAccessRuntime.Relational.metadata.RelationalField fld = stateField.storeField as OpenAccessRuntime.Relational.metadata.RelationalField; |
if (fld != null) |
{ |
maxLen = fld.mainTableCols[0].length; |
oaMaxLenCache[t].Add(fieldName, maxLen);//Store in cache |
} |
} |
} |
} |
} |
} |
} |
return maxLen; |
} |