Why AppDomain.ShadowCopyFiles is string?
Asked Answered
B

1

6

There is ShadowCopy functionality in .Net to preserve file locking by copying assemblies. There are two properties:

  1. AppDomain.ShadowCopyFiles that uses AppDomainSetup
  2. AppDomainSetup.ShadowCopyFiles that stores it in internal string[]

AppDomainSetup has string Value[] field, that used for storing configuration. The strange thing for me is that AppDomainSetup.ShadowCopyFiles is a string property, and we need to set "true" or "false" instead of real bool type.

Here is an implementation for that property in AppDomainSetup:

public string ShadowCopyFiles
{
  get
  {
    return this.Value[8];
  }
  set
  {
    if (value != null && string.Compare(value, "true", StringComparison.OrdinalIgnoreCase) == 0)
      this.Value[8] = value;
    else
      this.Value[8] = (string) null;
  }
}

And here is an implementation for AppDomain.ShadowCopyFiles:

public bool ShadowCopyFiles 
{ 
    get {
        String s = FusionStore.ShadowCopyFiles; 
        if((s != null) &&
           (String.Compare(s, "true", StringComparison.OrdinalIgnoreCase) == 0))
            return true;
        else 
            return false;
    } 
} 

But why in AppDomainSetup this property is a string? Why Microsoft didn't used the some bool conversion logic as in AppDomain.ShadowCopyFiles?

It strange that such a bit smelly code located in AppDomainSetup, and I was just thinking is there a real reason for that that I'm missing?

Belford answered 29/12, 2013 at 23:57 Comment(1)
possible duplicate of Why is AppDomainSetup.ShadowCopyFiles a string?Intorsion
P
9

It was a mistake in the early versions of .NET and MS have decided not to fix it as it would break existing code.

See this link.

http://connect.microsoft.com/VisualStudio/feedback/details/295269/appdomainsetup-shadowcopyfiles-should-be-of-the-type-bool-instead-of-string

Peach answered 30/12, 2013 at 0:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.