Ejemplo n.º 1
0
        public static CSAttribute LayoutKind(LayoutKind layout)
        {
            CSArgumentList args = new CSArgumentList();

            args.Add(new CSIdentifier(String.Format("LayoutKind.{0}", layout)));
            return(new CSAttribute(new CSIdentifier("StructLayout"), args, true));
        }
Ejemplo n.º 2
0
        public static CSAttribute MarshalAsFunctionPointer()
        {
            CSArgumentList list = new CSArgumentList();

            list.Add(new CSArgument(new CSIdentifier("UnmanagedType.FunctionPtr")));
            return(FromAttr(typeof(MarshalAsAttribute), list, false));
        }
Ejemplo n.º 3
0
        public static CSAttribute FieldOffset(int offset)
        {
            CSArgumentList args = new CSArgumentList();

            args.Add(CSConstant.Val(offset));
            return(new CSAttribute(new CSIdentifier("FieldOffset"), args, true));
        }
Ejemplo n.º 4
0
        public static CSAttribute DllImport(CSBaseExpression dllName, string entryPoint = null)
        {
            CSArgumentList args = new CSArgumentList();

            args.Add(dllName);
            if (entryPoint != null)
            {
                args.Add(new CSAssignment("EntryPoint", CSAssignmentOperator.Assign, CSConstant.Val(entryPoint)));
            }
            return(new CSAttribute(new CSIdentifier("DllImport"), args, true));
        }
Ejemplo n.º 5
0
        public static CSAttribute FromAttr(Type attribute, CSArgumentList args, bool isSingleLine = false)
        {
            Exceptions.ThrowOnNull(attribute, nameof(attribute));
            if (!attribute.IsSubclassOf(typeof(Attribute)))
            {
                throw new ArgumentException(String.Format("Type {0} is not an Attribute type.", attribute.Name), nameof(attribute));
            }
            var name = attribute.Name.EndsWith("Attribute") ?
                       attribute.Name.Substring(0, attribute.Name.Length - "Attribute".Length) : attribute.Name;

            return(new CSAttribute(new CSIdentifier(name), args, isSingleLine));
        }
Ejemplo n.º 6
0
 public CSAttribute(CSIdentifier name, CSArgumentList args, bool isSingleLine = false)
     : base(isSingleLine, false, isSingleLine)
 {
     Add(new SimpleElememt("["));
     Add(Exceptions.ThrowOnNull(name, nameof(name)));
     if (args != null)
     {
         Add(new SimpleElememt("("));
         Add(args);
         Add(new SimpleElememt(")"));
     }
     Add(new SimpleElememt("]"));
 }
Ejemplo n.º 7
0
 public CSAttribute(string name, CSArgumentList args)
     : this(new CSIdentifier(name), args)
 {
 }