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


C# PropertyInfo.GetValue方法代码示例

本文整理汇总了C#中PropertyInfo.GetValue方法的典型用法代码示例。如果您正苦于以下问题:C# PropertyInfo.GetValue方法的具体用法?C# PropertyInfo.GetValue怎么用?C# PropertyInfo.GetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PropertyInfo的用法示例。


在下文中一共展示了PropertyInfo.GetValue方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ProcessRes

 void ProcessRes(PropertyInfo pi)
 {
     var obj = pi.GetValue(null, null);
     var type = obj.GetType();
     if(type == typeof(string))
     {
         var item = new RString();
         item.name = pi.Name;
         item.value = obj as string;
         listString.Add(item);
     }
     else if (type == typeof(Texture2D))
     {
         var item = new RTexture();
         item.name = pi.Name;
         item.value = obj as Texture2D;
         listTexture.Add(item);
     }
     else
     {
         var item = new RUnknown();
         item.name = pi.Name;
         item.type = type.Name;
         item.value = obj.ToString();
         listUnknown.Add(item);
     }
 }
开发者ID:woncomp,项目名称:UnityLab,代码行数:27,代码来源:L002ResourcesPathsWindow.cs

示例2: Initialize

    protected override void Initialize()
    {
        base.Initialize();

        if (owner != null)
        {
            field = owner.GetType().GetField(name);
            if (field != null)
                value = field.GetValue(owner);
            else
            {
                prop = owner.GetType().GetProperty(name);
                if (prop != null)
                    value = prop.GetValue(owner, null);
            }

            if (value == null)
            {
                Debug.LogError("Orthello Action Tween variable [" + name + "] not found on " + (owner as OTObject).name + "!");
            }

        }
        else
        {
            Debug.LogError("Orthello Action Tween owner is null!");
        }


        if (getFromValue)
            fromValue = value;

    }
开发者ID:pravusjif,项目名称:PravusUnityTests,代码行数:32,代码来源:OTActionTween.cs

示例3: boolField

 public void boolField(object pObject, PropertyInfo pPropertyInfo)
 {
     bool lValue = (bool)pPropertyInfo.GetValue(pObject, null);
     content.text="";
     bool lNewValue = GUILayout.Toggle(lValue, content);
     if(lValue!=lNewValue)
         pPropertyInfo.SetValue(pObject, lNewValue, null);
 }
开发者ID:orange030,项目名称:modelPainter,代码行数:8,代码来源:FieldUIAttribute.cs

示例4: floatField

    public void floatField(object pObject, PropertyInfo pPropertyInfo)
    {
        float lPreValue = (float)pPropertyInfo.GetValue(pObject, null);

        string lPreText = zzGUIUtilities.toString(lPreValue);
        //if(stringBuffer!=null)
        //{
        //    lPreText = stringBuffer;
        //}
        //else
        //{
        //    lPreText = lPreValue.ToString();
        //}
        float lNewValue;
        string lNewText = TextField(lPreText, 8);
        //if (lNewText.Length == 0)
        //    lNewValue = 0f;
        //else
        //{
        //    var lNums = lNewText.Split('.');
        //    if (lNums.Length>2)
        //    {
        //        lNewText = lNums[0] + "." + lNums[1];
        //        for (int i = 2; i<lNums.Length;++i )
        //        {
        //            lNewText += lNums[i];
        //        }
        //    }
        //    float.TryParse(lNewText, out lNewValue);
        //}

        if (zzGUIUtilities.stringToFloat(lNewText, out lNewValue)
            &&lNewValue != lPreValue)
            pPropertyInfo.SetValue(pObject, lNewValue, null);
        //if(lPreText!=lNewText)
        //{
        //    try
        //    {
        //        pPropertyInfo.SetValue(pObject, float.Parse(lNewText), null);
        //        stringBuffer = null;
        //    }
        //    catch (System.Exception e)
        //    {
        //        stringBuffer = lNewText;
        //    }
        //}
    }
开发者ID:orange030,项目名称:modelPainter,代码行数:47,代码来源:FieldUIAttribute.cs

示例5: Initialize

    protected override void Initialize()
    {
        base.Initialize();

        if (owner!=null)
        {
            field = owner.GetType().GetField(name);
            if (field != null)
                value = field.GetValue(owner);
            else
            {
                prop = owner.GetType().GetProperty(name);
                if (prop != null)
                    value = prop.GetValue(owner, null);
            }

        }
    }
开发者ID:pravusjif,项目名称:PravusUnityTests,代码行数:18,代码来源:OTActionAdd.cs

示例6: intField

    //public bool isFloat(string pText)
    //{
    //    bool lOut = false;
    //    try
    //    {
    //        float.Parse(pText);
    //        lOut = true;
    //    }
    //    catch{}
    //    return lOut;
    //}
    public void intField(object pObject, PropertyInfo pPropertyInfo)
    {
        int lPreValue = (int)pPropertyInfo.GetValue(pObject, null);

        //string lPreText;
        //if (stringBuffer != null)
        //{
        //    lPreText = stringBuffer;
        //}
        //else
        //{
        //    lPreText = lPreValue.ToString();
        //}
        int lNewValue;
        string lNewText = TextField(lPreValue.ToString(), 8);
        if (lNewText.Length == 0)
            lNewValue = 0;
        else
            int.TryParse(lNewText, out lNewValue);

        if (lNewValue != lPreValue)
            pPropertyInfo.SetValue(pObject, lNewValue, null);
        //if (lPreText != lNewText)
        //{
        //    try
        //    {
        //        pPropertyInfo.SetValue(pObject, System.Int32.Parse(lNewText), null);
        //        stringBuffer = null;
        //    }
        //    catch (System.Exception e)
        //    {
        //        stringBuffer = lNewText;
        //    }
        //}
    }
开发者ID:orange030,项目名称:modelPainter,代码行数:46,代码来源:FieldUIAttribute.cs

示例7: FilterProperty

        public FilterProperty( PropertyInfo info, AGATFilter filterInstance )
        {
            _info = info;

            object[] attributes = info.GetCustomAttributes( typeof( FloatPropertyRange ), true );

            if( attributes.Length == 0 )
            {
                attributes = info.GetCustomAttributes( typeof( ToggleGroupProperty ), true );
                if( attributes.Length == 1 )
                {
                    _isGroupToggle = true;
                }
            }
            else
            {
                _range = ( FloatPropertyRange )attributes[ 0 ];
            }

            object val = info.GetValue( filterInstance, null );

            if( val is float )
            {
                _currentValue = ( float )val;
                _labelString = _info.Name + ": " + _currentValue.ToString("0.00");
            }
            else if( val is double )
            {
                _currentValue = ( float )( ( double )val );
                _labelString = _info.Name + ": " + _currentValue.ToString("0.00");
            }
            else if( val is bool )
            {
                GroupToggleState = ( bool )val;
                _labelString = _info.Name;
            }

            _filter = filterInstance;
        }
开发者ID:gregzo,项目名称:G-Audio,代码行数:39,代码来源:AGATFilter.cs

示例8: GetRowValue

    public object GetRowValue(PropertyInfo pi, Input0Buffer row)
    {
        var piCheckNull = (bool)typeof(Input0Buffer).GetProperty(pi.Name + "_IsNull").GetValue(row, null);

        if (piCheckNull)
            return "-";
        else
            return pi.GetValue(row, null);
    }
开发者ID:kidoman,项目名称:SSIS.Loader,代码行数:9,代码来源:BadFile.cs

示例9: TryGetPropertyValue

 private object TryGetPropertyValue(IEnumerable<object> path, object o, PropertyInfo prop)
 {
     try
     {
         return prop.GetValue(o, null);
     }
     catch (Exception e)
     {
         LogException(PathToString(path), e);
         return null;
     }
 }
开发者ID:GHScan,项目名称:DailyProjects,代码行数:12,代码来源:ReferenceFinder.cs

示例10: QuotePropertyValue

    /// <summary>
    /// Quote the value of the property <paramref name="property"/> of object <paramref
    /// name="node"/>
    /// </summary>
    private ApiCall QuotePropertyValue(SyntaxNode node, PropertyInfo property)
    {
        var value = property.GetValue(node, null);
        var propertyType = property.PropertyType;

        if (propertyType == typeof(SyntaxToken))
        {
            return QuoteToken((SyntaxToken)value, property.Name);
        }

        if (propertyType == typeof(SyntaxTokenList))
        {
            return QuoteList((IEnumerable)value, property.Name);
        }

        if (propertyType.IsGenericType &&
            (propertyType.GetGenericTypeDefinition() == typeof(SyntaxList<>) ||
             propertyType.GetGenericTypeDefinition() == typeof(SeparatedSyntaxList<>)))
        {
            return QuoteList((IEnumerable)value, property.Name);
        }

        if (value is SyntaxNode)
        {
            return QuoteNode((SyntaxNode)value, property.Name);
        }

        if (value is string)
        {
            return new ApiCall(property.Name, "\"" + Escape(value.ToString()) + "\"");
        }

        if (value is bool)
        {
            return new ApiCall(property.Name, value.ToString().ToLowerInvariant());
        }

        return null;
    }
开发者ID:SkightTeam,项目名称:RoslynQuoter,代码行数:43,代码来源:Quoter.cs

示例11: CloneProperties

    static void CloneProperties(PropertyInfo property, object from, object to)
    {
        var value = property.GetValue(
            from,
            null
            );

        MethodInfo setMethod = property.GetSetMethod();
        if(setMethod != null)
        {
            property.SetValue(
                to,
                value,
                null
                );
        }
        else
        {
            foreach(PropertyInfo subProperty in property.PropertyType.GetProperties())
            {
                CloneProperties(
                    subProperty,
                    property.GetValue(from, null),
                    property.GetValue(to, null)
                    );
            }
        }
    }
开发者ID:ChiU3D,项目名称:Core,代码行数:28,代码来源:EditorSkinExtractor.cs

示例12: GetPropertyValue

	// Get the current value of the specified property owned by instance. If instance is null then property is static.
	// Returns: results of the ToString method when called on the result of the property, "write-only" if property is write-only, or null if property is of unsupported type.
	public static string GetPropertyValue(object instance, PropertyInfo propertyInfo) {
		if(propertyInfo == null) { return null; }
		if(propertyInfo.GetGetMethod() == null) { return "write-only!"; }
		switch(propertyInfo.PropertyType.Name) {
			case "Vector2":
			case "Vector3":
			case "Color":
			case "String":
			case "Char":
			case "Byte":
			case "SByte":
			case "Int16":
			case "Int32":
			case "Int64":
			case "UInt16":
			case "UInt32":
			case "UInt64":
			case "Single":
			case "Double":
			case "Boolean":
				return propertyInfo.GetValue(instance, null).ToString();
			default:
				return null;
		}
	}
开发者ID:wfowler1,项目名称:Miscellaneous-Soundboards,代码行数:27,代码来源:Console.cs

示例13: SetPropertyObject

	private void SetPropertyObject(object objParent, PropertyInfo pi, XmlTextReader tr, NodeStyle ns)
	{
		object obj;

		switch (pi.PropertyType.FullName)
			{
				case "System.Drawing.Font" :
					structFont fnt;
					fnt.Style = 0;
					fnt.Unit = GraphicsUnit.Point;
					fnt.Name="";
					fnt.Size=0;
					fnt.gdiCharSet=0;
					fnt.gdiVerticalFont=false;

					for (int i = 0; i < tr.AttributeCount; i++)
					{
						tr.MoveToAttribute(i);

						switch (tr.Name.ToUpper())
						{
							case "NAME" : fnt.Name = tr.Value; break;
							case "SIZE" : fnt.Size = Convert.ToSingle(tr.Value); break;
							case "GDICHARSET" : fnt.gdiCharSet = Convert.ToByte(tr.Value); break;
							case "GDIVERTICALFONT" : fnt.gdiVerticalFont = Convert.ToBoolean(tr.Value); break;
							case "BOLD" : if (Convert.ToBoolean(tr.Value)) fnt.Style = fnt.Style | FontStyle.Bold ; break;
							case "ITALIC" : if (Convert.ToBoolean(tr.Value)) fnt.Style = fnt.Style | FontStyle.Italic ; break;
							case "STRIKEOUT" : if (Convert.ToBoolean(tr.Value)) fnt.Style = fnt.Style | FontStyle.Strikeout ; break;
							case "UNDERLINE" : if (Convert.ToBoolean(tr.Value)) fnt.Style = fnt.Style | FontStyle.Underline; break;
							case "UNIT" : 
								Type o = oTV.Style.NodeStyle.Font.Unit.GetType();
								fnt.Unit = (System.Drawing.GraphicsUnit)System.Enum.Parse(o , tr.Value, true);
								break;

							default :
								break;
						}
					}

					System.Drawing.Font NewFont = new System.Drawing.Font(fnt.Name, fnt.Size, fnt.Style, fnt.Unit, fnt.gdiCharSet, fnt.gdiVerticalFont);

				Type t1 = objParent.GetType();

				switch (t1.FullName)
				{
					case "PureComponents.TreeView.NodeStyle" :						
						ns.Font = NewFont;
						break;

					case "PureComponents.TreeView.NodeTooltipStyle" :
						ns.TooltipStyle.Font = NewFont;
						break;

				}

					break;

				default :
					

					obj = (System.Type.GetType(pi.GetType().Name));
					obj = pi.GetValue(objParent,null);

					for (int i = 0; i < tr.AttributeCount; i++)
					{

						tr.MoveToAttribute(i);

						SetProperty(obj, tr.Name, tr.Value);

					}
					break;
			}

	}
开发者ID:ChrisMoreton,项目名称:Test3,代码行数:75,代码来源:TreeViewXML.cs

示例14: GetDefaultValue

 private static JToken GetDefaultValue(object obj, PropertyInfo property)
 {
     object value = null;
     try
     {
         value = property.GetValue(obj, null);
     }
     catch { }
     if (value == null)
     {
         return new JValue("");
     }
     else if (property.PropertyType == typeof(int))
     {
         return new JValue((int)value);
     }
     else if (property.PropertyType == typeof(bool))
     {
         return new JValue(value.ToString().ToLower());
     }
     else if (property.PropertyType == typeof(System.Drawing.Font))
     {
         var font = (System.Drawing.Font)value;
         var fontValue = new List<string>();
         fontValue.Add(font.OriginalFontName);
         fontValue.Add(string.Format("{0}pt", font.Size));
         if (font.Style != System.Drawing.FontStyle.Regular)
         {
             fontValue.Add(font.Style.ToString());
         }
         return new JValue(string.Join(",", fontValue));
     }
     else if (typeof(System.Collections.IList).IsAssignableFrom(property.PropertyType))
     {
         var items = new JArray();
         if (property.PropertyType.IsGenericType && property.PropertyType.GetGenericArguments().Length == 1)
         {
             var itemType = property.PropertyType.GetGenericArguments()[0];
             var toolItems = new ArrayList();
             if (itemType == typeof(JQClientTools.JQToolItem))
             {
                 //增加grid的默认toolitems
                 toolItems.AddRange(new JQClientTools.JQToolItem[] { JQClientTools.JQToolItem.InsertItem, JQClientTools.JQToolItem.UpdateItem, JQClientTools.JQToolItem.DeleteItem
                     , JQClientTools.JQToolItem.ApplyItem, JQClientTools.JQToolItem.CancelItem, JQClientTools.JQToolItem.QueryItem });
             }
             else if (itemType == typeof(JQMobileTools.JQToolItem))
             {
                 //增加grid的默认toolitems
                 toolItems.AddRange(new JQMobileTools.JQToolItem[] { JQMobileTools.JQToolItem.InsertItem, JQMobileTools.JQToolItem.PreviousPageItem,  JQMobileTools.JQToolItem.NextPageItem
                     , JQMobileTools.JQToolItem.QueryItem, JQMobileTools.JQToolItem.RefreshItem, JQMobileTools.JQToolItem.BackItem });
             }
             foreach (var toolItem in toolItems)
             {
                 var item = new JObject();
                 var itemProperties = toolItem.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);
                 foreach (var itemProperty in itemProperties)
                 {
                     if (CanEdit(itemProperty))
                     {
                         item[itemProperty.Name] = GetDefaultValue(toolItem, itemProperty);
                     }
                 }
                 items.Add(item);
             }
         }
         else if (typeof(System.Collections.IList).IsAssignableFrom(property.PropertyType))
         {
             CodeParser helper = new CodeParser();
             foreach (var collectionItem in (IEnumerable)value)
             {
                 items.Add(helper.GetItemProperties(collectionItem));
             }
         }
         return items;
     }
     else
     {
         return new JValue(value.ToString());
     }
 }
开发者ID:san90279,项目名称:UK_OAS,代码行数:80,代码来源:JsonHelper.cs


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