Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: Support other assignment operators as part of the object initializer #109

Closed
iam3yal opened this issue Feb 15, 2017 · 4 comments
Closed

Comments

@iam3yal
Copy link
Contributor

iam3yal commented Feb 15, 2017

Summary

Support other assignment operators as part of the object initializer.

Motivation

We can use object initializes to reduce some repetitions in the code when it comes to assignment of fields or properties but currently doing something like combining flags isn't supported.

Detailed design

Today if we want to combine flags we have to do that outside to the object initializer like so:

XmlReaderSettings settings = new XmlReaderSettings {
    ValidationType = ValidationType.Schema
};

settings.ValidationFlags |= XmlSchemaValidationFlags.ProcessInlineSchema;
settings.ValidationFlags |= XmlSchemaValidationFlags.ProcessSchemaLocation;
settings.ValidationFlags |= XmlSchemaValidationFlags.ReportValidationWarnings;

I'm proposing to support additional assignment operators so with this change we could do the following:

var settings = new XmlReaderSettings {
    ValidationType = ValidationType.Schema,
    ValidationFlags |= (XmlSchemaValidationFlags.ProcessInlineSchema 
                       | XmlSchemaValidationFlags.ProcessSchemaLocation 
                       | XmlSchemaValidationFlags.ReportValidationWarnings)
};

Drawbacks

Not aware of any.

Alternatives

Assign the property/field outside to the object initializer.

@vladd
Copy link

vladd commented Feb 15, 2017

Does this proposal include relaxing the restriction on uniqueness? Which would allow something like

var settings = new XmlReaderSettings {
    ValidationType = ValidationType.Schema,
    ValidationFlags = XmlSchemaValidationFlags.ProcessInlineSchema,
    ValidationFlags |= XmlSchemaValidationFlags.ProcessSchemaLocation,
    ValidationFlags |= XmlSchemaValidationFlags.ReportValidationWarnings
};

Another question: is event subscription (which looks like assignment) included here too?

@iam3yal
Copy link
Contributor Author

iam3yal commented Feb 15, 2017

@vladd Nope, can you create a new issue about it? :)

@alrz
Copy link
Member

alrz commented Dec 29, 2017

Relates to #307

@Thaina
Copy link

Thaina commented Jan 2, 2019

@vladd I disagree on relaxing. Everything should only exist once

Your case is easier written as

var settings = new XmlReaderSettings {
    ValidationType = ValidationType.Schema,
    ValidationFlags = XmlSchemaValidationFlags.ProcessInlineSchema
                    | XmlSchemaValidationFlags.ProcessSchemaLocation
                    | XmlSchemaValidationFlags.ReportValidationWarnings,
};

@iam3yal iam3yal closed this as completed Jun 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants