private void WriteMethodModifiers(IMethodDefinition method)
        {
            if (method.IsMethodUnsafe() ||
                (method.IsConstructor && IsBaseConstructorCallUnsafe(method.ContainingTypeDefinition)))
            {
                WriteKeyword("unsafe");
            }

            if (method.IsStatic)
            {
                WriteKeyword("static");
            }

            if (method.IsPlatformInvoke)
            {
                WriteKeyword("extern");
            }

            if (method.IsVirtual)
            {
                if (method.ContainingTypeDefinition.IsInterface)
                {
                    if (method.IsStatic && method.IsAbstract)
                    {
                        WriteKeyword("abstract");
                    }
                }
                else if (method.IsNewSlot)
                {
                    if (method.IsAbstract)
                    {
                        WriteKeyword("abstract");
                    }
                    else if (!method.IsSealed) // non-virtual interfaces implementations are sealed virtual newslots
                    {
                        WriteKeyword("virtual");
                    }
                }
                else
                {
                    if (method.IsAbstract)
                    {
                        WriteKeyword("abstract");
                    }
                    else if (method.IsSealed)
                    {
                        WriteKeyword("sealed");
                    }
                    WriteKeyword("override");
                }
            }
        }
예제 #2
0
        private void WriteMethodDefinition(IMethodDefinition method)
        {
            if (method.IsPropertyOrEventAccessor())
            {
                return;
            }

            WriteMethodPseudoCustomAttributes(method);

            WriteAttributes(method.Attributes);
            WriteAttributes(method.SecurityAttributes);
            WriteAttributes(method.ReturnValueAttributes, prefix: "return");

            if (method.IsDestructor())
            {
                // If platformNotSupportedExceptionMessage is != null we're generating a dummy assembly which means we don't need a destructor at all.
                if (_platformNotSupportedExceptionMessage == null)
                {
                    WriteDestructor(method);
                }

                return;
            }

            if (method.ContainingTypeDefinition.IsInterface)
            {
                if (method.IsMethodUnsafe())
                {
                    WriteKeyword("unsafe");
                }
            }
            else
            {
                if (!method.IsExplicitInterfaceMethod() && !method.IsStaticConstructor)
                {
                    WriteVisibility(method.Visibility);
                }

                WriteMethodModifiers(method);
            }

            WriteInterfaceMethodModifiers(method);
            WriteMethodDefinitionSignature(method);
            WriteMethodBody(method);
        }
        private void WriteMethodModifiers(IMethodDefinition method)
        {
            if (method.IsMethodUnsafe())
            {
                WriteKeyword("unsafe");
            }

            if (method.IsStatic)
            {
                WriteKeyword("static");
            }

            if (method.IsVirtual)
            {
                if (method.IsNewSlot)
                {
                    if (method.IsAbstract)
                    {
                        WriteKeyword("abstract");
                    }
                    else if (!method.IsSealed) // non-virtual interfaces implementations are sealed virtual newslots
                    {
                        WriteKeyword("virtual");
                    }
                }
                else
                {
                    if (method.IsAbstract)
                    {
                        WriteKeyword("abstract");
                    }
                    else if (method.IsSealed)
                    {
                        WriteKeyword("sealed");
                    }
                    WriteKeyword("override");
                }
            }
        }
예제 #4
0
        public void WriteTypeDeclaration(ITypeDefinition type)
        {
            INamedTypeDefinition namedType = (INamedTypeDefinition)type;

            WriteAttributes(type.Attributes);
            WriteAttributes(type.SecurityAttributes);

            //TODO: We should likely add support for the SerializableAttribute something like:
            // if (type.IsSerializable) WriteFakeAttribute("System.Serializable");
            // But we need also consider if this attribute is filtered out or not but I guess
            // we have the same problem with all the fake attributes at this point.

            if ((type.IsStruct || type.IsClass) && type.Layout != LayoutKind.Auto)
            {
                FakeCustomAttribute structLayout = new FakeCustomAttribute("System.Runtime.InteropServices", "StructLayoutAttribute");
                string layoutKind = string.Format("System.Runtime.InteropServices.LayoutKind.{0}", type.Layout.ToString());

                if (_forCompilationIncludeGlobalprefix)
                {
                    layoutKind = "global::" + layoutKind;
                }

                var args = new List <string>();
                args.Add(layoutKind);

                if (type.SizeOf != 0)
                {
                    string sizeOf = string.Format("Size={0}", type.SizeOf);
                    args.Add(sizeOf);
                }

                if (type.Alignment != 0)
                {
                    string pack = string.Format("Pack={0}", type.Alignment);
                    args.Add(pack);
                }

                if (type.StringFormat != StringFormatKind.Ansi)
                {
                    string charset = string.Format("CharSet={0}System.Runtime.InteropServices.CharSet.{1}", _forCompilationIncludeGlobalprefix ? "global::" : "", type.StringFormat);
                    args.Add(charset);
                }

                if (IncludeAttribute(structLayout))
                {
                    WriteFakeAttribute(structLayout.FullTypeName, args.ToArray());
                }
            }

            WriteVisibility(TypeHelper.TypeVisibilityAsTypeMemberVisibility(type));

            IMethodDefinition invoke = type.GetInvokeMethod();

            if (invoke != null)
            {
                Contract.Assert(type.IsDelegate);

                if (invoke.IsMethodUnsafe())
                {
                    WriteKeyword("unsafe");
                }
                WriteKeyword("delegate");
                WriteTypeName(invoke.Type);
                WriteIdentifier(namedType.Name);
                if (type.IsGeneric)
                {
                    WriteGenericParameters(type.GenericParameters);
                }
                WriteParameters(invoke.Parameters, invoke.ContainingType);
                if (type.IsGeneric)
                {
                    WriteGenericContraints(type.GenericParameters);
                }
                WriteSymbol(";");
            }
            else
            {
                WriteTypeModifiers(type);
                WriteIdentifier(namedType.Name);
                Contract.Assert(!(type is IGenericTypeInstance), "Currently don't support generic type instances if we hit this then add support");
                if (type.IsGeneric)
                {
                    WriteGenericParameters(type.GenericParameters);
                }
                WriteBaseTypes(type);
                if (type.IsGeneric)
                {
                    WriteGenericContraints(type.GenericParameters);
                }

                if (type.IsEnum)
                {
                    WriteEnumType(type);
                }
            }
        }
예제 #5
0
        public void WriteTypeDeclaration(ITypeDefinition type)
        {
            INamedTypeDefinition namedType = (INamedTypeDefinition)type;

            WriteAttributes(type.Attributes);
            WriteAttributes(type.SecurityAttributes);

            //TODO: We should likely add support for the SerializableAttribute something like:
            // if (type.IsSerializable) WriteFakeAttribute("System.Serializable");
            // But we need also consider if this attribute is filtered out or not but I guess
            // we have the same problem with all the fake attributes at this point.

            if (type.IsStruct && type.Layout != LayoutKind.Auto)
            {
                // What about the Pack, and CharSet properties?
                string structLayout = "System.Runtime.InteropServices.StructLayoutAttribute";
                string layoutKind   = string.Format("System.Runtime.InteropServices.LayoutKind.{0}", type.Layout.ToString());

                if (type.SizeOf != 0)
                {
                    string sizeOf = string.Format("Size={0}", type.SizeOf);
                    WriteFakeAttribute(structLayout, layoutKind, sizeOf);
                }
                else
                {
                    WriteFakeAttribute(structLayout, layoutKind);
                }
            }

            WriteVisibility(TypeHelper.TypeVisibilityAsTypeMemberVisibility(type));

            IMethodDefinition invoke = type.GetInvokeMethod();

            if (invoke != null)
            {
                Contract.Assert(type.IsDelegate);

                if (invoke.IsMethodUnsafe())
                {
                    WriteKeyword("unsafe");
                }
                WriteKeyword("delegate");
                WriteTypeName(invoke.Type);
                WriteIdentifier(namedType.Name);
                if (type.IsGeneric)
                {
                    WriteGenericParameters(type.GenericParameters);
                }
                WriteParameters(invoke.Parameters);
                if (type.IsGeneric)
                {
                    WriteGenericContraints(type.GenericParameters);
                }
                WriteSymbol(";");
            }
            else
            {
                WriteTypeModifiers(type);
                WriteIdentifier(namedType.Name);
                Contract.Assert(!(type is IGenericTypeInstance), "Currently don't support generic type instances if we hit this then add support");
                if (type.IsGeneric)
                {
                    WriteGenericParameters(type.GenericParameters);
                }
                WriteBaseTypes(type);
                if (type.IsGeneric)
                {
                    WriteGenericContraints(type.GenericParameters);
                }

                if (type.IsEnum)
                {
                    WriteEnumType(type);
                }
            }
        }
        private void WriteMethodModifiers(IMethodDefinition method)
        {
            if (method.IsMethodUnsafe())
                WriteKeyword("unsafe");

            if (method.IsStatic)
                WriteKeyword("static");

            if (method.IsVirtual)
            {
                if (method.IsNewSlot)
                {
                    if (method.IsAbstract)
                        WriteKeyword("abstract");
                    else if (!method.IsSealed) // non-virtual interfaces implementations are sealed virtual newslots
                        WriteKeyword("virtual");
                }
                else
                {
                    if (method.IsAbstract)
                        WriteKeyword("abstract");
                    else if (method.IsSealed)
                        WriteKeyword("sealed");
                    WriteKeyword("override");
                }
            }
        }