public static object CreateRcwForComObject(IntPtr ptr)
        {
            if (ptr == IntPtr.Zero)
            {
                return(null);
            }

            IObjectReference identity = GetObjectReferenceForInterface(ptr).As <IUnknownVftbl>();

            object keepAliveSentinel = null;

            Func <IntPtr, System.WeakReference <object> > rcwFactory = (_) =>
            {
                object runtimeWrapper = null;
                if (identity.TryAs <IInspectable.Vftbl>(out var inspectableRef) == 0)
                {
                    var    inspectable      = new IInspectable(identity);
                    string runtimeClassName = inspectable.GetRuntimeClassName();
                    runtimeWrapper = TypedObjectFactoryCache.GetOrAdd(runtimeClassName, className => CreateTypedRcwFactory(className))(inspectable);
                }
                else if (identity.TryAs <ABI.WinRT.Interop.IWeakReference.Vftbl>(out var weakRef) == 0)
                {
                    runtimeWrapper = new ABI.WinRT.Interop.IWeakReference(weakRef);
                }
                keepAliveSentinel = runtimeWrapper; // We don't take a strong reference on runtimeWrapper at any point, so we need to make sure it lives until it can get assigned to rcw.
                var runtimeWrapperReference = new System.WeakReference <object>(runtimeWrapper);
                var cleanupSentinel         = new RuntimeWrapperCleanup(identity.ThisPtr, runtimeWrapperReference);
                return(runtimeWrapperReference);
            };
Пример #2
0
 public WeakReference(T target)
 {
     _managedWeakReference = new System.WeakReference <T>(target);
     if (target is object && ComWrappersSupport.TryUnwrapObject(target, out var objRef))
     {
         _nativeWeakReference = target.As <IWeakReferenceSource>().GetWeakReference();
     }
 }
Пример #3
0
        public int GetHashCode(System.WeakReference <T> w)
        {
            T t;

            return(w.TryGetTarget(out t)
                                ? t.GetHashCode()
                                : -1);
        }
 public FarmingHysteresisData(System.WeakReference <Zone_Growing> weakReference)
 {
     zoneWeakReference = weakReference;
     enabled           = false;
     lowerBound        = Constants.DefaultHysteresisLowerBound;
     upperBound        = Constants.DefaultHysteresisUpperBound;
     latchMode         = LatchMode.Unknown;
 }
Пример #5
0
        public bool Equals(System.WeakReference <T> w1, T t2)
        {
            T t1;

            var r1 = w1.TryGetTarget(out t1);

            return((!r1 && t1 != null) ||
                   t1.SafeEquals(t2));
        }
Пример #6
0
        public static T GetTarget <T>(this System.WeakReference <T> wr) where T : class
        {
            T value;

            if (!wr.TryGetTarget(out value))
            {
                value = default(T);
            }
            return(value);
        }
Пример #7
0
        public static T FindOrCreate <T>(this System.WeakReference <T> wr, Func <T> factory) where T : class
        {
            T value;

            if (!wr.TryGetTarget(out value))
            {
                value = factory();
                wr.SetTarget(value);
            }
            return(value);
        }
Пример #8
0
        public bool Equals(System.WeakReference <T> w1, System.WeakReference <T> w2)
        {
            T t1;
            T t2;

            var r1 = w1.TryGetTarget(out t1);
            var r2 = w2.TryGetTarget(out t2);

            return(((r1 && r2) || (!r1 && !r2)) &&
                   t1.SafeEquals(t2));
        }
        public bool Equals(System.WeakReference <T>?w1, System.WeakReference <T>?w2)
        {
            T?t1 = null;
            T?t2 = null;

            var r1 = w1?.TryGetTarget(out t1) ?? false;
            var r2 = w2?.TryGetTarget(out t2) ?? false;

            return(((r1 && r2) || (!r1 && !r2)) &&
                   SafeEquals <T>(t1, t2));
        }
Пример #10
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource   = Resource.Layout.Toolbar;
            base.SetTheme(Resource.Style.MainTheme);
            base.OnCreate(savedInstanceState);

            Xamarin.Forms.Forms.SetFlags("RadioButton_Experimental");
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            Xamarin.Forms.Forms.Init(this, savedInstanceState);
            Xamarin.Forms.FormsMaterial.Init(this, savedInstanceState);

            FFImageLoading.Forms.Platform.CachedImageRenderer.Init(enableFastRenderer: true);
            global::FFImageLoading.ImageService.Instance.Initialize(new FFImageLoading.Config.Configuration());

            UserDialogs.Init(this);

            // files へのファイルアクセスに必要かもしれない

            /*
             * var permission = ContextCompat.CheckSelfPermission(this, Manifest.Permission.WriteExternalStorage);
             * if (permission != (int)Permission.Granted)
             * {
             *  // We don't have permission so prompt the user
             *  ActivityCompat.RequestPermissions(this, new String[] { Manifest.Permission.WriteExternalStorage },1);
             * }
             */

            // ログ用のパスを一度取得する
            // こうしないと files フォルダが作られない
            var contextRef = new System.WeakReference <Context>(this);

            contextRef.TryGetTarget(out var c);
            var dir      = c.GetExternalFilesDir(null).AbsolutePath;
            var filename = Path.Combine(dir, $"trace-dummy.txt");

            using (var tw = System.IO.File.OpenWrite(filename))
            {
                using (var sw = new StreamWriter(tw))
                {
                    sw.WriteLine("START: " + DateTime.Now.ToString());
                }
            }


            //NotificationCenter.CreateNotificationChannel();
            LoadApplication(new App(new AndroidInitializer()));
            //NotificationCenter.NotifyNotificationTapped(base.Intent);


            // Appの初期化以降は、App.LoggerService.Debug が使える
            App.LoggerService.Info("START in Android: ");
        }
Пример #11
0
        public static bool HasTarget <T>(this System.WeakReference <T> wr) where T : class
        {
            T value;

            return(wr.TryGetTarget(out value));
        }
Пример #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="WF.Player.AsyncDrawable"/> class.
 /// </summary>
 /// <param name="res">Resources of the context.</param>
 /// <param name="bitmap">Bitmap to load.</param>
 /// <param name="asyncImageTask">AsyncImageTask, which belongs to this AsyncDrawable.</param>
 public AsyncDrawable(Resources res, Bitmap bitmap, AsyncImageTask asyncImageTask) : base(res, bitmap)
 {
     _asyncImageTaskReference = new WeakReference <AsyncImageTask>(asyncImageTask);
 }
Пример #13
0
		/// <summary>
		/// Initializes a new instance of the <see cref="WF.Player.AsyncDrawable"/> class.
		/// </summary>
		/// <param name="res">Resources of the context.</param>
		/// <param name="bitmap">Bitmap to load.</param>
		/// <param name="asyncImageTask">AsyncImageTask, which belongs to this AsyncDrawable.</param>
		public AsyncDrawable(Resources res, Bitmap bitmap, AsyncImageTask asyncImageTask) : base(res, bitmap)
		{
			_asyncImageTaskReference = new WeakReference<AsyncImageTask>(asyncImageTask);
		}
Пример #14
0
 public WeakReference(T target)
 {
     _managedWeakReference = new System.WeakReference <T>(target);
 }
Пример #15
0
 /**
  * Creates new entry.
  */
 public Entry(K key, int hash, Entry next)
 {
     this.weakRef = new WeakReference <K>(key);
     this.hash    = hash;
     this.next    = next;
 }