Skip to content

Commit

Permalink
Treaked the API for the ModelInspector<TModel>
Browse files Browse the repository at this point in the history
This is only currently used by advanced users of the Model Map to get at details of a model map at runtime.
  • Loading branch information
KevM committed May 14, 2012
1 parent 6691917 commit 1162dc0
Showing 1 changed file with 35 additions and 19 deletions.
54 changes: 35 additions & 19 deletions source/Dovetail.SDK.ModelMap/ModelInspectorVisitor.cs
Expand Up @@ -9,6 +9,28 @@

namespace Dovetail.SDK.ModelMap
{
public class ModelMapFieldDetails
{
/// <summary>
/// Property of the Model class
/// </summary>
public PropertyInfo Property { get; set; }
/// <summary>
/// Name of the database field
/// </summary>
public string FieldName { get; set; }

/// <summary>
/// Type of the field in the Clarify schema. Currently only string and integer types are supported.
/// </summary>
public Type SchemaFieldType { get; set; }
}

/// <summary>
/// Inspects the model map for a model (generic argument).
/// Currently used to get at the identifying field details for a given model map.
/// </summary>
/// <typeparam name="MODEL">Model whose ModelMap should be inspected.</typeparam>
public class ModelInspector<MODEL>
{
private readonly ModelMap<MODEL> _modelMap;
Expand All @@ -21,28 +43,22 @@ public ModelInspector(ModelMap<MODEL> modelMap, ModelInspectorVisitor modelInspe
_modelInspectorVisitor = modelInspectorVisitor;
}

public MapFieldDetails Identifier
/// <summary>
/// Inspects the model map and returns details about the identifying field of the map.
/// </summary>
/// <returns></returns>
public ModelMapFieldDetails GetIdentifier()
{
get
{
if(!_visited)
{
_modelMap.Accept(_modelInspectorVisitor);
_visited = true;
}
if(!_visited)
{
_modelMap.Accept(_modelInspectorVisitor);
_visited = true;
}

return _modelInspectorVisitor.IndentifierField;
}
return _modelInspectorVisitor.IndentifierField;
}
}

public class MapFieldDetails
{
public PropertyInfo Property { get; set; }
public string FieldName { get; set; }
public Type SchemaFieldType { get; set; }
}

public class ModelInspectorVisitor : IModelMapVisitor
{
private readonly ISchemaCache _schemaCache;
Expand All @@ -53,7 +69,7 @@ public ModelInspectorVisitor(ISchemaCache schemaCache)
_schemaCache = schemaCache;
}

public MapFieldDetails IndentifierField { get; set; }
public ModelMapFieldDetails IndentifierField { get; set; }

public void Visit(FieldMap fieldMap)
{
Expand All @@ -62,7 +78,7 @@ public void Visit(FieldMap fieldMap)
if(IndentifierField != null)
throw new ArgumentException("There are multiple identifying fields defined on the model map being visited.");

IndentifierField = new MapFieldDetails
IndentifierField = new ModelMapFieldDetails
{
FieldName = fieldMap.FieldNames.First(),
Property = fieldMap.Property,
Expand Down

0 comments on commit 1162dc0

Please sign in to comment.