本文整理汇总了C#中ModelType.TryGetPath方法的典型用法代码示例。如果您正苦于以下问题:C# ModelType.TryGetPath方法的具体用法?C# ModelType.TryGetPath怎么用?C# ModelType.TryGetPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ModelType
的用法示例。
在下文中一共展示了ModelType.TryGetPath方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InitializeFromTypeAndPath
/// <summary>
/// Attempts to initialize a <see cref="ModelSource"/> with the specified root type and path.
/// </summary>
/// <param name="rootType">The root type name, which is required for instance paths</param>
/// <param name="path">The source path, which is either an instance path or a static path</param>
/// <returns>True if the source was created, otherwise false</returns>
bool InitializeFromTypeAndPath(ModelType rootType, string path, out ModelProperty sourceProperty)
{
// Instance Path
ModelPath instancePath = null;
sourceProperty = null;
// clean up any array indices
string indexFreePath = arraySyntaxRegex.Replace(path, "");
try
{
if (rootType != null)
rootType.TryGetPath(indexFreePath, out instancePath);
}
catch
{ }
if (instancePath != null)
{
InitializeFromModelPath(instancePath, path, out sourceProperty);
return true;
}
// Static Path
else if (path.Contains('.'))
{
// Store the source path
var sourceModelType = ModelContext.Current.GetModelType(path.Substring(0, path.LastIndexOf('.')));
if (sourceModelType != null)
{
sourceProperty = sourceModelType.Properties[path.Substring(path.LastIndexOf('.') + 1)];
if (sourceProperty != null && sourceProperty.IsStatic)
{
this.Path = path;
this.IsStatic = true;
this.SourceProperty = sourceProperty.Name;
this.SourceType = sourceProperty.DeclaringType.Name;
return true;
}
}
}
return false;
}