public SecurableClassInfo GetMetadata(Type type, MetadataCache cache) { ArgumentUtility.CheckNotNullAndTypeIsAssignableFrom("type", type, typeof(ISecurableObject)); if (type.IsValueType) { throw new ArgumentException("Value types are not supported.", "type"); } ArgumentUtility.CheckNotNull("cache", cache); SecurableClassInfo info = cache.GetSecurableClassInfo(type); if (info == null) { info = new SecurableClassInfo(); info.Name = TypeUtility.GetPartialAssemblyQualifiedName(type); PermanentGuidAttribute guidAttribute = (PermanentGuidAttribute)Attribute.GetCustomAttribute(type, typeof(PermanentGuidAttribute), true); if (guidAttribute != null) { info.ID = guidAttribute.Value.ToString(); } info.Properties.AddRange(GetProperties(type, cache)); info.AccessTypes.AddRange(_accessTypeReflector.GetAccessTypesFromType(type, cache)); cache.AddSecurableClassInfo(type, info); if (typeof(ISecurableObject).IsAssignableFrom(type.BaseType)) { info.BaseClass = GetMetadata(type.BaseType, cache); info.BaseClass.DerivedClasses.Add(info); } } return(info); }
public EnumValueInfo GetValue(Enum value, MetadataCache cache) { ArgumentUtility.CheckNotNull("value", value); ArgumentUtility.CheckNotNull("cache", cache); EnumValueInfo info = cache.GetEnumValueInfo(value); if (info == null) { string name = value.ToString(); info = new EnumValueInfo(TypeUtility.GetPartialAssemblyQualifiedName(value.GetType()), name, Convert.ToInt32(value)); FieldInfo fieldInfo = value.GetType().GetField(name, BindingFlags.Static | BindingFlags.Public); PermanentGuidAttribute attribute = (PermanentGuidAttribute)Attribute.GetCustomAttribute(fieldInfo, typeof(PermanentGuidAttribute), false); if (attribute != null) { info.ID = attribute.Value.ToString(); } cache.AddEnumValueInfo(value, info); } return(info); }
public StatePropertyInfo GetMetadata(PropertyInfo property, MetadataCache cache) { ArgumentUtility.CheckNotNull("property", property); if (!property.PropertyType.IsEnum) { throw new ArgumentException( string.Format("The type of the property '{0}' in type '{1}' is not an enumerated type.", property.Name, property.DeclaringType.FullName), "property"); } if (!Attribute.IsDefined(property.PropertyType, typeof(SecurityStateAttribute), false)) { throw new ArgumentException(string.Format("The type of the property '{0}' in type '{1}' does not have the {2} applied.", property.Name, property.DeclaringType.FullName, typeof(SecurityStateAttribute).FullName), "property"); } ArgumentUtility.CheckNotNull("cache", cache); StatePropertyInfo info = cache.GetStatePropertyInfo(property); if (info == null) { info = new StatePropertyInfo(); info.Name = property.Name; PermanentGuidAttribute attribute = (PermanentGuidAttribute)Attribute.GetCustomAttribute(property, typeof(PermanentGuidAttribute), true); if (attribute != null) { info.ID = attribute.Value.ToString(); } info.Values = new List <EnumValueInfo> (_enumerationReflector.GetValues(property.PropertyType, cache).Values); cache.AddStatePropertyInfo(property, info); } return(info); }