コード例 #1
0
ファイル: ExtendProps.cs プロジェクト: aienabled/Managed
        private static ExtendPropertyData AddProperty(NativeTypePropsInfo info, PropertyInfo p, bool usePropertyInfo)
        {
            AddPropertyDelegate addPropFunction;

            if (_addPropertyFunctions.TryGetValue(p.PropertyType, out addPropFunction))
            {
                return(addPropFunction(info, p, usePropertyInfo));
            }

            IntPtr propertyType = EnsureNativeType(p.PropertyType);

            if (p.PropertyType.GetTypeInfo().IsEnum)
            {
                AddPropertyAccessor <int, object>(info, p,
                                                  (v) => (int)Convert.ToInt64(v),
                                                  (v) => Enum.ToObject(p.PropertyType, v),
                                                  true);

                return(CreatePropertyData(p, NativePropertyType.Enum, propertyType));
            }
            else
            {
                AddPropertyAccessor <object>(info, p, true);

                return(CreatePropertyData(p, NativePropertyType.BaseComponent, propertyType));
            }
        }
コード例 #2
0
 private static void AddPropertyAccessor(NativeTypePropsInfo info, PropertyInfo p,
                                         Func <PropertyAccessor> creatorRW, Func <PropertyAccessor> creatorRO)
 {
     if (p.GetSetMethod() != null)
     {
         info.Properties.Add(creatorRW());
     }
     else
     {
         info.Properties.Add(creatorRO());
     }
 }
コード例 #3
0
        private static void AddPropertyAccessorNullable <PropertyT>(NativeTypePropsInfo info, PropertyInfo p, bool usePropertyInfo)
        {
#if !ENABLE_IL2CPP && !UNITY_IOS
            if (!usePropertyInfo)
            {
                AddPropertyAccessor(info, p,
                                    () => new PropertyAccessorNullableRW <PropertyT>(p),
                                    () => new PropertyAccessorNullableRO <PropertyT>(p));
            }
            else
#endif
            {
                AddPropertyAccessor(info, p,
                                    () => new PropertyAccessorNullablePropRW <PropertyT>(p),
                                    () => new PropertyAccessorNullablePropRO <PropertyT>(p));
            }
        }
コード例 #4
0
        private static void AddPropertyAccessorNullable <PropertyT, SourceT>(NativeTypePropsInfo info, PropertyInfo p,
                                                                             Func <SourceT, PropertyT> castTo, Func <PropertyT, SourceT> castFrom, bool usePropertyInfo)
        {
#if !ENABLE_IL2CPP && !UNITY_IOS
            if (!usePropertyInfo)
            {
                AddPropertyAccessor(info, p,
                                    () => new PropertyAccessorNullableCastRW <PropertyT, SourceT>(p, new PropertyAccessorRW <SourceT>(p), castTo, castFrom),
                                    () => new PropertyAccessorNullableCastRO <PropertyT, SourceT>(p, new PropertyAccessorRO <SourceT>(p), castTo));
            }
            else
#endif
            {
                AddPropertyAccessor(info, p,
                                    () => new PropertyAccessorNullableCastRW <PropertyT, SourceT>(p, new PropertyAccessorPropRW <SourceT>(p), castTo, castFrom),
                                    () => new PropertyAccessorNullableCastRO <PropertyT, SourceT>(p, new PropertyAccessorPropRO <SourceT>(p), castTo));
            }
        }
コード例 #5
0
        private static ExtendPropertyData AddProperty(NativeTypePropsInfo info, PropertyInfo p, bool usePropertyInfo)
        {
            AddPropertyDelegate addPropFunction;

            if (_addPropertyFunctions.TryGetValue(p.PropertyType.TypeHandle, out addPropFunction))
            {
                return(addPropFunction(info, p, usePropertyInfo));
            }

            IntPtr propertyType = EnsureNativeType(p.PropertyType);

            if (p.PropertyType.GetTypeInfo().IsEnum)
            {
                AddPropertyAccessor <int, object>(info, p,
                                                  (v) => (int)Convert.ToInt64(v),
                                                  (v) => Enum.ToObject(p.PropertyType, v),
                                                  true);

                return(CreatePropertyData(p, NativePropertyType.Enum, propertyType));
            }
            else
            {
                if (p.PropertyType.TypeHandle == (object)typeof(System.Type).TypeHandle)
                {
                    AddPropertyAccessor <object, object>(info, p,
                                                         (v) => Noesis.Extend.GetResourceKeyType((Type)v),
                                                         (v) => v != null ? ((ResourceKeyType)v).Type : null,
                                                         true);
                }
                else
                {
                    AddPropertyAccessor <object>(info, p, true);
                }

                return(CreatePropertyData(p, NativePropertyType.BaseComponent, propertyType));
            }
        }