1
2
3
4
5
6
7
8
9
10
11
12
13
14
// BOM 추출하기
 
System.IO.FileStream fs = System.IO.File.OpenRead(xmlFilePath);
byte[] byteOrderMark = new byte[3];
fs.Read(byteOrderMark, 03);
 
if (byteOrderMark[0== 0xEF && byteOrderMark[1== 0xBB && byteOrderMark[2== 0xBF)
{
    // utf-8
}
else if (byteOrderMark[0== 0xFF && byteOrderMark[0== 0xFE)
{
    // utf-16
}
cs


'Languages > C#' 카테고리의 다른 글

[C#] Internal Property 접근하기  (0) 2016.03.23
[C#] InputBox 만들기  (0) 2014.01.21



1
2
3
4
5
6
7
8
9
10
11
12
catch (System.Xml.XmlException e)
{
    // Exception을 처리하려는데 Internal Property 로 접근이 필요한 상황이 되었다.
    // Internal Property : ResString
 
    // Reflection 옵션을 이용하여 Internal Property 의 접근을 요청한다.
    var t = e.GetType().GetProperty("ResString"System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
 
    // 저장된 값을 요청한다.
    string resString = (string)t.GetValue(e, null); 
}
 
cs


'Languages > C#' 카테고리의 다른 글

[C#] BOM 확인 (FileStream)  (0) 2016.03.23
[C#] InputBox 만들기  (0) 2014.01.21



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
        // InputBox 함수 구현.
        public DialogResult InputBox(string title, string promptText, ref string value)
        {
            Form form = new Form();
            Label label = new Label();
            TextBox textBox = new TextBox();
            Button buttonOk = new Button();
            Button buttonCancel = new Button();
            form.Text = title;
            label.Text = promptText;
            textBox.Text = value;
            buttonOk.Text = "OK";
            buttonCancel.Text = "Cancel";
            buttonOk.DialogResult = DialogResult.OK;
            buttonCancel.DialogResult = DialogResult.Cancel;
            label.SetBounds(9, 20, 372, 13);
            textBox.SetBounds(12, 36, 372, 20);
            buttonOk.SetBounds(228, 72, 75, 23);
            buttonCancel.SetBounds(309, 72, 75, 23);
            label.AutoSize = true;
            textBox.Anchor = textBox.Anchor | AnchorStyles.Right;
            buttonOk.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
            buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
            form.ClientSize = new Size(396, 107);
            form.Controls.AddRange(new Control[] { label, textBox, buttonOk, buttonCancel });
            form.ClientSize = new Size(Math.Max(300, label.Right + 10), form.ClientSize.Height);
            form.FormBorderStyle = FormBorderStyle.FixedDialog;
            form.StartPosition = FormStartPosition.CenterScreen;
            form.MinimizeBox = false;
            form.MaximizeBox = false;
            form.AcceptButton = buttonOk;
            form.CancelButton = buttonCancel;
            DialogResult dialogResult = form.ShowDialog();
            value = textBox.Text;
            return dialogResult;
        }
 
        private void ListView1DoubleClick(object sender, EventArgs e)
        {
            // InputBox 호출부 구현.
            string value = "0";
            if (this.InputBox("Enter values""Value :"ref value) == DialogResult.OK)
            {
                MessageBox.Show(value);
            }
        }


'Languages > C#' 카테고리의 다른 글

[C#] BOM 확인 (FileStream)  (0) 2016.03.23
[C#] Internal Property 접근하기  (0) 2016.03.23

+ Recent posts