문제

I'd like to parse through an Fluent NHibernate mapping file so I can get the table name and column names that are specified in there.

Loading the assembly and reflecting the type as ClassMap isn't a problem but that class only get methods to set the table and column names - nothing to get the names back again.

Any ideas?

도움이 되었습니까?

해결책

Using Reflector, it looks like Table method has this signature:

public void Table(string tableName)
{
    this.attributes.Set<string>(x => x.TableName, tableName);
}

Columns will be a lot harder as it keeps properties, references, and collections separate. Eg.

protected virtual PropertyPart Map(PropertyInfo property, string columnName)
{
    PropertyPart propertyMap = new PropertyPart(property, typeof(T));
    if (!string.IsNullOrEmpty(columnName))
    {
        propertyMap.Column(columnName);
    }
    this.properties.Add(propertyMap);
    return propertyMap;
}

In theory though you could get the private fields attributes, properties, and references via reflection and get the information that way.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top