Пример #1
0
    internal static ValueDescriptor CreateValueDescriptor(MemberInfo memberInfo, DVAttribute attr)
    {
      VDFlags flags = VDFlags.None;
      if (attr.RefOnly)
        flags |= VDFlags.RefOnly;

      string name = memberInfo.Name;

      Type type;
      if (memberInfo is FieldInfo)
        type = ((FieldInfo)memberInfo).FieldType;
      else
        type = ((PropertyInfo)memberInfo).PropertyType;

      if (type == typeof(NBool))
        return new NullableDescriptor(name, typeof(Boolean), type, memberInfo, flags);

      if (type == typeof(NInt))
        return new NullableDescriptor(name, typeof(Int32), type, memberInfo, flags);

      if (type == typeof(NDouble))
        return new NullableDescriptor(name, typeof(Double), type, memberInfo, flags);

      if (type == typeof(NString))
        return new NullableDescriptor(name, typeof(String), type, memberInfo, flags);

      if (type == typeof(String))
        return new ValueTypeDescriptor(name, typeof(String), type, memberInfo, flags);

      if (type == typeof(NEnum))
      {
        Type valueType = attr.Type;
        Debug.Assert(valueType.IsSubclassOf(typeof(Enum)), "NEnum must have 'Type' attribute with the underlying type");
        return new NullableDescriptor(name, valueType, type, memberInfo, flags);
      }

      if (type.IsSubclassOf(typeof(ValueType)))
        return new ValueTypeDescriptor(name, type, type, memberInfo, flags);

      if (typeof(DocumentObjectCollection).IsAssignableFrom(type))
        return new DocumentObjectCollectionDescriptor(name, type, type, memberInfo, flags);

      if (typeof(DocumentObject).IsAssignableFrom(type))
        return new DocumentObjectDescriptor(name, type, type, memberInfo, flags);

      Debug.Assert(false, type.FullName);
      return null;
    }
Пример #2
0
        internal static ValueDescriptor CreateValueDescriptor(MemberInfo memberInfo, DVAttribute attr)
        {
            VDFlags flags = VDFlags.None;

            if (attr.RefOnly)
            {
                flags |= VDFlags.RefOnly;
            }

            string name = memberInfo.Name;

            Type type;

            if (memberInfo is FieldInfo)
            {
                type = ((FieldInfo)memberInfo).FieldType;
            }
            else
            {
                type = ((PropertyInfo)memberInfo).PropertyType;
            }

            if (type == typeof(NBool))
            {
                return(new NullableDescriptor(name, typeof(Boolean), type, memberInfo, flags));
            }

            if (type == typeof(NInt))
            {
                return(new NullableDescriptor(name, typeof(Int32), type, memberInfo, flags));
            }

            if (type == typeof(NDouble))
            {
                return(new NullableDescriptor(name, typeof(Double), type, memberInfo, flags));
            }

            if (type == typeof(NString))
            {
                return(new NullableDescriptor(name, typeof(String), type, memberInfo, flags));
            }

            if (type == typeof(String))
            {
                return(new ValueTypeDescriptor(name, typeof(String), type, memberInfo, flags));
            }

            if (type == typeof(NEnum))
            {
                Type valueType = attr.Type;
                Debug.Assert(valueType.IsSubclassOf(typeof(Enum)), "NEnum must have 'Type' attribute with the underlying type");
                return(new NullableDescriptor(name, valueType, type, memberInfo, flags));
            }

            if (type.IsSubclassOf(typeof(ValueType)))
            {
                return(new ValueTypeDescriptor(name, type, type, memberInfo, flags));
            }

            if (typeof(DocumentObjectCollection).IsAssignableFrom(type))
            {
                return(new DocumentObjectCollectionDescriptor(name, type, type, memberInfo, flags));
            }

            if (typeof(DocumentObject).IsAssignableFrom(type))
            {
                return(new DocumentObjectDescriptor(name, type, type, memberInfo, flags));
            }

            Debug.Assert(false, type.FullName);
            return(null);
        }