예제 #1
0
        private IPropertySymbol RetrieveLinkedForeignKeyProperty(IPropertySymbol prop)
        {
            try
            {
                //We do this Do While so we can support properties in BaseTypes
                //This is ugly but it's possible the foreign key is references base properties
                var type = SerializableType;
                do
                {
                    var propResult = type.GetMembers()
                                     .Where(m => m.Kind == SymbolKind.Property)
                                     .Cast <IPropertySymbol>()
                                     .FirstOrDefault(m => m.Kind == SymbolKind.Property && m.Name == (string)prop.GetAttributeLike <ForeignKeyAttribute>().ConstructorArguments.First().Value);

                    if (propResult != null)
                    {
                        return(propResult);
                    }

                    type = type.BaseType;
                } while (type != null);

                throw new InvalidOperationException($"Failed to retrieve foreign key property for Type: {SerializableType.Name} Prop: {prop.Name}");
            }
            catch (Exception e)
            {
                throw new InvalidOperationException($"Failed to retrieve foreign key property for Type: {SerializableType.Name} Prop: {prop.Name}", e);
            }
        }