private static void WrapMethod(IFastDeepClonerProperty item, MethodBuilder raisePropertyChanged, TypeBuilder typeBuilder)
        {
            MethodInfo setMethod = item.PropertySetValue;

            var att = setMethod.Attributes;
            //get an array of the parameter types.
            var types = from t in setMethod.GetParameters()
                        select t.ParameterType;

            MethodBuilder setMethodBuilder = typeBuilder.DefineMethod(
                setMethod.Name, att | MethodAttributes.Final |
                MethodAttributes.HideBySig | MethodAttributes.NewSlot,
                setMethod.ReturnType, types.ToArray());

            typeBuilder.DefineMethodOverride(setMethodBuilder, setMethod);
            setMethodBuilder.SetImplementationFlags(MethodImplAttributes.AggressiveInlining);

            ILGenerator setMethodWrapperIl = setMethodBuilder.GetILGenerator();

            // base.[PropertyName] = value;
            setMethodWrapperIl.Emit(OpCodes.Ldarg_0);
            setMethodWrapperIl.Emit(OpCodes.Ldarg_1);
            setMethodWrapperIl.EmitCall(
                OpCodes.Call, setMethod, null);

            // RaisePropertyChanged("[PropertyName]");
            setMethodWrapperIl.Emit(OpCodes.Ldarg_0);
            setMethodWrapperIl.Emit(OpCodes.Ldstr, item.Name);
            setMethodWrapperIl.EmitCall(
                OpCodes.Call, raisePropertyChanged, null);

            // return;
            setMethodWrapperIl.Emit(OpCodes.Ret);
        }
Exemple #2
0
        /// <summary>
        /// Get PropertyName from the cashed Properties
        /// </summary>
        /// <param name="prop"></param>
        /// <returns></returns>
        public static string GetPropertyName(this IFastDeepClonerProperty prop)
        {
            if (CachedPropertyNames.ContainsKey(prop))
            {
                return(CachedPropertyNames[prop]);
            }

            return(CachedPropertyNames.GetOrAdd(prop, (prop.GetCustomAttribute <PropertyName>()?.Name ?? prop.Name).CleanName()));
        }
        /// <summary>
        /// Convert System Type to SqlType
        /// </summary>
        /// <param name="prop"></param>
        /// <param name="dbType"></param>
        /// <returns></returns>
        public static List <string> GetDbTypeListByType(this IFastDeepClonerProperty prop, DataBaseTypes dbType)
        {
            var type = prop.PropertyType;

            if (prop.ContainAttribute <Stringify>() ||
                prop.ContainAttribute <DataEncode>() ||
                prop.ContainAttribute <ToBase64String>() ||
                prop.ContainAttribute <JsonDocument>() ||
                prop.ContainAttribute <XmlDocument>())
            {
                return new List <string>()
                       {
                           typeof(string).GetDbTypeByType(dbType)
                       }
            }
            ;

            if (prop.ContainAttribute <ColumnType>() && prop.Attributes.Any(x => x is ColumnType && !string.IsNullOrEmpty((x as ColumnType).DataType) && ((x as ColumnType).DataBaseTypes == dbType) || !(x as ColumnType).DataBaseTypes.HasValue))
            {
                return(prop.Attributes.Where(x => x is ColumnType && !string.IsNullOrEmpty((x as ColumnType).DataType) && ((x as ColumnType).DataBaseTypes == dbType) || !(x as ColumnType).DataBaseTypes.HasValue).Select(x => (x as ColumnType).DataType).ToList());
            }

            if (type.GetTypeInfo().IsEnum)
            {
                type = typeof(long);
            }

            if (Nullable.GetUnderlyingType(type) != null)
            {
                type = Nullable.GetUnderlyingType(type);
            }
            if (dbType == DataBaseTypes.Mssql)
            {
                return(DbMsSqlMapper.ContainsKey(type) ? DbMsSqlMapper[type] : null);
            }
            else if (dbType == DataBaseTypes.Sqllight)
            {
                return(DbSQLiteMapper.ContainsKey(type) ? DbSQLiteMapper[type] : null);
            }
            else
            {
                return(DbPostGresqlMapper.ContainsKey(type) ? DbPostGresqlMapper[type] : null);
            }
        }
Exemple #4
0
 internal ModuleBuilderProperty(IFastDeepClonerProperty property, Type objectType)
 {
     _property   = property;
     _objectType = objectType;
 }
Exemple #5
0
 internal ModuleBuilderProperty(IFastDeepClonerProperty property)
 {
     _property   = property;
     _objectType = typeof(T);
 }