当前位置: 首页>>代码示例>>C#>>正文


C# PropertyInfo.GetValue方法代码示例

本文整理汇总了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);
 }
开发者ID:alexandreubaldo,项目名称:Thunderstruck,代码行数:7,代码来源:ParametersBinder.cs

示例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;
        }
开发者ID:leiTangDotNet,项目名称:JmMind,代码行数:29,代码来源:XmlManage.cs

示例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();
        }
开发者ID:gavinramm,项目名称:Afterglow,代码行数:34,代码来源:ReadOnlyControl.cs

示例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;
        }
开发者ID:Rizjiy,项目名称:RMarketMVC,代码行数:34,代码来源:ParamSelection.cs

示例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;
        }
开发者ID:WilliamCopland,项目名称:YPILIS,代码行数:33,代码来源:PersistenceHelper.cs

示例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;
			}
开发者ID:xyandro,项目名称:NeoEdit,代码行数:9,代码来源:EditDatabaseConnectDialog.xaml.cs

示例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();
        }
开发者ID:rodolpholl,项目名称:bakerymanager,代码行数:11,代码来源:AuditInsertEventListener.cs

示例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()
         });
     }
 }
开发者ID:danieleli,项目名称:YesMail-Adapter,代码行数:12,代码来源:SideTableTolkenMapper.cs

示例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);
     }
 }
开发者ID:duggiemitchell,项目名称:Mentor,代码行数:12,代码来源:ExportAgencies.cs

示例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);
        }
开发者ID:mparsin,项目名称:Elements,代码行数:52,代码来源:FieldValueExtractor.cs

示例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()}
         };
 }
开发者ID:x01673,项目名称:Lagou.UWP,代码行数:13,代码来源:ParamAttribute.cs

示例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);
     }
 }
开发者ID:jni-,项目名称:ToKO,代码行数:14,代码来源:ToKOExtensions.cs

示例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;
        }
开发者ID:parnham,项目名称:coincidental,代码行数:14,代码来源:PersistentContainer.cs

示例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);
        }
开发者ID:ericramses,项目名称:YPILIS,代码行数:15,代码来源:SpellCheckProperty.cs

示例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 );
        }
开发者ID:FreeReign,项目名称:Rebirth-Repack,代码行数:25,代码来源:SetTimeSpanGump.cs


注:本文中的System.Reflection.PropertyInfo.GetValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。