public static T GetValueAs <T>(this IEnumerable <TypedItem> items, string key) { T t = default(T); bool b = false; if (items != null) { List <TypedItem> list = items.ToList(); for (int i = 0; !b && i < list.Count; i++) { if (list[i].Key.Equals(key, StringComparison.OrdinalIgnoreCase)) { TypedItem item = list.First(x => x.Key.Equals(key, StringComparison.OrdinalIgnoreCase)); if (item != null) { try { t = (T)item.Value; } catch (Exception ex) { string s = ex.Message; } } b = true; } } } return(t); }
public static object GetValue(this ICriterion criterion, string key) { bool b = false; object o = null; List <TypedItem> items = criterion.Items.ToList(); if (items != null) { for (int i = 0; !b && i < items.Count; i++) { if (items[i].Key.Equals(key, StringComparison.OrdinalIgnoreCase)) { TypedItem item = items.First(x => x.Key.Equals(key, StringComparison.OrdinalIgnoreCase)); if (item != null) { try { o = item.Value; } catch (Exception ex) { string s = ex.Message; } } b = true; } } } return(o); }
public T GetValue <T>(string key) { T t = default(T); bool b = false; if (Items != null) { for (int i = 0; !b && i < Items.Count; i++) { if (Items[i].Key.Equals(key, StringComparison.OrdinalIgnoreCase)) { TypedItem item = Items.First(x => x.Key.Equals(key, StringComparison.OrdinalIgnoreCase)); if (item != null) { try { t = (T)item.Value; } catch { } } b = true; } } } return(t); }
private SqlCommand CreateCommand <T>(IContext context, ModelActionOption option, SqlConnection connection, ICriterion criteria) where T : class, new() { SqlCommand cmd = null; Discovery.SqlStoredProcedure sproc; if (SprocMapCache.Instance.TryGetStoredProcedure <T>(context, criteria, option, connection, out sproc)) { cmd = connection.CreateCommand(); cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = String.Format("[{0}].[{1}]", sproc.Schema, sproc.Name); if (criteria != null && sproc.Parameters != null && sproc.Parameters.Count > 0) { List <PropertyInfo> list = new List <PropertyInfo>(typeof(T).GetProperties()); foreach (var item in sproc.Parameters) { string paramName = item.ParamName.Replace("@", String.Empty); SqlParameter sqlparam = cmd.CreateParameter(); sqlparam.ParameterName = paramName; //sqlparam.DbType = (DbType)Enum.Parse(typeof(DbType), item.Datatype, true); if (paramName.Equals(XFConstants.Application.UserIdentityParamName, StringComparison.OrdinalIgnoreCase)) { string useridentityvalue = context.GetValue <string>(XFConstants.Application.UserIdentityParamName); if (!String.IsNullOrEmpty(useridentityvalue)) { sqlparam.Value = useridentityvalue; } } else { if (criteria.Contains(paramName)) { TypedItem found = criteria.Items.First(x => x.Key.Equals(paramName, StringComparison.OrdinalIgnoreCase)); if (found != null) { if (item.Datatype == "DateTime" && found.Value.GetType().Equals(typeof(DateTime))) { DateTime target = (DateTime)found.Value; if (target >= new DateTime(1753, 1, 1)) { sqlparam.Value = found.Value; } } else { sqlparam.Value = found.Value; } } } } cmd.Parameters.Add(sqlparam); } } } return(cmd); }
public static List <TypedItem> ToTypedItems <T>(this T t) where T : class { List <TypedItem> list = new List <TypedItem>(); string fullName = t.GetType().FullName; foreach (var info in t.GetType().GetProperties()) { if (info.PropertyType.IsPublic && info.CanRead) { if ((info.PropertyType.IsValueType || info.PropertyType == typeof(string))) { TypedItem item = new TypedItem(info.Name, info.GetValue(t)); list.Add(item); } } } return(list); }
private static bool TryGetValueInternal <T>(string key, bool isCustom, out T t) { bool b = false; t = default(T); string internalKey = isCustom ? String.Format(KeyPattern, key.Trim().ToLower()) : key.Trim().ToLower(); var principal = Thread.CurrentPrincipal as eXtensibleClaimsPrincipal; if (principal != null) { if (principal.Items != null) { List <TypedItem> items = principal.Items.ToList(); for (int i = 0; !b && i < items.Count; i++) { if (items[i].Key.Equals(internalKey, StringComparison.OrdinalIgnoreCase)) { TypedItem item = principal.Items.First(x => x.Key.Equals(internalKey, StringComparison.OrdinalIgnoreCase)); if (item != null) { try { t = (T)item.Value; b = true; } catch (Exception ex) { string s = ex.Message; } } } } } } return(b); }
U IContext.GetValue <U>(string key) { U u = default(U); bool b = false; if (Items != null) { for (int i = 0; !b && i < Items.Count; i++) { if (Items[i].Key.Equals(key, StringComparison.OrdinalIgnoreCase)) { TypedItem item = Items.Single(x => x.Key.Equals(key, StringComparison.OrdinalIgnoreCase)); if (item != null) { u = (U)item.Value; } b = true; } } } return(u); }
public bool TryGetValue <T>(string key, out T t) { bool b = false; t = default(T); for (int i = 0; !b && i < _Items.Count; i++) { if (_Items[i].Key.Equals(key, StringComparison.OrdinalIgnoreCase)) { TypedItem item = _Items[i];// _Items.First(x => x.Key.Equals(key, StringComparison.OrdinalIgnoreCase)); try { t = (T)item.Value; b = true; } catch (Exception ex) { string s = ex.Message; } } } return(b); }