protected FieldBuilder DefineField(
            TypeBuilder typeBuilder,
            string name,
            Type type,
            DCField field,
            bool isPrivate)
        {
            var fieldBuilder = typeBuilder.DefineField((isPrivate ? "_" : "") + name, type,
                                                       !isPrivate || _IsSilverlight ? FieldAttributes.Public : FieldAttributes.Family);

            if (_IsSilverlight)
            {
                var customBuilder = new CustomAttributeBuilder(
                    typeof(EditorBrowsableAttribute).GetConstructor(new Type[1]
                {
                    typeof(EditorBrowsableState)
                }), new object[1]
                {
                    EditorBrowsableState.Never
                });
                fieldBuilder.SetCustomAttribute(customBuilder);
            }

            AddMetadataAttribute(fieldBuilder, field);
            AddDataMemberAttribute(typeBuilder.Name, fieldBuilder, name);
            return(fieldBuilder);
        }
        protected void DefineLiteral(
            EnumBuilder enumBuilder,
            string name,
            int number,
            string defaultValue,
            DCField field)
        {
            var fieldBuilder   = enumBuilder.DefineLiteral(name, number);
            var customBuilder1 =
                new CustomAttributeBuilder(typeof(EnumMemberAttribute).GetConstructor(Type.EmptyTypes), new object[0]);

            fieldBuilder.SetCustomAttribute(customBuilder1);
            DCBuilderType dcBuilderType = dCTypeStore.GetDCBuilderType("EnumerationAttribute");

            if (dcBuilderType != null)
            {
                var customBuilder2 = new CustomAttributeBuilder(dcBuilderType.Type.GetConstructor(
                                                                    new Type[1]
                {
                    typeof(string)
                }), new object[1] {
                    defaultValue
                });
                fieldBuilder.SetCustomAttribute(customBuilder2);
            }

            if (field == null)
            {
                return;
            }
            AddMetadataAttribute(fieldBuilder, field);
        }
 protected PropertyBuilder DefineProperty(
     TypeBuilder typeBuilder,
     string name,
     Type type,
     DCField field)
 {
     return(DefineProperty(typeBuilder, name, type));
 }
        private void AddMetadataAttribute(FieldBuilder fieldBuilder, DCField field)
        {
            DCBuilderType dcBuilderType = dCTypeStore.GetDCBuilderType("MetadataAttribute");

            if (dcBuilderType == null || field == null)
            {
                return;
            }
            var customBuilder = new CustomAttributeBuilder(dcBuilderType.Type.GetConstructor(
                                                               new Type[11]
            {
                typeof(string),
                typeof(string),
                typeof(bool),
                typeof(bool),
                typeof(bool),
                typeof(string),
                typeof(int),
                typeof(bool),
                typeof(bool),
                typeof(bool),
                typeof(string)
            }), new object[11]
            {
                field.Description,
                field.FieldTypeName,
                field.IsUserDefinedField,
                field.IsRequired,
                field.IsReadOnly,
                field.IsEnum ? field.EnumFieldTypeName : (object)field.TypeName,
                field.Label,
                field.CreateOnInitialize,
                field.IsList,
                field.HasSelVal,
                string.IsNullOrEmpty(field.DefaultValue) ? null : (object)field.DefaultValue
            });

            fieldBuilder.SetCustomAttribute(customBuilder);
        }