static void ResolveRefOutArgs(AppFriend app, Type type, object src, out object arg, out ResolveArgument resolveArgument)
 {
     if (type.IsInterface)
     {
         ResolveInterfaceRefOutArgs(app, type, src, out arg, out resolveArgument);
     }
     else if (type == typeof(AppVar))
     {
         ResolveAppVarRefOutArgs(app, type, src, out arg, out resolveArgument);
     }
     else
     {
         var func = UserWrapperUtility.FindCreateConstructor(type);
         if (func != null)
         {
             ResolveUserWrapperRefOutArgs(func, app, src, out arg, out resolveArgument);
         }
         else
         {
             AppVar appVar = app.Dim(src);
             arg = appVar;
             resolveArgument = () => appVar.Core;
         }
     }
 }
 private static string GetFullNameFromAttr(AppFriend app, Type type, TargetTypeAttribute attr)
 {
     if (IsGeneric(attr.FullName))
     {
         List<string> genericArguments = new List<string>();
         foreach (var element in type.GetGenericArguments())
         {
             string innerType = GetFullName(app, element);
             if (string.IsNullOrEmpty(innerType))
             {
                 return string.Empty;
             }
             genericArguments.Add(innerType);
         }
         return MakeGenericTypeFullName(app, attr.FullName, genericArguments.ToArray());
     }
     else if (IsArray(attr.FullName))
     {
         var innerTypes = type.GetGenericArguments();
         if (innerTypes.Length != 1)
         {
             return string.Empty;
         }
         string arrayCoreType = GetFullName(app, innerTypes[0]);
         if (string.IsNullOrEmpty(arrayCoreType))
         {
             return string.Empty;
         }
         return arrayCoreType + attr.FullName;
     }
     else
     {
         return attr.FullName;
     }
 }
 internal ArgumentResolver(AppFriend app, MethodInfo method, bool isAsyunc, object[] src)
 {
     InvokeArguments = new object[src.Length];
     _resolveArguments = new ResolveArgument[src.Length];
     var parameters = method.GetParameters();
     for (int i = 0; i < parameters.Length; i++)
     {
         Type paramType = parameters[i].ParameterType;
         object srcObj = src[i];
         if (paramType.IsByRef)
         {
             Type elementType = paramType.GetElementType();
             object arg;
             ResolveArgument refoutFunc;
             ResolveRefOutArgs(app, elementType, srcObj, out arg, out refoutFunc);
             InvokeArguments[i] = arg;
             _resolveArguments[i] = (isAsyunc && elementType != typeof(AppVar)) ? (() => TypeUtility.GetDefault(elementType)) : refoutFunc;
         }
         else
         {
             InvokeArguments[i] = TryConvertProxy(srcObj);
             _resolveArguments[i] = () => srcObj;
         }
     }
 }
 internal static string GetFullNameTopMustHaveAttr(AppFriend app, Type type)
 {
     if (GetTargetTypeAttribute(type) == null)
     {
         return string.Empty;
     }
     return GetFullName(app, type);
 }
 internal static FriendlyOperation GetFriendlyOperation(AppFriend target, string name, Async async, OperationTypeInfo typeInfo)
 {
     if (async != null && typeInfo != null)
     {
         return target[name, typeInfo, async];
     }
     else if (async != null)
     {
         return target[name, async];
     }
     else if (typeInfo != null)
     {
         return target[name, typeInfo];
     }
     return target[name];
 }
 internal static OperationTypeInfo TryCreateOperationTypeInfo(AppFriend app, string declaringType, MethodInfo method)
 {
     if (string.IsNullOrEmpty(declaringType))
     {
         return null;
     }
     List<string> arguments = new List<string>();
     foreach (var arg in method.GetParameters())
     {
         string argTarget = GetFullName(app, arg.ParameterType);
         if (string.IsNullOrEmpty(argTarget))
         {
             return null;
         }
         arguments.Add(argTarget);
     }
     return new OperationTypeInfo(declaringType, arguments.ToArray());
 }
        internal static string GetFullName(AppFriend app, Type type)
        {
            Type coreType = type;
            if (coreType.IsByRef)
            {
                coreType = coreType.GetElementType();
            }

            TargetTypeAttribute attr = GetTargetTypeAttribute(coreType);

            string typeName = string.Empty;
            if (attr == null)
            {
                if (coreType.IsGenericType)
                {
                    List<string> genericArguments = new List<string>();
                    foreach (var element in coreType.GetGenericArguments())
                    {
                        string innerType = GetFullName(app, element);
                        if (string.IsNullOrEmpty(innerType))
                        {
                            return string.Empty;
                        }
                        genericArguments.Add(innerType);
                    }
                    typeName = MakeGenericTypeFullName(app, coreType.GetGenericTypeDefinition().FullName, genericArguments.ToArray());
                }
                else
                {
                    typeName = coreType.FullName;
                }
            }
            else
            {
                typeName = GetFullNameFromAttr(app, coreType, attr);
            }
            if (string.IsNullOrEmpty(typeName))
            {
                return string.Empty;
            }
            return typeName + (type.IsByRef ? "&" : string.Empty);
        }
 static void ResolveInterfaceRefOutArgs(AppFriend app, Type type, object src, out object arg, out ResolveArgument resolveArgument)
 {
     if (src == null)
     {
         AppVar appVar = app.Dim();
         arg = appVar;
         resolveArgument = () => FriendlyProxyFactory.WrapFriendlyProxyInstance(type, appVar);
     }
     else
     {
         var proxy = RemotingServices.GetRealProxy(src) as IAppVarOwner;
         if (proxy == null)
         {
             AppVar appVar = app.Dim(src);
             arg = appVar;
             resolveArgument = () => FriendlyProxyFactory.WrapFriendlyProxyInstance(type, appVar);
         }
         else
         {
             arg = proxy;
             resolveArgument = () => AppVarUtility.IsNull(proxy.AppVar) ? null : src;
         }
     }
 }
  static string MakeGenericTypeFullName(AppFriend app, string genericTypeFullName, string[] genericArgumentsFullName)
  {
      AppVar typeFinder = app.Dim(new NewInfo("Codeer.Friendly.DotNetExecutor.TypeFinder"));//magic name.
      AppVar genericType = typeFinder["GetType"](genericTypeFullName);
      AppVar genericArguments = app.Dim(new Type[genericArgumentsFullName.Length]);
      for (int i = 0; i < genericArgumentsFullName.Length; i++)
      {
          genericArguments["[]"](i, typeFinder["GetType"](genericArgumentsFullName[i]));
      }
      try
      {
          AppVar type = genericType["MakeGenericType"](genericArguments);
          return (string)type["FullName"]().Core;
      }
      catch (FriendlyOperationException) { }
      return string.Empty;
 
  }
 static void ResolveUserWrapperRefOutArgs(UserWrapperUtility.Construct func, AppFriend app, object src, out object arg, out ResolveArgument resolveArgument)
 {
     if (src == null)
     {
         AppVar appVar = app.Dim();
         arg = appVar;
         resolveArgument = () =>func(appVar);
     }
     else
     {
         arg = src;
         IAppVarOwner owner = src as IAppVarOwner;
         resolveArgument = () => (owner != null && AppVarUtility.IsNull(owner.AppVar)) ? null : src;
     }
 }
 static void ResolveAppVarRefOutArgs(AppFriend app, Type type, object src, out object arg, out ResolveArgument resolveArgument)
 {
     if (src == null)
     {
         AppVar appVar = app.Dim();
         arg = appVar;
         resolveArgument = () => appVar;
     }
     else
     {
         arg = src;
         resolveArgument = () => src;
     }
 }