public virtual object GetObject(TokenDataCollection collection, string name, Type t) { if (t == typeof(bool)) { return(collection.GetBoolean(name)); } if (t == typeof(string)) { return(collection.GetString(name)); } if (t == typeof(int)) { return(collection.GetString(name) == "True" ? 1 : 0); } throw new TokenCastException($"Unable to cast type {t.Namespace}.{t.Name} for TokenBooleanAttribute on property/field {name}. Acceptable types are bool, string, int."); }
public virtual object GetObject(TokenDataCollection collection, string name, Type t) { string id = collection.GetString(name); if (t == typeof(string)) { return(id); } if (t == typeof(Item)) { if (id == null) { return(null); } return ((Sitecore.Context.ContentDatabase ?? Sitecore.Context.Database ?? Factory.GetDatabase("master")).GetItem(id)); } if (t == typeof(ID)) { if (string.IsNullOrWhiteSpace(id)) { return(ID.Null); } return(new ID(id)); } throw new TokenCastException($"Unable to cast type {t.Namespace}.{t.Name} for TokenIdAttribute on property/field {name}. Acceptable types are ID, Item or string."); }
public virtual object GetObject(TokenDataCollection collection, string name, Type t) { if (t == typeof(string)) { return(collection.GetString(name)); } throw new TokenCastException($"Unable to cast type {t.Namespace}.{t.Name} for TokenStringAttribute on property/field {name}. Acceptable types are ID, Item or string."); }
public virtual object GetObject(TokenDataCollection collection, string name, Type t) { if (t == typeof(string)) { return(collection.GetString(name)); } if (t == typeof(Item)) { return((Sitecore.Context.ContentDatabase ?? Sitecore.Context.Database ?? Factory.GetDatabase("master")).GetItem(collection.GetId(name) ?? ID.Null)); } if (t == typeof(ID)) { return(collection.GetId(name)); } throw new TokenCastException($"Unable to cast type {t.Namespace}.{t.Name} for TokenDroplistAttribute on property/field {name}. Acceptable type is string."); }