浏览代码

Added new version of CoreUtils.GetPropertyValue

Kenric Nugteren 2 周之前
父节点
当前提交
100591d83b
共有 2 个文件被更改,包括 9 次插入0 次删除
  1. 7 0
      InABox.Core/CoreUtils.cs
  2. 2 0
      InABox.Core/DatabaseSchema/DatabaseSchema.cs

+ 7 - 0
InABox.Core/CoreUtils.cs

@@ -831,6 +831,13 @@ namespace InABox.Core
             return GetPropertyValue(o, string.Join(".", comps));
         }
 
+        public static TValue GetPropertyValue<T, TValue>(T obj, Expression<Func<T, TValue>> property)
+            where T : BaseObject
+        {
+            var prop = DatabaseSchema.PropertyStrict(property);
+            return (TValue)prop.Getter()(obj);
+        }
+
         /// <summary>
         /// Gets the value of the object's given property.
         /// </summary>

+ 2 - 0
InABox.Core/DatabaseSchema/DatabaseSchema.cs

@@ -437,6 +437,8 @@ namespace InABox.Core
             Property(type, name) ?? throw new PropertyNotFoundException(type, name);
         public static IProperty PropertyStrict<T>(Expression<Func<T, object?>> expression) =>
             Property(expression) ?? throw new PropertyNotFoundException(typeof(T), CoreUtils.GetFullPropertyName(expression, "."));
+        public static IProperty PropertyStrict<T, TType>(Expression<Func<T, TType>> expression) =>
+            Property(expression) ?? throw new PropertyNotFoundException(typeof(T), CoreUtils.GetFullPropertyName(expression, "."));
 
         public class PropertyNotFoundException : Exception
         {