Exemplo n.º 1
0
        private string GetObjDataType(ObjDataTypeEnum value)
        {
            Type                 type      = typeof(ObjDataTypeEnum);
            FieldInfo            fieldInfo = type.GetField(Enum.GetName(type, value));
            DescriptionAttribute descAtt   =
                (DescriptionAttribute)Attribute.GetCustomAttribute(
                    fieldInfo, typeof(DescriptionAttribute));

            if (descAtt != null)
            {
                return(descAtt.Description);
            }
            else
            {
                return(value.ToString());
            }
        }
Exemplo n.º 2
0
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            if (value is string)
            {
                try
                {
                    string s     = (string)value;
                    int    colon = s.IndexOf(':');
                    int    comma = s.IndexOf(',');
                    if (colon != -1 && comma != -1)
                    {
                        ObjDataTypeEnum objdatetype = GetObjDataTypeStr(s.Substring(colon + 1, (comma - colon - 1)));
                        colon = s.IndexOf(':', comma + 1);
                        comma = s.IndexOf(',', comma + 1);
                        bool isview = Boolean.Parse(s.Substring(colon + 1, (comma - colon - 1)));
                        colon = s.IndexOf(':', comma + 2);
                        comma = s.IndexOf(',', comma + 2);
                        string updatetablefrom = s.Substring(colon + 1, (comma - colon - 1));
                        colon = s.IndexOf(':', comma + 3);
                        string storeProcedureQuery = s.Substring(colon + 1);

                        ObjDataPresentation op = new ObjDataPresentation();
                        op.ObjDataType         = objdatetype;
                        op.IsSchemaForOther    = isview;
                        op.UpdateTableName     = updatetablefrom;
                        op.StoreProcedureQuery = storeProcedureQuery;
                        return(op);
                    }
                }
                catch
                {
                    throw new ArgumentException(
                              "无法将“" + (string)value +
                              "”转换为 SpellingOptions 类型");
                }
            }
            return(base.ConvertFrom(context, culture, value));
        }