本文整理汇总了C#中FieldAttributes.HasFlag方法的典型用法代码示例。如果您正苦于以下问题:C# FieldAttributes.HasFlag方法的具体用法?C# FieldAttributes.HasFlag怎么用?C# FieldAttributes.HasFlag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FieldAttributes
的用法示例。
在下文中一共展示了FieldAttributes.HasFlag方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ModifyFieldDefProps
/// <summary>
/// The backing field of a WinRT enumeration type is not public although the backing fields
/// of managed enumerations are. To allow managed languages to directly access this field,
/// it is made public by the metadata adapter.
/// </summary>
private void ModifyFieldDefProps(FieldHandle fieldDef, string name, ref FieldAttributes flags)
{
if (name == "value__" && flags.HasFlag(FieldAttributes.RTSpecialName))
{
TypeHandle typeDef = FindContainingType(fieldDef);
Debug.Assert(!typeDef.IsNil);
MetadataToken extendsRef = GetTypeDefExtends(typeDef);
if (extendsRef.HandleType == HandleType.TypeReference)
{
string extendsName, extendsNamespace;
MetadataToken unused;
GetTypeRefProps(
(TypeReferenceHandle)extendsRef,
out extendsName,
out extendsNamespace,
out unused);
if (extendsName == "Enum" && extendsNamespace == "System")
{
flags = flags & ~FieldAttributes.Private;
flags |= FieldAttributes.Public;
}
}
}
}
示例2: DefineField
/// <summary>
/// Defines a new field to the type.
/// </summary>
/// <param name="name">The name of the field. <paramref name="name"/> cannot contain embedded nulls.</param>
/// <param name="type">The type of the field/</param>
/// <param name="attributes">A bitwise combination of the field attributes.</param>
/// <param name="initializer">The expression which is not reduced to be <see cref="LambdaExpression"/> for the initializer of the field, with a parameter for "this" instance, returns <paramref name="type"/> value.</param>
/// <returns>The defined field.</returns>
public FieldBuilder DefineField(
String name,
Type type,
FieldAttributes attributes,
Expression initializer
)
{
var isStatic = attributes.HasFlag(FieldAttributes.Static);
return this._type.DefineField(
name,
type,
attributes
)
.If(_ => initializer != null, f =>
this._implType.DefineMethod(
GetName(f, "Init"),
MethodAttributes.Assembly | MethodAttributes.Static,
type,
isStatic ? Type.EmptyTypes : this._typeArray
)
.Apply(
i =>
(isStatic
? (this._cctor ?? (this._cctor = this._type.DefineTypeInitializer())).GetILGenerator()
: this._prologue.GetILGenerator()
)
.Apply(
g => g.If(_ => !isStatic, _ => LoadArgs(g, 0, 0)),
g => g.Emit(OpCodes.Call, i),
g => g.Emit(isStatic ? OpCodes.Stsfld : OpCodes.Stfld, f)
),
i => this.RequestInitializing(i, initializer, type, isStatic ? this._typeArray : Type.EmptyTypes)
)
)
.Apply(this._members.Add);
}
示例3: GetIcons
string[] GetIcons(string b, FieldAttributes a)
{
if (a.HasFlag(FieldAttributes.Private)) return GetIconsStub(b, "Private");
return GetIconsStub(b, string.Empty);
}