示例#1
0
    public EnumSourceGeneratorState(
        INamedTypeSymbol type,
        INamedTypeSymbol enumInterface)
    {
        if (enumInterface is null)
        {
            throw new ArgumentNullException(nameof(enumInterface));
        }

        _enumType = type ?? throw new ArgumentNullException(nameof(type));

        Namespace = type.ContainingNamespace?.IsGlobalNamespace == true ? null : type.ContainingNamespace?.ToString();
        EnumTypeFullyQualified     = type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
        EnumTypeMinimallyQualified = type.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat);
        Name = type.Name;

        IsReferenceType = type.IsReferenceType;
        IsAbstract      = type.IsAbstract;
        IsValidatable   = enumInterface.IsValidatableEnumInterface();
        Settings        = new EnumSettings(type.FindEnumGenerationAttribute());

        BaseEnum = GetBaseEnum(type);

        var keyType = enumInterface.TypeArguments[0];

        KeyProperty = (BaseEnum?.Settings ?? Settings).CreateKeyProperty(keyType);
        HasCreateInvalidImplementation = type.HasCreateInvalidImplementation(keyType);

        ItemNames = type.EnumerateEnumItems().Select(i => i.Name).ToList();
        AssignableInstanceFieldsAndProperties = type.GetAssignableFieldsAndPropertiesAndCheckForReadOnly(true).ToList();
        FullyQualifiedDerivedTypes            = type.FindDerivedInnerEnums().Select(t => t.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)).ToList();

        AttributeInfo = new AttributeInfo(type);
    }
 /// <summary>
 /// Initialize Texture from an image that has a set of Sprites in one image file
 /// Currently not implemented in Draw method but if needed will be very quick to add
 /// </summary>
 /// <param name="imagePath">String Path to Texture</param>
 /// <param name="x">On screen TopLeft X Coordinate</param>
 /// <param name="y">On Screen TopLeft Y Coordinate</param>
 /// <param name="itemOrientation">Currently only Vertically Oriented</param>
 /// <param name="content">ContentManager that needs the texture to be loaded</param>
 /// <param name="spriteBounds">Position of the sprite in a sprite sheet</param>
 public BackgroundItem(Texture2D spriteTex, Rectangle position, float itemOrientation, Vector2 origin, EnumSettings.ItemOrientation flip)
 {
     this.Position = position;
     this.Orient = itemOrientation;
     SpriteTexture = spriteTex;
     Origin = new Vector2(0, 0);
     this.Flip = flip;
 }
    private static string GetKeyPropertyName(this EnumSettings settings)
    {
        var name = settings.KeyPropertyName;

        if (name is not null && !StringComparer.OrdinalIgnoreCase.Equals(name, "item"))
        {
            return(name);
        }

        return("Key");
    }
示例#4
0
    public BaseEnumState(INamedTypeSymbol type)
    {
        _type = type;

        TypeFullyQualified     = type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
        TypeMinimallyQualified = type.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat);

        Settings       = new EnumSettings(type.FindEnumGenerationAttribute());
        InnerTypesInfo = new TypeMemberInfo(type);

        ConstructorArguments = GetConstructorArguments(type);
        Items = _type.EnumerateEnumItems().Select(DefaultMemberState.CreateFrom).ToList();
    }
    public SameAssemblyBaseEnumState(INamedTypeSymbol type, ITypeSymbol keyType)
    {
        _type = type;

        TypeFullyQualified     = type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
        TypeMinimallyQualified = type.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat);

        Settings       = new EnumSettings(type.FindEnumGenerationAttribute());
        InnerTypesInfo = new TypeMemberInfo(type);

        ConstructorArguments = GetConstructorArguments(type, Settings.CreateKeyProperty(keyType));
        Items = type.EnumerateEnumItems().Select(InstanceMemberInfo.CreateFrom).ToList();
    }
示例#6
0
        public void EnumGroupConfigTest()
        {
            EnumGroupConfigurationElementCollection groups = EnumSettings.GetConfig().Groups;

            foreach (EnumGroupConfigurationElement group in groups)
            {
                Console.WriteLine(group.Name);

                foreach (EnumConfigurationElement property in group.Items)
                {
                    Console.WriteLine("\t{0}, {1}", property.Name, property.Description);
                }
            }
        }
    public static DefaultMemberState CreateKeyProperty(this EnumSettings settings, ITypeSymbol keyType)
    {
        var keyPropertyName = settings.GetKeyPropertyName();

        return(new DefaultMemberState(keyPropertyName, keyType, keyPropertyName.MakeArgumentName(), false));
    }