2012-03-28 2 views
0

사용자 지정 컨트롤, 도구 모음을 만드는 방법을 배우려고합니다. .NET Reflector를 사용하여 ToolStripDesigner 클래스를 "다시 작성"하려고했습니다 (지금은 리플렉터의 코드를 Visual Studio로 복사하는 것만을 의미합니다). System.Design.dll 내부에 많은 클래스를 사용하기 때문에 Reflector를 사용하여 클래스를 더 복사해야했습니다. 이 필드,플래그 열거 형에 대한 이진 연산

DragDropEffects allowedEffects = DragDropEffects.Move | DragDropEffects.Copy; 
for (int i = 0; i < components.Length; i++) 
{ 
    InheritanceAttribute attribute = (InheritanceAttribute) TypeDescriptor.GetAttributes(components[i])[typeof(InheritanceAttribute)]; 
    if (!attribute.Equals(InheritanceAttribute.NotInherited) && !attribute.Equals(InheritanceAttribute.InheritedReadOnly)) 
    { 
     allowedEffects &= ~DragDropEffects.Move; 
     allowedEffects |= 0x4000000;  // this causes error 
    } 
} 

DragDropEffects 열거 공개 : System.Windows.Forms.Design.OleDragDropHandler 클래스에서이 코드를 발견했습니다 당신이 볼 수있는

[Flags] 
public enum DragDropEffects { 
    Scroll = -2147483648, // 0x80000000 
    All = -2147483645,  // 0x80000003 
    None = 0, 
    Copy = 1, 
    Move = 2, 
    Link = 4, 
} 

는 첫 조각에 표시된 값을 더 필드가 없다 코드 (0x4000000). 또한이 코드는 VS에 오류가 발생합니다. operator |= cannot be applied to operands of type System.Windows.Forms.DragDropEffects and int

제 질문은 -이 컴파일 방법은 무엇입니까? 아니면 .NET Reflector가 디 컴파일 프로세스에서 실수를 저질렀습니까? 거기에 어떤 방식 으로든 그것을 우회 (allowedEffects 변수에 이상한, 이름없는 정보를 잃어 버리지 않고)?

답변

1

을 정수는 DragDropEffects 객체에 캐스팅되고 , ILSpy 여기에서 볼 수 있듯이 :

enter image description here

+0

ILSpy를 metioning 주셔서 감사합니다, 다른 도구를 사용하여 배울 시간;) –

2

리플렉터가 뭔가를 놓친 것처럼 보입니다. 당신이 명시 적으로 0x4000000DragDropEffects에 캐스팅해야합니다 컴파일하기 위해서는이에

allowedEffects &= ~DragDropEffects.Move; 
allowedEffects |= (DragDropEffects)0x4000000; 
+0

내가 알고하지 않았다, 열거 defini에 지정되지 않은 값을 캐스팅 할 수 있음 . 감사합니다 –

1

변경에게 그것을 그것은 컴파일 :

allowedEffects |= (DragDropEffects)0x4000000; 
관련 문제