当前位置: 首页>>代码示例>>C#>>正文


C# IScreen.GetType方法代码示例

本文整理汇总了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));
 }
开发者ID:Slesa,项目名称:Playground,代码行数:8,代码来源:NamingConventions.cs

示例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;
        }
开发者ID:Slesa,项目名称:Playground,代码行数:16,代码来源:NamingConventions.cs

示例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"
//.........这里部分代码省略.........
开发者ID:ProjectTako,项目名称:HearthstoneTracker,代码行数:101,代码来源:LabelDescriptionAttribute.cs

示例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));
 }
开发者ID:Slesa,项目名称:Playground,代码行数:14,代码来源:NamingConventions.cs


注:本文中的IScreen.GetType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。