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


C# PropertyInfo.SetValue方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: propertyFromTable

 public void propertyFromTable(object pObject, PropertyInfo lPropertyInfo, Hashtable pTable)
 {
     if (pTable.Contains(lPropertyInfo.Name))
     {
         var lPropertyType = lPropertyInfo.PropertyType;
         var lSerializeString = zzSerializeString.Singleton;
         object lTableValue = pTable[lPropertyInfo.Name];
         object lValue = null;
         if (lSerializeString.isSupportedType(lPropertyType))
             lValue = lTableValue;
         else
         {
             lValue = getMethod(lPropertyType).deserialize(lPropertyType, lTableValue);
         }
         if (lValue == null)
             Debug.LogError("error in " + pObject.GetType().ToString() + "." + lPropertyInfo.Name);
         else
         {
             //Debug.Log(lPropertyInfo.Name + " " + lValue + ":" + lPropertyInfo.PropertyType);
             lPropertyInfo.SetValue(pObject, lValue, null);
         }
     }
 }
开发者ID:Seraphli,项目名称:TheInsectersWar,代码行数:23,代码来源:zzSerializeObject.cs

示例5: TweenVar

    private void TweenVar(object fromValue, object toValue, OTEase easing, FieldInfo field, PropertyInfo prop)
    {
        object value = null;
        if (toValue == null || fromValue == null) return;

        switch (fromValue.GetType().Name.ToLower())
        {
            case "single":
                if (!(toValue is float))
                    toValue = System.Convert.ToSingle(toValue);
                value = easing.ease(time, (float)fromValue, (float)toValue - (float)fromValue, duration);
                break;
            case "double":
                if (!(toValue is double))
                    toValue = System.Convert.ToDouble(toValue);
                value = easing.ease(time, (float)fromValue, (float)toValue - (float)fromValue, duration);
                break;
            case "int":
                if (!(toValue is int))
                    toValue = System.Convert.ToInt32(toValue);

                value = easing.ease(time, (int)fromValue, (int)toValue - (int)fromValue, duration);
                break;
            case "vector2":
                Vector2 _toValue2 = (Vector2)toValue;
                Vector2 _fromValue2 = (Vector2)fromValue;
                Vector2 _value2 = Vector2.zero;

                if ((_toValue2 - _fromValue2).x != 0)
                    _value2.x = easing.ease(time, _fromValue2.x, (_toValue2 - _fromValue2).x, duration);
                else
                    _value2.x = _fromValue2.x;

                if ((_toValue2 - _fromValue2).y != 0)
                    _value2.y = easing.ease(time, _fromValue2.y, (_toValue2 - _fromValue2).y, duration);
                else
                    _value2.y = _fromValue2.y;

                value = _value2;
                break;
            case "vector3":
                Vector3 _toValue3 = (Vector3)toValue;
                Vector3 _fromValue3 = (Vector3)fromValue;
                Vector3 _value3 = Vector3.zero;

                if ((_toValue3 - _fromValue3).x != 0)
                    _value3.x = easing.ease(time, _fromValue3.x, (_toValue3 - _fromValue3).x, duration);
                else
                    _value3.y = _fromValue3.y;
                if ((_toValue3 - _fromValue3).y != 0)
                    _value3.y = easing.ease(time, _fromValue3.y, (_toValue3 - _fromValue3).y, duration);
                else
                    _value3.y = _fromValue3.y;
                if ((_toValue3 - _fromValue3).z != 0)
                    _value3.z = easing.ease(time, _fromValue3.z, (_toValue3 - _fromValue3).z, duration);
                else
                    _value3.z = _fromValue3.z;

                value = _value3;
                break;
            case "color":
                Color _toColor = (Color)toValue;
                Color _fromColor = (Color)fromValue;

                float r = easing.ease(time, _fromColor.r, _toColor.r - _fromColor.r, duration);
                float g = easing.ease(time, _fromColor.g, _toColor.g - _fromColor.g, duration);
                float b = easing.ease(time, _fromColor.b, _toColor.b - _fromColor.b, duration);
                float a = easing.ease(time, _fromColor.a, _toColor.a - _fromColor.a, duration);

                value = new Color(r, g, b, a);
                break;
        }

        if (field != null)
            field.SetValue(owner, value);
        else
            if (prop != null)
                prop.SetValue(owner, value, null);
    }
开发者ID:AlexTiTanium,项目名称:Kombain-game,代码行数:79,代码来源:OTTween.cs

示例6: 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

示例7: PropProxy

 public PropProxy(PropertyInfo prop, SteeringBehavior behavior, object defaultValue)
 {
     this.property = prop;
     this.behavior = behavior;
     property.SetValue(behavior, defaultValue, null);
 }
开发者ID:xpresso,项目名称:SanityEngine,代码行数:6,代码来源:SteeringBehaviorProxy.cs

示例8: SetPropertyValue

	// Set the current value of the specified property owned by instance. If instance is null then property is static.
	// Returns: boolean indicating whether the property was successfully changed, or if property is read-only.
	public static bool SetPropertyValue(object instance, PropertyInfo propertyInfo, List<string> parameters) {
		if(propertyInfo.GetSetMethod() == null) {
			string output = GetPropertyValue(instance, propertyInfo);
			if(output == null) { return false; } // Fail: Property is not of a supported type
			Echo(propertyInfo.Name + " is read-only!");
			Echo(propertyInfo.Name + " is " + output);
			return true; // Success: Value is printed when property is read-only
		}
		object result = ParseParameterListIntoType(propertyInfo.PropertyType.Name, parameters);
		if(result != null) {
			propertyInfo.SetValue(instance, result, null);
			return true;
		} else {
			return false; // Fail: The parameters could not be parsed into the desired type
		}
	}
开发者ID:wfowler1,项目名称:Miscellaneous-Soundboards,代码行数:18,代码来源:Console.cs


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