void GetControlProperty(ControlInfo _CurrentControlInfo, PropertyInfoAttribute pia) { //-->哪个控件,哪个属性 //PropertyInfoAttribute pia = v as PropertyInfoAttribute; if (null == pia) { return; } //-->得到选中的控件 string controlName = string.Format("{0}|{1}", _CurrentControlInfo.Name, pia.Name); if (_DictResult.ContainsKey(controlName)) { return; } string dataType = "varchar"; MetaDataInfo mdi = this.IDesignFramework.GetMetaDataInfoByTableName(_CurrentControlInfo.MetaData); if (null == mdi) { var controlObj = _CurrentPageControl.FindName(_CurrentControlInfo.Name); if (null != controlObj) { var pi = controlObj.GetType().GetProperty(pia.Name); dataType = pi != null ? pi.PropertyType.FullName : dataType; } } else { MetaDataColumnInfo mdci = mdi.Item.Where(p => p.column_name.Equals(_CurrentControlInfo.ColumnName)).GetFirst <MetaDataColumnInfo>(); } _DictResult.Add(controlName, dataType); }
void btnRight_Click(object sender, RoutedEventArgs e) { //-->哪个控件,哪个属性 PropertyInfoAttribute pia = pftm.SelectedControlProperty; var _CurrentControlInfo = pftm.SelectedControlInfo; GetControlProperty(_CurrentControlInfo, pia); BindResultControl(); }
public void CreateProperty <T, TProperty>(Expression <Func <T, TProperty> > propertyExpr) where T : CrmPlusPlusEntity, new() { var entityName = EntityNameAttribute.GetFromType <T>(); var propertyName = PropertyNameAttribute.GetFromType(propertyExpr); var propertyInfo = PropertyInfoAttribute.GetFromType(propertyExpr); var attributes = ((MemberExpression)propertyExpr.Body).Member.GetCustomAttributes(true); CreateProperty(entityName, typeof(TProperty), attributes, propertyName, propertyInfo); }
static PropertyInfoAttribute GetDependencyProperty(UIElement ui, DependencyProperty dp, string description) { PropertyInfoAttribute pia = new PropertyInfoAttribute(); Type tt = dp.GetType(); pia.Name = tt.Name; pia.Source = ui; pia.Description = description; pia.DataType = tt; pia.DefaultValue = ui.GetValue(dp); return(pia); }
static PropertyInfoAttribute GetPropertyInfoAttribute(UIElement ui, Type tt, string propertyName, string description) { PropertyInfoAttribute pia = new PropertyInfoAttribute(); PropertyInfo pi = tt.GetProperty(propertyName); if (null == pi) { return(null); } pia.Name = propertyName; pia.Description = description; pia.DataType = pi.PropertyType; pia.DefaultValue = pi.GetValue(ui, null); return(pia); }
/// <summary> /// Gets the properties marked with the PropertyInfoAttribute. /// </summary> /// <param name="pluginType">The plugin type.</param> /// <returns></returns> public static PropertyInfoAttribute[] GetProperties(Type pluginType) { List <PropertyInfoAttribute> propertyInfos = new List <PropertyInfoAttribute>(); foreach (PropertyInfo pInfo in pluginType.GetProperties()) { PropertyInfoAttribute[] attributes = (PropertyInfoAttribute[])pInfo.GetCustomAttributes(typeof(PropertyInfoAttribute), false); if (attributes.Length == 1) { PropertyInfoAttribute attr = attributes[0]; attr.PropertyName = pInfo.Name; attr.PluginType = pluginType; attr.PropertyInfo = pInfo; propertyInfos.Add(attr); } } return(propertyInfos.ToArray()); }
/// <summary> /// /// </summary> /// <param name="ui"></param> /// <returns></returns> public static List <PropertyInfoAttribute> CommonPropertyItem(UIElement ui) { List <PropertyInfoAttribute> item = new List <PropertyInfoAttribute>(); Type tt = ui.GetType(); ControlConfig cc = ParseControlConfig.GetControlConfig(tt.Name); if (null == cc) { return(item); } FrameworkElement fe = ui as FrameworkElement; foreach (var v in cc.DictProperty) { //string[] a = v.Split(';'); PropertyInfoAttribute pia = GetPropertyInfoAttribute(ui, tt, v.Key, v.Value); item.Add(pia); } return(item); }
private Core.PropertyInfo MakeWritableStaticProperty(FieldInfo field, PropertyInfoAttribute attribute, Func <Entity, ulong> getEntityAddress, Func <EntityLink, Core.EntityLink> convertEntityLink) { if (attribute.Container == Core.ContainerType.StaticArray && attribute.ArraySize == 1) { return(PropertyInfoFactory.MakeStaticArrayProperty(field.Name, attribute.Type, ConvertValueToFox(attribute.Type, getEntityAddress, convertEntityLink, field.GetValue(this)))); } if (attribute.Container == Core.ContainerType.StaticArray) { var values = from value in (field.GetValue(this) as IList).Cast <object>() select ConvertValueToFox(attribute.Type, getEntityAddress, convertEntityLink, value); return(PropertyInfoFactory.MakeStaticArrayProperty(field.Name, attribute.Type, values.ToArray())); } if (attribute.Container == Core.ContainerType.DynamicArray) { var values = from value in (field.GetValue(this) as IList).Cast <object>() select ConvertValueToFox(attribute.Type, getEntityAddress, convertEntityLink, value); return(PropertyInfoFactory.MakeDynamicArrayProperty(field.Name, attribute.Type, values.ToArray())); } if (attribute.Container == Core.ContainerType.List) { var values = from value in (field.GetValue(this) as IList).Cast <object>() select ConvertValueToFox(attribute.Type, getEntityAddress, convertEntityLink, value); return(PropertyInfoFactory.MakeListProperty(field.Name, attribute.Type, values.ToArray())); } if (attribute.Container == Core.ContainerType.StringMap) { var enumerableDictionary = IDictionaryToIEnumerable(field.GetValue(this) as IDictionary); var dict = enumerableDictionary.ToDictionary( entry => entry.Key as string, entry => ConvertValueToFox(attribute.Type, getEntityAddress, convertEntityLink, entry.Value)); return(PropertyInfoFactory.MakeStringMapProperty(field.Name, attribute.Type, dict)); } Assert.IsTrue(false, "Invalid container."); return(null); }
/// <summary> /// 读取控件属性 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="ui"></param> /// <param name="ei"></param> /// <returns></returns> public static T GetControlAttribute <T>(UIElement ui, MemberInfo ei) where T : BaseAttribute { T eia = default(T); foreach (var v in ei.GetCustomAttributes(true)) { if (!(v is T)) { continue; } eia = (T)v; eia.Source = ui; eia.Name = ei.Name; if (v is PropertyInfoAttribute) { PropertyInfoAttribute pia = v as PropertyInfoAttribute; PropertyInfo pi = ui.GetType().GetProperty(ei.Name); eia.DefaultValue = pi.GetValue(ui, null); pia.DataType = pi.PropertyType; } break; } return(eia); }
private void CreateProperty(string entityName, Type propertyType, IEnumerable <object> attributes, string propertyName, PropertyInfoAttribute info) { var createAttributeRequest = new CreateAttributeRequest() { EntityName = entityName }; if (propertyType == typeof(string)) { var attrInfo = attributes.SingleOrDefault(attr => attr.GetType() == typeof(StringAttribute)); if (attrInfo != null) { var stringInfo = (StringAttribute)attrInfo; createAttributeRequest.Attribute = new StringAttributeMetadata { SchemaName = propertyName, RequiredLevel = new AttributeRequiredLevelManagedProperty(info.AttributeRequiredLevel), DisplayName = info.DisplayName.ToLabel(), Description = info.Description.ToLabel(), MaxLength = stringInfo.MaxLength, FormatName = stringInfo.StringFormat }; service.Execute(createAttributeRequest); } } else if (propertyType == typeof(bool)) { var attrInfo = attributes.SingleOrDefault(attr => attr.GetType() == typeof(BooleanAttribute)); if (attrInfo != null) { var booleanAttr = (BooleanAttribute)attrInfo; createAttributeRequest.Attribute = new BooleanAttributeMetadata { SchemaName = propertyName, RequiredLevel = new AttributeRequiredLevelManagedProperty(info.AttributeRequiredLevel), DisplayName = info.DisplayName.ToLabel(), Description = info.Description.ToLabel(), OptionSet = new BooleanOptionSetMetadata( new OptionMetadata("True".ToLabel(), 1), new OptionMetadata("False".ToLabel(), 0)), }; } service.Execute(createAttributeRequest); } else if (propertyType == typeof(DateTime)) { var attrInfo = attributes.SingleOrDefault(attr => attr.GetType() == typeof(DateTimeAttribute)); if (attrInfo != null) { var dateTimeInfo = (DateTimeAttribute)attrInfo; createAttributeRequest.Attribute = new DateTimeAttributeMetadata { SchemaName = propertyName, RequiredLevel = new AttributeRequiredLevelManagedProperty(info.AttributeRequiredLevel), DisplayName = info.DisplayName.ToLabel(), Description = info.Description.ToLabel(), Format = dateTimeInfo.Format, ImeMode = dateTimeInfo.ImeMode }; } service.Execute(createAttributeRequest); } else if (propertyType == typeof(decimal)) { var attrInfo = attributes.SingleOrDefault(attr => attr.GetType() == typeof(DecimalAttribute)); if (attrInfo != null) { var decimalInfo = (DecimalAttribute)attrInfo; createAttributeRequest.Attribute = new DecimalAttributeMetadata { SchemaName = propertyName, RequiredLevel = new AttributeRequiredLevelManagedProperty(info.AttributeRequiredLevel), DisplayName = info.DisplayName.ToLabel(), Description = info.Description.ToLabel(), MaxValue = decimalInfo.MaxValue, MinValue = decimalInfo.MinValue, Precision = decimalInfo.Precision }; } service.Execute(createAttributeRequest); } else if (propertyType == typeof(double)) { var attrInfo = attributes.SingleOrDefault(attr => attr.GetType() == typeof(DoubleAttribute)); if (attrInfo != null) { var decimalInfo = (DoubleAttribute)attrInfo; createAttributeRequest.Attribute = new DoubleAttributeMetadata { SchemaName = propertyName, RequiredLevel = new AttributeRequiredLevelManagedProperty(info.AttributeRequiredLevel), DisplayName = info.DisplayName.ToLabel(), Description = info.Description.ToLabel(), MaxValue = decimalInfo.MaxValue, MinValue = decimalInfo.MinValue, Precision = decimalInfo.Precision }; } service.Execute(createAttributeRequest); } else if (propertyType == typeof(int)) { var attrInfo = attributes.SingleOrDefault(attr => attr.GetType() == typeof(IntegerAttribute)); if (attrInfo != null) { var integerInfo = (IntegerAttribute)attrInfo; createAttributeRequest.Attribute = new IntegerAttributeMetadata { SchemaName = propertyName, RequiredLevel = new AttributeRequiredLevelManagedProperty(info.AttributeRequiredLevel), DisplayName = info.DisplayName.ToLabel(), Description = info.Description.ToLabel(), MaxValue = integerInfo.MaxValue, MinValue = integerInfo.MinValue, Format = integerInfo.Format }; } service.Execute(createAttributeRequest); } else if (propertyType.IsEnum) { var attrInfo = attributes.SingleOrDefault(attr => attr.GetType() == typeof(OptionSetAttribute)); if (attrInfo != null) { var options = new OptionMetadataCollection(); foreach (var value in Enum.GetValues(propertyType)) { options.Add(new OptionMetadata(value.ToString().ToLabel(), (int)value)); } createAttributeRequest.Attribute = new PicklistAttributeMetadata { SchemaName = propertyName, RequiredLevel = new AttributeRequiredLevelManagedProperty(info.AttributeRequiredLevel), DisplayName = info.DisplayName.ToLabel(), Description = info.Description.ToLabel(), OptionSet = new OptionSetMetadata(options) { IsGlobal = false, DisplayName = info.DisplayName.ToLabel(), Description = info.Description.ToLabel(), IsCustomOptionSet = true, OptionSetType = OptionSetType.Picklist, Name = propertyName } }; service.Execute(createAttributeRequest); } } }
void lboxProperty_SelectionChanged(object sender, SelectionChangedEventArgs e) { _SelectedControlProperty = lboxProperty.SelectedItem as PropertyInfoAttribute; _SelectionPropertyMethod(this, e); }
/// <summary> /// Generate a single Connector of this Plugin. /// </summary> /// <param name="propertyInfoAttribute"></param> internal void generateConnector(PropertyInfoAttribute propertyInfoAttribute) { if (propertyInfoAttribute.Direction.Equals(Direction.InputData)) { ConnectorModel connectorModel = new ConnectorModel(); connectorModel.Caption = propertyInfoAttribute.Caption; connectorModel.ConnectorType = propertyInfoAttribute.PropertyInfo.PropertyType; connectorModel.WorkspaceModel = WorkspaceModel; connectorModel.PluginModel = this; connectorModel.IsMandatory = propertyInfoAttribute.Mandatory; connectorModel.PropertyName = propertyInfoAttribute.PropertyName; connectorModel.Name = propertyInfoAttribute.PropertyName; connectorModel.ToolTip = propertyInfoAttribute.ToolTip; connectorModel.IControl = false; connectorModel.PluginModel.Plugin.PropertyChanged += connectorModel.PropertyChangedOnPlugin; InputConnectors.Add(connectorModel); WorkspaceModel.AllConnectorModels.Add(connectorModel); } else if (propertyInfoAttribute.Direction.Equals(Direction.ControlSlave)) { ConnectorModel connectorModel = new ConnectorModel(); connectorModel.Caption = propertyInfoAttribute.Caption; connectorModel.ConnectorType = propertyInfoAttribute.PropertyInfo.PropertyType; connectorModel.WorkspaceModel = WorkspaceModel; connectorModel.PluginModel = this; connectorModel.IsMandatory = propertyInfoAttribute.Mandatory; connectorModel.PropertyName = propertyInfoAttribute.PropertyName; connectorModel.Name = propertyInfoAttribute.PropertyName; connectorModel.ToolTip = propertyInfoAttribute.ToolTip; connectorModel.IControl = true; connectorModel.PluginModel.Plugin.PropertyChanged += connectorModel.PropertyChangedOnPlugin; InputConnectors.Add(connectorModel); WorkspaceModel.AllConnectorModels.Add(connectorModel); } else if (propertyInfoAttribute.Direction.Equals(Direction.OutputData)) { ConnectorModel connectorModel = new ConnectorModel(); connectorModel.Caption = propertyInfoAttribute.Caption; connectorModel.ConnectorType = propertyInfoAttribute.PropertyInfo.PropertyType; connectorModel.WorkspaceModel = WorkspaceModel; connectorModel.PluginModel = this; connectorModel.IsMandatory = propertyInfoAttribute.Mandatory; connectorModel.PropertyName = propertyInfoAttribute.PropertyName; connectorModel.Name = propertyInfoAttribute.PropertyName; connectorModel.ToolTip = propertyInfoAttribute.ToolTip; connectorModel.Outgoing = true; connectorModel.IControl = false; connectorModel.PluginModel.Plugin.PropertyChanged += connectorModel.PropertyChangedOnPlugin; OutputConnectors.Add(connectorModel); WorkspaceModel.AllConnectorModels.Add(connectorModel); } else if (propertyInfoAttribute.Direction.Equals(Direction.ControlMaster)) { ConnectorModel connectorModel = new ConnectorModel(); connectorModel.Caption = propertyInfoAttribute.Caption; connectorModel.ConnectorType = propertyInfoAttribute.PropertyInfo.PropertyType; connectorModel.WorkspaceModel = WorkspaceModel; connectorModel.PluginModel = this; connectorModel.IsMandatory = propertyInfoAttribute.Mandatory; connectorModel.PropertyName = propertyInfoAttribute.PropertyName; connectorModel.Name = propertyInfoAttribute.PropertyName; connectorModel.ToolTip = propertyInfoAttribute.ToolTip; connectorModel.Outgoing = true; connectorModel.IControl = true; connectorModel.PluginModel.Plugin.PropertyChanged += connectorModel.PropertyChangedOnPlugin; OutputConnectors.Add(connectorModel); WorkspaceModel.AllConnectorModels.Add(connectorModel); } }