public HowTo_Read_DataObject_Property_Attributes() { //<document> OGen.NTier.lib.datalayer.DOPropertyAttribute _attribute = (OGen.NTier.lib.datalayer.DOPropertyAttribute)Attribute.GetCustomAttribute( typeof(OGen.NTier.UTs.lib.datalayer.proxy.SO_User).GetProperty("IDUser"), typeof(OGen.NTier.lib.datalayer.DOPropertyAttribute), true ); Console.WriteLine( "name:{0}; isPK:{1}; isIdentity:{2}; DefaultValue:{3};", _attribute.Name, _attribute.isPK, _attribute.isIdentity, _attribute.DefaultValue, // many other properties available, like: _attribute.AditionalInfo, _attribute.DefaultValue, _attribute.ExtendedDescription, _attribute.FK_FieldName, _attribute.FK_TableName, _attribute.FriendlyName, _attribute.isBool, _attribute.isConfig_Config, _attribute.isConfig_Datatype, _attribute.isConfig_Name, _attribute.isDateTime, _attribute.isDecimal, _attribute.isInt, _attribute.isListItemText, _attribute.isListItemValue, _attribute.isNullable, _attribute.isText, _attribute.Size ); //</document> }
public HowTo_Read_and_Write_to_DataObject_Properties() { //<document> OGen.NTier.UTs.lib.datalayer.DO_User _user = new OGen.NTier.UTs.lib.datalayer.DO_User(); _user.Fields.IDUser = 123; _user.Fields.Login = "******"; _user.Fields.Password = "******"; System.Reflection.PropertyInfo[] _properties = typeof(OGen.NTier.UTs.lib.datalayer.proxy.SO_User).GetProperties( System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance ); for (int _prop = 0; _prop < _properties.Length; _prop++) { if (Attribute.IsDefined( _properties[_prop], typeof(OGen.NTier.lib.datalayer.DOPropertyAttribute) )) { Console.Write( "{0}: ", _properties[_prop].Name ); Attribute[] _attributes = Attribute.GetCustomAttributes( _properties[_prop], typeof(OGen.NTier.lib.datalayer.DOPropertyAttribute), true ); for (int _att = 0; _att < _attributes.Length; _att++) { //if (_attributes[_att].GetType() == typeof(DOPropertyAttribute)) { OGen.NTier.lib.datalayer.DOPropertyAttribute _attribute = (OGen.NTier.lib.datalayer.DOPropertyAttribute)_attributes[_att]; Console.Write( "name:{0}; isPK:{1}; isIdentity:{2}; DefaultValue:{3}; ", _attribute.Name, _attribute.isPK, _attribute.isIdentity, _attribute.DefaultValue ); //} } Console.Write( "value: {0}; ", _properties[_prop].GetValue(_user.Fields, null) ); _properties[_prop].SetValue( _user.Fields, Convert.ChangeType( 456, _properties[_prop].PropertyType ), null ); Console.WriteLine( "new value: {0}", _properties[_prop].GetValue(_user.Fields, null) ); } } //</document> }
public HowTo_List_DataObjects() { //<document> System.Reflection.Assembly _assembly = System.Reflection.Assembly.Load( #if NET_1_1 "OGen.NTier.UTs.lib.datalayer-1.1" #elif NET_2_0 "OGen.NTier.UTs.lib.datalayer-2.0" #endif ); if (_assembly != null) { Type[] _types = _assembly.GetTypes(); for (int _tp = 0; _tp < _types.Length; _tp++) { Type _type = (Type)_types[_tp]; object[] _doclassattributes = _type.GetCustomAttributes( typeof(OGen.NTier.lib.datalayer.DOClassAttribute), true//false ); if ( (_doclassattributes.Length > 0) && (_type.Name.IndexOf("DO0_") != 0) ) { Console.Write("{0}; ", _type.Name); for (int _catt = 0; _catt < _doclassattributes.Length; _catt++) { OGen.NTier.lib.datalayer.DOClassAttribute _classattribute = (OGen.NTier.lib.datalayer.DOClassAttribute)_doclassattributes[_catt]; Console.WriteLine( "name: {0}; isVirtualTable: {1}; isConfig: {2}; ", _classattribute.Name, _classattribute.isVirtualTable, _classattribute.isConfig ); System.Reflection.PropertyInfo[] _properties = _type.GetProperties( System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance ); for (int _prop = 0; _prop < _properties.Length; _prop++) { if (Attribute.IsDefined( _properties[_prop], typeof(OGen.NTier.lib.datalayer.DOPropertyAttribute) )) { Console.Write( "\t{0}: ", _properties[_prop].Name ); Attribute[] _attributes = Attribute.GetCustomAttributes( _properties[_prop] //, typeof(DOPropertyAttribute) //, true ); //Console.WriteLine("Name \t isPK \t isIdentity \t DefaultValue \t \t \t \t isBool"); for (int _att = 0; _att < _attributes.Length; _att++) { //if (_attributes[_att].GetType() == typeof(DOPropertyAttribute)) { OGen.NTier.lib.datalayer.DOPropertyAttribute _propertyattribute = (OGen.NTier.lib.datalayer.DOPropertyAttribute)_attributes[_att]; Console.Write( "name:{0}; isPK:{1}; isIdentity:{2}; isText:{3};", _propertyattribute.Name, _propertyattribute.isPK, _propertyattribute.isIdentity, //att3.DefaultValue, //att3.isConfig_Name, //att3.isConfig_Config, //att3.isConfig_Datatype, _propertyattribute.isText ); //} } Console.WriteLine(); } } Console.WriteLine(); } } } } //</document> }