public string BuildCompositeKeyCreationExpression(IPropertySymbol property, string modelReference, string keyTypeNameOverride = null) { INamedTypeSymbol type = (INamedTypeSymbol)property.Type; //Important we get PROPERTIES key defs and not from //the prop type because they may not match. string[] keyProperties = property .GetAttributeExact <CompositeKeyHintAttribute>() .ConstructorArguments .First() .Values .Select(v => v.Value) .Cast <string>() .ToArray(); if (keyTypeNameOverride == null) { keyTypeNameOverride = Parse(type); } StringBuilder builder = new StringBuilder(); builder.Append($"new {keyTypeNameOverride}("); for (int i = 0; i < keyProperties.Length; i++) { builder.Append($"{modelReference}.{keyProperties[i]}"); if (i < keyProperties.Length - 1) { builder.Append(", "); } } builder.Append(')'); return(builder.ToString()); }