// TODO: Put strings into the resources. // public Cloneable Clone(ICloneContext cloneCtx) { var result = (Cloneable)MemberwiseClone(); if (cloneCtx != null && cloneCtx.SetCloneOrigin) { throw new NotSupportedException($"Setting clone origin is not supported for this object.{Environment.NewLine}\tObject:{this.FmtStr().GNLI2()}").SetErrorCode(code: GeneralErrorCodes.Operation.NotSupported); } PopulateClone(cloneCtx, result); return(result); }
public override async Task MutateOnClone(JObject content, ICloneContext context) { var mutatedContentItems = await _embeddedContentItemsGraphSyncer.MutateOnClone((JArray?)content[ContainerName], context); var mutatedContentItemsJArray = JArray.FromObject(mutatedContentItems); content[ContainerName] = mutatedContentItemsJArray; // we could return the mutated contentitems from this method and the derived class could use Alter with the appropriate part // context.ContentItem.Alter<FlowPart>(p => p.Widgets = mutatedContentItems.ToList()); }
public override Task MutateOnClone(JObject content, ICloneContext context) { string title = (string?)content[nameof(TitlePart.Title)] ?? string.Empty; var newTitle = _titlePartCloneGenerator.Generate(title); context.ContentItem.DisplayText = newTitle; content[nameof(TitlePart.Title)] = newTitle; return(Task.CompletedTask); }
public object Clone(ICloneContext context, object src) { var target = FormatterServices.GetUninitializedObject(_type); foreach (var cloneField in _cloneFields) { var value = cloneField.Get(src); if (cloneField.Deep) { value = context.Clone(value); } cloneField.Set(target, value); } return(target); }
public CloneableDisposable Clone(ICloneContext cloneCtx) { EnsureNotDisposeState(considerDisposeRequest: true); // var clone = (CloneableDisposable)MemberwiseClone(); clone.RecreateDisposableImplementation(); try { PopulateClone(cloneCtx: cloneCtx, clone: clone); if (cloneCtx?.SetCloneOrigin == true) { clone.WriteDA(location: ref _cloneOrigin, value: this); } EnsureNotDisposeState(considerDisposeRequest: true); return(clone); } catch (Exception exception) { clone?.Dispose(exception: exception); throw; } }
public override async Task MutateOnClone(JObject content, ICloneContext context) { string?urlName = (string?)content[nameof(PageLocationPart.UrlName)]; string?fullUrl = (string?)content[nameof(PageLocationPart.FullUrl)]; if (string.IsNullOrWhiteSpace(urlName) || string.IsNullOrWhiteSpace(fullUrl)) { throw new InvalidOperationException($"Cannot mutate {nameof(PageLocationPart)} if {nameof(PageLocationPart.UrlName)} or {nameof(PageLocationPart.FullUrl)} are missing."); } List <ContentItem> pages = await _contentItemsService.GetActive(ContentTypes.Page); string urlSearchFragment = _generator.GenerateUrlSearchFragment(fullUrl); IEnumerable <ContentItem> existingClones = pages.Where(x => ((string)x.Content[nameof(PageLocationPart)][nameof(PageLocationPart.FullUrl)]).Contains(urlSearchFragment)); var result = _generator.GenerateClonedPageLocationProperties(urlName, fullUrl, existingClones); content[nameof(PageLocationPart.UrlName)] = result.UrlName; content[nameof(PageLocationPart.FullUrl)] = result.FullUrl; content[nameof(PageLocationPart.DefaultPageForLocation)] = false; content[nameof(PageLocationPart.RedirectLocations)] = null; }
public CloneableDisposeNotifying Clone(ICloneContext cloneContext) { EnsureNotDisposeState(considerDisposeRequest: true); // var clone = (CloneableDisposeNotifying)MemberwiseClone(); clone.RecreateDisposableImplementation(); try { PopulateClone(cloneContext: cloneContext, clone: clone); if (cloneContext?.SetCloneOrigin == true) { clone.WriteDA(location: ref _cloneOrigin, value: this); } else { EnsureNotDisposeState(considerDisposeRequest: true); } return(clone); } catch (Exception exception) { DisposeMany(exception: exception, disposables: clone); throw; } }
// It's used by reflection from CloneObjectEx public static object Clone(ICloneContext context, object src) { return(Array.ConvertAll((T[])src, x => (T)context.Clone(x))); }
public object Clone(ICloneContext context, object src) { return(_cache.GetOrAdd(src.GetType(), CreateObjectClone)(context, src)); }
protected abstract void PopulateClone(ICloneContext cloneCtx, CloneableDisposable clone);
object IEonCloneable.Clone(ICloneContext cloneCtx) => Clone(cloneCtx: cloneCtx);
public virtual Task MutateOnClone(JObject content, ICloneContext context) { return(Task.CompletedTask); }
protected abstract void PopulateClone(ICloneContext cloneContext, CloneableDisposeNotifying clone);
object IEonCloneable.Clone(ICloneContext cloneContext) => Clone(cloneContext: cloneContext);