Exemple #1
0
 private void PackValue(ref object source, NetVariant destination)
 {
     if (source == null)
     {
         destination.Clear();
     }
     else
     {
         var type = source.GetType();
         if (type == typeof(bool))
         {
             destination.SetBool((bool)source);
         }
         else if (type == typeof(char))
         {
             destination.SetChar((char)source);
         }
         else if (type == typeof(double))
         {
             destination.SetDouble((double)source);
         }
         else if (type == typeof(int))
         {
             destination.SetInt((int)source);
         }
         else if (type == typeof(uint))
         {
             destination.SetUInt((uint)source);
         }
         else if (type == typeof(string))
         {
             destination.SetString((string)source);
         }
         else if (type == typeof(DateTime))
         {
             destination.SetDateTime((DateTime)source);
         }
         else
         {
             destination.SetNetInstance(NetTypeInfoManager.WrapCreatedInstance(
                                            GCHandle.ToIntPtr(GCHandle.Alloc(source)),
                                            NetTypeInfoManager.GetTypeInfo(GetUnproxiedType(type))));
         }
     }
 }
Exemple #2
0
        public override void BuildTypeInfo(NetTypeInfo typeInfo)
        {
            var type = Type.GetType(typeInfo.GetFullTypeName());

            typeInfo.SetClassName(type.Name);

            if (type == typeof(bool))
            {
                typeInfo.SetPrefVariantType(NetVariantTypeEnum.NetVariantTypeEnum_Bool);
            }
            else if (type == typeof(char))
            {
                typeInfo.SetPrefVariantType(NetVariantTypeEnum.NetVariantTypeEnum_Char);
            }
            else if (type == typeof(int))
            {
                typeInfo.SetPrefVariantType(NetVariantTypeEnum.NetVariantTypeEnum_Int);
            }
            else if (type == typeof(uint))
            {
                typeInfo.SetPrefVariantType(NetVariantTypeEnum.NetVariantTypeEnum_UInt);
            }
            else if (type == typeof(double))
            {
                typeInfo.SetPrefVariantType(NetVariantTypeEnum.NetVariantTypeEnum_Double);
            }
            else if (type == typeof(string))
            {
                typeInfo.SetPrefVariantType(NetVariantTypeEnum.NetVariantTypeEnum_String);
            }
            else if (type == typeof(DateTime))
            {
                typeInfo.SetPrefVariantType(NetVariantTypeEnum.NetVariantTypeEnum_DateTime);
            }
            else
            {
                typeInfo.SetPrefVariantType(NetVariantTypeEnum.NetVariantTypeEnum_Object);
            }

            if (type.Namespace == "System")
            {
                return; // built in type!
            }
            foreach (var method in type.GetMethods(BindingFlags.Public | BindingFlags.Instance))
            {
                if (method.DeclaringType == typeof(Object))
                {
                    continue;
                }

                NetTypeInfo returnType = null;

                if (method.ReturnParameter.ParameterType != typeof(void))
                {
                    returnType = NetTypeInfoManager.GetTypeInfo(method.ReturnParameter.ParameterType);
                }

                var methodInfo = NetTypeInfoManager.NewMethodInfo(typeInfo, method.Name, returnType);

                foreach (var parameter in method.GetParameters())
                {
                    methodInfo.AddParameter(parameter.Name, NetTypeInfoManager.GetTypeInfo(parameter.ParameterType));
                }

                typeInfo.AddMethod(methodInfo);
            }

            foreach (var property in type.GetProperties(BindingFlags.Public | BindingFlags.Instance))
            {
                typeInfo.AddProperty(NetTypeInfoManager.NewPropertyInfo(
                                         typeInfo, property.Name,
                                         NetTypeInfoManager.GetTypeInfo(property.PropertyType),
                                         property.CanRead,
                                         property.CanWrite));
            }
        }