internal static object GetConstantValue(System.Reflection.FieldInfo field)
 {
     if ((field.GetType().Assembly == typeof(TypeReferences).Assembly) || !field.DeclaringType.Assembly.ReflectionOnly)
     {
         return field.GetValue(null);
     }
     System.Type fieldType = field.FieldType;
     object rawConstantValue = field.GetRawConstantValue();
     if (fieldType.IsEnum)
     {
         return MetadataEnumValue.GetEnumValue(fieldType, rawConstantValue);
     }
     return rawConstantValue;
 }
Пример #2
0
        // Check if the current field has the supplied value.
        private static string _GetNameIfMatches(ServiceAttributeId id, System.Reflection.FieldInfo curField)
        {
            object rawValue;
#if PocketPC
            // This does the job too.  As a static field the parameter is ignored.
            rawValue = curField.GetValue(null);
#else
            // Does this require less permissions than the GetValue version.
            rawValue = curField.GetRawConstantValue();
#endif
            ServiceAttributeId fieldValue = (ServiceAttributeId)rawValue;
            if (fieldValue == id) {
                string fieldName = curField.Name;
                return fieldName;
            }
            return null;
        }