Unity3D/C#
(C#) 타입 비교
일등하이
2019. 4. 5. 15:41
반응형
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Newtonsoft.Json;
namespace ConsoleApp2
{
class App
{
public App() { }
Dictionary<int, WeaponData> dicWeaponData;
Dictionary<int, CharacterData> dicChracterData;
public void Start()
{
this.dicWeaponData = new Dictionary<int, WeaponData>();
this.dicChracterData = new Dictionary<int, CharacterData>();
this.ConsoleFromDictionary(this.dicWeaponData);
this.ConsoleFromDictionary(this.dicChracterData);
}
// 파일이있는 경로(문자열)를 전달하면 사전에 등록 해줬으면...
private void ReadFileAndAddToDictionary<T>(string path, Dictionary<int, T> dic) where T : RawData
{
//파일 읽기
var json = File.ReadAllText(path);
//역직렬화
var arrDatas = JsonConvert.DeserializeObject<T[]>(json);
foreach (var data in arrDatas)
{
}
}
//내가 원하는 사전에 있는 내용들이 출력되었으면..
private void ConsoleFromDictionary<T>(Dictionary<int, T> dic)
{
Console.WriteLine("ConsoleFromDictionary: {0}", dic);
foreach (var element in dic)
{
var type = element.Value.GetType();
if (type == typeof(WeaponData))
{
}
{
// 처리로직
}
//{
// var weaponData = element.Value as WeaponData;
// Console.WriteLine("{0}, {1}, {2}", weaponData.id, weaponData.name, weaponData.max_level);
//}
//else if (element.Value.GetType() is CharacterData)
//{
// var characterData = element.Value as CharacterData;
// Console.WriteLine("{0}, {1}", characterData.id, characterData.name);
//}
}
}
}
}
|
https://docko.tistory.com/entry/C-%ED%81%B4%EB%9E%98%EC%8A%A4-%ED%83%80%EC%9E%85-%EB%B9%84%EA%B5%90
C# 클래스 타입 비교
C#에서 클래스 타입을 비교하는 2가지 방법입니다. 1 2 3 4 5 6 7 8 9 10 11 string str = "문자"; if (str.GetType() == typeof(string)) { // 처리 로직 } if (str is string) { // 처리로직 } Colored by Color..
docko.tistory.com
반응형