本文整理汇总了C#中System.GetProperties方法的典型用法代码示例。如果您正苦于以下问题:C# System.GetProperties方法的具体用法?C# System.GetProperties怎么用?C# System.GetProperties使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System
的用法示例。
在下文中一共展示了System.GetProperties方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Search
public Search(Dictionary<string, string> searchTerms, System.Type type, FormStorage<bool> storage)
{
_searchTerms = searchTerms;
_storage = storage;
_searchList = new BindingList<string>();
InitializeComponent();
List<string> list = type.GetProperties().Select(p => p.Name).ToList();
this.comboCriteria.DataSource = type.GetProperties().Select(p => p.Name).ToList();
this.listSearchTerms.DataSource = _searchList;
this.buttonRemove.Enabled = false;
}
示例2: PersistentInfo
public static IEnumerable<DeclaredPersistentProperty> PersistentInfo(System.Type @class, IEnumerable<Property> properties, bool includeEmbedded)
{
// a persistent property can be anything including a noop "property" declared in the mapping
// for query only. In this case I will apply some trick to get the MemberInfo.
var candidateMembers =
@class.GetFields(DefaultBindingFlags).Concat(@class.GetProperties(DefaultBindingFlags).Cast<MemberInfo>()).ToList();
var candidateMembersNames = candidateMembers.Select(m => m.Name).ToList();
foreach (var property in properties)
{
if(includeEmbedded && property.PropertyAccessorName=="embedded")
yield return new DeclaredPersistentProperty(property, DeclaredPersistentProperty.NotAvailableMemberInfo);
var exactMemberIdx = candidateMembersNames.IndexOf(property.Name);
if (exactMemberIdx >= 0)
{
// No metter which is the accessor the audit-attribute should be in the property where available and not
// to the member used to read-write the value. (This method work even for access="field").
yield return new DeclaredPersistentProperty(property, candidateMembers[exactMemberIdx]);
}
else
{
// try to find the field using field-name-strategy
//
// This part will run for:
// 1) query only property (access="none" or access="noop")
// 2) a strange case where the element <property> is declared with a "field.xyz" but only a field is used in the class. (Only God may know way)
var exactFieldIdx = GetMemberIdxByFieldNamingStrategies(candidateMembersNames, property);
if (exactFieldIdx >= 0)
{
yield return new DeclaredPersistentProperty(property, candidateMembers[exactFieldIdx]);
}
}
}
}
示例3: GetInterfaceProperties
private static List<PropertyInfo> GetInterfaceProperties(System.Type interfaceToReflect, List<PropertyInfo> properties)
{
var interfaces = interfaceToReflect.GetInterfaces();
foreach (var inter in interfaces)
{
properties.AddRange(GetInterfaceProperties(inter, properties));
}
properties.AddRange(interfaceToReflect.GetProperties(BindingFlags.Public | BindingFlags.Instance).ToList());
return properties.Distinct().OrderBy(i => i.Name).ToList();
}
示例4: searchForRevisionInfoCfgInProperties
private void searchForRevisionInfoCfgInProperties(System.Type t, ref bool revisionNumberFound,
ref bool revisionTimestampFound, String accessType) {
foreach (PropertyInfo property in t.GetProperties()) {
//RevisionNumber revisionNumber = property.getAnnotation(RevisionNumber.class);
RevisionNumberAttribute revisionNumber = (RevisionNumberAttribute)Attribute.GetCustomAttribute(property, typeof(RevisionNumberAttribute));
RevisionTimestampAttribute revisionTimestamp = (RevisionTimestampAttribute)Attribute.GetCustomAttribute(property, typeof(RevisionTimestampAttribute));
if (revisionNumber != null) {
if (revisionNumberFound) {
throw new MappingException("Only one property may have the attribute [RevisionNumber]!");
}
System.Type revNrType = property.PropertyType;
if (revNrType.Equals( typeof(int)) || revNrType.Equals( typeof(Int16)) || revNrType.Equals( typeof(Int32)) || revNrType.Equals( typeof(Int64))) {
revisionInfoIdData = new PropertyData(property.Name, property.Name, accessType, ModificationStore._NULL);
revisionNumberFound = true;
} else if (revNrType.Equals(typeof(long))) {
revisionInfoIdData = new PropertyData(property.Name, property.Name, accessType, ModificationStore._NULL);
revisionNumberFound = true;
// The default is integer
revisionPropType = "long";
} else {
throw new MappingException("The field decorated with [RevisionNumberAttribute] must be of type " +
"int, Int16, Int32, Int64 or long");
}
// Getting the @Column definition of the revision number property, to later use that info to
// generate the same mapping for the relation from an audit table's revision number to the
// revision entity revision number.
ColumnAttribute revisionPropColumn = (ColumnAttribute)Attribute.GetCustomAttribute(property,typeof(ColumnAttribute));
if (revisionPropColumn != null) {
revisionPropSqlType = revisionPropColumn.columnDefinition;
}
}
if (revisionTimestamp != null) {
if (revisionTimestampFound) {
throw new MappingException("Only one property may be decorated with [RevisionTimestampAttribute]!");
}
System.Type revisionTimestampType = property.GetType();
if (typeof(DateTime).Equals(revisionTimestampType)) {
revisionInfoTimestampData = new PropertyData(property.Name, property.Name, accessType, ModificationStore._NULL);
revisionTimestampFound = true;
} else {
throw new MappingException("The field decorated with @RevisionTimestamp must be of type DateTime");
}
}
}
}
示例5: AddPropertiesFromClass
private void AddPropertiesFromClass(System.Type clazz) {
//No need to go to base class, the .NET GetProperty method can bring the base properties also
//System.Type superclazz = clazz.BaseType;
//if (!"System.Object".Equals(superclazz.FullName))
//{
// AddPropertiesFromClass(superclazz);
//}
//ORIG: addFromProperties(clazz.getDeclaredProperties("field"), "field", fieldAccessedPersistentProperties);
//addFromProperties(clazz.getDeclaredProperties("property"), "property", _propertyAccessedPersistentProperties);
//only one call is needed, .NET does not differentiate between field and property
//AddFromProperties(clazz.GetProperties(BindingFlags.GetField), "field", _fieldAccessedPersistentProperties);
AddFromProperties(clazz.GetProperties(), "property", _propertyAccessedPersistentProperties);
}
示例6: EntityBuilder
public EntityBuilder(System.Type type)
{
if (type == null)
throw new ArgumentNullException("type");
Type = type;
Accessor = TypeAccessor.Create(type);
Properties = new Dictionary<string, PropertyInfo>();
foreach (var property in type.GetProperties())
{
Properties[property.Name] = property;
}
}
示例7: CreateProperties
protected override IList<Newtonsoft.Json.Serialization.JsonProperty> CreateProperties(System.Type type, MemberSerialization memberSerialization)
{
var props = type.GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
List<Newtonsoft.Json.Serialization.JsonProperty> jsonProps = new List<Newtonsoft.Json.Serialization.JsonProperty>();
foreach (var prop in props)
{
jsonProps.Add(base.CreateProperty(prop, memberSerialization));
}
foreach (var field in type.GetFields(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance))
{
jsonProps.Add(base.CreateProperty(field, memberSerialization));
}
jsonProps.ForEach(p => { p.Writable = true; p.Readable = true; });
return jsonProps;
}
示例8: SetDisplayType
/// <summary>
/// Configures the display of the list view control based upon the attributes exposed by the object
/// </summary>
/// <param name="ObjType"></param>
public void SetDisplayType(System.Type ObjType)
{
List<string> ColumnList = new List<String>();
PropertyInfo[] Properties = ObjType.GetProperties();
List<PropertyInfo> listPropInfoForColumn = new List<PropertyInfo>();
foreach(PropertyInfo Property in Properties)
{
ColumnAttribute[] Attributes = Property.GetCustomAttributes(typeof(ColumnAttribute), true) as ColumnAttribute[];
foreach (ColumnAttribute Attrib in Attributes)
{
ColumnList.Add(Attrib.ColumnName);
listPropInfoForColumn.Add(Property);
}
if (Property.GetCustomAttributes(typeof(ThisToOneRelationAttribute), true).Length > 0)
{
ColumnList.Add(Property.Name);
listPropInfoForColumn.Add(Property);
}
}
Trace.WriteLineIf(ColumnList.Count == 0, "No columns defined for type: " + ObjType.ToString(), "UI");
this.BeginUpdate();
this.Items.Clear();
this.Columns.Clear();
this.Columns.Add("Name", 150, HorizontalAlignment.Left);
foreach(string ColumnName in ColumnList)
{
this.Columns.Add(ColumnName, _ColumnDefaultWidth, HorizontalAlignment.Left);
}
this.EndUpdate();
this.ColumnProperties = listPropInfoForColumn.ToArray();
/*
this.ColumnProperties = new PropertyInfo[ColumnList.Count];
for(int iColumn = 0; iColumn < ColumnList.Count; iColumn++)
{
ColumnHeader Column = this.Columns[iColumn + 1];
ColumnProperties[iColumn] = ObjType.GetProperty(listPropInfoForColumn[iColumn].Name);
Debug.Assert(ColumnProperties[iColumn] != null);
}
*/
LoadColumnVisibilitySettings();
}
示例9: CreateControlContentForSingleEntry
private void CreateControlContentForSingleEntry (CVM.TableLayoutDefinition ContentInstance,
System.Type ContentClass, Grid Parent)
{
Parent.Children.Clear ();
Parent.RowDefinitions.Clear ();
Parent.ColumnDefinitions.Clear ();
PropertyInfo [] Properties = ContentClass.GetProperties ();
GridLengthConverter GLConverter = new GridLengthConverter ();
int RowIndex = 0;
foreach (PropertyInfo PropInfo in Properties)
{
String LabePropertyName = PropInfo.Name;
String OptionStringName = LabePropertyName + "_Option";
FieldInfo OptionField = (FieldInfo)ContentClass.GetField (OptionStringName);
String Options;
if (OptionField != null)
{
Options = (String)OptionField.GetValue (ContentInstance);
if (Options.IndexOf ("NoUpdate") != -1)
continue;
}
String HelpStringName = LabePropertyName + "_Help";
FieldInfo HelpField = (FieldInfo) ContentClass.GetField (HelpStringName);
RowDefinition MainRow = new RowDefinition ();
Parent.RowDefinitions.Add (MainRow);
Grid SubGrid = new Grid ();
Parent.Children.Add (SubGrid);
Grid.SetRow (SubGrid, RowIndex++);
Grid.SetColumn (SubGrid, 0);
Label PropertyNameLabel = new Label ();
PropertyNameLabel.Content = LabePropertyName;
SubGrid.Children.Add (PropertyNameLabel);
Grid.SetRow (PropertyNameLabel, 0);
SubGrid.ColumnDefinitions.Add (new ColumnDefinition ());
SubGrid.ColumnDefinitions [0].Width = (GridLength)GLConverter.ConvertFromString ("6" + "*");
SubGrid.ColumnDefinitions.Add (new ColumnDefinition ());
SubGrid.ColumnDefinitions [1].Width = (GridLength)GLConverter.ConvertFromString ("8" + "*");
SubGrid.RowDefinitions.Add (new RowDefinition ());
SubGrid.RowDefinitions [0].Height = (GridLength)GLConverter.ConvertFromString ("*");
if (PropInfo.PropertyType == typeof (int))
{
TextBox ContentBox = CreateSimpleLine (ContentInstance, PropInfo, MainRow, SubGrid, HelpField);
}
if (PropInfo.PropertyType == typeof (double))
{
TextBox ContentBox = CreateSimpleLine (ContentInstance, PropInfo, MainRow, SubGrid, HelpField);
}
if (PropInfo.PropertyType == typeof (Size))
{
TextBox [] ContentBoxes = CreateTwoSubLines (ContentInstance, PropInfo, MainRow, SubGrid,
new String [] { "Weite", "Höhe" }, HelpField);
}
if (PropInfo.PropertyType == typeof (Point))
{
TextBox [] ContentBoxes = CreateTwoSubLines (ContentInstance, PropInfo, MainRow, SubGrid,
new String [] { "Links", "Oben" }, HelpField);
}
if (PropInfo.PropertyType == typeof (String))
{
TextBox ContentBox = CreateSimpleLine (ContentInstance, PropInfo, MainRow, SubGrid, HelpField);
}
if (PropInfo.PropertyType == typeof (bool))
{
RadioButton [] Buttons = CreateBoolLine (ContentInstance, PropInfo, MainRow, SubGrid,
new String [] { "Ja", "Nein" }, HelpField);
}
}
}
示例10: GetTypedIndexer
private static PropertyInfo GetTypedIndexer(System.Type type)
{
if ((!typeof(IList).IsAssignableFrom(type) && !typeof(ITypedList).IsAssignableFrom(type)) && !typeof(IListSource).IsAssignableFrom(type))
{
return null;
}
PropertyInfo info = null;
PropertyInfo[] properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
for (int i = 0; i < properties.Length; i++)
{
if ((properties[i].GetIndexParameters().Length > 0) && (properties[i].PropertyType != typeof(object)))
{
info = properties[i];
if (info.Name == "Item")
{
return info;
}
}
}
return info;
}
示例11: ListProperties
private void ListProperties(System.Type objType)
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
ed.WriteMessage("\nReadable Properties for: " + objType.Name + " : ");
PropertyInfo[] propInfos = objType.GetProperties();
foreach (PropertyInfo propInfo in propInfos)
{
if (propInfo.CanRead)
{
ed.WriteMessage("\n " + propInfo.Name + " : " + propInfo.PropertyType);
}
}
ed.WriteMessage(System.Environment.NewLine); // "\n";
}
示例12: BindClass
private void BindClass(System.Type entity, PersistentClass pclass)
{
pclass.IsLazy = true;
pclass.EntityName = entity.FullName;
pclass.ClassName = entity.AssemblyQualifiedName;
pclass.ProxyInterfaceName = entity.AssemblyQualifiedName;
string tableName = GetClassTableName(pclass);
Table table = mappings.AddTable(null, null, tableName, null, pclass.IsAbstract.GetValueOrDefault(), null);
((ITableOwner) pclass).Table = table;
pclass.IsMutable = true;
PropertyInfo[] propInfos = entity.GetProperties();
PropertyInfo toExclude = new IdBinder(this, propInfos).Bind(pclass, table);
pclass.CreatePrimaryKey(dialect);
BindProperties(pclass, propInfos.Where(x => x != toExclude));
mappings.AddClass(pclass);
string qualifiedName = pclass.MappedClass == null ? pclass.EntityName : pclass.MappedClass.AssemblyQualifiedName;
mappings.AddImport(qualifiedName, pclass.EntityName);
if (mappings.IsAutoImport && pclass.EntityName.IndexOf('.') > 0) {
mappings.AddImport(qualifiedName, StringHelper.Unqualify(pclass.EntityName));
}
}
示例13: ResolveMappingPropertyByType
/// <summary>
/// Resolves mapping type in target type without caching and returning with Exception
/// if Mapping does not exists
/// </summary>
/// <param name="aTarget">
/// Object type to resolve property from <see cref="System.Type"/>
/// </param>
/// <param name="aMapping">
/// Property name <see cref="System.String"/>
/// </param>
/// <param name="aThrowException">
/// Set true if throwing exception on non success is needed <see cref="System.Boolean"/>
/// </param>
/// <returns>
/// Property info if successful, null if not <see cref="PropertyInfo"/>
/// </returns>
public static PropertyInfo ResolveMappingPropertyByType (System.Type aTarget, string aMapping, bool aThrowException)
{
if ((aMapping == "") || (aTarget == null))
return (null);
/* if (TypeValidator.IsCompatible(aTarget, TypeValidator.typeIVirtualObject) == true)
throw new Exception ("Searching property by type for VirtualObject is not possible! Check and correct implementation!");*/
foreach (PropertyInfo pInfo in aTarget.GetProperties ())
if (pInfo.Name == aMapping)
return (pInfo);
if (aThrowException == true)
throw new ExceptionPropertyNotFound (aMapping);
return (null);
}
示例14: RemoveDeletedProperties
private static void RemoveDeletedProperties(List<CustomProperty> propCollection, System.Type customActivityType, IServiceProvider serviceProvider)
{
IMemberCreationService service = serviceProvider.GetService(typeof(IMemberCreationService)) as IMemberCreationService;
if (service == null)
{
throw new Exception(SR.GetString("General_MissingService", new object[] { typeof(IMemberCreationService).FullName }));
}
foreach (PropertyInfo info in customActivityType.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly))
{
bool flag = false;
foreach (CustomProperty property in propCollection)
{
if ((info.Name == property.oldPropertyName) && (info.PropertyType.FullName == property.oldPropertyType))
{
flag = true;
break;
}
}
if (!flag)
{
service.RemoveProperty(customActivityType.FullName, info.Name, info.PropertyType);
}
}
foreach (EventInfo info2 in customActivityType.GetEvents(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly))
{
bool flag2 = false;
foreach (CustomProperty property2 in propCollection)
{
if ((info2.Name == property2.oldPropertyName) && (info2.EventHandlerType.FullName == property2.oldPropertyType))
{
flag2 = true;
break;
}
}
if ((!flag2 && (info2.Name != null)) && (info2.EventHandlerType != null))
{
service.RemoveEvent(customActivityType.FullName, info2.Name, info2.EventHandlerType);
}
}
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:40,代码来源:CustomActivityDesignerHelper.cs
示例15: MatchComponentPattern
protected bool MatchComponentPattern(System.Type subject)
{
const BindingFlags flattenHierarchyMembers =
BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
if (declaredModel.IsEntity(subject))
{
return false;
}
var modelInspector = (IModelInspector) this;
return !subject.IsEnum && (subject.Namespace == null || !subject.Namespace.StartsWith("System")) /* hack */
&& !modelInspector.IsEntity(subject)
&& !subject.GetProperties(flattenHierarchyMembers).Cast<MemberInfo>().Concat(
subject.GetFields(flattenHierarchyMembers)).Any(m => modelInspector.IsPersistentId(m));
}