Beispiel #1
0
        public void ResolveMarshalAsAttributeForString(FieldBuilder field, MemberRubric member, Type type)
        {
            MemberInfo _member = member.RubricInfo;

            if (member is MemberRubric && ((MemberRubric)member).FigureField != null)
            {
                _member = ((MemberRubric)member).FigureField;
            }

            object[] o = _member.GetCustomAttributes(typeof(MarshalAsAttribute), false);
            if (o == null || !o.Any())
            {
                o = _member.GetCustomAttributes(typeof(FigureAsAttribute), false);
                if (o != null && o.Any())
                {
                    FigureAsAttribute maa = (FigureAsAttribute)o.First();
                    CreateFigureAsAttribute(field, new FigureAsAttribute(UnmanagedType.ByValTStr)
                    {
                        SizeConst = maa.SizeConst
                    });
                }
                else
                {
                    int size = 64;
                    if (member.RubricSize > 0)
                    {
                        size = member.RubricSize;
                    }
                    CreateFigureAsAttribute(field, new FigureAsAttribute(UnmanagedType.ByValTStr)
                    {
                        SizeConst = size
                    });
                }
            }
            else
            {
                MarshalAsAttribute maa = (MarshalAsAttribute)o.First();
                CreateMarshaAslAttribute(field, new MarshalAsAttribute(UnmanagedType.ByValTStr)
                {
                    SizeConst = maa.SizeConst
                });
            }
        }
Beispiel #2
0
 public void CreateFigureAsAttribute(FieldBuilder field, FigureAsAttribute attrib)
 {
     field.SetCustomAttribute(new CustomAttributeBuilder(marshalAsCtor, new object[] { attrib.Value },
                                                         new FieldInfo[] { typeof(MarshalAsAttribute).GetField("SizeConst") },
                                                         new object[] { attrib.SizeConst }));
 }