Black.Beard.ComponentModel.Attributes 1.0.4

There is a newer version of this package available.
See the version list below for details.
dotnet add package Black.Beard.ComponentModel.Attributes --version 1.0.4                
NuGet\Install-Package Black.Beard.ComponentModel.Attributes -Version 1.0.4                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Black.Beard.ComponentModel.Attributes" Version="1.0.4" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Black.Beard.ComponentModel.Attributes --version 1.0.4                
#r "nuget: Black.Beard.ComponentModel.Attributes, 1.0.4"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Black.Beard.ComponentModel.Attributes as a Cake Addin
#addin nuget:?package=Black.Beard.ComponentModel.Attributes&version=1.0.4

// Install Black.Beard.ComponentModel.Attributes as a Cake Tool
#tool nuget:?package=Black.Beard.ComponentModel.Attributes&version=1.0.4                

Black.Beard.ComponentModel

Build status

Method helper for resolve types and methods.

How to use

You can use in non-intrusive mode. use the type descriptor.

Register the new TypeDescriptorProvider

GenericTypeDescriptionProvider.Register<ExampleType>();

Create a new instance for the specified type

var instance = (ExampleType)TypeDescriptor.CreateInstance(null, typeof(ExampleType), null, null);
var p = TypeDescriptor.GetProperties(i);
var property = p[nameof(ExampleType.Message)];
property.GetValue(i).Should().Be("3");

Add a virtual property

The part based on PropertyTypeDescriptor is insparated from MatthewKing / DynamicDescriptors

var instanceToBind = new ExampleClass();

var descriptor = DynamicDescriptor.CreateFromInstance(instanceToBind);

descriptor.GetDynamicProperty("PropertyOne") // Get the property using its name.
    .SetDisplayName("Property #1")
    .SetDescription("The first property")
    .SetCategory("Example category");

descriptor.GetDynamicProperty((ExampleClass x) => x.Property2) // Get the property using an expression.
    .SetDisplayName("Property #2")
    .SetDescription("The second property")
    .SetCategory("Example category");

propertyGrid.SelectedObject = descriptor;

Binding to an object instance

We can create a DynamicDescriptor for an object instance:

var instance = new ExampleClass();

var descriptor = DynamicDescriptor.CreateFromInstance(instance);

Binding to a dictionary

We can create a DynamicDescriptor backed by a dictionary. This will act as if the dictionary key/value pairs are properties of a bound object:

var data = new Dictionary<string, object>();
data["Property1"] = "hello";
data["Property2"] = "world";

var descriptor = DynamicDescriptor.CreateFromDictionary(data);

We can also supply type information:

var data = new Dictionary<string, object>();
data["Property1"] = "value";
data["Property2"] = 1;

var types = new Dictionary<string, Type>();
types["Property1"] = typeof(string);
types["Property2"] = typeof(int);

var descriptor = DynamicDescriptor.CreateFromDictionary(data, types);

What can be customized?

DisplayName:

descriptor.GetDynamicProperty("PropertyName").SetDisplayName("Property display name");

This modifies the value returned by the DisplayName property.

Description:

descriptor.GetDynamicProperty("PropertyName").SetDescription("A description of the property");

This modifies the value returned by the Description property.

Category:

descriptor.GetDynamicProperty("PropertyName").SetCategory("Category name");

This modifies the value returned by the Category property.

Converter:

TypeConverter converter = /* your custom type converter */;
descriptor.GetDynamicProperty("PropertyName").SetConverter(converter);

This modifies the value returned by the Converter property.

IsReadOnly:

descriptor.GetDynamicProperty("PropertyName").SetReadOnly(true);

This modifies the value returned by the IsReadOnly property.

Property order:

descriptor.GetDynamicProperty("PropertyOne").SetPropertyOrder(1);
descriptor.GetDynamicProperty("PropertyTwo").SetPropertyOrder(2);
descriptor.GetDynamicProperty("PropertyThree").SetPropertyOrder(3);

This modifies the order in which properties are returned by the GetProperties method.

Installation

Just grab it from NuGet

PM> Install-Package DynamicDescriptors

Copyright Matthew King 2012-2020. Distributed under the MIT License. Refer to license.txt for more information.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.

NuGet packages (5)

Showing the top 5 NuGet packages that depend on Black.Beard.ComponentModel.Attributes:

Package Downloads
Black.Beard.ComponentModel

Package Description

Black.Beard.Configurations.ConfigurationProvider.SqlServer

Package Description

Black.Beard.Web.Server

Provide a service base for just concentrate your services

Black.Beard.Sql

Package Description

Black.Beard.Configurations

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.114 112 9/10/2024
1.0.113 121 9/10/2024
1.0.112 117 9/10/2024
1.0.111 118 9/10/2024
1.0.110 114 9/3/2024
1.0.109 114 8/28/2024
1.0.108 118 8/27/2024
1.0.107 127 8/13/2024
1.0.106 103 7/17/2024
1.0.105 108 7/6/2024
1.0.104 108 7/6/2024
1.0.103 115 7/6/2024
1.0.102 104 7/5/2024
1.0.101 116 7/5/2024
1.0.100 116 7/3/2024
1.0.99 111 7/3/2024
1.0.98 128 7/3/2024
1.0.97 107 7/3/2024
1.0.96 126 7/2/2024
1.0.95 153 5/5/2024
1.0.94 144 5/4/2024
1.0.93 98 5/3/2024
1.0.92 111 5/3/2024
1.0.91 217 5/2/2024
1.0.90 122 5/1/2024
1.0.89 142 4/24/2024
1.0.88 124 4/24/2024
1.0.87 123 4/24/2024
1.0.86 161 4/22/2024
1.0.85 128 4/22/2024
1.0.84 129 4/21/2024
1.0.83 133 4/21/2024
1.0.82 123 4/21/2024
1.0.81 124 4/21/2024
1.0.80 130 4/21/2024
1.0.79 127 4/18/2024
1.0.78 108 4/18/2024
1.0.77 128 4/18/2024
1.0.76 111 4/18/2024
1.0.75 119 4/15/2024
1.0.74 141 4/14/2024
1.0.73 124 4/14/2024
1.0.72 133 4/14/2024
1.0.71 123 4/14/2024
1.0.70 144 4/13/2024
1.0.69 119 4/13/2024
1.0.68 141 4/13/2024
1.0.67 119 4/13/2024
1.0.66 122 4/13/2024
1.0.65 139 4/13/2024
1.0.64 136 4/12/2024
1.0.63 118 4/12/2024
1.0.62 125 4/11/2024
1.0.61 125 4/10/2024
1.0.60 137 4/8/2024
1.0.58 223 4/6/2024
1.0.57 1,284 3/9/2024
1.0.56 162 3/5/2024
1.0.55 159 3/5/2024
1.0.54 146 3/4/2024
1.0.53 195 3/4/2024
1.0.52 332 3/3/2024
1.0.51 134 3/3/2024
1.0.50 142 3/3/2024
1.0.49 140 3/2/2024
1.0.48 826 2/4/2024
1.0.47 126 1/27/2024
1.0.46 185 1/6/2024
1.0.45 145 1/6/2024
1.0.44 166 1/6/2024
1.0.43 141 1/6/2024
1.0.41 1,762 6/17/2023
1.0.40 286 6/17/2023
1.0.37 6,626 3/19/2022
1.0.36 4,383 3/15/2022
1.0.35 590 3/6/2022
1.0.34 2,347 2/11/2022
1.0.33 670 2/11/2022
1.0.32 591 2/11/2022
1.0.30 569 2/11/2022
1.0.29 593 2/9/2022
1.0.28 560 2/8/2022
1.0.27 551 2/8/2022
1.0.26 549 2/8/2022
1.0.25 569 2/6/2022
1.0.24 617 2/4/2022
1.0.23 590 2/2/2022
1.0.22 581 2/1/2022
1.0.21 584 1/27/2022
1.0.20 588 1/27/2022
1.0.19 598 1/26/2022
1.0.18 597 1/26/2022
1.0.17 581 1/20/2022
1.0.16 581 1/15/2022
1.0.15 590 1/15/2022
1.0.14 588 1/12/2022
1.0.13 495 1/12/2022
1.0.12 595 1/12/2022
1.0.9 340 1/9/2022
1.0.8 345 1/9/2022
1.0.7 330 1/9/2022
1.0.6 349 1/8/2022
1.0.5 11,496 12/19/2021
1.0.4 364 12/19/2021
1.0.3 399 12/19/2021