本文整理汇总了C#中System.Reflection.GetValue方法的典型用法代码示例。如果您正苦于以下问题:C# Reflection.GetValue方法的具体用法?C# Reflection.GetValue怎么用?C# Reflection.GetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection
的用法示例。
在下文中一共展示了Reflection.GetValue方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessField
public void ProcessField(SysReflection.FieldInfo aField)
{
string xFieldName = LabelName.GetFullName(aField);
xFieldName = DataMember.GetStaticFieldName(aField);
if (Cosmos.Assembler.Assembler.CurrentInstance.DataMembers.Count(x => x.Name == xFieldName) == 0)
{
var xItemList = (from item in aField.GetCustomAttributes(false)
where item.GetType().FullName == "ManifestResourceStreamAttribute"
select item).ToList();
object xItem = null;
if (xItemList.Count > 0)
xItem = xItemList[0];
string xManifestResourceName = null;
if (xItem != null)
{
var xItemType = xItem.GetType();
xManifestResourceName = (string)xItemType.GetField("ResourceName").GetValue(xItem);
}
if (xManifestResourceName != null)
{
// todo: add support for manifest streams again
//string xFileName = Path.Combine(mOutputDir,
// (xCurrentField.DeclaringType.Assembly.FullName + "__" + xManifestResourceName).Replace(",",
// "_") + ".res");
var xTarget = new StringBuilder();
using (var xStream = aField.DeclaringType.Assembly.GetManifestResourceStream(xManifestResourceName))
{
if (xStream == null)
{
throw new Exception("Resource '" + xManifestResourceName + "' not found!");
}
xTarget.Append("0,");
// todo: abstract this array code out.
xTarget.Append((uint)InstanceTypeEnum.StaticEmbeddedArray);
xTarget.Append(",");
xTarget.Append((int)xStream.Length);
xTarget.Append(",");
xTarget.Append("1,");
while (xStream.Position < xStream.Length)
{
xTarget.Append(xStream.ReadByte());
xTarget.Append(",");
}
xTarget.Append(",");
}
Assembler.DataMembers.Add(new DataMember("___" + xFieldName + "___Contents",
"db",
xTarget));
Assembler.DataMembers.Add(new DataMember(xFieldName,
"dd",
"___" + xFieldName + "___Contents"));
}
else
{
uint xTheSize;
//string theType = "db";
Type xFieldTypeDef = aField.FieldType;
if (!xFieldTypeDef.IsClass || xFieldTypeDef.IsValueType)
{
xTheSize = ILOp.SizeOfType(aField.FieldType);
}
else
{
xTheSize = 8;
}
byte[] xData = new byte[xTheSize];
try
{
object xValue = aField.GetValue(null);
if (xValue != null)
{
try
{
Type xTyp = xValue.GetType();
if (xTyp.IsEnum)
{
xValue = Convert.ChangeType(xValue, Enum.GetUnderlyingType(xTyp));
}
if (xTyp.IsValueType)
{
for (int x = 4; x < xTheSize; x++)
{
xData[x] = Marshal.ReadByte(xValue,
x);
}
}
}
catch
{
}
}
}
catch
{
}
Cosmos.Assembler.Assembler.CurrentInstance.DataMembers.Add(new DataMember(xFieldName, xData));
}
}
//.........这里部分代码省略.........