当前位置: 首页>>代码示例>>C#>>正文


C# IContent.Retrieve方法代码示例

本文整理汇总了C#中IContent.Retrieve方法的典型用法代码示例。如果您正苦于以下问题:C# IContent.Retrieve方法的具体用法?C# IContent.Retrieve怎么用?C# IContent.Retrieve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IContent的用法示例。


在下文中一共展示了IContent.Retrieve方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ExecuteSync

        protected override void ExecuteSync(IContent content, Index index, object parameter)
        {
            var value = content.Retrieve(index);
            var collectionDescriptor = (CollectionDescriptor)TypeDescriptorFactory.Default.Find(value.GetType());

            object itemToAdd = null;
            var elementType = collectionDescriptor.ElementType;
            if (CanAddNull(elementType) || IsReferenceType(elementType))
            {
                // If the parameter is a type instead of an instance, try to construct an instance of this type
                var type = parameter as Type;
                if (type?.GetConstructor(Type.EmptyTypes) != null)
                    itemToAdd = ObjectFactoryRegistry.NewInstance(type);
            }
            else if (collectionDescriptor.ElementType == typeof(string))
            {
                itemToAdd = parameter ?? "";
            }
            else
            {
                itemToAdd = parameter ?? ObjectFactoryRegistry.NewInstance(collectionDescriptor.ElementType);
            }
            if (index.IsEmpty)
            {
                content.Add(itemToAdd);
            }
            else
            {
                // Handle collections in collections
                // TODO: this is not working on the observable node side
                var collectionNode = content.Reference.AsEnumerable[index].TargetNode;
                collectionNode.Content.Add(itemToAdd);
            }
        }
开发者ID:Kryptos-FR,项目名称:xenko-reloaded,代码行数:34,代码来源:AddNewItemCommand.cs

示例2: ExecuteSync

 protected override void ExecuteSync(IContent content, Index index, object parameter)
 {
     var value = content.Retrieve(index);
     var collectionDescriptor = (CollectionDescriptor)TypeDescriptorFactory.Default.Find(value.GetType());
     object itemToAdd = null;
     // TODO: Find a better solution for ContentSerializerAttribute that doesn't require to reference Core.Serialization (and unreference this assembly)
     if (collectionDescriptor.ElementType.IsAbstract || collectionDescriptor.ElementType.IsNullable() || collectionDescriptor.ElementType.GetCustomAttributes(typeof(ContentSerializerAttribute), true).Any())
     {
         // If the parameter is a type instead of an instance, try to construct an instance of this type
         var type = parameter as Type;
         if (type?.GetConstructor(Type.EmptyTypes) != null)
             itemToAdd = Activator.CreateInstance(type);
     }
     else if (collectionDescriptor.ElementType == typeof(string))
     {
         itemToAdd = parameter ?? "";
     }
     else
     {
         itemToAdd = parameter ?? ObjectFactory.NewInstance(collectionDescriptor.ElementType);
     }
     if (index.IsEmpty)
     {
         content.Add(itemToAdd);
     }
     else
     {
         // Handle collections in collections
         // TODO: this is not working on the observable node side
         var collectionNode = content.Reference.AsEnumerable[index].TargetNode;
         collectionNode.Content.Add(itemToAdd);
     }
 }
开发者ID:cg123,项目名称:xenko,代码行数:33,代码来源:AddNewItemCommand.cs

示例3: ExecuteSync

        protected override IActionItem ExecuteSync(IContent content, object index, object parameter, IEnumerable<IDirtiable> dirtiables)
        {
            var value = content.Retrieve();
            var collectionDescriptor = (CollectionDescriptor)TypeDescriptorFactory.Default.Find(value.GetType());
            object itemToAdd = null;
            // TODO: Find a better solution for ContentSerializerAttribute that doesn't require to reference Core.Serialization (and unreference this assembly)
            if (collectionDescriptor.ElementType.IsAbstract || collectionDescriptor.ElementType.IsNullable() || collectionDescriptor.ElementType.GetCustomAttributes(typeof(ContentSerializerAttribute), true).Any())
            {
                // If the parameter is a type instead of an instance, try to construct an instance of this type
                var type = parameter as Type;
                if (type?.GetConstructor(Type.EmptyTypes) != null)
                    itemToAdd = Activator.CreateInstance(type);
            }
            else if (collectionDescriptor.ElementType == typeof(string))
            {
                itemToAdd = parameter ?? "";
            }
            else
            {
                itemToAdd = parameter ?? ObjectFactory.NewInstance(collectionDescriptor.ElementType);
            }
            content.Add(itemToAdd);

            return null;
        }
开发者ID:subajat1,项目名称:xenko,代码行数:25,代码来源:AddNewItemCommand.cs

示例4: ExecuteSync

 protected override void ExecuteSync(IContent content, Index index, object parameter)
 {
     var oldName = index;
     var newName = new Index(parameter);
     var renamedObject = content.Retrieve(oldName);
     content.Remove(renamedObject, oldName);
     content.Add(renamedObject, newName);
 }
开发者ID:cg123,项目名称:xenko,代码行数:8,代码来源:RenameStringKeyCommand.cs

示例5: ExecuteSync

 protected override void ExecuteSync(IContent content, Index index, object parameter)
 {
     var oldName = index;
     var renamedObject = content.Retrieve(oldName);
     content.Remove(renamedObject, oldName);
     var newName = AddPrimitiveKeyCommand.GenerateStringKey(content.Value, content.Descriptor, (string)parameter);
     content.Add(renamedObject, newName);
 }
开发者ID:Kryptos-FR,项目名称:xenko-reloaded,代码行数:8,代码来源:RenameStringKeyCommand.cs

示例6: ExecuteSync

 protected override IActionItem ExecuteSync(IContent content, object index, object parameter, IEnumerable<IDirtiable> dirtiables)
 {
     var oldName = (string)index;
     var newName = (string)parameter;
     var removedObject = content.Retrieve(oldName);
     content.Remove(oldName);
     content.Add(newName, removedObject);
     return null;
 }
开发者ID:psowinski,项目名称:xenko,代码行数:9,代码来源:RenameStringKeyCommand.cs

示例7: ExecuteSync

 protected override void ExecuteSync(IContent content, Index index, object parameter)
 {
     var indices = (Tuple<int, int>)parameter;
     var sourceIndex = new Index(indices.Item1);
     var targetIndex = new Index(indices.Item2);
     var value = content.Retrieve(sourceIndex);
     content.Remove(value, sourceIndex);
     content.Add(value, targetIndex);
 }
开发者ID:Kryptos-FR,项目名称:xenko-reloaded,代码行数:9,代码来源:MoveItemCommand.cs

示例8: Execute

 public override Task<IActionItem> Execute(IContent content, object index, object parameter, IEnumerable<IDirtiable> dirtiables)
 {
     var currentValue = content.Retrieve(index);
     var newValue = ChangeValue(currentValue, parameter);
     if (!Equals(newValue, currentValue))
     {
         content.Update(newValue, index);
     }
     return Task.FromResult<IActionItem>(null);
 }
开发者ID:psowinski,项目名称:xenko,代码行数:10,代码来源:ChangeValueCommand.cs

示例9: ExecuteSync

 protected override IActionItem ExecuteSync(IContent content, object index, object parameter, IEnumerable<IDirtiable> dirtiables)
 {
     var indices = (Tuple<int, int>)parameter;
     var sourceIndex = indices.Item1;
     var targetIndex = indices.Item2;
     var value = content.Retrieve(sourceIndex);
     content.Remove(sourceIndex);
     content.Add(targetIndex, value);
     return null;
 }
开发者ID:subajat1,项目名称:xenko,代码行数:10,代码来源:MoveItemCommand.cs

示例10: Execute

 public override Task Execute(IContent content, Index index, object parameter)
 {
     var currentValue = content.Retrieve(index);
     var newValue = ChangeValue(currentValue, parameter);
     if (!Equals(newValue, currentValue))
     {
         content.Update(newValue, index);
     }
     return Task.FromResult(0);
 }
开发者ID:cg123,项目名称:xenko,代码行数:10,代码来源:ChangeValueCommand.cs

示例11: ExecuteSync

 protected override void ExecuteSync(IContent content, Index index, object parameter)
 {
     var value = content.Retrieve(index);
     var dictionaryDescriptor = (DictionaryDescriptor)TypeDescriptorFactory.Default.Find(value.GetType());
     var newKey = dictionaryDescriptor.KeyType != typeof(string) ? new Index(Activator.CreateInstance(dictionaryDescriptor.KeyType)) : GenerateStringKey(value, dictionaryDescriptor, parameter as string);
     object newItem = null;
     // TODO: Find a better solution that doesn't require to reference Core.Serialization (and unreference this assembly)
     if (!dictionaryDescriptor.ValueType.GetCustomAttributes(typeof(ContentSerializerAttribute), true).Any())
         newItem = CreateInstance(dictionaryDescriptor.ValueType);
     content.Add(newItem, newKey);
 }
开发者ID:Kryptos-FR,项目名称:xenko-reloaded,代码行数:11,代码来源:AddPrimitiveKeyCommand.cs

示例12: ExecuteSync

 protected override IActionItem ExecuteSync(IContent content, object index, object parameter, IEnumerable<IDirtiable> dirtiables)
 {
     var value = content.Retrieve(index);
     var dictionaryDescriptor = (DictionaryDescriptor)TypeDescriptorFactory.Default.Find(value.GetType());
     var newKey = dictionaryDescriptor.KeyType != typeof(string) ? Activator.CreateInstance(dictionaryDescriptor.KeyType) : GenerateStringKey(value, dictionaryDescriptor, parameter as string);
     object newItem = null;
     // TODO: Find a better solution that doesn't require to reference Core.Serialization (and unreference this assembly)
     if (!dictionaryDescriptor.ValueType.GetCustomAttributes(typeof(ContentSerializerAttribute), true).Any())
         newItem = !dictionaryDescriptor.ValueType.IsAbstract ? Activator.CreateInstance(dictionaryDescriptor.ValueType) : null;
     content.Add(newKey, newItem);
     return null;
 }
开发者ID:psowinski,项目名称:xenko,代码行数:12,代码来源:AddPrimitiveKeyCommand.cs

示例13: Execute

 public override Task<IActionItem> Execute(IContent content, object index, object parameter, IEnumerable<IDirtiable> dirtiables)
 {
     var currentValue = content.Retrieve(index);
     var newValue = ChangeValue(currentValue, parameter);
     IActionItem actionItem = null;
     if (!Equals(newValue, currentValue))
     {
         content.Update(newValue, index);
         actionItem = new ContentValueChangedActionItem("Change property via command '{Name}'", content, index, currentValue, dirtiables);
     }
     return Task.FromResult(actionItem);
 }
开发者ID:FERRERDEV,项目名称:xenko,代码行数:12,代码来源:ChangeValueCommand.cs

示例14: Execute

 public override Task Execute(IContent content, Index index, object parameter)
 {
     var hasIndex = content.Indices == null || content.Indices.Contains(index);
     var currentValue = hasIndex ? content.Retrieve(index) : (content.Type.IsValueType ? Activator.CreateInstance(content.Type) : null);
     var newValue = ChangeValue(currentValue, parameter);
     if (hasIndex)
     {
         if (!Equals(newValue, currentValue))
         {
             content.Update(newValue, index);
         }
     }
     else
     {
         content.Add(newValue, index);
     }
     return Task.FromResult(0);
 }
开发者ID:Kryptos-FR,项目名称:xenko-reloaded,代码行数:18,代码来源:ChangeValueCommand.cs

示例15: AssertCollection

 private static void AssertCollection(IContent content, params string[] items)
 {
     for (var i = 0; i < items.Length; i++)
     {
         var item = items[i];
         Assert.AreEqual(item, content.Retrieve(new Index(i)));
     }
 }
开发者ID:Kryptos-FR,项目名称:xenko-reloaded,代码行数:8,代码来源:TestArchetypesAdvanced.cs


注:本文中的IContent.Retrieve方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。