本文整理汇总了C#中IAttribute.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# IAttribute.GetType方法的具体用法?C# IAttribute.GetType怎么用?C# IAttribute.GetType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IAttribute
的用法示例。
在下文中一共展示了IAttribute.GetType方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ToString
public static string ToString(IAttribute attribute)
{
var builder = new StringBuilder();
var attributeType = attribute.GetType();
builder.Append(" - ").Append(attributeType.Name).AppendLine();
foreach (var eachProperty in attributeType.GetProperties())
{
var propertyValue = eachProperty.GetValue(attribute);
builder.Append(" - ").Append(eachProperty.Name).Append('=').Append(propertyValue).AppendLine();
}
return builder.ToString();
}
示例2: Assign
public static void Assign(this IAttribute attribute, IAttribute other)
{
Debug.Assert(attribute != null);
if (other == null)
return;
Debug.Assert(attribute.GetType() == other.GetType());
foreach (var eachProperty in attribute.GetType().GetProperties())
{
eachProperty.SetValue(attribute, eachProperty.GetValue(other));
}
}
示例3: ApplyMaxConstraints
private static object ApplyMaxConstraints(ConstraintsAttribute constraints, object newValue, IAttribute attribute, PropertyInfo propertyInfo)
{
switch (constraints.ValueType)
{
case ConstraintsValueType.IntValue:
return Math.Min(newValue.As<int>(), constraints.IntValue);
case ConstraintsValueType.FloatValue:
return Math.Min(newValue.As<float>(), constraints.FloatValue);
case ConstraintsValueType.Reference:
{
var attributeType = attribute.GetType();
var referenceProperty = attributeType.GetProperty(constraints.FieldName.ToCamelCase());
return Math.Min(newValue.As<float>(), referenceProperty.GetValue(attribute).As<float>());
}
}
throw new InvalidOperationException("invalid value-type for max constraints: " + constraints.ValueType);
}
示例4: ApplyConstraints
public static object ApplyConstraints(IAttribute attribute, string propertyName, object newValue)
{
Debug.Assert(attribute != null);
var attributeType = attribute.GetType();
var propertyInfo = attributeType.GetProperty(propertyName);
Debug.Assert(propertyInfo != null);
foreach (var constraints in propertyInfo.GetCustomAttributes(typeof(ConstraintsAttribute), false).OfType<ConstraintsAttribute>())
{
switch (constraints.Type)
{
case ConstraintsType.Min:
newValue = ApplyMinConstraints(constraints, newValue, attribute, propertyInfo);
break;
case ConstraintsType.Max:
newValue = ApplyMaxConstraints(constraints, newValue, attribute, propertyInfo);
break;
}
}
return Convert.ChangeType(newValue, propertyInfo.PropertyType);
}
示例5: GetTypeName
public static string GetTypeName(IAttribute attribute)
{
return GetTypeName(attribute.GetType());
}