Пример #1
0
        async Task <object> IAsyncCloneable <Program> .CloneInstance(Program program)
        {
            var looks = Looks == null ? null : await Looks.ToReadOnlyDictionaryAsync(
                keySelector : look => look,
                elementSelector : look => look.CloneAsync(program));

            var sounds = Sounds == null ? null : await Sounds.ToReadOnlyDictionaryAsync(
                keySelector : sound => sound,
                elementSelector : sound => sound.CloneAsync(program));

            var localVariables = LocalVariables == null ? null : LocalVariables.ToReadOnlyDictionary(
                keySelector: variable => variable,
                elementSelector: variable => variable.Clone());
            var context = new CloneSpriteContext(looks, sounds, localVariables);

            return(new Sprite
            {
                Name = Name,
                Looks = looks == null ? null : looks.Values.ToObservableCollection(),
                Sounds = sounds == null ? null : sounds.Values.ToObservableCollection(),
                LocalVariables = localVariables == null ? null : localVariables.Values.ToObservableCollection(),
                Scripts = Scripts.Select(script => script.Clone(context)).ToObservableCollection()
            });
        }