本文整理汇总了C#中IScreen.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# IScreen.GetType方法的具体用法?C# IScreen.GetType怎么用?C# IScreen.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IScreen
的用法示例。
在下文中一共展示了IScreen.GetType方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetQualifiedViewModelName
private static string GetQualifiedViewModelName(IScreen screen, string targetPostFix, string viewModelPostFix)
{
var qualifiedName = screen.GetType().AssemblyQualifiedName;
if (qualifiedName == null) throw new ArgumentException("No qualified name", "screen");
return qualifiedName.Replace(
screen.GetType().Name,
GetViewModelName(screen, targetPostFix, viewModelPostFix));
}
示例2: GetViewModelName
private static string GetViewModelName(IScreen screen, string targetPostFix, string viewModelPostFix)
{
var s = screen.GetType().Name;
var postFix = targetPostFix + viewModelPostFix;
if (s.EndsWith(SinglePostFix + ViewModelPostFix))
return s.Replace(SinglePostFix + ViewModelPostFix, postFix);
if (s.EndsWith(HomePostFix + ViewModelPostFix))
return s.Replace(HomePostFix + ViewModelPostFix, postFix);
if (s.EndsWith(ViewModelPostFix))
return s.Replace(ViewModelPostFix, postFix);
return string.Empty;
}
示例3: ApplyLabels
/// <summary>
/// Static method to apply labels for a model's properties. The model specified MUST be view aware.
/// </summary>
/// <param name="model">The view to which the label should be applied</param>
public static void ApplyLabels(IScreen model)
{
if (model == null)
{
return;
}
var va = model as IViewAware;
if (va == null)
{
return;
}
var view = va.GetView();
if (view == null)
{
return;
}
// Create a dictionary of the label (if any) associated with each class property
var modelsLabels =
(from p in model.GetType().GetProperties()
let attrs = p.GetAttributes<LabelDescriptionAttribute>(true).ToArray()
where attrs.Length != 0
select new KeyValuePair<string, LabelDescriptionAttribute[]>(p.Name, attrs)
).ToDictionary(p => p.Key, p => p.Value);
// Grab any model level properties
var modelAttrs = model.GetType().GetAttributes<LabelDescriptionAttribute>(true).ToArray();
if (modelAttrs.Count() > 0)
{
modelsLabels.Add("", modelAttrs);
}
// Grab the dictionary
foreach (var name in modelsLabels.Keys)
{
foreach (var l in modelsLabels[name])
{
var label = "";
// Used to hold previously created classes
var references = new Dictionary<string, object>();
if (l.LabelResourceType == null
|| string.IsNullOrEmpty(l.LabelResourceName))
{
label = l.Label;
}
else
{
// Look up the description (if possible)
object reference = null;
if (references.ContainsKey(l.LabelResourceType.Name))
{
reference = references[l.LabelResourceType.Name];
}
else
{
// Try to get the type
reference = Activator.CreateInstance(l.LabelResourceType, true);
references.Add(l.LabelResourceType.Name, reference);
}
// Now try to find the description in the reference class
var pi = reference.GetType().GetProperty(l.LabelResourceName);
if (pi == null)
{
continue;
}
var v = pi.GetValue(reference, null);
label = v.ToString();
}
// If this is a model level label then the attribute MUST specify an element name
if (string.IsNullOrEmpty(name)
&& string.IsNullOrEmpty(l.ElementName))
{
continue;
}
var labelName = string.IsNullOrEmpty(l.ElementName) ? name + "Label" : l.ElementName;
// Next, find the named element in the view
// Named elements appear as properties of the view
var element = (view as FrameworkElement).FindName(labelName);
if (element == null)
{
continue;
}
var labelPropertyName = string.IsNullOrEmpty(l.LabelPropertyName)
? element.GetType().Name == "Button"
? "Content"
//.........这里部分代码省略.........
示例4: GetQualifiedViewModelName
/// <summary>
/// Gets the fully qualified name of a ViewModel. Just adds the AssemblyQualifiedName to the <see cref="GetViewModelName"/>.
/// </summary>
/// <param name="screen">The screen</param>
/// <param name="targetPostFix">Either <see cref="HomePostFix"/> or <see cref="SinglePostFix"/></param>
/// <param name="viewModelPostFix">The <see cref="ViewModelPostFix"/></param>
/// <returns>The fully qualified ViewModel-Name</returns>
private static string GetQualifiedViewModelName(IScreen screen, string targetPostFix, string viewModelPostFix)
{
string qualifiedName = screen.GetType().AssemblyQualifiedName;
return qualifiedName.Replace(
screen.GetType().Name,
GetViewModelName(screen, targetPostFix, viewModelPostFix));
}