C# 7 syntax in autofac

51 views
Skip to first unread message

Christos Paisios

unread,
Apr 5, 2017, 3:15:04 PM4/5/17
to Autofac
Hi,

I would like to apply the new syntax of C# in to autofac code base, since this would make it more compact, removing any clutter. For instance, the DeferredCallback constructor could change from this

 public DeferredCallback(Action<IComponentRegistry> callback)
        {
            if (callback == null)
            {
                throw new ArgumentNullException(nameof(callback));
            }

            this.Id = Guid.NewGuid();
            this.Callback = callback;
            get
            {
                return this._callback;
            }

            set
            {
                if (value == null)
                {
                    throw new ArgumentNullException(nameof(value));
                }

                this._callback = value;
            }
        }

To the following:

        public DeferredCallback(Action<IComponentRegistry> callback)
        {
            Callback = callback ?? throw new ArgumentNullException(nameof(callback));
            Id = Guid.NewGuid();
            get => _callback;
            set => _callback = value ?? throw new ArgumentNullException(nameof(value));
        }

I have noticed also other places of the code base, where could be benefit of the new features of the language.

I would like to ask you if you think that this could benefit the code base and if I could proceed with something like this? 

Thanks in advance ! 

Travis Illig

unread,
Apr 6, 2017, 1:20:34 PM4/6/17
to Autofac
It would be nice to not change code that isn't being modified for a specific purpose like a bug fix or patch. I recognize the desire to make things cleaner, but I think it'd be better to do it incrementally alongside other changes rather than big bang change for the sake of change.

I could see a lot of other interesting cleanup ideas, too, like splitting out the RegistrationExtensions into smaller classes that are easier to navigate... But that's a breaking change so it'll have to wait.

Michael Powell

unread,
Apr 7, 2017, 12:38:04 PM4/7/17
to Autofac


On Thursday, April 6, 2017 at 1:20:34 PM UTC-4, Travis Illig wrote:
It would be nice to not change code that isn't being modified for a specific purpose like a bug fix or patch. I recognize the desire to make things cleaner, but I think it'd be better to do it incrementally alongside other changes rather than big bang change for the sake of change.

I tend to agree. If you're visiting code for some purpose, bug fix, enhancement, etc, potentially take advantage of new language features. But then again, not everyone is on board with VS2017 (C# 7) (yet). In fact, I dare say folks are catching up from VS2015 (C# 6), potentially. At least IMO.
Reply all
Reply to author
Forward
0 new messages