[C#] ref, out의 차이

.Net/C# 2013. 6. 12. 13:54

링크 : http://blog.naver.com/thx4alice?Redirect=Log&logNo=110023260951 

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

[C#] Linq for xml tutorial  (0) 2013.05.23
[C#] XML Serialize Tutorial  (0) 2013.05.08
[C#] Mutex를 통한 다중 인스턴스 실행방지  (0) 2013.02.08
[C#] Visual Studio TODO 만들기  (0) 2013.01.30
[C#] Form close와 Dispose  (0) 2013.01.28
posted by 뚱2

[C#] Linq for xml tutorial

.Net/C# 2013. 5. 23. 16:29

링크 : http://www.dotnetcurry.com/ShowArticle.aspx?ID=564 

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

[C#] ref, out의 차이  (0) 2013.06.12
[C#] XML Serialize Tutorial  (0) 2013.05.08
[C#] Mutex를 통한 다중 인스턴스 실행방지  (0) 2013.02.08
[C#] Visual Studio TODO 만들기  (0) 2013.01.30
[C#] Form close와 Dispose  (0) 2013.01.28
posted by 뚱2

[C#] XML Serialize Tutorial

.Net/C# 2013. 5. 8. 16:33

링크 : http://tech.pro/tutorial/798/csharp-tutorial-xml-serialization 

링크 : http://msdn.microsoft.com/ko-kr/library/58a18dwa.aspx

 

A long while ago we posted a tutorial on how to serialize objects to a binary file. While this is very useful, unfortunately the resulting file is not very human readable. In this tutorial, I'm going to demonstrate how to serialize your own objects to and from an XML file.

Since .NET can use reflection to get property names, basic serialization is unbelievably simple. It only gets slightly difficult when you want to name your XML tags differently than your property names (but still not very hard). If you've ever used an XML serialization package in C++ like boost, tinyXML, or libXML2, you'll see how comparatively easy C# is to use.

Let's start with a basic example. Below is an object that stores some information about a movie.

public class Movie
{
  public string Title
  { get; set; }

  public int Rating
  { get; set; }

  public DateTime ReleaseDate
  { get; set; }
}

All right, now that we have an object, let's write a function that will save it to XML.

static public void SerializeToXML(Movie movie)
{
  XmlSerializer serializer = new XmlSerializer(typeof(Movie));
  TextWriter textWriter = new StreamWriter(@"C:\movie.xml");
  serializer.Serialize(textWriter, movie);
  textWriter.Close();
}

The first thing I do is create an XMLSerializer (located in the System.Xml.Serialization namespace) that will serialize objects of type Movie. The XMLSerializer will serialize objects to a stream, so we'll have to create one of those next. In this case, I want to serialize it to a file, so I create a TextWriter. I then simply call Serialize on the XMLSerializer passing in the stream (textWriter) and the object (movie). Lastly I close the TextWriter because you should always close opened files. That's it! Let's create a movie object and see how this is used.

static void Main(string[] args)
{
  Movie movie = new Movie();
  movie.Title = "Starship Troopers";
  movie.ReleaseDate = DateTime.Parse("11/7/1997");
  movie.Rating = 6.9f;

  SerializeToXML(movie);
}

static public void SerializeToXML(Movie movie)
{
  XmlSerializer serializer = new XmlSerializer(typeof(Movie));
  TextWriter textWriter = new StreamWriter(@"C:\movie.xml");
  serializer.Serialize(textWriter, movie);
  textWriter.Close();
}

After this code executes, we'll have an XML file with the contents of our movie object.

<?xml version="1.0" encoding="utf-8"?>
<Movie xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <Title>Starship Troopers</Title>
  <Rating>6.9</Rating>
  <ReleaseDate>1997-11-07T00:00:00</ReleaseDate>
</Movie>

If you noticed, all of the XML tag names are the same as the property names. If we want to change those, we can simply add an attribute above each property that sets the tag name.

public class Movie
{
  [XmlElement("MovieName")]
  public string Title
  { get; set; }

  [XmlElement("MovieRating")]
  public float Rating
  { get; set; }

  [XmlElement("MovieReleaseDate")]
  public DateTime ReleaseDate
  { get; set; }
}

Now when the same code is executed again, we get our custom tag names.

<?xml version="1.0" encoding="utf-8"?>
<Movie xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <MovieName>Starship Troopers</MovieName>
  <MovieRating>6.9</MovieRating>
  <MovieReleaseDate>1997-11-07T00:00:00</MovieReleaseDate>
</Movie>

Sometimes, in XML, you want information stored as an attribute of another tag instead of a tag by itself. This can be easily accomplished with another property attribute.

public class Movie
{
  [XmlAttribute("MovieName")]
  public string Title
  { get; set; }

  [XmlElement("MovieRating")]
  public float Rating
  { get; set; }

  [XmlElement("MovieReleaseDate")]
  public DateTime ReleaseDate
  { get; set; }
}

With this code, MovieName will now be an attribute on the Movie tag.

<?xml version="1.0" encoding="utf-8"?>
<Movie xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    MovieName="Starship Troopers">
  <MovieRating>6.9</MovieRating>
  <MovieReleaseDate>1997-11-07T00:00:00</MovieReleaseDate>
</Movie>

Let's move on to something a little more interesting. Let's create another movie and serialize a List of them to our XML file. Here's the modified code to do just that:

static void Main(string[] args)
{
  Movie movie = new Movie();
  movie.Title = "Starship Troopers";
  movie.ReleaseDate = DateTime.Parse("11/7/1997");
  movie.Rating = 6.9f;

  Movie movie2 = new Movie();
  movie2.Title = "Ace Ventura: When Nature Calls";
  movie2.ReleaseDate = DateTime.Parse("11/10/1995");
  movie2.Rating = 5.4f;

  List<Movie> movies = new List<Movie>() { movie, movie2 };

  SerializeToXML(movies);
}

static public void SerializeToXML(List<Movie> movies)
{
  XmlSerializer serializer = new XmlSerializer(typeof(List<Movie>));
  TextWriter textWriter = new StreamWriter(@"C:\movie.xml");
  serializer.Serialize(textWriter, movies);
  textWriter.Close();
}

Now we have XML that looks like this:

<?xml version="1.0" encoding="utf-8"?>
<ArrayOfMovie xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <Movie MovieName="Starship Troopers">
    <MovieRating>6.9</MovieRating>
    <MovieReleaseDate>1997-11-07T00:00:00</MovieReleaseDate>
  </Movie>
  <Movie MovieName="Ace Ventura: When Nature Calls">
    <MovieRating>5.4</MovieRating>
    <MovieReleaseDate>1995-11-10T00:00:00</MovieReleaseDate>
  </Movie>
</ArrayOfMovie>

Ok, so you can see how easy it is to get your objects into an XML document. Let's now look at how to read an XML document back into our objects - deserialization. The process of deserializing is very similar to what we did for serialization.

static List<Movie> DeserializeFromXML()
{
   XmlSerializer deserializer = new XmlSerializer(typeof(List<Movie>));
   TextReader textReader = new StreamReader(@"C:\movie.xml");
   List<Movie> movies; 
   movies = (List<Movie>)deserializer.Deserialize(textReader);
   textReader.Close();

   return movies;
}

Just like before, we first create an XmlSerializer that can deserialize objects of type List\. The XmlSerializer also deserializes from a stream, so we create a file stream from our XML file. We then simply call Deserialize on the stream and cast the output to our desired type. Now the movies List is populated with objects that we previously serialized to the XML file.

The deserializer is very good at handling missing pieces of information in your XML file. Let's say the second movie didn't have the MovieName attribute on the Movie tag. When the XML file is deserialized, it simply populates that field with null. If MovieRating wasn't there, you'd receive 0. Since a DateTime object can't be null, if MovieReleaseDate was missing, you'd receive DateTime.MinValue (1/1/0001 12:00:00AM).

If the XML document contains invalid syntax, like say the first opening Movie tag was missing, the Deserialize call will fail with an InvalidOperationException. It will also be kind enough to specify the location in the file where it encountered the error (line number, column number).

One thing to remember is that the basic XML serialization won't maintain references. Let's say I populated my movies list with the same movie reference multiple times:

Movie movie = new Movie();
movie.Title = "Starship Troopers";
movie.ReleaseDate = DateTime.Parse("11/7/1997");
movie.Rating = 6.9f;

List<Movie> movies = new List<Movie>() { movie, movie };

Now I have a list containing two of the exact same movie reference. When I serialize and deserialize this list, it will be converted to two separate instances of the movie object - they would just have the same information. Along this same line, the XMLSerializer also doesn't support circular references. If you need this kind of flexibility, you should consider binary serialization.

There's still a lot to cover when it comes to XML serialization, but I think this tutorial covers enough of the basics to get things rolling.

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

[C#] ref, out의 차이  (0) 2013.06.12
[C#] Linq for xml tutorial  (0) 2013.05.23
[C#] Mutex를 통한 다중 인스턴스 실행방지  (0) 2013.02.08
[C#] Visual Studio TODO 만들기  (0) 2013.01.30
[C#] Form close와 Dispose  (0) 2013.01.28
posted by 뚱2

링크 : http://www.cyworld.com/programer1234/9368817 

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

[C#] Linq for xml tutorial  (0) 2013.05.23
[C#] XML Serialize Tutorial  (0) 2013.05.08
[C#] Visual Studio TODO 만들기  (0) 2013.01.30
[C#] Form close와 Dispose  (0) 2013.01.28
[C#] 정적 생성자 (static 멤버 초기화)  (0) 2013.01.15
posted by 뚱2

[C#] Visual Studio TODO 만들기

.Net/C# 2013. 1. 30. 13:56

 

 

출력창에 위와같이 출력이 된다.

해당 라인을 더블클릭 하면은

 

 

실제 소스페이지의 라인으로 이동한다.

using System;

namespace KIS.Util
{
    /// <summary>
    /// 디버깅을 도와주는 유틸 클래스
    /// </summary>
    public static class MyDebug
    {
        /// <summary>
        /// 현재까지 스택트레이스를 출력한다.
        /// </summary>
        public static void GetStackTrace()
        {
            System.Diagnostics.Debug.Write(Environment.StackTrace);
        }

        /// <summary>
        /// 콘솔에 스트릴을 출력한다.
        /// </summary>
        /// <param name="format"></param>
        /// <param name="args"></param>
        public static void PrintConsole(string format, params object[] args)
        {
            string msg = string.Format(format, args);
            System.Console.Write(msg);
        }

        /// <summary>
        /// 현재 파일 이름
        /// </summary>
        public static string CurrentFile
        {
            get
            {
                return new System.Diagnostics.StackTrace(true).GetFrame(1).GetFileName();           
            }
        }

        /// <summary>
        /// 현재 파일의 라인번호
        /// </summary>
        public static int CurrentLine
        {
            get
            {
                return new System.Diagnostics.StackTrace(true).GetFrame(1).GetFileLineNumber();
            }
        }


        public static void TODO(string format, params object[] args)
        {
            string file_name    = new System.Diagnostics.StackTrace(true).GetFrame(1).GetFileName();
            int    file_number  = new System.Diagnostics.StackTrace(true).GetFrame(1).GetFileLineNumber();
            string msg  = string.Format(format, args);
            string todo = string.Format("{0}({1}) : {2}", file_name, file_number, msg);
            System.Console.WriteLine(todo);
        }
    }
}

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

[C#] XML Serialize Tutorial  (0) 2013.05.08
[C#] Mutex를 통한 다중 인스턴스 실행방지  (0) 2013.02.08
[C#] Form close와 Dispose  (0) 2013.01.28
[C#] 정적 생성자 (static 멤버 초기화)  (0) 2013.01.15
[C#] Assemble.load  (0) 2013.01.15
posted by 뚱2

[C#] Form close와 Dispose

.Net/C# 2013. 1. 28. 20:19

링크 (Form.Dispose) : http://msdn.microsoft.com/ko-kr/library/aw58wzka(v=vs.90).aspx

링크 (Form.Close) : http://msdn.microsoft.com/ko-kr/library/system.windows.forms.form.close(v=vs.90).aspx 


모달리스로 닫을시에는 Form.Close()를 호출

모달로 닫을시에는 Form.DialogResult 프로퍼티에 값을 대입

posted by 뚱2

링크 : http://msdn.microsoft.com/ko-kr/library/k9x6w0hc(v=vs.80).aspx 

 

public class Bus
{
    // Static constructor:
    static Bus()
    {
        System.Console.WriteLine("The static constructor invoked.");
    }

    public static void Drive()
    {
        System.Console.WriteLine("The Drive method invoked.");
    }
}

class TestBus
{
    static void Main()
    {
        Bus.Drive();
    }
}

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

[C#] Visual Studio TODO 만들기  (0) 2013.01.30
[C#] Form close와 Dispose  (0) 2013.01.28
[C#] Assemble.load  (0) 2013.01.15
[Visual Studio 2010] C# 선언할때 공백 제거 문제  (0) 2013.01.14
[C#] C# as 연산자  (0) 2013.01.09
posted by 뚱2

[C#] Assemble.load

.Net/C# 2013. 1. 15. 12:22

링크 : http://msdn.microsoft.com/ko-kr/library/system.reflection.assembly.load.aspx

 

어셈블리를 로드합니다.

이 멤버는 오버로드됩니다. 구문, 사용법 및 예제를 비롯하여 이 멤버에 대한 자세한 내용을 보려면 오버로드 목록에서 이름을 클릭합니다.

이름 설명
Public 메서드정적 멤버 Load(AssemblyName) 해당 AssemblyName이 지정된 어셈블리를 로드합니다.
Public 메서드정적 멤버 Load(Byte[]) 내보낸 어셈블리가 포함된 COFF(Common Object File Format) 기반 이미지를 사용하여 어셈블리를 로드합니다.이 어셈블리는 호출자의 응용 프로그램 도메인에 로드됩니다.
Public 메서드정적 멤버 Load(String) 긴 형식의 이름으로 지정된 어셈블리를 로드합니다.
Public 메서드정적 멤버 Load(AssemblyName, Evidence) 사용되지 않습니다. 해당 AssemblyName이 지정된 어셈블리를 로드합니다.어셈블리는 제공된 증명을 사용하여 호출자의 도메인에 로드됩니다.
Public 메서드정적 멤버 Load(Byte[], Byte[]) 생성된 어셈블리가 들어 있고 경우에 따라 어셈블리에 대한 기호도 포함하는 COFF(공용 개체 파일 형식) 기반 이미지를 사용하여 어셈블리를 로드합니다.이 어셈블리는 호출자의 응용 프로그램 도메인에 로드됩니다.
Public 메서드정적 멤버 Load(String, Evidence) 사용되지 않습니다. 해당 표시 이름이 지정된 어셈블리를 로드한 다음 제공된 증명을 사용하여 이 어셈블리를 호출자의 도메인에 로드합니다.
Public 메서드정적 멤버 Load(Byte[], Byte[], Evidence) 사용되지 않습니다. 생성된 어셈블리가 들어 있고 경우에 따라 어셈블리에 대한 기호 및 증명 정보도 포함하는 COFF(공용 개체 파일 형식) 기반 이미지를 사용하여 어셈블리를 로드합니다.이 어셈블리는 호출자의 응용 프로그램 도메인에 로드됩니다.
Public 메서드정적 멤버 Load(Byte[], Byte[], SecurityContextSource) 생성된 어셈블리가 들어 있고 경우에 따라 기호도 포함하고 보안 컨텍스트의 소스도 지정하는 COFF(공용 개체 파일 형식) 기반 이미지를 사용하여 어셈블리를 로드합니다.이 어셈블리는 호출자의 응용 프로그램 도메인에 로드됩니다.
위쪽

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

[C#] Form close와 Dispose  (0) 2013.01.28
[C#] 정적 생성자 (static 멤버 초기화)  (0) 2013.01.15
[Visual Studio 2010] C# 선언할때 공백 제거 문제  (0) 2013.01.14
[C#] C# as 연산자  (0) 2013.01.09
[C#] StackTrace  (0) 2013.01.08
posted by 뚱2

선언할때 줄 잘 맞춰서 코딩해 놨는데 공백이 사라지는 억울함이....

 

도구 -> 옵션 -> 텍스트 편집기 -> C# -> 서식 -> 간격 -> 기타 간격 옵션을 설정합니다. -> 선언문의 공백을 무시합니다.

' 체크 '

 

 

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

[C#] 정적 생성자 (static 멤버 초기화)  (0) 2013.01.15
[C#] Assemble.load  (0) 2013.01.15
[C#] C# as 연산자  (0) 2013.01.09
[C#] StackTrace  (0) 2013.01.08
[C#] DllImportAttribut  멤버  (0) 2013.01.04
posted by 뚱2

[C#] C# as 연산자

.Net/C# 2013. 1. 9. 14:42

링크 : http://msdn.microsoft.com/ko-kr/library/cscsdfbt(VS.80).aspx 


호환되는 참조 형식 간에 변환을 수행하는 데 사용됩니다. 예를 들면 다음과 같습니다.

string s = someObject as string;
if (s != null)
{
    // someObject is a string.
}

as 연산자는 캐스트 연산과 비슷하지만 변환이 가능하지 않은 경우에 as를 사용하면 예외가 발생하지 않고 대신 null이 반환됩니다. 식의 정확한 형식은 다음과 같습니다.

expression as type

이 식은 아래의 식과 동일합니다.

expression is type ? (type)expression : (type)null

그러나 expression 이 한 번만 계산된다는 점은 다릅니다.

as 연산자는 오직 참조 변환과 boxing 변환만을 수행합니다. as 연산자는 사용자 정의 변환과 같은 다른 변환을 수행할 수 없습니다. 사용자 정의 변환은 이 연산자 대신 캐스트 식을 사용하여 수행해야 합니다.

// cs_keyword_as.cs
// The as operator.
using System;
class Class1
{
}

class Class2
{
}

class MainClass
{
    static void Main()
    {
        object[] objArray = new object[6];
        objArray[0] = new Class1();
        objArray[1] = new Class2();
        objArray[2] = "hello";
        objArray[3] = 123;
        objArray[4] = 123.4;
        objArray[5] = null;

        for (int i = 0; i < objArray.Length; ++i)
        {
            string s = objArray[i] as string;
            Console.Write("{0}:", i);
            if (s != null)
            {
                Console.WriteLine("'" + s + "'");
            }
            else
            {
                Console.WriteLine("not a string");
            }
        }
    }
}

출력

0:not a string
1:not a string
2:'hello'
3:not a string
4:not a string
5:not a string

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

[C#] Assemble.load  (0) 2013.01.15
[Visual Studio 2010] C# 선언할때 공백 제거 문제  (0) 2013.01.14
[C#] StackTrace  (0) 2013.01.08
[C#] DllImportAttribut  멤버  (0) 2013.01.04
[C#] Visual C# 메소드를 비동기로 호출하는 방법  (0) 2012.04.14
posted by 뚱2

[C#] StackTrace

.Net/C# 2013. 1. 8. 15:36

아는 동생이 알려주길래 얼른 사용해봄 나중을 위해서 기록...

private void GetDebugInfo()
{
    string szDebugInfo = string.Empty;

    System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace(true);

    System.Diagnostics.Debug.Write("*******************************");
    for(int i=1; i<trace.FrameCount; i++)
    {
        if(trace.GetFrame(i).GetFileName() != null)
        {
            if(trace.GetFrame(i).GetFileName() != String.Empty)
                 System.Diagnostics.Debug.Write(trace.GetFrame(i).ToString());
        }
    }
    System.Diagnostics.Debug.Write("*******************************");
}

 

posted by 뚱2

[C#] DllImportAttribut  멤버

.Net/C# 2013. 1. 4. 14:03

링크 : http://msdn.microsoft.com/ko-kr/library/system.runtime.interopservices.dllimportattribute_members(v=vs.90).aspx 

참조 : http://blog.naver.com/luvinuns?Redirect=Log&logNo=90051065276


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

[C#] C# as 연산자  (0) 2013.01.09
[C#] StackTrace  (0) 2013.01.08
[C#] Visual C# 메소드를 비동기로 호출하는 방법  (0) 2012.04.14
[C#] Assembly Version Loading  (0) 2012.04.06
[C#] VS 2008 서식 자동 해제  (0) 2012.04.06
posted by 뚱2

링크 : http://support.microsoft.com/kb/315582 


비동기로 UI 호출 하기 : http://jongkok4.net/entry/%C6%DFc-UI-%BE%B2%B7%B9%B5%E5-%B8%B6%BC%A3%B8%B5-Invoke-BeginInvoke?TSSESSIONjongkok4net=6e5ec00b34c31e0126e9a64412f7a627


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

[C#] StackTrace  (0) 2013.01.08
[C#] DllImportAttribut  멤버  (0) 2013.01.04
[C#] Assembly Version Loading  (0) 2012.04.06
[C#] VS 2008 서식 자동 해제  (0) 2012.04.06
[C#] log4net  (0) 2012.04.03
posted by 뚱2

[C#] Assembly Version Loading

.Net/C# 2012. 4. 6. 19:35

현재 어셈블리 버전을 읽는 방법 이다.




// AssemblyInfo.cs
// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 버전이 자동으로
// 지정되도록 할 수 있습니다.
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.5.*")]
[assembly: AssemblyFileVersion("0.5.*")]

// Test.cs
// 현재 실행 프로그램의 어셈플리를 로딩한다.
string msg = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
MessageBox.Show("Version=" + msg);

참고로 버전은 Major.Minor.Build.Revision 입니다.

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

[C#] DllImportAttribut  멤버  (0) 2013.01.04
[C#] Visual C# 메소드를 비동기로 호출하는 방법  (0) 2012.04.14
[C#] VS 2008 서식 자동 해제  (0) 2012.04.06
[C#] log4net  (0) 2012.04.03
[C#] vshosting.exe 가 뭘까요?  (0) 2012.03.26
posted by 뚱2

[C#] VS 2008 서식 자동 해제

.Net/C# 2012. 4. 6. 10:09

줄 맞춰서 코딩 열심히 하고 Copy & Paste하면은 서식이 자동으로 다시 만들어 진다. ㅡㅡ;

나에게는 참 불편한 기능중에 하나

해제 방법은

'도구 -> 옵션 -> 텍스트 편집기 -> C# -> 서식 -> 일반' 으로 들어가서

모든 서식을 체크 해제한다.



추가 : 이렇게 하니 복사 붙여넣기 할때마다 인던트를 조절해야 하는 불편함이 생긴다.

그럴때는 체크 해주고


선언문의 공백을 무시합니다. 를 체크해준다.



그리고 서식 -> 간격 -> 연산자의 간격을 설정 합니다. -> 이항 연산자 주위의 공백을 무시합니다. 선택

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

[C#] Visual C# 메소드를 비동기로 호출하는 방법  (0) 2012.04.14
[C#] Assembly Version Loading  (0) 2012.04.06
[C#] log4net  (0) 2012.04.03
[C#] vshosting.exe 가 뭘까요?  (0) 2012.03.26
[C#] Dynamic Method Call With Out Parameter  (0) 2012.03.22
posted by 뚱2

[C#] log4net

.Net/C# 2012. 4. 3. 14:24
링크 :  http://logging.apache.org/log4net/index.html

링크 : http://blog.suromind.com/90 

레퍼런스 : http://logging.apache.org/log4net/release/sdk/index.html

참고 : http://www.venomi.pe.kr/3191513

프로젝트에서 로그를 사용해야 하는데 log4j와 같이 유용하게 사용할수 있을 것 같다.

아래는 내가 사용하는 환경설정이다.




  
    


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

[C#] Assembly Version Loading  (0) 2012.04.06
[C#] VS 2008 서식 자동 해제  (0) 2012.04.06
[C#] vshosting.exe 가 뭘까요?  (0) 2012.03.26
[C#] Dynamic Method Call With Out Parameter  (0) 2012.03.22
[즐겨찾기] C# TreeView MultiSelect  (0) 2012.03.15
posted by 뚱2

[C#] vshosting.exe 가 뭘까요?

.Net/C# 2012. 3. 26. 14:27
WinForm으로 프로그램을 생성하면은 출력 디렉토리에 XXX.vshosting.exe 파일이 생성됩니다.
이게 궁금해서 찾아보니 잘 설명된 블로그가 있어서 링크 걸어둡니다.

링크 : http://blog.naver.com/saltynut?Redirect=Log&logNo=120017351107 

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

[C#] VS 2008 서식 자동 해제  (0) 2012.04.06
[C#] log4net  (0) 2012.04.03
[C#] Dynamic Method Call With Out Parameter  (0) 2012.03.22
[즐겨찾기] C# TreeView MultiSelect  (0) 2012.03.15
[C#] internal 지정자  (0) 2012.03.12
posted by 뚱2
해당 오프젝트의 타입을 확인하고 메소드가 존재하고 파라미터가 일치한다면
호출해 준다.

// class
public class MyObject
{
    pub int Connect()
    {
        // 접속 ...
    }
    public void GetLastError(out int errorCode, out string errorMessage)
    {
        // 내부 코드들 ...
    }
}


    // ErrorUtil
    public class ErrorUtil
    {
        private static readonly string methodName = "GetLastError";
        private static int errorCode = 0;
        private static string errorMessage = "";

        public static int ErrorCode
        {
            get { return errorCode; }
        }

        public static string ErrorMessage
        {
            get { return errorMessage; }
        }

        public static bool GetLastError(object obj)
        {
            try
            {
                Type t = obj.GetType();
                MethodInfo info = t.GetMethod(
                    ErrorUtil.methodName,
                    BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance,
                    null,
                    new[] 
                    {
                        typeof(int).MakeByRefType(),
                        typeof(string).MakeByRefType()
                    },
                    null
                );

                if (info != null)
                {
                    object[] parameters = new object[2];
                    info.Invoke(obj, parameters);

                    errorCode = (int)parameters[0];
                    errorMessage = (string)parameters[1];
                    return true;
                }
                else
                {
                    errorMessage = String.Format("{0} 메소드를 찾을수 없거나, 파라미터가 정확하지 않습니다.", ErrorUtil.methodName);
                    return false;
                }
            }
            catch (Exception ex)
            {
                errorMessage = ex.Message;
                return false;
            }
        }
    }


// 사용예
    MyObject oCommpany = new MyObject();
    int retCode = oCompany.Connect();
    if (retCode != 0)
    {
           ErrorUtil.GetLastError(oCompany);
           MessageBox.Show(ErrorUtil.ErrorMessage);
    }


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

[C#] log4net  (0) 2012.04.03
[C#] vshosting.exe 가 뭘까요?  (0) 2012.03.26
[즐겨찾기] C# TreeView MultiSelect  (0) 2012.03.15
[C#] internal 지정자  (0) 2012.03.12
[즐겨찾기] 무료서적 Inside C# 2nd  (0) 2012.03.10
posted by 뚱2

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

[C#] log4net  (0) 2012.04.03
[C#] vshosting.exe 가 뭘까요?  (0) 2012.03.26
[C#] Dynamic Method Call With Out Parameter  (0) 2012.03.22
[C#] internal 지정자  (0) 2012.03.12
[즐겨찾기] 무료서적 Inside C# 2nd  (0) 2012.03.10
posted by 뚱2

[C#] internal 지정자

.Net/C# 2012. 3. 12. 14:26

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

[C#] log4net  (0) 2012.04.03
[C#] vshosting.exe 가 뭘까요?  (0) 2012.03.26
[C#] Dynamic Method Call With Out Parameter  (0) 2012.03.22
[즐겨찾기] C# TreeView MultiSelect  (0) 2012.03.15
[즐겨찾기] 무료서적 Inside C# 2nd  (0) 2012.03.10
posted by 뚱2

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

[C#] log4net  (0) 2012.04.03
[C#] vshosting.exe 가 뭘까요?  (0) 2012.03.26
[C#] Dynamic Method Call With Out Parameter  (0) 2012.03.22
[즐겨찾기] C# TreeView MultiSelect  (0) 2012.03.15
[C#] internal 지정자  (0) 2012.03.12
posted by 뚱2