public CObjectProperty(string name, CCategoryInfo category, object target, object value, Type type, PropertyInfo propertyInfo, FieldInfo fieldInfo) { Name = name; Category = category; Value = value; ValueType = type; FieldInfo = fieldInfo; PropertyInfo = propertyInfo; Target = target; Type = EObjectType.Property; }
public static CObjectProperties GetObjectProperties(object instance) { if (instance == null) { return(null); } CObjectProperties properties = new CObjectProperties { target = instance }; Type type = instance.GetType(); foreach (var field in type.GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance)) { KlaxPropertyAttribute attribute = field.GetCustomAttribute <KlaxPropertyAttribute>(); if (attribute != null && !attribute.IsReadOnly) { string name = attribute.DisplayName ?? field.Name; string categoryName = attribute.Category ?? "Default"; CCategoryInfo category = new CCategoryInfo() { Name = categoryName, Priority = attribute.CategoryPriority }; CObjectProperty property = new CObjectProperty(name, category, instance, field.GetValue(instance), field.FieldType, null, field); properties.properties.Add(property); } } foreach (var property in type.GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance)) { KlaxPropertyAttribute attribute = property.GetCustomAttribute <KlaxPropertyAttribute>(); if (attribute != null && !attribute.IsReadOnly) { string name = attribute.DisplayName ?? property.Name; string categoryName = attribute.Category ?? "Default"; CCategoryInfo category = new CCategoryInfo() { Name = categoryName, Priority = attribute.CategoryPriority }; CObjectProperty objectProperty = new CObjectProperty(name, category, instance, property.GetValue(instance), property.PropertyType, property, null); properties.properties.Add(objectProperty); } } foreach (var KlaxProperty in type.GetMethods(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance)) { EditorFunctionAttribute attribute = KlaxProperty.GetCustomAttribute <EditorFunctionAttribute>(); if (attribute != null) { if (KlaxProperty.ReturnType != typeof(void) || KlaxProperty.GetParameters().Length > 0) { LogUtility.Log("The function {0} of Type {1} cannot be converted into a parameterless, void returning function. This is necessary for an editor function.", KlaxProperty.Name, type.Name); continue; } string name = attribute.DisplayName ?? KlaxProperty.Name; string categoryName = attribute.Category ?? "Default"; CCategoryInfo category = new CCategoryInfo() { Name = categoryName, Priority = attribute.CategoryPriority }; CObjectFunction objectFunction = new CObjectFunction(name, category, instance, KlaxProperty); properties.properties.Add(objectFunction); } } return(properties); }
public CObjectFunction(string name, CCategoryInfo category, object target, MethodInfo KlaxProperty) { Name = name; Category = category; Function = (Action)Delegate.CreateDelegate(typeof(Action), target, KlaxProperty); }