本文整理汇总了C#中IContent.Add方法的典型用法代码示例。如果您正苦于以下问题:C# IContent.Add方法的具体用法?C# IContent.Add怎么用?C# IContent.Add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IContent
的用法示例。
在下文中一共展示了IContent.Add方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
// 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);
}
}
示例2: 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;
}
示例3: 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);
}
}
示例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);
}
示例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);
}
示例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;
}
示例7: 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;
content.Remove(sourceIndex);
content.Add(targetIndex);
return null;
}
示例8: 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);
}
示例9: 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);
}
示例10: 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;
}
示例11: 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);
}
示例12: AddContent
public void AddContent(IContent content)
{
content.Add();
AppState.TriggerNotification(content.Name + " content added");
}