public static CADMetadataCriteria GetCADMetadataCriteria(CADProduct cadProduct)
 {
     return(cadProduct == null
         ? null
         : new CADMetadataCriteria
     {
         Identifier = new CADMetadataIdentifier
         {
             Application = new CADApplication
             {
                 Name = "Revit",
                 Version = ApplicationGlobals.GetRevitVersion()
             },
             ETIM = new ETIM
             {
                 ClassCode = cadProduct.EtimClassCode,
                 ClassCodeVersion = cadProduct.EtimClassCodeVersion == null || cadProduct.EtimClassCodeVersion.Equals("0") ? "1" : cadProduct.EtimClassCodeVersion,
                 ModelCode = cadProduct.ModellingClassCode,
                 ModelCodeVersion = cadProduct.ModellingClassCodeVersion == null || cadProduct.ModellingClassCodeVersion.Equals("0") ? "1" : cadProduct.ModellingClassCodeVersion
             }
         },
         Options = new CADMetadataIdentifierOptions
         {
             LanguageCode = "nl"
         }
     });
 }
        private bool HasChangedProperties(CADProduct cadProductOld, CADProduct cadProductNew)
        {
            var hasChangedPropertyValues = false;

            foreach (var propertyNew in cadProductNew.Properties)
            {
                var propertyOld = cadProductOld.Properties.FirstOrDefault(property => property.Code.Equals(propertyNew.Code, StringComparison.OrdinalIgnoreCase) && property.PortCode.Equals(propertyNew.PortCode));

                if (propertyOld == null ||
                    (propertyNew.Value == null && (propertyOld.UserDefinedValue != null || propertyOld.Value != null)) ||
                    (propertyNew.Value != null && propertyOld.UserDefinedValue == null && propertyOld.Value == null))
                {
                    hasChangedPropertyValues = true;
                    break;
                }

                if (propertyNew.Value != null)
                {
                    var propertyOldCode         = propertyOld.UserDefinedValue == null || propertyOld.UserDefinedValue.Code == null ? propertyOld.Value.Code : propertyOld.UserDefinedValue.Code;
                    var propertyOldDescription  = propertyOld.UserDefinedValue == null || propertyOld.UserDefinedValue.Description == null ? propertyOld.Value.Description : propertyOld.UserDefinedValue.Description;
                    var propertyOldLogicalValue = propertyOld.UserDefinedValue == null || propertyOld.UserDefinedValue.LogicalValue == null ? propertyOld.Value.LogicalValue : propertyOld.UserDefinedValue.LogicalValue;
                    var propertyOldNumericValue = propertyOld.UserDefinedValue == null || propertyOld.UserDefinedValue.NumericValue == null ? propertyOld.Value.NumericValue : propertyOld.UserDefinedValue.NumericValue;

                    if (propertyNew.Selected != propertyOld.Selected)
                    {
                        hasChangedPropertyValues = true;
                        break;
                    }
                    else if (propertyNew.Selected)
                    {
                        if (!(string.IsNullOrEmpty(propertyNew.Value.Code).Equals(string.IsNullOrEmpty(propertyOldCode)) || string.Equals(propertyNew.Value.Code, propertyOldCode, StringComparison.OrdinalIgnoreCase)) ||
                            !(string.IsNullOrEmpty(propertyNew.Value.Description).Equals(string.IsNullOrEmpty(propertyOldDescription)) || string.Equals(propertyNew.Value.Description, propertyOldDescription, StringComparison.OrdinalIgnoreCase) ||
                              (propertyNew.Value.Code != null && string.Equals(propertyNew.Value.Code, propertyOldCode, StringComparison.OrdinalIgnoreCase))) ||
                            !bool.Equals(propertyNew.Value.LogicalValue, propertyOldLogicalValue) ||
                            !decimal.Equals(propertyNew.Value.NumericValue, propertyOldNumericValue))
                        {
                            hasChangedPropertyValues = true;
                            break;
                        }
                    }
                }
            }

            return(hasChangedPropertyValues);
        }