void CreatePropertyFromFieldInfo <TContainer, TValue>(FieldInfo field, ReflectedPropertyBag <TContainer> propertyBag) { for (var index = m_Generators.Count - 1; index >= 0; index--) { var generator = m_Generators[index]; if (!generator.Generate <TContainer, TValue>(field, propertyBag)) { continue; } break; } }
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); }
public bool Generate <TContainer, TValue>(FieldInfo field, ReflectedPropertyBag <TContainer> propertyBag) { if (!typeof(TContainer).IsValueType) { return(false); } if (!UnsafeUtility.IsBlittable(field.FieldType)) { return(false); } var propertyType = typeof(UnmanagedProperty <,>).MakeGenericType(typeof(TContainer), field.FieldType); var property = Activator.CreateInstance(propertyType, field.Name, UnsafeUtility.GetFieldOffset(field), new PropertyAttributeCollection(field.GetCustomAttributes().ToArray())); propertyBag.AddProperty <IProperty <TContainer, TValue>, TValue>((IProperty <TContainer, TValue>)property); return(true); }
public IPropertyBag <TContainer> Generate <TContainer>() { if (typeof(TContainer).IsEnum) { return(null); } var propertyBag = new ReflectedPropertyBag <TContainer>(); var fields = typeof(TContainer).GetFields(BindingFlags.Public | BindingFlags.Instance); foreach (var field in fields) { var method = m_CreatePropertyMethod.MakeGenericMethod(typeof(TContainer), field.FieldType); method.Invoke(this, new object[] { field, propertyBag }); } return(propertyBag); }
public IPropertyBag <TContainer> Generate <TContainer>() { if (typeof(TContainer).IsEnum) { return(null); } var propertyBag = new ReflectedPropertyBag <TContainer>(); var fields = typeof(TContainer).GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic); foreach (var field in fields) { if (field.IsPrivate && field.GetCustomAttribute <PropertyAttribute>() == null) { continue; } var method = m_CreatePropertyFromFieldInfoMethod.MakeGenericMethod(typeof(TContainer), field.FieldType); method.Invoke(this, new object[] { field, propertyBag }); } var properties = typeof(TContainer).GetProperties(BindingFlags.Public | BindingFlags.Instance); foreach (var property in properties) { if (property.GetCustomAttribute <PropertyAttribute>() == null) { continue; } var method = m_CreatePropertyFromPropertyInfoMethod.MakeGenericMethod(typeof(TContainer), property.PropertyType); method.Invoke(this, new object[] { property, propertyBag }); } return(propertyBag); }
public bool Generate <TContainer, TValue>(PropertyInfo propertyInfo, ReflectedPropertyBag <TContainer> propertyBag) { // Can't do unmanaged C# properties. return(false); }
private void GenerateListProperty <TContainer, TValue, TElement>(FieldInfo field, ReflectedPropertyBag <TContainer> propertyBag) where TValue : IList <TElement> { propertyBag.AddCollectionProperty <ReflectedListProperty <TContainer, TValue, TElement>, TValue>( new ReflectedListProperty <TContainer, TValue, TElement>(field)); }