本文整理汇总了C#中TypeWrapper.GetFields方法的典型用法代码示例。如果您正苦于以下问题:C# TypeWrapper.GetFields方法的具体用法?C# TypeWrapper.GetFields怎么用?C# TypeWrapper.GetFields使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TypeWrapper
的用法示例。
在下文中一共展示了TypeWrapper.GetFields方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteFields
private static void WriteFields(BigEndianStream bes, TypeWrapper tw)
{
List<FieldWrapper> list = new List<FieldWrapper>();
foreach (FieldWrapper fw in tw.GetFields())
{
if (!fw.IsHideFromReflection)
{
list.Add(fw);
}
}
list.Sort(delegate(FieldWrapper fw1, FieldWrapper fw2) { return String.CompareOrdinal(fw1.Name, fw2.Name); });
foreach (FieldWrapper fw in list)
{
Modifiers mods = fw.Modifiers & (Modifiers.Public | Modifiers.Private | Modifiers.Protected | Modifiers.Static | Modifiers.Final | Modifiers.Volatile | Modifiers.Transient);
if (((mods & Modifiers.Private) == 0) || ((mods & (Modifiers.Static | Modifiers.Transient)) == 0))
{
bes.WriteUtf8(fw.Name);
bes.WriteUInt32((uint)mods);
bes.WriteUtf8(fw.Signature.Replace('.', '/'));
}
}
}
示例2: WriteClass
//.........这里部分代码省略.........
{
ExceptionsAttribute attrib = new ExceptionsAttribute(writer);
if (throws.classes != null)
{
foreach (string ex in throws.classes)
{
attrib.Add(ex.Replace('.', '/'));
}
}
if (throws.types != null)
{
foreach (Type ex in throws.types)
{
attrib.Add(ClassLoaderWrapper.GetWrapperFromType(ex).Name.Replace('.', '/'));
}
}
m.AddAttribute(attrib);
}
if (mb.IsDefined(JVM.Import(typeof(ObsoleteAttribute)), false)
// HACK the instancehelper methods are marked as Obsolete (to direct people toward the ikvm.extensions methods instead)
// but in the Java world most of them are not deprecated (and to keep the Japi results clean we need to reflect this)
&& (!mb.Name.StartsWith("instancehelper_")
|| mb.DeclaringType.FullName != "java.lang.String"
// the Java deprecated methods actually have two Obsolete attributes
|| GetObsoleteCount(mb) == 2))
{
m.AddAttribute(new DeprecatedAttribute(writer));
}
CustomAttributeData attr = GetAnnotationDefault(mb);
if (attr != null)
{
m.AddAttribute(new AnnotationDefaultClassFileAttribute(writer, GetAnnotationDefault(writer, attr.ConstructorArguments[0])));
}
if (includeParameterNames)
{
ParameterInfo[] parameters = mb.GetParameters();
if (parameters.Length != 0)
{
ushort[] names = new ushort[parameters.Length];
for (int i = 0; i < names.Length; i++)
{
if (parameters[i].Name != null)
{
names[i] = writer.AddUtf8(parameters[i].Name);
}
}
m.AddAttribute(new MethodParametersAttribute(writer, names));
}
}
}
string sig = tw.GetGenericMethodSignature(mw);
if (sig != null)
{
m.AddAttribute(writer.MakeStringAttribute("Signature", sig));
}
AddAnnotations(writer, m, mw.GetMethod());
AddParameterAnnotations(writer, m, mw.GetMethod());
}
}
bool hasSerialVersionUID = false;
foreach (FieldWrapper fw in tw.GetFields())
{
if (!fw.IsHideFromReflection)
{
bool isSerialVersionUID = includeSerialVersionUID && fw.Name == "serialVersionUID" && fw.FieldTypeWrapper == PrimitiveTypeWrapper.LONG;
hasSerialVersionUID |= isSerialVersionUID;
if (fw.IsPublic || fw.IsProtected || isSerialVersionUID || includeNonPublicMembers)
{
object constant = null;
if (fw.GetField() != null && fw.GetField().IsLiteral && (fw.FieldTypeWrapper.IsPrimitive || fw.FieldTypeWrapper == CoreClasses.java.lang.String.Wrapper))
{
constant = fw.GetField().GetRawConstantValue();
if (fw.GetField().FieldType.IsEnum)
{
constant = EnumHelper.GetPrimitiveValue(EnumHelper.GetUnderlyingType(fw.GetField().FieldType), constant);
}
}
FieldOrMethod f = writer.AddField(fw.Modifiers, fw.Name, fw.Signature.Replace('.', '/'), constant);
string sig = tw.GetGenericFieldSignature(fw);
if (sig != null)
{
f.AddAttribute(writer.MakeStringAttribute("Signature", sig));
}
if (fw.GetField() != null && fw.GetField().IsDefined(JVM.Import(typeof(ObsoleteAttribute)), false))
{
f.AddAttribute(new DeprecatedAttribute(writer));
}
AddAnnotations(writer, f, fw.GetField());
}
}
}
if (includeSerialVersionUID && !hasSerialVersionUID && IsSerializable(tw))
{
// class is serializable but doesn't have an explicit serialVersionUID, so we add the field to record
// the serialVersionUID as we see it (mainly to make the Japi reports more realistic)
writer.AddField(Modifiers.Private | Modifiers.Static | Modifiers.Final, "serialVersionUID", "J", SerialVersionUID.Compute(tw));
}
AddMetaAnnotations(writer, tw);
writer.Write(stream);
}