private IEnumerable <XElement> GetSerializedProperies(LibraryElement libraryElement) { if (!ValidatePropertiesWithCallBack(libraryElement)) { return(null); } return(libraryElement .GetType() .GetProperties() .Select(property => new XElement(property.Name, property.GetValue(libraryElement)))); }
private bool ValidatePropertiesWithCallBack(LibraryElement libraryElement) { var isHasEmptyMandatoryProperty = libraryElement .GetType() .GetProperties() .Any(property => property.CustomAttributes.Any(attribute => attribute.AttributeType == typeof(MandatoryAttribute)) && IsTypeEqualDefault(property.GetValue(libraryElement), property.PropertyType)); try { if (isHasEmptyMandatoryProperty) { throw new NullReferenceException("Element can't be null"); } } catch (Exception ex) { Console.WriteLine(ex.Message); return(false); } return(true); }