本文整理汇总了C#中System.Reflection.PropertyInfo.GetValue方法的典型用法代码示例。如果您正苦于以下问题:C# PropertyInfo.GetValue方法的具体用法?C# PropertyInfo.GetValue怎么用?C# PropertyInfo.GetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.PropertyInfo
的用法示例。
在下文中一共展示了PropertyInfo.GetValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateKeyValuePair
private KeyValuePair<string, object> CreateKeyValuePair(object target, PropertyInfo property)
{
object value;
if (property.PropertyType.IsEnum) value = (int) property.GetValue(target, null);
else value = property.GetValue(target, null);
return new KeyValuePair<string, object>(property.Name, value);
}
示例2: GetPropertyValue
public static string GetPropertyValue(PropertyInfo propertyInfo, object ob)
{
string value = "";
if (propertyInfo != null)
{
if(propertyInfo.PropertyType==typeof(Color))
{
Color color = (Color)(propertyInfo.GetValue(ob, null));
value = color.ToArgb().ToString();
}
else if(propertyInfo.PropertyType== typeof(Font))
{
Font font = (Font)(propertyInfo.GetValue(ob, null));
value = string.Format("{0},{1},{2},{3}", font.Name, font.Size.ToString(), font.Bold?"1":"0", font.Italic?"1":"0");
}
else if (propertyInfo.PropertyType == typeof(Image))
{
Image image = (Image)(propertyInfo.GetValue(ob, null));
byte[] imageBuffer = Helpers.ImageHelper.ImageToBytes(image);
value = System.Convert.ToBase64String(imageBuffer);
}
else
{
value = propertyInfo.GetValue(ob, null) == null ? "" : propertyInfo.GetValue(ob, null).ToString();
}
}
return value;
}
示例3: ReadOnlyControl
public ReadOnlyControl(PropertyInfo prop, IAfterglowPlugin plugin)
: base(prop, FONT_SIZE)
{
ConfigReadOnlyAttribute configAttribute = Attribute.GetCustomAttribute(prop, typeof(ConfigReadOnlyAttribute)) as ConfigReadOnlyAttribute;
if (configAttribute == null)
{
throw new Exception("prop is not a ConfigReadOnlyAttribute");
}
//Create value Label
if (configAttribute.IsHyperlink)
{
string link = prop.GetValue(plugin, null).ToString();
_valueLinkLabel = new LinkLabel();
_valueLinkLabel.Name = Guid.NewGuid().ToString();
_valueLinkLabel.Text = link;
Font font = new Font(_valueLinkLabel.Font.FontFamily, FONT_SIZE);
_valueLinkLabel.Font = font;
_valueLinkLabel.Links.Add(0,link.Length,link);
_valueLinkLabel.LinkClicked += new LinkLabelLinkClickedEventHandler(LinkClicked);
this.Controls.Add(_valueLinkLabel);
}
else
{
_valueLabel = new Label();
_valueLabel.Name = Guid.NewGuid().ToString();
_valueLabel.Text = prop.GetValue(plugin, null).ToString();
Font font = new Font(_valueLabel.Font.FontFamily, FONT_SIZE);
_valueLabel.Font = font;
this.Controls.Add(_valueLabel);
}
InitializeComponent();
}
示例4: RepairValue
public override void RepairValue(PropertyInfo prop, object entity)
{
ParameterAttribute attr = (ParameterAttribute)prop.GetCustomAttribute((Type)typeof(ParameterAttribute), (bool)false);
FieldName = prop.Name;
try
{
ValueMin = CastToType(ValueMin);
}
catch (Exception)
{
ValueMin = null;
}
if (ValueMin == null)
ValueMin = prop.GetValue(entity);
try
{
ValueMax = CastToType(ValueMax);
}
catch (Exception)
{
ValueMax = null;
}
if (ValueMax == null)
ValueMax = prop.GetValue(entity);
DisplayName = (attr.Name == null) ? prop.Name : attr.Name;
Description = (attr.Description == null) ? "" : attr.Description;
TypeName = prop.PropertyType.FullName;
}
示例5: ArePropertiesEqual
public static bool ArePropertiesEqual(PropertyInfo property, object object1, object object2)
{
bool result = true;
object object1Value = null;
object object2Value = null;
if (object1 != null)
{
object1Value = property.GetValue(object1, null);
}
if (object2 != null)
{
object2Value = property.GetValue(object2, null);
}
if (object1Value != null)
{
if (object1Value.Equals(object2Value) == false)
{
result = false;
}
}
else
{
if (object2Value != null)
{
result = false;
}
}
return result;
}
示例6: DBParam
public DBParam(DBConnectInfo.DBType dbType, PropertyInfo prop, DbConnectionStringBuilder values, DbConnectionStringBuilder defaults)
{
DBType = dbType;
Name = prop.Name;
try { Original = prop.GetValue(values); } catch { }
try { Default = prop.GetValue(defaults); } catch { }
Value = Original;
Type = prop.PropertyType;
}
示例7: GetValueByProperty
protected static string GetValueByProperty(PropertyInfo property, object entity)
{
if (!property.PropertyType.IsPrimitive && !property.PropertyType.Namespace.Contains("System"))
{
return property.GetValue(entity).ToString();
}
else
return property.GetValue(entity) == null ? string.Empty : property.GetValue(entity).ToString();
}
示例8: AddToList
private static void AddToList(object dto, List<keyValue> list, PropertyInfo property)
{
var propertyValue = property.GetValue(dto, null);
if (propertyValue != null)
{
list.Add(new keyValue()
{
name = property.Name.ToLower(),
value = property.GetValue(dto, null).ToString()
});
}
}
示例9: GetValue
private static object GetValue(PropertyInfo prop, Agency agency, IDictionary<string, string> codeDict)
{
if (prop.PropertyType == typeof(string[]))
{
var arr = (string[])prop.GetValue(agency);
return string.Join("; ", arr.Select(x => codeDict[x]));
}
else
{
return prop.GetValue(agency);
}
}
示例10: GetCrossRefAttributeValue
public static object GetCrossRefAttributeValue(this IDynamicObject item, PropertyInfo propertyInfo)
{
if (propertyInfo == null)
{
throw new ArgumentNullException("propertyInfo");
}
if (item == null)
{
throw new ArgumentNullException("item");
}
var crossRefAttr = propertyInfo.GetCustomAttributes(typeof(CrossRefFieldAttribute), false).Select(d => d).FirstOrDefault() as CrossRefFieldAttribute;
if (crossRefAttr == null)
{
return Convert.ToString(propertyInfo.GetValue(item), CultureInfo.InvariantCulture);
}
var memberProperty = item.GetType().GetProperty(propertyInfo.Name + "Member");
var memberValue = (IDynamicObject)memberProperty.GetValue(item);
if (memberValue != null)
{
var sourceProp = memberValue.GetType().GetProperty(crossRefAttr.RefFieldName);
if (sourceProp != null)
{
if (sourceProp.GetCustomAttributes(typeof(ApprovalDefinitionAttribute), false).Any())
{
return item.GetApprovalDisplayValue(crossRefAttr.RefFieldName);
}
if (sourceProp.GetCustomAttributes(typeof(IsSwitchToggleAttribute), false).Any())
{
return item.GetBooleanDisplayValue(crossRefAttr.RefFieldName, sourceProp);
}
if (sourceProp.GetCustomAttributes(typeof(DateTimeFormatAttribute), false).Any())
{
return item.GetDateTimeDisplayValue(crossRefAttr.RefFieldName, sourceProp);
}
if (sourceProp.GetCustomAttributes(typeof(CrossRefFieldAttribute), false).Any())
{
return GetCrossRefAttributeValue(memberValue, sourceProp);
}
}
return Convert.ToString(memberValue.GetValueByPropertyName(crossRefAttr.RefFieldName));
}
return Convert.ToString(propertyInfo.GetValue(item), CultureInfo.InvariantCulture);
}
示例11: GetParams
public virtual Dictionary<string, string> GetParams(object obj, PropertyInfo p) {
var value = p.GetValue(obj, null);
if (value == null && this.Required)
return new Dictionary<string, string>(){
{this.Name, ""}
};
else if (value == null && !this.Required)
return null;
else
return new Dictionary<string, string>(){
{this.Name, p.GetValue(obj, null).ToString()}
};
}
示例12: AddArray
private static void AddArray(object item, PropertyInfo property, KOModel model, bool observable)
{
var listType = GetListType(property.PropertyType);
if (IsSimpleType(listType))
{
dynamic list = property.GetValue(item) ?? new List<object>();
model.AddArray(ToJavascriptName(property), list, observable);
}
else
{
var list = property.GetValue(item) as IEnumerable<object> ?? new List<object>();
model.AddArray(ToJavascriptName(property), list.Select(x => x.ToKO()), observable);
}
}
示例13: GetProperty
public object GetProperty(PropertyInfo property)
{
object result = null;
Type type = property.PropertyType;
if (Persistence.Required(type))
{
object obj = this.Read(() => property.GetValue(this.Object, null));
result = this.cache.GetPersistent(obj);
}
else result = this.Read(() => property.GetValue(this.Object, null));
return result;
}
示例14: SpellCheckProperty
public SpellCheckProperty(PropertyInfo property, object o, string description)
{
this.m_Regex = new System.Text.RegularExpressions.Regex(@"\b\w+\b");
this.m_CurrentMatchIndex = -1;
this.m_Property = property;
this.m_O = o;
this.m_Description = description;
string text = string.Empty;
if (property.GetValue(this.m_O) != null)
{
text = (string)property.GetValue(this.m_O);
}
this.m_Matches = this.m_Regex.Matches(text);
}
示例15: SetTimeSpanGump
public SetTimeSpanGump( PropertyInfo prop, Mobile mobile, object o, Stack stack, int page, ArrayList list )
: base(GumpOffsetX, GumpOffsetY)
{
m_Property = prop;
m_Mobile = mobile;
m_Object = o;
m_Stack = stack;
m_Page = page;
m_List = list;
TimeSpan ts = (TimeSpan)prop.GetValue( o, null );
AddPage( 0 );
AddBackground( 0, 0, BackWidth, BackHeight, BackGumpID );
AddImageTiled( BorderSize, BorderSize, TotalWidth - (OldStyle ? SetWidth + OffsetSize : 0), TotalHeight, OffsetGumpID );
AddRect( 0, prop.Name, 0, -1 );
AddRect( 1, ts.ToString(), 0, -1 );
AddRect( 2, "Zero", 1, -1 );
AddRect( 3, "From H:M:S", 2, -1 );
AddRect( 4, "H:", 3, 0 );
AddRect( 5, "M:", 4, 1 );
AddRect( 6, "S:", 5, 2 );
}