示例#1
0
        internal static Delegate Deserialize(UdfData udfData)
        {
            Type       udfType   = DeserializeType(udfData.TypeData);
            MethodInfo udfMethod = udfType.GetMethod(
                udfData.MethodName,
                BindingFlags.Instance |
                BindingFlags.Static |
                BindingFlags.Public |
                BindingFlags.NonPublic);

            var udfParameters = udfMethod.GetParameters().Select(p => p.ParameterType).ToList();

            udfParameters.Add(udfMethod.ReturnType);
            Type funcType = Expression.GetFuncType(udfParameters.ToArray());

            if (udfData.TargetData == null)
            {
                // The given UDF is a static function.
                return(Delegate.CreateDelegate(funcType, udfMethod));
            }
            else
            {
                return(Delegate.CreateDelegate(
                           funcType,
                           DeserializeTargetData(udfData.TargetData),
                           udfData.MethodName));
            }
        }
示例#2
0
 public bool Equals(UdfData other)
 {
     return((other != null) &&
            TypeData.Equals(other.TypeData) &&
            (MethodName == other.MethodName) &&
            TargetData.Equals(other.TargetData));
 }
示例#3
0
        internal static UdfData Serialize(Delegate udf)
        {
            MethodInfo method = udf.Method;
            object     target = udf.Target;

            var udfData = new UdfData()
            {
                TypeData   = SerializeType(method.DeclaringType),
                MethodName = method.Name,
                TargetData = SerializeTarget(target)
            };

            return(udfData);
        }