private PropertyDefinition _CreatePropertyDefinition(PropertyDeclarationSyntax inputPropertyDeclaration, ClassDeclarationSyntax inputClassDeclaration) { var _propertyDefinition = PropertyDefinition.Create(inputPropertyDeclaration.Identifier.Text, inputPropertyDeclaration.Type.ToString()); var _propertyValidationMethod = inputClassDeclaration.Members .Where(_member => _member.Kind() == SyntaxKind.MethodDeclaration) .Cast <MethodDeclarationSyntax>() .Where(_method => _method.Modifiers.Any(SyntaxKind.StaticKeyword)) .Where(_method => _method.ParameterList.Parameters.Count == 1) .SingleOrDefault(_method => _method.Identifier.Text == NameHelper.TextToPublicMethodIdentifier("Is" + _propertyDefinition.Name + "Valid").Text); if (_propertyValidationMethod != null) { var _valueParameter = _propertyValidationMethod.ParameterList.Parameters[_propertyValidationMethod.ParameterList.Parameters.Count - 1]; Must.Assert(_valueParameter.Type.ToString() == _propertyDefinition.Type); _propertyDefinition = _propertyDefinition .WithValidateMethodName(SyntaxFactory.IdentifierName(_propertyValidationMethod.Identifier)); } var _defaultProperty = inputClassDeclaration.Members .Where(_member => _member.Kind() == SyntaxKind.PropertyDeclaration) .Cast <PropertyDeclarationSyntax>() .Where(_p => _p.Modifiers.Any(SyntaxKind.StaticKeyword)) .SingleOrDefault(_p => _p.Identifier.Text == NameHelper.TextToPublicPropertyIdentifier("Default" + _propertyDefinition.Name).Text); if (_defaultProperty != null) { Must.Assert(_defaultProperty.Type.ToString() == _propertyDefinition.Type); _propertyDefinition = _propertyDefinition.WithDefaultValuePropertyName(SyntaxFactory.IdentifierName(_defaultProperty.Identifier)); } return(_propertyDefinition); }
public IEnumerable <PropertyDefinition> GetProperties() { Dictionary <string, List <PropertyDefinition> > propertiesMap = new Dictionary <string, List <PropertyDefinition> >(); foreach (PropertyDefinition property in partDefinitions.SelectMany(CreateProperties)) { string propertyName = property.Name; if (!propertiesMap.TryGetValue(propertyName, out List <PropertyDefinition> existingProperties)) { existingProperties = new List <PropertyDefinition>(); propertiesMap.Add(propertyName, existingProperties); } existingProperties.Add(property); } foreach (KeyValuePair <string, List <PropertyDefinition> > pair in propertiesMap) { PropertyDefinition propertyDefinition = PropertyDefinition.Create(pair.Value.First().PropertyType, pair.Key, pair.Value); if (propertyDefinition != null) { yield return(propertyDefinition); } } }