Nettiers.AdventureWorks.Entities.EntityUtil.SetEntityKeyValue C# (CSharp) Method

SetEntityKeyValue() public static method

Sets the value of the property with the specified name to the value returned by the Guid.NewGuid() method.
public static SetEntityKeyValue ( Object entity, String entityKeyName ) : System.Guid
entity Object An object instance.
entityKeyName String The property name.
return System.Guid
		public static Guid SetEntityKeyValue(Object entity, String entityKeyName)
		{
			PropertyInfo property = null;
			Object objId = GetPropertyValue(entity, entityKeyName, out property);
			Guid entityId = Guid.Empty;

			if ( property != null && property.PropertyType.IsAssignableFrom(typeof(Guid)) )
			{
				if ( Guid.Empty.Equals(objId) && property.CanWrite )
				{
					entityId = Guid.NewGuid();
					property.SetValue(entity, entityId, null);
				}
			}

			return entityId;
		}