本文整理汇总了C#中TypeAttributes.HasFlag方法的典型用法代码示例。如果您正苦于以下问题:C# TypeAttributes.HasFlag方法的具体用法?C# TypeAttributes.HasFlag怎么用?C# TypeAttributes.HasFlag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TypeAttributes
的用法示例。
在下文中一共展示了TypeAttributes.HasFlag方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DefineNestedType
public void DefineNestedType(string name, TypeAttributes attributes, Type parent, PackingSize packingSize, int typesize, Type[] implementedInterfaces)
{
bool isDefaultImplementedInterfaces = implementedInterfaces?.Length == 0;
bool isDefaultPackingSize = packingSize == PackingSize.Unspecified;
bool isDefaultSize = typesize == 0;
bool isDefaultParent = parent == null;
bool isDefaultAttributes = attributes == TypeAttributes.NestedPrivate;
Action<TypeBuilder, TypeBuilder> verify = (type, declaringType) =>
{
bool allowsNullParent = attributes.HasFlag(TypeAttributes.Abstract) && attributes.HasFlag(TypeAttributes.ClassSemanticsMask);
Type baseType = allowsNullParent ? parent : (parent ?? typeof(object));
Helpers.VerifyType(type, declaringType.Module, declaringType, name, attributes, baseType, typesize, packingSize, implementedInterfaces);
};
if (isDefaultImplementedInterfaces)
{
if (isDefaultSize && isDefaultPackingSize)
{
if (isDefaultParent)
{
if (isDefaultAttributes)
{
// Use DefineNestedType(string)
TypeBuilder type1 = Helpers.DynamicType(TypeAttributes.Public);
verify(type1.DefineNestedType(name), type1);
}
// Use DefineNestedType(string, TypeAttributes)
TypeBuilder type2 = Helpers.DynamicType(TypeAttributes.Public);
verify(type2.DefineNestedType(name, attributes), type2);
}
// Use DefineNestedType(string, TypeAttributes, Type)
TypeBuilder type3 = Helpers.DynamicType(TypeAttributes.Public);
verify(type3.DefineNestedType(name, attributes, parent), type3);
}
else if (isDefaultSize)
{
// Use DefineNestedType(string, TypeAttributes, Type, PackingSize)
TypeBuilder type4 = Helpers.DynamicType(TypeAttributes.Public);
verify(type4.DefineNestedType(name, attributes, parent, packingSize), type4);
}
else if (isDefaultPackingSize)
{
// Use DefineNestedType(string, TypeAttributes, Type, int)
TypeBuilder type5 = Helpers.DynamicType(TypeAttributes.Public);
verify(type5.DefineNestedType(name, attributes, parent, typesize), type5);
}
// Use DefineNestedType(string, TypeAttributes, Type, PackingSize, int);
TypeBuilder type6 = Helpers.DynamicType(TypeAttributes.Public);
verify(type6.DefineNestedType(name, attributes, parent, packingSize, typesize), type6);
}
else
{
// Use DefineNestedType(string, TypeAttributes, Type, Type[])
Assert.True(isDefaultSize && isDefaultPackingSize); // Sanity check
TypeBuilder type7 = Helpers.DynamicType(TypeAttributes.Public);
verify(type7.DefineNestedType(name, attributes, parent, implementedInterfaces), type7);
}
}
示例2: DefineType
public void DefineType(string name, TypeAttributes attributes, Type parent, PackingSize packingSize, int typesize, Type[] implementedInterfaces)
{
bool isDefaultImplementedInterfaces = implementedInterfaces?.Length == 0;
bool isDefaultPackingSize = packingSize == PackingSize.Unspecified;
bool isDefaultSize = typesize == 0;
bool isDefaultParent = parent == null;
bool isDefaultAttributes = attributes == TypeAttributes.NotPublic;
Action<TypeBuilder, Module> verify = (type, module) =>
{
Type baseType = attributes.HasFlag(TypeAttributes.Abstract) && parent == null ? null : (parent ?? typeof(object));
Helpers.VerifyType(type, module, null, name, attributes, baseType, typesize, packingSize, implementedInterfaces);
};
if (isDefaultImplementedInterfaces)
{
if (isDefaultSize && isDefaultPackingSize)
{
if (isDefaultParent)
{
if (isDefaultAttributes)
{
// Use DefineType(string)
ModuleBuilder module1 = Helpers.DynamicModule();
verify(module1.DefineType(name), module1);
}
// Use DefineType(string, TypeAttributes)
ModuleBuilder module2 = Helpers.DynamicModule();
verify(module2.DefineType(name, attributes), module2);
}
// Use DefineType(string, TypeAttributes, Type)
ModuleBuilder module3 = Helpers.DynamicModule();
verify(module3.DefineType(name, attributes, parent), module3);
}
else if (isDefaultSize)
{
// Use DefineType(string, TypeAttributes, Type, PackingSize)
ModuleBuilder module4 = Helpers.DynamicModule();
verify(module4.DefineType(name, attributes, parent, packingSize), module4);
}
else if (isDefaultPackingSize)
{
// Use DefineType(string, TypeAttributes, Type, int)
ModuleBuilder module5 = Helpers.DynamicModule();
verify(module5.DefineType(name, attributes, parent, typesize), module5);
}
// Use DefineType(string, TypeAttributes, Type, PackingSize, int)
ModuleBuilder module6 = Helpers.DynamicModule();
verify(module6.DefineType(name, attributes, parent, packingSize, typesize), module6);
}
else
{
// Use DefineType(string, TypeAttributes, Type, Type[])
Assert.True(isDefaultSize && isDefaultPackingSize); // Sanity check
ModuleBuilder module7 = Helpers.DynamicModule();
verify(module7.DefineType(name, attributes, parent, implementedInterfaces), module7);
}
}