本文整理汇总了C#中Type.GetProperties方法的典型用法代码示例。如果您正苦于以下问题:C# Type.GetProperties方法的具体用法?C# Type.GetProperties怎么用?C# Type.GetProperties使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Type
的用法示例。
在下文中一共展示了Type.GetProperties方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetKeyProperty
public static PropertyInfo GetKeyProperty(Type entityType, bool throwOnError = false)
{
IEnumerable<PropertyInfo> keys = entityType.GetProperties()
.Where(p => (p.Name.Equals(entityType.Name + "Id", StringComparison.OrdinalIgnoreCase) || p.Name.Equals("Id", StringComparison.OrdinalIgnoreCase))
&& EdmLibHelpers.GetEdmPrimitiveTypeOrNull(p.PropertyType) != null);
if (keys.Count() == 0)
{
if (throwOnError)
{
throw Error.InvalidOperation(SRResources.NoKeyFound, entityType.FullName);
}
}
else if (keys.Count() > 1)
{
if (throwOnError)
{
throw Error.InvalidOperation(SRResources.MultipleKeysFound, entityType.FullName);
}
}
else
{
return keys.Single();
}
return null;
}
示例2: showProperties
private void showProperties(Type type)
{
PropertyInfo[] propertyInfos = type.GetProperties();
foreach(PropertyInfo propertyInfo in propertyInfos)
if (propertyInfo.IsDefined (typeof(KeyAttribute), true))
textView.Buffer.Text = textView.Buffer.Text + propertyInfo.Name + " " + propertyInfo.PropertyType + "\n";
}
示例3: GetSystemParam_DG
private void GetSystemParam_DG(string[] familyList, Type t, int p, TreeNode FatherTN)
{
foreach (PropertyInfo info in t.GetProperties())
{
TreeNode child = new TreeNode();
if (info.PropertyType.BaseType != typeof(Array))
{
child.SelectAction = TreeNodeSelectAction.Expand;
child.Text = info.Name;
child.ToolTip = FatherTN.ToolTip + "." + info.Name;
FatherTN.ChildNodes.Add(child);
}
if (familyList != null)
{
string str;
if (p >= familyList.Length)
{
return;
}
if ((info.PropertyType.IsClass && (info.PropertyType.BaseType != typeof(Array))) && (((str = info.PropertyType.FullName) == null) || (str != "System.String")))
{
this.GetSystemParam_DG(familyList, info.PropertyType, p + 1, child);
}
}
else
{
string str2;
if ((((p <= 1) && info.PropertyType.IsClass) && (info.PropertyType.BaseType != typeof(Array))) && (((str2 = info.PropertyType.FullName) == null) || (str2 != "System.String")))
{
this.GetSystemParam_DG(familyList, info.PropertyType, p + 1, child);
}
}
}
}
示例4: GetProperties
public IEnumerable<PropertyInfo> GetProperties(
Type type,
bool declaredOnly,
IEnumerable<PropertyInfo> explicitlyMappedProperties = null,
IEnumerable<Type> knownTypes = null,
bool includePrivate = false)
{
DebugCheck.NotNull(type);
explicitlyMappedProperties = explicitlyMappedProperties ?? Enumerable.Empty<PropertyInfo>();
knownTypes = knownTypes ?? Enumerable.Empty<Type>();
ValidatePropertiesForModelVersion(type, explicitlyMappedProperties);
var bindingFlags
= declaredOnly
? DefaultBindingFlags | BindingFlags.DeclaredOnly
: DefaultBindingFlags;
var propertyInfos
= from p in type.GetProperties(bindingFlags)
where p.IsValidStructuralProperty()
let m = p.GetGetMethod(true)
where (includePrivate || (m.IsPublic || explicitlyMappedProperties.Contains(p) || knownTypes.Contains(p.PropertyType)))
&& (!declaredOnly || type.BaseType.GetProperties(DefaultBindingFlags).All(bp => bp.Name != p.Name))
&& (EdmV3FeaturesSupported || (!IsEnumType(p.PropertyType) && !IsSpatialType(p.PropertyType)))
&& (Ef6FeaturesSupported || !p.PropertyType.IsNested)
select p;
return propertyInfos;
}
示例5: getObjectFromDict
private static Object getObjectFromDict(Type objectType, Dictionary<string, object> dataDictionary)
{
Object tempObject = Activator.CreateInstance(objectType);
foreach (string key in dataDictionary.Keys)
{
foreach (PropertyInfo propInfo in objectType.GetProperties())
{
if (propInfo.Name.ToLower().Equals(key.ToLower()))
{
PropertyInfo newProp = objectType.GetProperty(propInfo.Name, BindingFlags.Public | BindingFlags.Instance);
newProp.GetValue(tempObject,null);
if (propInfo.PropertyType.IsEnum) //Enum
{
object enumObj = Enum.Parse(propInfo.PropertyType, dataDictionary[key].ToString());
newProp.SetValue(tempObject, enumObj,null);
}
else if (propInfo.PropertyType.GetInterfaces().Contains(typeof(ICollection)))
{
List<long> indexList = getListFromObject(dataDictionary[key]);
newProp.SetValue(tempObject, indexList, null);
}
else
{
newProp.SetValue(tempObject, dataDictionary[key], null);
}
}
}
}
return tempObject;
}
示例6: GetProperties
public IEnumerable<PropertyInfo> GetProperties(
Type type,
bool declaredOnly,
IEnumerable<PropertyInfo> explicitlyMappedProperties = null,
IEnumerable<Type> knownTypes = null)
{
Contract.Requires(type != null);
explicitlyMappedProperties = explicitlyMappedProperties ?? Enumerable.Empty<PropertyInfo>();
knownTypes = knownTypes ?? Enumerable.Empty<Type>();
ValidatePropertiesForModelVersion(type, explicitlyMappedProperties);
var bindingFlags
= declaredOnly
? DefaultBindingFlags | BindingFlags.DeclaredOnly
: DefaultBindingFlags;
var propertyInfos
= from p in type.GetProperties(bindingFlags)
where p.IsValidStructuralProperty()
let m = p.GetGetMethod(true)
where (m.IsPublic || explicitlyMappedProperties.Contains(p) || knownTypes.Contains(p.PropertyType))
&&
(!declaredOnly || !type.BaseType.GetProperties(DefaultBindingFlags).Any(bp => bp.Name == p.Name))
&& (EdmV3FeaturesSupported || !IsEnumType(p.PropertyType)
&& (EdmV3FeaturesSupported || !IsSpatialType(p.PropertyType)))
select p;
return propertyInfos;
}
示例7: ListProps
static void ListProps(Type t)
{
Console.WriteLine("***** Properties *****");
var propNames = from p in t.GetProperties() select p.Name;
foreach (var name in propNames) {
Console.WriteLine("->{0}", name);
}
}
示例8: GetProperties
public static PropertyInfo[] GetProperties(Type type)
{
if (type == null)
{
throw Error.ArgumentNull("type");
}
return type
.GetProperties()
.Where(p => p.IsValidStructuralProperty())
.ToArray();
}
示例9: showInfo
private void showInfo(Type type)
{
Console.WriteLine ("type={0}", type.Name);
PropertyInfo[] properties = type.GetProperties ();
foreach (PropertyInfo property in properties)
Console.WriteLine ("property.Name={0, -20} property.PropertyType={1}", property.Name, property.PropertyType);
FieldInfo[] fields = type.GetFields (BindingFlags.Instance | BindingFlags.NonPublic);
foreach (FieldInfo field in fields)
//if (field.IsDefined(typeof(IdAttribute), true))
Console.WriteLine ("field.Name={0, -30} field.FieldType={1}", field.Name, field.FieldType);
}
示例10: GetFilteredProperties
internal string[] GetFilteredProperties(Type type, BindingFlags bindingFlags)
{
PropertyInfo[] properties = type.GetProperties(bindingFlags);
if (this._targetFrameworkProvider == null)
{
return this.GetMemberNames(properties);
}
PropertyInfo[] infoArray2 = this._targetFrameworkProvider.GetReflectionType(type).GetProperties(bindingFlags);
IEnumerable<string> reflectionPropertyNames = from p in infoArray2 select p.Name;
return (from p in properties
where reflectionPropertyNames.Contains<string>(p.Name)
select p.Name).ToArray<string>();
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:13,代码来源:ClientBuildManagerTypeDescriptionProviderBridge.cs
示例11: showInfo
private void showInfo(Type type)
{
Console.WriteLine (type.Name);
foreach (PropertyInfo pi in type.GetProperties ())
Console.WriteLine ("PropertyType of {0} > {1}", pi.Name, pi.PropertyType);
Console.WriteLine ("");
foreach (FieldInfo fi in type.GetFields (BindingFlags.Instance | BindingFlags.NonPublic))
//if (fi.IsDefined(typeof(IdAttribute), true))
Console.WriteLine ("FieldType of {0} > {1}", fi.Name, fi.FieldType);
Console.WriteLine ("\n");
}
示例12: FillConstants
private static void FillConstants(Dictionary<string, Color> colors, Type enumType)
{
const MethodAttributes attrs = MethodAttributes.Public | MethodAttributes.Static;
PropertyInfo[] props = enumType.GetProperties();
foreach (PropertyInfo prop in props)
{
if (prop.PropertyType == typeof(Color))
{
MethodInfo method = prop.GetGetMethod();
if (method != null && (method.Attributes & attrs) == attrs)
{
colors[prop.Name] = (Color)prop.GetValue(null, null);
}
}
}
}
示例13: Calculate
public static long Calculate(Type t)
{
MemoryStream ms = new MemoryStream();
BinaryWriter bw = new BinaryWriter(ms);
bw.Write(t.FullName);
bw.Write((int)t.Attributes);
foreach(FieldInfo fi in t.GetFields(BindingFlags.Public |
BindingFlags.NonPublic | BindingFlags.Instance).OrderBy(f => f.Name))
{
bw.Write(fi.Name);
bw.Write((int)fi.Attributes);
}
foreach(PropertyInfo pi in
t.GetProperties(BindingFlags.Public | BindingFlags.Instance).OrderBy(p
=> p.Name))
{
bw.Write(pi.Name);
bw.Write((int)pi.Attributes);
}
foreach(ConstructorInfo ci in
t.GetConstructors(BindingFlags.Public | BindingFlags.Instance).OrderBy(c
=> Signature(c.Name, c.GetParameters())))
{
bw.Write(Signature(ci.Name, ci.GetParameters()));
bw.Write((int)ci.Attributes);
}
foreach(MethodInfo mi in t.GetMethods(BindingFlags.Public |
BindingFlags.Instance | BindingFlags.Static).OrderBy(m =>
Signature(m.Name, m.GetParameters())))
{
bw.Write(Signature(mi.Name, mi.GetParameters()));
bw.Write((int)mi.Attributes);
}
bw.Close();
ms.Close();
byte[] b = ms.ToArray();
byte[] hash = sha.TransformFinalBlock(b, 0, b.Length);
return (((long)hash[0]) << 56) | (((long)hash[1]) << 48) |
(((long)hash[2]) << 40) | (((long)hash[3]) << 32)
| (((long)hash[4]) << 24) | (((long)hash[5]) << 16) |
(((long)hash[6]) << 8) | (((long)hash[7]) << 0);
}
示例14: CreateConvertorCS
public static string CreateConvertorCS(Type type)
{
PropertyInfo[] props = type.GetProperties();
PropertyInfo keyInfo = null;
foreach (var prop in props)
{
if (prop.IsDefined(typeof(KeyPropAttributes), false))
{
keyInfo = prop;
break;
}
}
if (null != keyInfo)
{
return CreateDictionayConvertor(type, keyInfo);
}
else
{
return CreateListConvertor(type);
}
}
示例15: CreateObjectFromDB
public void CreateObjectFromDB(Type objType)
{
//instantiate an object of the type specified
object instance = Activator.CreateInstance(objType, true);
//get all properties of the class specified
PropertyInfo[] properties = objType.GetProperties();
for (int i = 0; i < properties.Length; i++)
{
//add the DBColumnAttributes for each property
DBColumnAttribute[] attribute = (DBColumnAttribute[])properties[i].GetCustomAttributes(typeof(DBColumnAttribute), true);
//make sure the property has a column attribute
if (attribute.Length > 0)
{
//fill in the value for the property
object value = reader[attribute[0].Name];
properties[i].SetValue(instance, value, null);
}
}
}