static void Main(string[] args) { var factory = new PropertyFactory(); Property property = factory.GetProperty('I'); property.Display(); property = factory.GetProperty('M'); property.Display(); }
/// <summary> /// Creates a new instance /// </summary> /// <param name="modelPath">The path to the model class</param> public ModelMetadata(string modelPath) { if (string.IsNullOrWhiteSpace(modelPath)) { throw new ArgumentException("You must enter a model path."); } if (!File.Exists(modelPath)) { throw new ArgumentException($"{modelPath} doesn't exist."); } var rootNode = CSharpSyntaxTree.ParseText(File.ReadAllText(modelPath)).GetRoot(); var namespaceNode = rootNode.DescendantNodes() .OfType <NamespaceDeclarationSyntax>() .FirstOrDefault(); var classNode = rootNode.DescendantNodes() .OfType <ClassDeclarationSyntax>() .FirstOrDefault(); var propertyNodes = classNode.DescendantNodes().OfType <PropertyDeclarationSyntax>(); Name = classNode.Identifier.Text; PluralName = Name.Pluralize(); Namespace = namespaceNode.Name.ToString(); Properties = propertyNodes .Select(s => PropertyFactory.GetProperty(s.Identifier.ValueText, s.Type.ToString())) .Where(w => w != null) .ToDictionary(d => d.Name, d => d); KeyName = propertyNodes .FirstOrDefault(f => f.AttributeLists.Any(a => KEY_ATTRIBUTES.Contains(a.ToString()))) ?.Identifier.ValueText; KeyName ??= propertyNodes.FirstOrDefault(f => f.Identifier.ValueText.ToLower() == "id") ?.Identifier.ValueText; }
public List <Product> ParseXmlDocument(string inputFilePath) { List <Product> _productList = new List <Product>(); XDocument document = XDocument.Load(inputFilePath); var productList = from prod in document.Descendants("product") select prod; foreach (var item in productList) { //iteram fiecare produs //luam proprietatile simple var product = new Product { NedisPartnr = item.Element("nedisPartnr").Value, NedisArtId = item.Element("nedisArtlid").Value, VendorPartnr = item.Element("vendorPartnr").Value, Brand = item.Element("brand").Value, Ean = item.Element("EAN").Value, InstraStatCode = item.Element("intrastatCode").Value, Unspsc = item.Element("UNSPSC").Value, HeaderText = item.Element("headerText").Value, InternetText = item.Element("internetText").Value, GeneralText = item.Element("generalText").Value, IntroductionDate = item.Element("introductionDate").Value, SerialnumberKeeping = item.Element("serialnumberKeeping").Value }; var complexNodes = item.Descendants().Where(node => node.HasElements == true).ToList(); foreach (var descendant in complexNodes) { //iteram fiecare proprietate complexa a produsului var propertyInstance = PropertyFactory.GetProperty(descendant.Name.LocalName); if (propertyInstance != null) { var complexPropertyParser = new ComplexPropertyParser(propertyInstance); complexPropertyParser.ParseComplexProperty(ref product, descendant); } } _productList.Add(product); } return(_productList); }