//used for WCF known types
        internal static WebServiceTypeData GetWebServiceTypeData(Type type)
        {
            WebServiceTypeData      typeData = null;
            XsdDataContractExporter exporter = new XsdDataContractExporter();
            XmlQualifiedName        qname    = exporter.GetSchemaTypeName(type);

            if (!qname.IsEmpty)
            {
                if (type.IsEnum)
                {
                    bool isUlong = (Enum.GetUnderlyingType(type) == typeof(ulong));
                    typeData = new WebServiceEnumData(XmlConvert.DecodeName(qname.Name), XmlConvert.DecodeName(qname.Namespace), Enum.GetNames(type), Enum.GetValues(type), isUlong);
                }
                else
                {
                    typeData = new WebServiceTypeData(XmlConvert.DecodeName(qname.Name), XmlConvert.DecodeName(qname.Namespace));
                }
            }
            return(typeData);
        }
        //used for WCF known types
        internal static WebServiceTypeData GetWebServiceTypeData(Type type) {

            WebServiceTypeData typeData = null;       
            XsdDataContractExporter exporter = new XsdDataContractExporter();
            XmlQualifiedName qname = exporter.GetSchemaTypeName(type);
            if (!qname.IsEmpty) {
                if (type.IsEnum) {
                    bool isUlong = (Enum.GetUnderlyingType(type) == typeof(ulong));
                    typeData = new WebServiceEnumData(XmlConvert.DecodeName(qname.Name), XmlConvert.DecodeName(qname.Namespace), Enum.GetNames(type), Enum.GetValues(type), isUlong);
                }
                else {
                    typeData = new WebServiceTypeData(XmlConvert.DecodeName(qname.Name), XmlConvert.DecodeName(qname.Namespace));
                }
            }
            return typeData;
        }
Exemple #3
0
        internal void ProcessClientType(Type t, bool force, bool isWCF)
        {
            if (!force && _processedTypes.Contains(t))
            {
                return;
            }
            _processedTypes[t] = null;

            // Keep track of all enum Types
            if (t.IsEnum)
            {
                WebServiceEnumData enumData = null;
                if (isWCF)
                {
                    enumData = (WebServiceEnumData)WebServiceTypeData.GetWebServiceTypeData(t);
                }
                else
                {
                    enumData = new WebServiceEnumData(t.Name, t.Namespace, t, Enum.GetNames(t), Enum.GetValues(t), Enum.GetUnderlyingType(t) == typeof(ulong));
                }
                _enumTypesDictionary[GetTypeStringRepresentation(enumData.TypeName, false)] = enumData;
                return;
            }

            // For generics, we only allow generic types with one parameter, which we will try to process
            if (t.IsGenericType)
            {
                if (isWCF)
                {
                    ProcessKnownTypes(t);
                }
                else
                {
                    Type[] genericArgs = t.GetGenericArguments();
                    if (genericArgs.Length > 1)
                    {
                        return;
                    }
                    ProcessClientType(genericArgs[0], false, isWCF);
                }
            }
            // Support arrays explicitly
            else if (t.IsArray)
            {
                ProcessClientType(t.GetElementType(), false, isWCF);
            }
            else
            {
                // Ignore primitive types
                // Ignore DateTime, since we have special serialization handling for it in the JavaScriptSerializer
                // Ignore IDctionary and IEnumerables as well
                if (t.IsPrimitive || t == typeof(object) || t == typeof(string) || t == typeof(DateTime) ||
                    t == typeof(void) || t == typeof(System.Decimal) || t == typeof(Guid) ||
                    typeof(IEnumerable).IsAssignableFrom(t) || typeof(IDictionary).IsAssignableFrom(t) ||
                    (!isWCF && !ObjectConverter.IsClientInstantiatableType(t, _serializer)))
                {
                    return;
                }

                // Only add it to the list of client types if it can be instantiated.
                // pass false to skip the lock
                if (isWCF)
                {
                    ProcessKnownTypes(t);
                }
                else
                {
                    string typeStringRepresentation = GetTypeStringRepresentation(t.FullName, false);
                    _clientTypesDictionary[typeStringRepresentation] = new WebServiceTypeData(t.Name, t.Namespace, t);
                    _clientTypeNameDictionary[t] = typeStringRepresentation;
                }
            }
        }
        internal void ProcessClientType(Type t, bool force, bool isWCF)
        {
            if (!force && _processedTypes.Contains(t))
                return;
            _processedTypes[t] = null;

            // Keep track of all enum Types
            if (t.IsEnum) {
                WebServiceEnumData enumData = null;
                if (isWCF) {
                    enumData = (WebServiceEnumData)WebServiceTypeData.GetWebServiceTypeData(t);
                }
                else {
                    enumData = new WebServiceEnumData(t.Name, t.Namespace, t, Enum.GetNames(t), Enum.GetValues(t), Enum.GetUnderlyingType(t) == typeof(ulong));
                }
                _enumTypesDictionary[GetTypeStringRepresentation(enumData.TypeName, false)] = enumData;
                return;
            }

            // For generics, we only allow generic types with one parameter, which we will try to process
            if (t.IsGenericType) {
                if (isWCF) {
                     ProcessKnownTypes(t);
                }
                else {
                    Type[] genericArgs = t.GetGenericArguments();
                    if (genericArgs.Length > 1) {
                        return;
                    }
                    ProcessClientType(genericArgs[0], false, isWCF);
                }
            }
            // Support arrays explicitly
            else if (t.IsArray) {
                ProcessClientType(t.GetElementType(), false, isWCF);
            }
            else {
                // Ignore primitive types
                // Ignore DateTime, since we have special serialization handling for it in the JavaScriptSerializer
                // Ignore IDctionary and IEnumerables as well
                if (t.IsPrimitive || t == typeof(object) || t == typeof(string) || t == typeof(DateTime) ||
                    t == typeof(void) || t == typeof(System.Decimal) || t == typeof(Guid) ||
                    typeof(IEnumerable).IsAssignableFrom(t) || typeof(IDictionary).IsAssignableFrom(t) ||
                    (!isWCF && !ObjectConverter.IsClientInstantiatableType(t, _serializer)))
                    return;

                // Only add it to the list of client types if it can be instantiated.
                // pass false to skip the lock
                if (isWCF) {
                    ProcessKnownTypes(t);
                }
                else {
                    string typeStringRepresentation = GetTypeStringRepresentation(t.FullName, false);
                    _clientTypesDictionary[typeStringRepresentation] = new WebServiceTypeData(t.Name, t.Namespace, t);
                    _clientTypeNameDictionary[t] = typeStringRepresentation;

                }
            }
        }