本文整理汇总了C#中EnumMemberDeclaration类的典型用法代码示例。如果您正苦于以下问题:C# EnumMemberDeclaration类的具体用法?C# EnumMemberDeclaration怎么用?C# EnumMemberDeclaration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EnumMemberDeclaration类属于命名空间,在下文中一共展示了EnumMemberDeclaration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetActions
public IEnumerable<CodeAction> GetActions(RefactoringContext context)
{
var expr = GetCreatePropertyOrFieldNode(context);
if (expr == null)
yield break;
if (!(expr is MemberReferenceExpression))
yield break;
var propertyName = CreatePropertyAction.GetPropertyName(expr);
if (propertyName == null)
yield break;
if (IsInvocationTarget(expr))
yield break;
var statement = expr.GetParent<Statement>();
if (statement == null)
yield break;
if (!(context.Resolve(expr).IsError))
yield break;
var guessedType = CreateFieldAction.GuessType(context, expr);
if (guessedType == null || guessedType.Kind != TypeKind.Enum)
yield break;
var state = context.GetResolverStateBefore(expr);
if (state.CurrentMember == null || state.CurrentTypeDefinition == null)
yield break;
yield return new CodeAction(context.TranslateString("Create enum value"), script => {
var decl = new EnumMemberDeclaration {
Name = propertyName
};
script.InsertWithCursor(context.TranslateString("Create enum value"), guessedType.GetDefinition (), decl);
});
}
示例2: VisitEnumMemberDeclaration
public override object VisitEnumMemberDeclaration(EnumMemberDeclaration enumMemberDeclaration, object data)
{
if(!enumMemberDeclaration.Initializer.IsNull)
{
UnlockWith(enumMemberDeclaration.Initializer);
}
return base.VisitEnumMemberDeclaration(enumMemberDeclaration, data);
}
示例3: VisitEnumMemberDeclaration
public override void VisitEnumMemberDeclaration(EnumMemberDeclaration ed)
{
ModelV2.Code.Enum e = (ModelV2.Code.Enum) GetDeclarationFor(ed);
string[] keyValue = ed.GetText().Split('=');
e.Values.Add(new KeyValuePair<string,string>(keyValue[0], (keyValue.Length == 2) ? keyValue[1] : ""));
// call base
base.VisitEnumMemberDeclaration(ed);
}
示例4: VisitEnumMemberDeclaration
public override void VisitEnumMemberDeclaration(EnumMemberDeclaration enumMemberDeclaration)
{
Expression initializer = enumMemberDeclaration.Initializer;
if (enumMemberDeclaration.Initializer.IsNull)
{
initializer = new PrimitiveExpression(this.CurrentType.LastEnumValue);
}
this.CurrentType.StaticConfig.Fields.Add(new TypeConfigItem
{
Name = enumMemberDeclaration.Name,
Entity = enumMemberDeclaration,
Initializer = initializer
});
}
示例5: VisitEnumMemberDeclaration
public override void VisitEnumMemberDeclaration(EnumMemberDeclaration enumMemberDeclaration)
{
Expression initializer = enumMemberDeclaration.Initializer;
if (enumMemberDeclaration.Initializer.IsNull)
{
if (this.CurrentType.Type.GetDefinition().Attributes.Any(attr => attr.AttributeType.FullName == "System.FlagsAttribute"))
{
if (this.CurrentType.LastEnumValue <= 0)
{
this.CurrentType.LastEnumValue = 1;
}
else
{
this.CurrentType.LastEnumValue *= 2;
}
initializer = new PrimitiveExpression(this.CurrentType.LastEnumValue);
}
else
{
initializer = new PrimitiveExpression(++this.CurrentType.LastEnumValue);
}
}
else
{
var rr = this.Resolver.ResolveNode(enumMemberDeclaration.Initializer, null) as ConstantResolveResult;
if (rr != null)
{
initializer = new PrimitiveExpression(rr.ConstantValue);
this.CurrentType.LastEnumValue = (int)rr.ConstantValue;
}
}
this.CurrentType.StaticConfig.Fields.Add(new TypeConfigItem
{
Name = enumMemberDeclaration.Name,
Entity = enumMemberDeclaration,
Initializer = initializer
});
}
示例6: VisitEnumMemberDeclaration
public override void VisitEnumMemberDeclaration(EnumMemberDeclaration enumMemberDeclaration)
{
Expression initializer = enumMemberDeclaration.Initializer;
if (enumMemberDeclaration.Initializer.IsNull)
{
initializer = new PrimitiveExpression(++this.CurrentType.LastEnumValue);
}
else
{
var rr = this.Resolver.ResolveNode(enumMemberDeclaration.Initializer, null) as ConstantResolveResult;
if (rr != null)
{
initializer = new PrimitiveExpression(rr.ConstantValue);
this.CurrentType.LastEnumValue = (int)rr.ConstantValue;
}
}
this.CurrentType.StaticConfig.Fields.Add(new TypeConfigItem
{
Name = enumMemberDeclaration.Name,
Entity = enumMemberDeclaration,
Initializer = initializer
});
}
示例7: VisitEnumDecl
public override void VisitEnumDecl(EnumDecl decl, VisitKind visitKind)
{
if (visitKind != VisitKind.Enter || !decl.IsCompleteDefinition || decl.QualifiedName == null)
return;
if (!decl.QualifiedName.StartsWith ("Urho")) {
if (!decl.QualifiedName.ToLower ().Contains ("loopmode2d"))
return;
}
//Console.WriteLine($"VisitingType: {decl.QualifiedName}");
string typeName = RemapTypeName(decl.Name);
PushType(new TypeDeclaration
{
Name = typeName,
ClassType = ClassType.Enum,
Modifiers = Modifiers.Public
}, StringUtil.GetTypeComments(decl));
foreach (var constantDecl in decl.Decls<EnumConstantDecl>()) {
var valueName = RemapEnumName (typeName, constantDecl.Name);
switch (valueName) {
// LIST HERE ANY Values we want to skip
case "foo":
case null:
continue;
}
var x = new EnumMemberDeclaration();
var enumValue = new EnumMemberDeclaration { Name = valueName };
if (constantDecl.InitExpr != null) {
APSInt v;
constantDecl.InitExpr.EvaluateAsInt (decl.AstContext, out v);
var ul = v.GetLimitedValue ();
PrimitiveExpression value;
if ((ul & 0xffffffff) == ul)
value = new PrimitiveExpression ((int)ul);
else
throw new NotImplementedException ($"Got a {ul} value which will not fit on an int, you must manually handle this case in the generatorg");
enumValue.Initializer = value;
}
currentType.Members.Add(enumValue);
}
}
示例8: CreateType
public TypeDeclaration CreateType(TypeDefinition typeDef)
{
TypeDefinition oldCurrentType = context.CurrentType;
context.CurrentType = typeDef;
TypeDeclaration astType = new TypeDeclaration();
ConvertAttributes(astType, typeDef);
astType.AddAnnotation(typeDef);
astType.Modifiers = ConvertModifiers(typeDef);
astType.Name = CleanName(typeDef.Name);
if (typeDef.IsEnum) { // NB: Enum is value type
astType.ClassType = ClassType.Enum;
astType.Modifiers &= ~Modifiers.Sealed;
} else if (typeDef.IsValueType) {
astType.ClassType = ClassType.Struct;
astType.Modifiers &= ~Modifiers.Sealed;
} else if (typeDef.IsInterface) {
astType.ClassType = ClassType.Interface;
astType.Modifiers &= ~Modifiers.Abstract;
} else {
astType.ClassType = ClassType.Class;
}
IEnumerable<GenericParameter> genericParameters = typeDef.GenericParameters;
if (typeDef.DeclaringType != null && typeDef.DeclaringType.HasGenericParameters)
genericParameters = genericParameters.Skip(typeDef.DeclaringType.GenericParameters.Count);
astType.TypeParameters.AddRange(MakeTypeParameters(genericParameters));
astType.Constraints.AddRange(MakeConstraints(genericParameters));
// Nested types
foreach(TypeDefinition nestedTypeDef in typeDef.NestedTypes) {
if (MemberIsHidden(nestedTypeDef, context.Settings))
continue;
astType.AddChild(CreateType(nestedTypeDef), TypeDeclaration.MemberRole);
}
if (typeDef.IsEnum) {
long expectedEnumMemberValue = 0;
bool forcePrintingInitializers = IsFlagsEnum(typeDef);
foreach (FieldDefinition field in typeDef.Fields) {
if (field.IsRuntimeSpecialName) {
// the value__ field
if (field.FieldType != typeDef.Module.TypeSystem.Int32) {
astType.AddChild(ConvertType(field.FieldType), TypeDeclaration.BaseTypeRole);
}
} else {
EnumMemberDeclaration enumMember = new EnumMemberDeclaration();
enumMember.Name = CleanName(field.Name);
long memberValue = (long)CSharpPrimitiveCast.Cast(TypeCode.Int64, field.Constant, false);
if (forcePrintingInitializers || memberValue != expectedEnumMemberValue) {
enumMember.AddChild(new PrimitiveExpression(field.Constant), EnumMemberDeclaration.InitializerRole);
}
expectedEnumMemberValue = memberValue + 1;
astType.AddChild(enumMember, TypeDeclaration.MemberRole);
}
}
} else {
// Base type
if (typeDef.BaseType != null && !typeDef.IsValueType && typeDef.BaseType.FullName != "System.Object") {
astType.AddChild(ConvertType(typeDef.BaseType), TypeDeclaration.BaseTypeRole);
}
foreach (var i in typeDef.Interfaces)
astType.AddChild(ConvertType(i), TypeDeclaration.BaseTypeRole);
AddTypeMembers(astType, typeDef);
}
context.CurrentType = oldCurrentType;
return astType;
}
示例9: Visit
public override void Visit (EnumMember em)
{
EnumMemberDeclaration newField = new EnumMemberDeclaration ();
VariableInitializer variable = new VariableInitializer ();
variable.AddChild (new Identifier (em.Name, Convert (em.Location)), AstNode.Roles.Identifier);
if (em.Initializer != null) {
var initializer = (AstNode)em.Initializer.Accept (this);
if (initializer != null)
variable.AddChild (initializer, AstNode.Roles.Initializer);
}
newField.AddChild (variable, AstNode.Roles.Initializer);
typeStack.Peek ().AddChild (newField, TypeDeclaration.Roles.Member);
}
示例10: VisitEnumMemberDeclaration
public void VisitEnumMemberDeclaration(EnumMemberDeclaration node)
{
// Ensure all enum members have a value
if (node.Initializer.IsNull) {
node.Initializer = new PrimitiveExpression(nextEnumValue++);
} else {
var result = resolver.Resolve(node.Initializer) as ConstantResolveResult;
if (result != null && result.ConstantValue is int) {
node.Initializer = new PrimitiveExpression((int)result.ConstantValue);
nextEnumValue = (int)result.ConstantValue + 1;
} else {
NotSupported(node.Initializer);
}
}
VisitChildren(node);
}
示例11: VisitEnumMemberDeclaration
public virtual void VisitEnumMemberDeclaration (EnumMemberDeclaration enumMemberDeclaration)
{
VisitChildren (enumMemberDeclaration);
}
示例12: VisitEnumMemberDeclaration
public override void VisitEnumMemberDeclaration(EnumMemberDeclaration enumMemberDeclaration)
{
_currentEnumMembers.Add(new NameNode(enumMemberDeclaration.Name, enumMemberDeclaration));
base.VisitEnumMemberDeclaration(enumMemberDeclaration);
}
示例13: Visit
public override void Visit (EnumMember em)
{
EnumMemberDeclaration newField = new EnumMemberDeclaration ();
AddAttributeSection (newField, em);
newField.AddChild (Identifier.Create (em.Name, Convert (em.Location)), AstNode.Roles.Identifier);
if (em.Initializer != null) {
newField.AddChild (new CSharpTokenNode (Convert (em.Initializer.Location), 1), EnumMemberDeclaration.Roles.Assign);
newField.AddChild ((Expression)em.Initializer.Accept (this), EnumMemberDeclaration.InitializerRole);
}
typeStack.Peek ().AddChild (newField, TypeDeclaration.MemberRole);
}
示例14: VisitEnumMemberDeclaration
public virtual void VisitEnumMemberDeclaration(EnumMemberDeclaration enumMemberDeclaration)
{
if (this.ThrowException)
{
throw (Exception)this.CreateException(enumMemberDeclaration);
}
}
示例15: CreateType
public TypeDeclaration CreateType(TypeDefinition typeDef)
{
TypeDeclaration astType = new TypeDeclaration();
astType.Modifiers = ConvertModifiers(typeDef);
astType.Name = typeDef.Name;
if (typeDef.IsEnum) { // NB: Enum is value type
astType.ClassType = ClassType.Enum;
astType.Modifiers &= ~Modifiers.Sealed;
} else if (typeDef.IsValueType) {
astType.ClassType = ClassType.Struct;
astType.Modifiers &= ~Modifiers.Sealed;
} else if (typeDef.IsInterface) {
astType.ClassType = ClassType.Interface;
astType.Modifiers &= ~Modifiers.Abstract;
} else {
astType.ClassType = ClassType.Class;
}
// Nested types
foreach(TypeDefinition nestedTypeDef in typeDef.NestedTypes) {
astType.AddChild(CreateType(nestedTypeDef), TypeDeclaration.MemberRole);
}
if (typeDef.IsEnum) {
foreach (FieldDefinition field in typeDef.Fields) {
if (field.IsRuntimeSpecialName) {
// the value__ field
astType.AddChild(ConvertType(field.FieldType), TypeDeclaration.BaseTypeRole);
} else {
EnumMemberDeclaration enumMember = new EnumMemberDeclaration();
enumMember.Name = field.Name;
astType.AddChild(enumMember, TypeDeclaration.MemberRole);
}
}
} else {
// Base type
if (typeDef.BaseType != null && !typeDef.IsValueType && typeDef.BaseType.FullName != Constants.Object) {
astType.AddChild(ConvertType(typeDef.BaseType), TypeDeclaration.BaseTypeRole);
}
foreach (var i in typeDef.Interfaces)
astType.AddChild(ConvertType(i), TypeDeclaration.BaseTypeRole);
AddTypeMembers(astType, typeDef);
}
return astType;
}