本文整理汇总了C#中Cache.GetObject方法的典型用法代码示例。如果您正苦于以下问题:C# Cache.GetObject方法的具体用法?C# Cache.GetObject怎么用?C# Cache.GetObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cache
的用法示例。
在下文中一共展示了Cache.GetObject方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FetchValue
internal override object FetchValue(Element element, object target, TypeCache typeCache, Cache cache)
{
// Get the primary element
Element child;
if (!GetNodeFromQuery(Query, null, element, out child))
{
child = element.Children.OfType<Element>().Where(e => e.Name.Equals(Name)).FirstOrDefault();
}
if (child == null)
{
return null;
}
// Get all the item nodes
IList<object> items = new List<object>(!String.IsNullOrEmpty(ItemQuery) ? child.Eval(ItemQuery)
: child.Children.OfType<Element>().Where(e => e.Name.Equals(ItemName)).Cast<object>());
// Create the collection (or reuse it if appropriate)
object collection = _getCollection(target, items.Count);
// Populate with values
int c = 0;
foreach(object item in items)
{
if(ItemsArePersistentObjects)
{
// Get, attach, and fetch the persistent object instance
Element itemElement = item as Element;
if (itemElement == null) throw new Exception("Persistent value node must be an element.");
object itemObject = cache.GetObject(_itemTypeCache, itemElement, AttachItems);
if(itemObject != null) _setCollectionItem(collection, c++, itemObject);
}
else
{
Node.Node itemNode = item as Node.Node;
object itemObject = GetObjectFromString(
itemNode != null ? itemNode.Value : item.ToString(), null, null, _itemTypeCache.Type, _itemTypeConverter);
if (itemObject != null) _setCollectionItem(collection, c++, itemObject);
}
}
return collection;
}
示例2: FetchValue
private object FetchValue(Element item, string attributeName, string elementName, string query,
bool arePersistentObjects, bool attach, TypeCache typeCache, TypeConverter typeConverter, Cache cache)
{
object value = null;
if (!String.IsNullOrEmpty(attributeName))
{
Node.Attribute attribute = item.Attribute(attributeName);
value = attribute == null ? null : GetObjectFromString(attribute.Value, null, null, typeCache.Type, typeConverter);
}
else
{
object result = !String.IsNullOrEmpty(query) ? item.EvalSingle(query)
: item.Children.OfType<Element>().FirstOrDefault(e => e.Name.Equals(elementName));
if (arePersistentObjects)
{
// Get, attach, and fetch the persistent object instance
Element element = result as Element;
if (element == null) throw new Exception("Persistent value node must be an element.");
value = cache.GetObject(typeCache, element, attach);
}
else
{
Node.Node itemNode = result as Node.Node;
value = GetObjectFromString(itemNode != null ? itemNode.Value
: result == null ? null : result.ToString(), null, null, typeCache.Type, typeConverter);
}
}
return value;
}