小编Pav*_*ska的帖子

如何用D将颜色打印到控制台?

我已尝试使用writeln()函数转义序列,我也尝试将它们与从std.c.stdlib模块导入的printf()函数一起使用,但它只打印一个空行.

printf("\0x1B[5;32;40m Blink Text");

printf("\e[5;32;40m Blink Text\e[m");

writeln("\0x1b\x5b1;31;40m\tColor");
Run Code Online (Sandbox Code Playgroud)

这些都不起作用.

我已经尝试了我能想到的一切,有办法吗?

搜索D网站的图书馆参考对我没有帮助.


编辑:解决方案

好的,所以我试图导入函数SetConsoleTextAttribute,正如Mars所建议的那样:

extern (Windows) bool SetConsoleTextAttribute(void*, ushort);
Run Code Online (Sandbox Code Playgroud)

我还导入了另一个函数(我只是猜测我需要导入,因为我之前没有使用Win编程的经验)

extern (Windows) void* GetStdHandle(uint);
Run Code Online (Sandbox Code Playgroud)

简单地称之为两个功能

auto handle  = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(handle, FOREGROUND_BLUE);
writeln("In Color");
Run Code Online (Sandbox Code Playgroud)

这非常有效,非常感谢您的时间和帮助

console d escaping colors

9
推荐指数
1
解决办法
737
查看次数

为什么我的班级不符合CLS?

这真让我感到困惑.我已经尝试删除只读,更改名称..我在这里做错了什么?

public abstract class CatalogBase<T> where T : class
{
    protected readonly String DataPath;
    protected readonly XmlSerializer Serializer;
    private readonly XmlSerializerNamespaces _namespaces;

    protected CatalogBase(String dataPath)
    {
        DataPath = dataPath;
        Serializer = new XmlSerializer(typeof (T));
        _namespaces = new XmlSerializerNamespaces();
        _namespaces.Add(String.Empty, String.Empty);
    }

    public virtual void Write(T obj)
    {
        var streamWriter = new StreamWriter(DataPath);

        Serializer.Serialize(streamWriter, obj, _namespaces);
        streamWriter.Close();
    }

    public abstract IDictionary<String, T> Read();
}
Run Code Online (Sandbox Code Playgroud)

编辑:

警告:

警告1'Ar.ViewModel.Workspaces.MaterialCatalogBase':基本类型'Or.Files.CatalogBase'不符合CLS C:_Center_Work_Programming_Cs\Ar\Ar\ViewModel\Workspaces\MaterialCatalogBase.cs 9 18 Ar

EDIT2:

即使我改变了下面的类,我仍然得到错误:

public abstract class CatalogBase<T> where T : class …
Run Code Online (Sandbox Code Playgroud)

c# cls-compliant .net-4.5

7
推荐指数
1
解决办法
3488
查看次数

C#中使用GLFW的AccessViolationException

我有一个glfwSetCharCallback函数的问题.每当我调用它时,glfwPollEvents都会抛出一个AccessViolationException:"试图读取或写入受保护的内存.这通常表明其他内存已损坏."

我创建了一个非常简单的包装器来演示问题:

using System;
using System.Runtime.InteropServices;
using System.Security;

namespace Test
{
    public delegate void GlfwCharCallback(GlfwWindow window, Char character);

    [StructLayout(LayoutKind.Explicit)]
    public struct GlfwMonitor
    {
        private GlfwMonitor(IntPtr ptr)
        {
            _nativePtr = ptr;
        }

        [FieldOffset(0)] private readonly IntPtr _nativePtr;

        public static readonly GlfwMonitor Null = new GlfwMonitor(IntPtr.Zero);
    }

    [StructLayout(LayoutKind.Explicit)]
    public struct GlfwWindow
    {
        private GlfwWindow(IntPtr ptr)
        {
            _nativePtr = ptr;
        }

        [FieldOffset(0)] private readonly IntPtr _nativePtr;

        public static GlfwWindow Null = new GlfwWindow(IntPtr.Zero);
    }

    public class Wrap
    {
        [DllImport("GLFW3", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] …
Run Code Online (Sandbox Code Playgroud)

.net c# dllimport access-violation glfw

7
推荐指数
1
解决办法
805
查看次数

通过点运算符调用基本操作失败

我在理解UFCS(通用函数调用语法)如何在Ada中工作时遇到了问题.

假设我有一个类型,例如:

package People
    type Person is tagged private;

    -- This procedure is a primitive operation:
    procedure Say_Name (Person_Object : in Person);
private
    type Person is tagged record
        Name : String;
    end record;
end People;
Run Code Online (Sandbox Code Playgroud)

然后我可以调用该过程,就好像它实际上属于Person类型:

Some_Person_Instance.Say_Name;
Run Code Online (Sandbox Code Playgroud)

现在这样可行,但在我的特定实例中,拥有一条记录是没有意义的,一个子类型就足够了.

subtype Person is String;
Run Code Online (Sandbox Code Playgroud)

此时(假设我改变了程序的工作方式),它无法编译,我收到错误:

invalid prefix in selected component "Person".
Run Code Online (Sandbox Code Playgroud)

为什么?如果我这样做,它甚至没有帮助:

type Person is new String;
Run Code Online (Sandbox Code Playgroud)

UFCS只适用于记录吗?

如果这是一个无聊的问题,我很抱歉,但我没有为Ada学习材料(除了几本电子书),我订购的教科书还没有到.

ada

2
推荐指数
1
解决办法
117
查看次数

可以在WinForms中使用ASP.NET控件吗?

这可能是一个愚蠢的问题,但我不得不问.

我发现这个优秀的(主要是免费的)控件套件(Ext.NET),我想知道是否可以在WinForms中使用它.

如果它可以,通常是可行的还是噩梦?

c# asp.net winforms

1
推荐指数
1
解决办法
855
查看次数

CONSTRAINT_ERROR读取包含"["的文件

我正在阅读一个简单的文本文件.一切都按预期工作,除非遇到一个开括号("[")字符.然后我得到一个CONSTRAINT_ERROR.

我的功能是:

----------------------------------------------
-- GET_FILE_CONTENTS
function Get_File_Contents (File_Name : in String)
    return String_Array is
    -- Loads the entire file into a dynamically sized
    -- array of Unbounded_Wide_String.

    -- The line count is used to dynamically size the array.
    Line_Count : Natural
               := 0;

    File : Ada.Wide_Text_IO.File_Type;
begin
    -- Get the line count before opening the file.
    Line_Count := Get_File_Line_Count (File_Name);

    Ada.Wide_Text_IO.Open (File,
                           In_File,
                           File_Name);
    declare
        Lines : String_Array (1 .. Line_Count);
    begin

        -- Step through the file and save each …
Run Code Online (Sandbox Code Playgroud)

ada gnat

1
推荐指数
1
解决办法
160
查看次数