DataContractBase.SetProperty<T> Method (T, T, String, Boolean)

 

Changes the property to the given value. Returns whether the new value is different from the old value.

Namespace:   Microsoft.MasterDataServices.Services.DataContracts
Assembly:  Microsoft.MasterDataServices.Services.Contracts (in Microsoft.MasterDataServices.Services.Contracts.dll)

protected bool SetProperty<T>(
	ref T propertyBackingField,
	T newValue,
	string propertyName = null,
	bool emptyStringIsNull = false
)

Parameters

propertyBackingField
Type: T

The backing field of the property to change.

newValue
Type: T

The new value to give to the property.

propertyName
Type: System.String

The name of the property. It is recommended that this value be hardcoded by the method caller, rather than using a less performant (but more refactor-friendly) approach like using reflection or lambda expressions to get the property name. The downside of hardcoding is vulnerability to typo and copy-paste type errors. However, this vulnerability is mitigated by unit tests that use reflection to verify this parameter for all data contract class properties. The idea being that it is better to pay the reflection performance penalty in the unit tests, rather than in production code.

emptyStringIsNull
Type: System.Boolean

A flag that indicates what to do if newValue happens to be an empty string. If this value is set to true, empty strings are treated the same as null values. That is to say that if the existing value is null and an empty string is set with this flag on, it will have no effect.

Return Value

Type: System.Boolean

Whether the property was changed. I.e, whether the given new value is different from the property's old value.

Type Parameters

T

The property type.

Return to top
Show: