本文整理汇总了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);
}
示例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;
// }
//}
}
示例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;
// }
//}
}
示例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);
}
}
}
示例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);
}
示例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)
);
}
}
}
示例7: PropProxy
public PropProxy(PropertyInfo prop, SteeringBehavior behavior, object defaultValue)
{
this.property = prop;
this.behavior = behavior;
property.SetValue(behavior, defaultValue, null);
}
示例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
}
}