[Reflection.Assembly]::LoadFile("C:\temp\Microsoft.SharePoint.dll")
foreach ($value in [Microsoft.SharePoint.SPFieldType]::GetValues
([Microsoft.SharePoint.SPFieldType]))
{
$int = [Convert]::ToInt32($value)
Write-Host $value = $int
}
Wednesday, August 17, 2011
Powershell script to list the integer value of each member of an Enumeration
I couldn't easily find something that did this, so here is what I came up with.
Wednesday, August 3, 2011
Using PowerShell to do a find and replace on all files and subfolders
I looked around for a while and just couldn't find a script that did this for me. So here it is so I don't lose it. It was useful as part of setting up a new VS2010 project that was a complete copy of the one from another project.
$search = "SearchString"
$replace = "ReplaceString"
function RenameFile ($fileInfo)
{
if ($fileInfo.Name.Contains($search))
{
$newFullName = $fileInfo.DirectoryName + "\" + $fileInfo.Name.Replace($search, $replace)
Move-Item $fileInfo.FullName $newFullName
return 1
}
return 0
}
function RenameDirectory ($dirInfo)
{
if ($dirInfo.Name.Contains($search))
{
$newFullName = $dirInfo.Parent.FullName + "\" + $dirInfo.Name.Replace($search, $replace)
Move-Item $dirInfo.FullName $newFullName
return 1
}
return 0
}
$files = Get-ChildItem -Path . * -Recurse -Force
$i = 0
$j = 0
# Rename files
foreach ($file in $files)
{
if ($file.GetType().ToString() -eq "System.IO.FileInfo")
{
if (RenameFile($file) -eq 1)
{
$i = $i + 1
}
}
}
# Now rename directories
foreach ($file in $files)
{
if ($file.GetType().ToString() -eq "System.IO.DirectoryInfo")
{
if (RenameDirectory($file) -eq 1)
{
$j = $j + 1
}
}
}
Write-Host Renamed $i files, $j directories.
Tuesday, August 2, 2011
Musings on using Unity Interception to achieve automatic INotifyPropertyChanged
I was just about to look at using Unity to implement automatic INotifyPropertyChanged. I've been meaning to do it ever since I heard the latest version of Unity for Silverlight supported method interception. It has just dawned on me however, that I might want to look again for a better option because (and I could be wrong) but using method interception will cause me one nasty little problem.
So, Unity will do a good job with something like this:
But what about this code?
What am I going on about here? In a nutshell, the change notification won't happen when setting property values from within the object itself, since internally it isn't going through Unity.
I've only thought about it for a few minutes... But I think the workaround for this won't be terribly nice... and I've just seen a posting about this project, so I think I'll go check it out first.
So, Unity will do a good job with something like this:
var x = container.Resolve<IMyInterface>();
x.PropertyOne = "This will work";
But what about this code?
public void SomeMethod()
{
this.PropertyOne = "I don't think this will work";
}
What am I going on about here? In a nutshell, the change notification won't happen when setting property values from within the object itself, since internally it isn't going through Unity.
I've only thought about it for a few minutes... But I think the workaround for this won't be terribly nice... and I've just seen a posting about this project, so I think I'll go check it out first.
Subscribe to:
Posts (Atom)