Beispiel #1
0
        private IEnumerable <XElement> GetSerializedProperies(LibraryElement libraryElement)
        {
            if (!ValidatePropertiesWithCallBack(libraryElement))
            {
                return(null);
            }

            return(libraryElement
                   .GetType()
                   .GetProperties()
                   .Select(property => new XElement(property.Name, property.GetValue(libraryElement))));
        }
Beispiel #2
0
        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);
        }