- Slink_bin_0700.zip
- CodeSmithParser.dll
- CR_Slink.dll
- CR_Slink.pdb
- Interop.CodeSmithParser.dll
- README.INSTALL.txt
- Slink.Core.dll
- Slink.Core.pdb
- Slink.exe
- Slink.Generator.dll
- Slink.Generator.pdb
- TaHoGen.Core.dll
- Slink_bin_0701.zip
- CodeSmithParser.dll
- CR_Slink.dll
- CSharpOptParse.dll
- Interop.CodeSmithParser.dll
- README.INSTALL.txt
- Slink.Core.dll
- Slink.exe
- Slink.Generator.dll
- TaHoGen.Core.dll
- Slink_src.zip
- Slink_src
- source
- BinaryRelease
- CleanSources.bat
- Licence.txt
- SharedLibraries
- CodeSmithParser.dll
- CSharpOptParse.dll
- NLog.dll
- Slink.build
- Slink.sln
- Slink.suo
- SourceCode
- CR_Slink
- ProjectInfo.cs
- Slink.Core
- Slink.Generator
- Slink
- TaHoGenv3_Src
- TestWebsite
- TestWebsite2
- TestWebsite.sln
- TestWebsite.suo
- ThirdPartySupportFiles
- CSharpOptParse.zip
- CSharpOptParse-src.zip
- TaHoGen_Sample.zip
- TaHoGen_v3_Bin.zip
- TaHoGenv3_Src.zip
- Tools
- CleanSourcesPlus
- scdl.exe
- scdl_src
|
using System;
using System.ComponentModel;
using System.Reflection;
namespace TaHoGen
{
/// <summary>
/// An extension of the PropertyTable class that assumes the properties of any
/// type that it is given.
/// </summary>
///
[Serializable]
public class PropertyMimic : PropertyTable
{
private System.Type _subject = null;
public PropertyMimic() : base()
{
}
public PropertyMimic(System.Type subject) : this()
{
_subject = subject;
Mimic(Subject);
}
public System.Type Subject
{
get { return _subject; }
}
public void Mimic(System.Type subject)
{
Mimic(subject, null);
}
public void Mimic(System.Type subject, PropertyInfoPredicate predicate)
{
// Read the properties of the subject
PropertyInfo[] pi = subject.GetProperties();
// If there aren't any properties, do nothing
if (pi == null)
return;
Mimic(pi, predicate);
}
public void Mimic(PropertyInfo[] pi)
{
Mimic(pi, null);
}
public void Mimic(PropertyInfo[] pi, PropertyInfoPredicate predicate)
{
if (pi == null)
return;
// Clear the current list of properties (if any)
if (Properties.Count > 0)
{
Properties.Clear();
Clear();
}
foreach(PropertyInfo property in pi)
{
// Skip the property if it fails the predicate condition
if (predicate != null && predicate(property) == false)
continue;
// Create a property that looks like the type's property
PropertySpec spec = CreatePropertySpec(property);
// Add it to the list of properties
if (spec != null)
Properties.Add(spec);
}
}
public override string GetClassName()
{
if (_subject == null)
return base.GetClassName ();
return _subject.FullName;
}
private PropertySpec CreatePropertySpec(PropertyInfo pi)
{
string name = pi.Name;
Type propertyType = pi.PropertyType;
// Get the name, category, description, type,
// and default value of the property
PropertyHelper helper = new PropertyHelper(pi);
PropertySpec result = new PropertySpec(pi.Name, pi.PropertyType);
if (helper.Category.Length > 0)
result.Category = helper.Category;
if (helper.DefaultValue != null)
result.DefaultValue = helper.DefaultValue;
if (helper.Description != null)
result.Description = helper.Description;
return result;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here
I'm a .NET developer with a crazy drive to create neat computer stuff.
You can find me coding the night away in my small garage working on various fun projects for my small startup,
Bit Armory, with the hopes of making it big someday, just like the YouTube and MySpace guys did.
You can read my blog here
http://bchavez.bitarmory.com