本文整理汇总了C#中IType.GetFieldByName方法的典型用法代码示例。如果您正苦于以下问题:C# IType.GetFieldByName方法的具体用法?C# IType.GetFieldByName怎么用?C# IType.GetFieldByName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IType
的用法示例。
在下文中一共展示了IType.GetFieldByName方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetEnumGetHashCodeMethod
public static void GetEnumGetHashCodeMethod(
IType enumType,
ITypeResolver typeResolver,
out object[] code,
out IList<object> tokenResolutions,
out IList<IType> locals,
out IList<IParameter> parameters)
{
Debug.Assert(enumType.ToNormal().IsEnum, "This is for enum only");
var codeList = new List<object>();
codeList.Add(Code.Ldarg_0);
codeList.AppendInt(Code.Ldfld, 1);
codeList.Add(Code.Conv_I4);
// return
codeList.Add(Code.Ret);
// End of Code
// tokens
tokenResolutions = new List<object>();
// data
tokenResolutions.Add(enumType.GetFieldByName("Value", typeResolver));
// locals
locals = new List<IType>();
// code
code = codeList.ToArray();
// parameters
parameters = new List<IParameter>();
}
示例2: GetSingleDimensionArrayCtor
public static void GetSingleDimensionArrayCtor(
IType arrayType,
ITypeResolver typeResolver,
out object[] code,
out IList<object> tokenResolutions,
out IList<IType> locals,
out IList<IParameter> parameters)
{
Debug.Assert(arrayType.IsArray && !arrayType.IsMultiArray, "This is for single dim arrays only");
var codeList = new List<object>();
var arrayRank = arrayType.ArrayRank;
var elementType = arrayType.GetElementType();
var typeCode = elementType.GetTypeCode();
var elementSize = elementType.GetTypeSize(typeResolver, true);
codeList.AddRange(
new object[]
{
Code.Ldarg_0,
Code.Dup,
Code.Dup,
Code.Dup,
});
codeList.AppendLoadInt(arrayRank);
codeList.AppendInt(Code.Stfld, 1);
codeList.AppendLoadInt(typeCode);
codeList.AppendInt(Code.Stfld, 2);
codeList.AppendLoadInt(elementSize);
codeList.AppendInt(Code.Stfld, 3);
codeList.AppendLoadArgument(1);
codeList.AppendInt(Code.Stfld, 4);
// return
codeList.AddRange(
new object[]
{
Code.Ret
});
// locals
locals = new List<IType>();
locals.Add(typeResolver.System.System_Int32.ToArrayType(1));
locals.Add(typeResolver.System.System_Int32.ToArrayType(1));
// tokens
tokenResolutions = new List<object>();
tokenResolutions.Add(arrayType.GetFieldByName("rank", typeResolver));
tokenResolutions.Add(arrayType.GetFieldByName("typeCode", typeResolver));
tokenResolutions.Add(arrayType.GetFieldByName("elementSize", typeResolver));
tokenResolutions.Add(arrayType.GetFieldByName("length", typeResolver));
// code
code = codeList.ToArray();
// parameters
parameters = ArrayMultiDimensionGen.GetParameters(arrayType, typeResolver);
}
示例3: GetIndexPartMethodBody
private static List<object> GetIndexPartMethodBody(
IType arrayType,
ITypeResolver typeResolver,
out IList<object> tokenResolutions,
out IList<IType> locals)
{
var codeList = new List<object>();
// init multiplier
codeList.Add(Code.Ldc_I4_1);
codeList.Add(Code.Stloc_0);
// load index, load lowerBound value, calculate shift
foreach (var i in Enumerable.Range(0, arrayType.ArrayRank))
{
// load index (first is 'this')
//codeList.AppendLoadArgument(i + 1);
codeList.AppendLoadArgument(arrayType.ArrayRank - i);
// - lowerBounds[index]
// load lowerBound value by index
codeList.Add(Code.Ldarg_0);
// load field 1 = lowerBounds
codeList.AppendInt(Code.Ldfld, 2);
// lower bound index
codeList.AppendLoadInt(i);
// load element
codeList.Add(Code.Ldelem_I4);
// calculate diff.
codeList.Add(Code.Sub);
if (i > 0)
{
// * bounds[index - 1]
// load bound value by index
codeList.Add(Code.Ldarg_0);
// load field 2 = bounds
codeList.AppendInt(Code.Ldfld, 3);
// lower bound index
codeList.AppendLoadInt(i - 1);
// load element
codeList.Add(Code.Ldelem_I4);
// calculate multiplier
codeList.Add(Code.Ldloc_0);
codeList.Add(Code.Mul);
codeList.Add(Code.Dup);
codeList.Add(Code.Stloc_0);
// multiply index.
codeList.Add(Code.Mul);
// + sum
codeList.Add(Code.Add);
}
}
// End of Code
// tokens
tokenResolutions = new List<object>();
// data
tokenResolutions.Add(arrayType.GetFieldByName("data", typeResolver));
// lowerBounds
tokenResolutions.Add(arrayType.GetFieldByName("lowerBounds", typeResolver));
// bounds
tokenResolutions.Add(arrayType.GetFieldByName("lengths", typeResolver));
// element type
tokenResolutions.Add(arrayType.GetElementType());
// element type as pointer
tokenResolutions.Add(arrayType.GetElementType().ToPointerType());
locals = new List<IType>();
locals.Add(typeResolver.System.System_Int32);
return codeList;
}
示例4: GetMultiDimensionArrayCtor
//.........这里部分代码省略.........
new object[]
{
Code.Ldarg_0,
Code.Dup,
Code.Dup,
});
codeList.AppendLoadInt(arrayRank);
codeList.AppendInt(Code.Stfld, 1);
codeList.AppendLoadInt(typeCode);
codeList.AppendInt(Code.Stfld, 2);
codeList.AppendLoadInt(elementSize);
codeList.AppendInt(Code.Stfld, 3);
// init lowerBounds
// set all 0
codeList.AppendLoadInt(arrayRank);
codeList.AppendInt(Code.Newarr, 4);
codeList.Add(Code.Stloc_0);
// init each item in lowerBounds
foreach (var i in Enumerable.Range(0, arrayRank))
{
codeList.Add(Code.Ldloc_0);
codeList.AppendLoadInt(i);
codeList.AddRange(
new object[]
{
Code.Ldc_I4_0,
Code.Stelem_I4
});
}
// save new array into field lowerBounds
codeList.AddRange(
new object[]
{
Code.Ldarg_0,
Code.Ldloc_0,
});
codeList.AppendInt(Code.Stfld, 5);
// init Bounds
codeList.AppendLoadInt(arrayRank);
codeList.AppendInt(Code.Newarr, 6);
codeList.Add(Code.Stloc_1);
// init each item in lowerBounds
foreach (var i in Enumerable.Range(0, arrayRank))
{
codeList.Add(Code.Ldloc_1);
codeList.AppendLoadInt(i);
//codeList.AppendLoadArgument(i + 1);
codeList.AppendLoadArgument(arrayRank - i);
codeList.AddRange(
new object[]
{
Code.Stelem_I4
});
}
// save new array into field lowerBounds
codeList.AddRange(
new object[]
{
Code.Ldarg_0,
Code.Ldloc_1,
});
codeList.AppendInt(Code.Stfld, 7);
// return
codeList.AddRange(
new object[]
{
Code.Ret
});
// locals
locals = new List<IType>();
locals.Add(typeResolver.System.System_Int32.ToArrayType(1));
locals.Add(typeResolver.System.System_Int32.ToArrayType(1));
// tokens
tokenResolutions = new List<object>();
tokenResolutions.Add(arrayType.GetFieldByName("rank", typeResolver));
tokenResolutions.Add(arrayType.GetFieldByName("typeCode", typeResolver));
tokenResolutions.Add(arrayType.GetFieldByName("elementSize", typeResolver));
// lowerBounds
tokenResolutions.Add(typeResolver.System.System_Int32);
tokenResolutions.Add(arrayType.GetFieldByName("lowerBounds", typeResolver));
// bounds
tokenResolutions.Add(typeResolver.System.System_Int32);
tokenResolutions.Add(arrayType.GetFieldByName("lengths", typeResolver));
// code
code = codeList.ToArray();
// parameters
parameters = GetParameters(arrayType, typeResolver);
}
示例5: GetEnumToStringMethod
public static void GetEnumToStringMethod(
IType enumType,
ITypeResolver typeResolver,
out object[] code,
out IList<object> tokenResolutions,
out IList<IType> locals,
out IList<IParameter> parameters)
{
Debug.Assert(enumType.ToNormal().IsEnum, "This is for enum only");
var codeList = new List<object>();
codeList.Add(Code.Ldarg_0);
codeList.AppendInt(Code.Ldfld, 1);
var sizeOfEnum = enumType.GetEnumUnderlyingType().IntTypeBitSize() / 8;
// build cmp/jmp cases
var stringValues = 1;
foreach (var enumConstValue in IlReader.Fields(enumType, typeResolver).Where(f => f.IsConst))
{
codeList.Add(Code.Dup);
if (sizeOfEnum == 8)
{
codeList.AppendULong(
Code.Ldc_I8, enumConstValue.ConstantValue.ToString() == "-1" ? 0xffffffffffffffff : Convert.ToUInt64(enumConstValue.ConstantValue));
}
else
{
codeList.AppendUInt(Code.Ldc_I4, unchecked((uint)Convert.ToInt64(enumConstValue.ConstantValue)));
}
codeList.Add(Code.Bne_Un_S);
codeList.Add(6);
codeList.AppendInt(Code.Ldstr, ++stringValues);
codeList.Add(Code.Ret);
}
codeList.Add(Code.Pop);
codeList.AppendInt(Code.Ldstr, ++stringValues);
codeList.Add(Code.Ret);
// End of Code
// tokens
tokenResolutions = new List<object>();
// data
tokenResolutions.Add(enumType.GetFieldByName("Value", typeResolver));
foreach (var enumConstValue in IlReader.Fields(enumType, typeResolver).Where(f => f.IsConst))
{
tokenResolutions.Add(enumConstValue.Name);
}
// default value
tokenResolutions.Add(string.Empty);
// locals
locals = new List<IType>();
// code
code = codeList.ToArray();
// parameters
parameters = new List<IParameter>();
}