public void Initialize(PropertyMapperConfig config) { Config = config; // Create accessor for the column property var columnProp = typeof(IGenericColumns).GetProperty(config.Column); if (columnProp == null || columnProp.PropertyType != typeof(TColumn)) { throw new ArgumentException($"Column not found or type mismatch {config.PropertyName}"); } ColumnAccessor = ReflectionTool.PropertyAccessor <IGenericColumns, TColumn>(columnProp); // Retrieve and validate properties var objectProp = TargetType.GetProperty(config.PropertyName); if (objectProp == null) { throw new ArgumentException($"Target type {TargetType.Name} does not have a property {config.PropertyName}"); } // Create delegates for the object property as well ObjectAccessor = CreatePropertyAccessor(objectProp); }
/// <summary> /// 创建公共成员 /// </summary> protected void CreateCommonMember() { PropertyInfo[] propertiesSource = SourceType.GetProperties(); foreach (PropertyInfo propSource in propertiesSource) { PropertyInfo propDest = TargetType.GetProperty(propSource.Name); if (propDest != null) { // 检查是否已存在或被忽略。 bool ignorePropDest = _propertiesToIgnore.Exists(x => x.Name == propDest.Name) || PropertiesMapping.Exists(x => GetPropertyInfo(x.Item2).Name == propDest.Name); if (propDest.CanWrite && !ignorePropDest) { Type sourceType = propSource.PropertyType; Type destType = propDest.PropertyType; bool isList = IsListOf(destType); if (isList) { sourceType = TypeSystem.GetElementType(propSource.PropertyType); destType = TypeSystem.GetElementType(propDest.PropertyType); } var canCreateConfig = CanCreateConfig(sourceType, destType); if (canCreateConfig.CanCreate) { // 只创造现有的关系 Expression expSource = Expression.MakeMemberAccess(paramClassSource, propSource); ParameterExpression paramDest = Expression.Parameter(TargetType, "t"); Expression expDest = Expression.MakeMemberAccess(paramDest, propDest); PropertiesMapping.Add(Tuple.Create(expSource, expDest, false, canCreateConfig.MapperName)); } } } } }
/// <summary> /// checks rule is valid /// </summary> internal void RuleIsValid() { if (string.IsNullOrEmpty(TargetKey)) { throw new ArgumentNullException($"{nameof(TargetKey)} must not be null"); } if (string.IsNullOrEmpty(PrimaryKey)) { throw new ArgumentNullException($"{nameof(PrimaryKey)} must not be null"); } var type = typeof(TEntity); if (type.GetProperty(PrimaryKey) == null) { throw new ArgumentException($"{type.Name} primary key is not found"); } if (TargetType.GetProperty(TargetKey) == null) { throw new ArgumentException($"{TargetType.Name} relation key is not found"); } else { //check targetkey is struct } }
public Type GetObjectType() { System.Reflection.PropertyInfo pInfo = TargetType.GetProperty(TargetProperty, BindingFlags.Static | BindingFlags.Public); if (pInfo == null) { throw new MissingMemberException(TargetType.ToString(), TargetProperty); } return(pInfo.PropertyType); }
public virtual void SetTargetPropertyValue(string name, object value) { var propInfo = TargetType.GetProperty(name); if (propInfo == null || !propInfo.CanWrite) { return; } propInfo.SetValue(Target, value, null); }
public virtual object GetTargetPropertyValue(string name) { var propInfo = TargetType.GetProperty(name); if (!propInfo.CanRead) { return(BindingInfo.DoNothing); } return(propInfo != null?propInfo.GetValue(Target, null) : null); }
/// <summary> /// Provides the implementation for operations that set a value by index. Classes derived from the <see cref="T:System.Dynamic.DynamicObject" /> class can override this method to specify dynamic behavior for operations that access objects by a specified index. /// </summary> /// <param name="binder">Provides information about the operation.</param> /// <param name="indexes">The indexes that are used in the operation. For example, for the sampleObject[3] = 10 operation in C# (sampleObject(3) = 10 in Visual Basic), where sampleObject is derived from the <see cref="T:System.Dynamic.DynamicObject" /> class, <paramref name="indexes[0]" /> is equal to 3.</param> /// <param name="value">The value to set to the object that has the specified index. For example, for the sampleObject[3] = 10 operation in C# (sampleObject(3) = 10 in Visual Basic), where sampleObject is derived from the <see cref="T:System.Dynamic.DynamicObject" /> class, <paramref name="value" /> is equal to 10.</param> /// <returns> /// true if the operation is successful; otherwise, false. If this method returns false, the run-time binder of the language determines the behavior. (In most cases, a language-specific run-time exception is thrown. /// </returns> public override bool TrySetIndex(System.Dynamic.SetIndexBinder binder, object[] indexes, object value) { try { PropertyInfo prop = TargetType.GetProperty("Item", AccessFlags); prop.SetValue(Target, value, indexes); return(true); } catch (Exception) { return(base.TrySetIndex(binder, indexes, value)); } }
/// <summary> /// Initialize the type strategy /// </summary> public override void Initialize(ProductLinkConfiguration config) { base.Initialize(config); var property = TargetType.GetProperty(PropertyName); var linkType = property.PropertyType; // Extract element type from collections if (typeof(IEnumerable <IProductPartLink>).IsAssignableFrom(linkType)) { linkType = linkType.GetGenericArguments()[0]; } EntityMapper.Initialize(linkType, Config); }
protected override void OnSelectedPropertyChanged() { base.OnSelectedPropertyChanged(); if (this.Model.DummyObject == null || this.TargetType == null) { this.ValueSetter?.Dispose(); this.ValueSetter = null; return; } if (this.SelectedProperty == null) { return; } var pi = TargetType.GetProperty(SelectedProperty.Name); var attr = pi.GetAttribute <DesignElementAttribute>(); this.ValueSetter?.Dispose(); if (string.IsNullOrEmpty(attr.Key)) { this.ValueSetter = SetterManager.CreateSetter(this.Model.DummyObject, pi); } else { this.ValueSetter = SetterManager.CreateSetter(this.Model.DummyObject, pi, attr.Key); } if (this.ValueSetter != null) { (this.ValueSetter as FrameworkElement).Width = 150; if (this.ValueSetter is ValueBoxSetter vBoxSetter) { vBoxSetter.Foreground = Brushes.Black; vBoxSetter.Background = Brushes.Transparent; } BindingHelper.SetBinding( this.ValueSetter as BaseSetter, BaseSetter.ValueProperty, this.Model.ValueBinder, PBinder.DirectValueProperty); } }
/// <summary> /// Provides the implementation for operations that get a value by index. Classes derived from the <see cref="T:System.Dynamic.DynamicObject" /> class can override this method to specify dynamic behavior for indexing operations. /// </summary> /// <param name="binder">Provides information about the operation.</param> /// <param name="indexes">The indexes that are used in the operation. For example, for the sampleObject[3] operation in C# (sampleObject(3) in Visual Basic), where sampleObject is derived from the DynamicObject class, <paramref name="indexes[0]" /> is equal to 3.</param> /// <param name="result">The result of the index operation.</param> /// <returns> /// true if the operation is successful; otherwise, false. If this method returns false, the run-time binder of the language determines the behavior. (In most cases, a run-time exception is thrown.) /// </returns> public override bool TryGetIndex(System.Dynamic.GetIndexBinder binder, object[] indexes, out object result) { try { PropertyInfo prop = TargetType.GetProperty("Item", AccessFlags); result = prop.GetValue(Target, indexes); if (WrapReturn) { result = new DynamicReflector(result) { WrapReturn = this.WrapReturn }; } return(true); } catch (Exception) { return(base.TryGetIndex(binder, indexes, out result)); } }
protected TagsHelper ViewConfig(string properyt) { return(new TagsHelper(properyt, ViewPortDescriptors, TargetType, TargetType.GetProperty(properyt))); }
/// <summary> /// 视图配置,界面显示 /// </summary> /// <param name="properyt">实体字段名称</param> /// <returns></returns> protected TagsHelper ViewConfig(string properyt) { return(new TagsHelper(properyt, ref _htmlTags, TargetType, TargetType.GetProperty(properyt))); }
protected TagsHelper AttrConfig(string prop) { return(new TagsHelper(prop, ContextDescriptors, TargetType, TargetType.GetProperty(prop))); }
public virtual Type GetTargetPropertyType(string name) { var propInfo = TargetType.GetProperty(name); return(propInfo != null ? propInfo.PropertyType : null); }