Beispiel #1
0
        private static void AddKeywordFromProperty(PropertyInfo pi)
        {
            string name        = pi.Name.ToLower(CultureInfo.InvariantCulture);
            string displayName = name;

            // now see if we have defined a display name for this property
            object[] attr = pi.GetCustomAttributes(false);
            foreach (Attribute a in attr)
            {
                if (a is DisplayNameAttribute)
                {
                    displayName = (a as DisplayNameAttribute).DisplayName;
                    break;
                }
            }

            validKeywords[name]        = displayName;
            validKeywords[displayName] = displayName;

            foreach (Attribute a in attr)
            {
                if (a is ValidKeywordsAttribute)
                {
                    foreach (string keyword in (a as ValidKeywordsAttribute).Keywords)
                    {
                        validKeywords[keyword.ToLower(CultureInfo.InvariantCulture).Trim()] = displayName;
                    }
                }
                else if (a is DefaultValueAttribute)
                {
                    defaultValues[displayName] = new PropertyDefaultValue(pi.PropertyType,
                                                                          Convert.ChangeType((a as DefaultValueAttribute).Value, pi.PropertyType, CultureInfo.CurrentCulture));
                }
            }
        }
    private static void AddKeywordFromProperty(PropertyInfo pi)
    {
      string name = pi.Name.ToLower(CultureInfo.InvariantCulture);
      string displayName = name;

      // now see if we have defined a display name for this property
      object[] attr = pi.GetCustomAttributes(false);
      foreach (Attribute a in attr)
        if (a is DisplayNameAttribute)
        {
          displayName = (a as DisplayNameAttribute).DisplayName;
          break;
        }

      validKeywords[name] = displayName;
      validKeywords[displayName] = displayName;

      foreach (Attribute a in attr)
      {
        if (a is ValidKeywordsAttribute)
        {
          foreach (string keyword in (a as ValidKeywordsAttribute).Keywords)
            validKeywords[keyword.ToLower(CultureInfo.InvariantCulture).Trim()] = displayName;
        }
        else if (a is DefaultValueAttribute)
        {
          defaultValues[displayName] = new PropertyDefaultValue(pi.PropertyType,
                  Convert.ChangeType((a as DefaultValueAttribute).Value, pi.PropertyType, CultureInfo.CurrentCulture));
        }
      }
    }