I am working on some code that was written years ago and I am just trying to understand how it works. On some pages, there is the following code:
var context = new SitecoreService(Sitecore.Context.Database.Name);
item = context.GetItem<ISomething>(DataSourceItem);
I'm trying to determine how the value DataSourceItem is populated - it is not set by my code explicitly. A full search of my code never shows it being set; plus, it doesn't have a 'set' accessor anyway. The question is: for each rendered page, how does Glass Mapper determine the value it should be set to?
If I follow it to it's source, it's in an abstract class that appears auto-generated:
// Summary:
// Returns the item specificed by the data source only. Returns null if no datasource
// set
public Item DataSourceItem { get; }
If I debug the code, the value of DataSourceItem is a GUID that I can easily find in the content editor of Sitecore. Where is this variable populated? I've searched the code, Google, the Sitecore community, and elsewhere. Should be simple, right?
Edit: A couple of people are suggesting that I decompile the Glass Mapper code to see where the value of DataSourceItem is set. Also, a search of my entire codebase doesn't show that this variable is set by my code.
What I really want to know is what determines how DataSourceItem is set. This variable is being set internally by Glass Mapper, but something must have been passed in to it, instructing Glass Mapper to pull an item from Sitecore. I don't see that in the code.
Glass
in your website bin folder and use JustDecompile or dotPeek to decompile. Chances are that Glass Mapper is doing this somewhere in an external DLL. Also try searching for all instances ofDataSourceItem
in your code (or right clicking and select find all references).DataSourceItem
is typically associated with theIRenderingModelBase
interface.