I believe you could change Sitecore Glass Mapper SitecoreFieldAttribute to accomplish that.
You could implement the interface IIndexFieldNameFormatterAttribute
on the Glass MapperSitecoreFieldAttribute
.
This interface you will find in the Sitecore.ContentSearch.Linq.dll
and it looks like that:
namespace Sitecore.ContentSearch
{
public interface IIndexFieldNameFormatterAttribute : _Attribute
{
string GetIndexFieldName(string fieldName);
string GetTypeFieldName(string fieldName);
}
}
Your implementation would be that, I pasted only the interface methods here.
namespace Glass.Sitecore.Mapper.Configuration.Attributes
{
/// <summary>
/// Used to populate the property with data from a Sitecore field
/// </summary>
public class SitecoreFieldAttribute: AbstractSitecorePropertyAttribute, IIndexFieldNameFormatterAttribute
{
public string GetIndexFieldName(string fieldName)
{
return this.FieldName;
}
public string GetTypeFieldName(string fieldName)
{
return fieldName;
}
I haven`t test it, but as I could see Sitecore Linq rely on this interface to find the fields names. You can investigate it yourself, but here is the piece of code which made me deduce that:
var variable = (from p in (IEnumerable<PropertyInfo>)typeof(TItem).GetProperties()
select new { Property = p, Attribute = (IIndexFieldNameFormatterAttribute)p.GetCustomAttributes().FirstOrDefault<Attribute>((Attribute a) => a is IIndexFieldNameFormatterAttribute) }).FirstOrDefault((p) => p.Attribute != null);
if (variable != null && variable.Attribute.GetIndexFieldName(variable.Property.Name) == this.FieldName)
{
property = variable.Property;
}
Hope it helps..