public bool Generate <TContainer, TValue>(FieldInfo fieldInfo, ReflectedPropertyBag <TContainer> propertyBag) { if (!typeof(TContainer).IsValueType) { return(false); } if (!fieldInfo.FieldType.IsValueType) { return(false); } if (!UnsafeUtility.IsBlittable(fieldInfo.FieldType) && fieldInfo.FieldType != typeof(char)) { return(false); } var propertyType = typeof(UnmanagedProperty <,>).MakeGenericType(typeof(TContainer), fieldInfo.FieldType); var property = Activator.CreateInstance(propertyType, fieldInfo.Name, UnsafeUtility.GetFieldOffset(fieldInfo), null != fieldInfo.GetCustomAttribute <ReadOnlyAttribute>(), new PropertyAttributeCollection(fieldInfo.GetCustomAttributes().ToArray())); propertyBag.AddProperty <IProperty <TContainer, TValue>, TValue>((IProperty <TContainer, TValue>)property); return(true); }
public bool Generate <TContainer, TValue>(FieldInfo field, ReflectedPropertyBag <TContainer> propertyBag) { if (typeof(IList).IsAssignableFrom(typeof(TValue))) { var elementType = typeof(TValue).GetGenericArguments()[0]; var method = typeof(ReflectedFieldPropertyGenerator).GetMethod(nameof(GenerateListProperty), BindingFlags.Instance | BindingFlags.NonPublic); var genericMethod = method.MakeGenericMethod(typeof(TContainer), field.FieldType, elementType); genericMethod.Invoke(this, new object[] { field, propertyBag }); } else { propertyBag.AddProperty <ReflectedFieldProperty <TContainer, TValue>, TValue>( new ReflectedFieldProperty <TContainer, TValue>(field)); } return(true); }