本文整理汇总了C#中System.Reflection.MemberInfo.GetVariableType方法的典型用法代码示例。如果您正苦于以下问题:C# MemberInfo.GetVariableType方法的具体用法?C# MemberInfo.GetVariableType怎么用?C# MemberInfo.GetVariableType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.MemberInfo
的用法示例。
在下文中一共展示了MemberInfo.GetVariableType方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddMapping
static void AddMapping(LightDBDefinitionSet defs, TableDefinition[] defaultTables, SimpleFlatFieldDefinition fieldDef,
Dictionary<string, List<SimpleDataColumn>> mappedFields, IFlatDataFieldAccessor accessor, MemberInfo member)
{
var column = fieldDef.Column;
var tables = defs.EnsureTables(fieldDef.Table, defaultTables);
object defaultValue;
if (!String.IsNullOrEmpty(fieldDef.DefaultStringValue))
{
defaultValue = StringParser.Parse(fieldDef.DefaultStringValue, member.GetVariableType());
}
else
{
if (String.IsNullOrEmpty(column))
{
return;
}
defaultValue = null;
}
foreach (var table in tables)
{
var dataHolders = defs.m_tableDataHolderMap.GetOrCreate(table);
if (!dataHolders.Contains(accessor.DataHolderDefinition))
{
dataHolders.Add(accessor.DataHolderDefinition);
}
var mappedFieldMap = mappedFields.GetOrCreate(table.Name);
SimpleDataColumn dataColumn;
var dbAttrs = member.GetCustomAttributes<DBAttribute>();
var attr = dbAttrs.Where(attribute => attribute is PersistentAttribute).FirstOrDefault() as PersistentAttribute;
if (String.IsNullOrEmpty(column))
{
// use default value
mappedFieldMap.Add(dataColumn = new SimpleDataColumn(fieldDef.Name, defaultValue));
}
else
{
dataColumn = mappedFieldMap.Find((cmpField) => cmpField.ColumnName == column);
if (dataColumn == null)
{
var type = member.GetActualType();
if (attr != null)
type = attr.ReadType ?? type;
var reader = Converters.GetReader(type);
mappedFieldMap.Add(dataColumn = new SimpleDataColumn(column, reader));
}
}
dataColumn.FieldList.Add(accessor);
}
}
示例2: ModProp
public static void ModProp(object propHolder, MemberInfo prop, CmdTrigger<RealmServerCmdArgs> trigger)
{
if (prop != null && ReflectUtil.Instance.CanWrite(prop, trigger.Args.Role))
{
var exprType = prop.GetVariableType();
if (!exprType.IsInteger())
{
trigger.Reply("Can only modify Integer-values.");
}
else
{
var expr = trigger.Text.Remainder.Trim();
if (expr.Length == 0)
{
trigger.Reply("No expression given");
}
else
{
object error = null;
var value = Convert.ToInt64(prop.GetUnindexedValue(propHolder));
if (!Utility.Eval(exprType, ref value, expr, ref error, true))
{
trigger.Reply("Invalid expression: " + error);
}
else
{
var actualValue = TryParseEnum(value, exprType);
prop.SetUnindexedValue(propHolder, actualValue);
string strValue;
if (exprType.IsEnum)
{
strValue = Enum.Format(exprType, actualValue, "g");
}
else
{
strValue = value.ToString();
}
trigger.Reply("Success: {0} is now {1}.", prop.Name, strValue);
}
}
}
}
else
{
trigger.Reply("Invalid field.");
}
}
示例3: SetProp
public static void SetProp(object propHolder, MemberInfo prop, CmdTrigger<RealmServerCmdArgs> trigger)
{
if (prop != null && ReflectUtil.Instance.CanWrite(prop, trigger.Args.Role))
{
var expr = trigger.Text.Remainder.Trim();
if (expr.Length == 0)
{
trigger.Reply("No expression given");
}
else
{
var exprType = prop.GetVariableType();
object actualValue = null;
if (exprType.IsInteger())
{
object error = null;
long value = 0;
if (!Utility.Eval(exprType, ref value, expr, ref error, false))
{
trigger.Reply("Invalid expression: " + error);
return;
}
actualValue = ConvertActualType(value, exprType);
}
else
{
if (!Utility.Parse(expr, exprType, ref actualValue))
{
trigger.Reply("Could not change value \"{0}\" to Type: {1}", expr, exprType);
return;
}
}
prop.SetUnindexedValue(propHolder, actualValue);
string strValue;
if (exprType.IsEnum)
{
strValue = Enum.Format(exprType, actualValue, "g");
}
else
{
strValue = actualValue.ToString();
}
trigger.Reply("{0} is now {1}.", prop.Name, strValue);
}
}
else
{
trigger.Reply("Invalid field.");
}
}
示例4: AddMapping
static void AddMapping(LightDBDefinitionSet defs, TableDefinition[] defaultTables, SimpleFlatFieldDefinition fieldDef,
Dictionary<string, List<SimpleDataColumn>> mappedFields, IFlatDataFieldAccessor accessor, MemberInfo member)
{
var column = fieldDef.Column;
var tables = defs.EnsureTables(fieldDef.Table, defaultTables);
object defaultValue;
if (!String.IsNullOrEmpty(fieldDef.DefaultStringValue))
{
defaultValue = Utility.Parse(fieldDef.DefaultStringValue, member.GetVariableType());
}
else
{
if (String.IsNullOrEmpty(column))
{
return;
}
defaultValue = null;
}
if (accessor.DataHolderDefinition.Type.Name.EndsWith("TrainerEntry"))
{
defs.ToString();
}
foreach (var table in tables)
{
var dataHolders = defs.m_tableDataHolderMap.GetOrCreate(table);
if (!dataHolders.Contains(accessor.DataHolderDefinition))
{
dataHolders.Add(accessor.DataHolderDefinition);
}
var mappedFieldMap = mappedFields.GetOrCreate(table.Name);
SimpleDataColumn dataColumn;
if (String.IsNullOrEmpty(column))
{
// use default value
mappedFieldMap.Add(dataColumn = new SimpleDataColumn(fieldDef.Name, defaultValue));
}
else
{
dataColumn = mappedFieldMap.Find((cmpField) => cmpField.ColumnName == column);
if (dataColumn == null)
{
mappedFieldMap.Add(dataColumn = new SimpleDataColumn(column, Converters.GetReader(member.GetActualType())));
}
}
dataColumn.FieldList.Add(accessor);
}
}